Hi - does anyone know if it is possible to create ...
# azure
l
Hi - does anyone know if it is possible to create a BlobContainer SAS URL with Pulumi?
m
As far as I know, there isn't anything built in. I've used some custom code to generate the SAS string. Not sure where I got it from, but here's the C# method I use:
Copy code
public static Input<string> GetSasTokenedUrlToReadBlob(Input<string> resourceGroupName, Input<string> accountName, BlobContainer blobContainer, Blob blob)
    {
        const string signatureExpiration = "2100-01-01";
        const string signatureStart = "2000-01-01";

        var primaryStorageKey = GetConnectionString(resourceGroupName, accountName);
        
        var sasToken = Output.Tuple(primaryStorageKey, blobContainer.Name)
            .Apply(parameters =>
            {
                var primaryStorageKey = parameters.Item1;
                var containerName = parameters.Item2;

                return AzureClassicStorage.GetAccountBlobContainerSAS.InvokeAsync(new AzureClassicStorage.GetAccountBlobContainerSASArgs
                {
                    ConnectionString = primaryStorageKey,
                    ContainerName = containerName,
                    HttpsOnly = true,
                    Start = signatureStart,
                    Expiry = signatureExpiration,
                    Permissions = new AzureClassicStorage.Inputs.GetAccountBlobContainerSASPermissionsArgs
                    {
                        Read = true,
                        Write = false,
                        Delete = false,
                        List = false,
                        Add = false,
                        Create = false
                    }
                });
            });

        return Output.Tuple(blob.Url, sasToken).Apply(x => $"{x.Item1}{x.Item2.Sas}");
    }
👍 1
l
That's great, thanks!
Just in case anyone else looks for this, I also managed to create one with:
public static Output<string> GenerateContainerSasUrl(GrahamsBlobContainer container,
Output<string> storageAccountName,
Output<string> resourceGroupName)
{
var serviceSasToken = ListStorageAccountServiceSAS.Invoke(new ListStorageAccountServiceSASInvokeArgs
{
AccountName = storageAccountName,
Protocols = HttpProtocol.Https,
SharedAccessStartTime = "2021-01-01",
SharedAccessExpiryTime = "2230-01-01",
Resource = SignedResource.C,
ResourceGroupName = resourceGroupName,
Permissions = Permissions.R,
CanonicalizedResource = Output.Format($"/blob/{storageAccountName}/{container.Name}"),
ContentType = "application/json",
CacheControl = "max-age=5",
ContentDisposition = "inline",
ContentEncoding = "deflate",
}).Apply(blobSas => blobSas.ServiceSasToken);
return Output.Format(
$"https://{storageAccountName}.<http://blob.core.windows.net/{container.Name}/{container.Name}?{serviceSasToken}|blob.core.windows.net/{container.Name}/{container.Name}?{serviceSasToken}>");
}