Sample code for 30+ languages & platforms
Tcl

Set Container ACL

See more Azure Cloud Storage Examples

Azure Storage Blob Service REST API: Sample code to set the permissions of a container.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

# Azure Blob Service Example: Set Container ACL
# See also: https://msdn.microsoft.com/en-us/library/azure/dd179391.aspx

# This example requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.

set rest [new_CkRest]

# Connect to the Azure Storage Blob Service
set bTls 1
set port 443
set bAutoReconnect 1
# In this example, the storage account name is "chilkat".
set success [CkRest_Connect $rest "chilkat.blob.core.windows.net" $port $bTls $bAutoReconnect]
if {$success != 1} then {
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    exit
}

# Provide Azure Cloud credentials for the REST call.
set azAuth [new_CkAuthAzureStorage]

CkAuthAzureStorage_put_AccessKey $azAuth "AZURE_ACCESS_KEY"
# The account name used here should match the 1st part of the domain passed in the call to Connect (above).
CkAuthAzureStorage_put_Account $azAuth "chilkat"
CkAuthAzureStorage_put_Scheme $azAuth "SharedKey"
CkAuthAzureStorage_put_Service $azAuth "Blob"
# This causes the "x-ms-version: 2021-08-06" header to be automatically added.
CkAuthAzureStorage_put_XMsVersion $azAuth "2021-08-06"
set success [CkRest_SetAuthAzureStorage $rest $azAuth]

# Note: The application does not need to explicitly set the following
# headers: x-ms-date, Authorization.  These headers
# are automatically set by Chilkat.

# The XML body of the request will look like this:

# <?xml version="1.0" encoding="utf-8"?>
# <SignedIdentifiers>
#   <SignedIdentifier> 
#     <Id>unique-character-value-of-up-to-64-chars</Id>
#     <AccessPolicy>
#       <Start>start-time</Start>
#       <Expiry>expiry-time</Expiry>
#       <Permission>abbreviated-permission-list</Permission>
#     </AccessPolicy>
#   </SignedIdentifier>
# </SignedIdentifiers>

# Generate a random 32-character string.
set prng [new_CkPrng]

set randomId [CkPrng_randomString $prng 32 1 1 1]

# Get the current system date/time in ISO 8061 format
set dt [new_CkDateTime]

CkDateTime_SetFromCurrentSystemTime $dt
set bLocal 0
# Get the current date/time in ISO 8061 UTC format.
set curDtStr [CkDateTime_getAsTimestamp $dt $bLocal]
# The expire time will be 365 days in the future.
set success [CkDateTime_AddDays $dt 365]
set expireDtStr [CkDateTime_getAsTimestamp $dt $bLocal]

# Build the request:
set xml [new_CkXml]

CkXml_put_Tag $xml "SignedIdentifiers"
# xSignedId is a CkXml
set xSignedId [CkXml_NewChild $xml "SignedIdentifier" ""]
CkXml_NewChild2 $xSignedId "Id" $randomId
# xAccessPolicy is a CkXml
set xAccessPolicy [CkXml_NewChild $xSignedId "AccessPolicy" ""]
CkXml_NewChild2 $xAccessPolicy "Start" $curDtStr
CkXml_NewChild2 $xAccessPolicy "Expiry" $expireDtStr
CkXml_NewChild2 $xAccessPolicy "Permission" "rwd"
delete_CkXml $xAccessPolicy

delete_CkXml $xSignedId

# Show the XML..
puts [CkXml_getXml $xml]

# The expected response is a 200 response status code with no response body.
set responseStr [CkRest_fullRequestString $rest "PUT" "/mycontainer?restype=container&comp=acl" [CkXml_getXml $xml]]
if {[CkRest_get_LastMethodSuccess $rest] != 1} then {
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    delete_CkAuthAzureStorage $azAuth
    delete_CkPrng $prng
    delete_CkDateTime $dt
    delete_CkXml $xml
    exit
}

# When successful, the Azure Storage service will respond with a 200 response status code,
# with no response body.

if {[CkRest_get_ResponseStatusCode $rest] != 200} then {
    # Examine the request/response to see what happened.
    puts "response status code = [CkRest_get_ResponseStatusCode $rest]"
    puts "response status text = [CkRest_responseStatusText $rest]"
    puts "response header: [CkRest_responseHeader $rest]"
    puts "response body (if any): $responseStr"
    puts "---"
    puts "LastRequestStartLine: [CkRest_lastRequestStartLine $rest]"
    puts "LastRequestHeader: [CkRest_lastRequestHeader $rest]"
    delete_CkRest $rest
    delete_CkAuthAzureStorage $azAuth
    delete_CkPrng $prng
    delete_CkDateTime $dt
    delete_CkXml $xml
    exit
}

puts "Success."

delete_CkRest $rest
delete_CkAuthAzureStorage $azAuth
delete_CkPrng $prng
delete_CkDateTime $dt
delete_CkXml $xml