Tcl
Tcl
Configure Azure Storage Shared Key Authentication
See more REST Examples
Demonstrates Rest.SetAuthAzureStorage, which associates an AuthAzureStorage provider so Chilkat automatically adds a Shared Key Authorization header. The provider supplies the account name, base64 account key, service, and scheme.
Background. Azure Storage Shared Key authorization signs each request with the account access key. The provider also manages the
x-ms-version header required by the storage REST API.Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
set rest [new_CkRest]
set bTls 1
set bAutoReconnect 1
set success [CkRest_Connect $rest "example.com" 443 $bTls $bAutoReconnect]
if {$success == 0} then {
puts [CkRest_lastErrorText $rest]
delete_CkRest $rest
exit
}
# Configure Azure Storage Shared Key authentication. Provide the account name, base64 account
# access key, service, and (optionally) the x-ms-version.
set azAuth [new_CkAuthAzureStorage]
CkAuthAzureStorage_put_Account $azAuth "myStorageAccount"
# Normally you would not hard-code secrets in source. You should instead obtain them from an
# interactive prompt, environment variable, or a secrets vault.
CkAuthAzureStorage_put_AccessKey $azAuth "BASE64_ACCOUNT_ACCESS_KEY"
CkAuthAzureStorage_put_Scheme $azAuth "SharedKey"
CkAuthAzureStorage_put_Service $azAuth "Blob"
CkAuthAzureStorage_put_XMsVersion $azAuth "2021-08-06"
# Associate the provider so Chilkat automatically adds the Shared Key Authorization header.
set success [CkRest_SetAuthAzureStorage $rest $azAuth]
if {$success == 0} then {
puts [CkRest_lastErrorText $rest]
delete_CkRest $rest
delete_CkAuthAzureStorage $azAuth
exit
}
set responseText [CkRest_fullRequestNoBody $rest "GET" "/mycontainer?restype=container&comp=list"]
if {[CkRest_get_LastMethodSuccess $rest] == 0} then {
puts [CkRest_lastErrorText $rest]
delete_CkRest $rest
delete_CkAuthAzureStorage $azAuth
exit
}
puts "$responseText"
delete_CkRest $rest
delete_CkAuthAzureStorage $azAuth