tessl install tessl/golang-github-com--azure--azure-sdk-for-go--sdk--storage--azblob@1.6.0Azure Blob Storage SDK for Go providing comprehensive blob storage operations including uploads, downloads, container management, and advanced features like leases and SAS generation
The SAS package provides functionality to generate and parse Shared Access Signature tokens for delegated access to Azure Storage resources.
import "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/sas"type AccountSignatureValues struct {
Version string
Protocol Protocol
StartTime time.Time
ExpiryTime time.Time
Permissions string
IPRange IPRange
ResourceTypes string
EncryptionScope string
}
func (v AccountSignatureValues) SignWithSharedKey(sharedKeyCredential *SharedKeyCredential) (QueryParameters, error)Example:
import (
"time"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/sas"
)
// Set up signature values
values := sas.AccountSignatureValues{
Protocol: sas.ProtocolHTTPS,
ExpiryTime: time.Now().Add(24 * time.Hour),
Permissions: sas.AccountPermissions{Read: true, List: true}.String(),
ResourceTypes: sas.AccountResourceTypes{Service: true, Container: true, Object: true}.String(),
}
// Sign with shared key
queryParams, err := values.SignWithSharedKey(sharedKeyCred)
sasURL := serviceURL + "?" + queryParams.Encode()type AccountPermissions struct {
Read bool
Write bool
Delete bool
DeletePreviousVersion bool
PermanentDelete bool
List bool
Add bool
Create bool
Update bool
Process bool
FilterByTags bool
Tag bool
SetImmutabilityPolicy bool
}
func (p *AccountPermissions) String() string
func Parse(s string) (AccountPermissions, error)Permission string format: rwdxylacupfti
type AccountResourceTypes struct {
Service bool
Container bool
Object bool
}
func (rt *AccountResourceTypes) String() stringResource types string format: sco
type BlobSignatureValues struct {
Version string
Protocol Protocol
StartTime time.Time
ExpiryTime time.Time
SnapshotTime time.Time
Permissions string
IPRange IPRange
Identifier string
ContainerName string
BlobName string
Directory string
CacheControl string
ContentDisposition string
ContentEncoding string
ContentLanguage string
ContentType string
BlobVersion string
AuthorizedObjectID string
UnauthorizedObjectID string
CorrelationID string
EncryptionScope string
SignedDelegatedUserObjectID string
}
func (v BlobSignatureValues) SignWithSharedKey(sharedKeyCredential *SharedKeyCredential) (QueryParameters, error)
func (v BlobSignatureValues) SignWithUserDelegation(userDelegationCredential *UserDelegationCredential) (QueryParameters, error)Example:
// Blob SAS with shared key
values := sas.BlobSignatureValues{
Protocol: sas.ProtocolHTTPS,
ExpiryTime: time.Now().Add(1 * time.Hour),
ContainerName: "mycontainer",
BlobName: "myblob.txt",
Permissions: sas.BlobPermissions{Read: true}.String(),
}
queryParams, err := values.SignWithSharedKey(sharedKeyCred)
// Container SAS (leave BlobName empty)
containerValues := sas.BlobSignatureValues{
Protocol: sas.ProtocolHTTPS,
ExpiryTime: time.Now().Add(24 * time.Hour),
ContainerName: "mycontainer",
BlobName: "", // Empty for container SAS
Permissions: sas.ContainerPermissions{Read: true, List: true}.String(),
}
queryParams, err = containerValues.SignWithSharedKey(sharedKeyCred)type BlobPermissions struct {
Read bool
Add bool
Create bool
Write bool
Delete bool
DeletePreviousVersion bool
PermanentDelete bool
List bool
Tag bool
Move bool
Execute bool
Ownership bool
Permissions bool
SetImmutabilityPolicy bool
}
func (p *BlobPermissions) String() string
func Parse(s string) (BlobPermissions, error)Permission string format: racwdxylmeptoi
type ContainerPermissions struct {
Read bool
Add bool
Create bool
Write bool
Delete bool
DeletePreviousVersion bool
List bool
Tag bool
FilterByTags bool
Move bool
SetImmutabilityPolicy bool
Execute bool
ModifyOwnership bool
ModifyPermissions bool
}
func (p *ContainerPermissions) String() string
func Parse(s string) (ContainerPermissions, error)Permission string format: racwdxlftmeoi
type QueryParameters struct {
// contains filtered or unexported fields
}
func NewQueryParameters(values url.Values, deleteSASParametersFromValues bool) QueryParametersfunc (p QueryParameters) Version() string
func (p QueryParameters) Protocol() string
func (p QueryParameters) StartTime() time.Time
func (p QueryParameters) ExpiryTime() time.Time
func (p QueryParameters) Permissions() string
func (p QueryParameters) IPRange() IPRange
func (p QueryParameters) Identifier() string
func (p QueryParameters) Resource() string
func (p QueryParameters) ResourceTypes() string
func (p QueryParameters) Services() string
func (p QueryParameters) Signature() string
func (p QueryParameters) SignedService() string
func (p QueryParameters) SignedVersion() string
func (p QueryParameters) SignedStart() time.Time
func (p QueryParameters) SignedExpiry() time.Time
func (p QueryParameters) SignedOID() string
func (p QueryParameters) SignedTID() string
func (p QueryParameters) SnapshotTime() time.Time
func (p QueryParameters) CacheControl() string
func (p QueryParameters) ContentDisposition() string
func (p QueryParameters) ContentEncoding() string
func (p QueryParameters) ContentLanguage() string
func (p QueryParameters) ContentType() string
func (p QueryParameters) SignedDirectoryDepth() string
func (p QueryParameters) SignedCorrelationID() string
func (p QueryParameters) AuthorizedObjectID() string
func (p QueryParameters) UnauthorizedObjectID() string
func (p QueryParameters) SignedDelegatedUserObjectID() string
func (p QueryParameters) Encode() stringfunc ParseURL(u string) (URLParts, error)Parses a blob URL into its component parts.
type URLParts struct {
Scheme string
Host string
IPEndpointStyleInfo IPEndpointStyleInfo
ContainerName string
BlobName string
Snapshot string
SAS QueryParameters
UnparsedParams string
VersionID string
}
func (up URLParts) String() stringExample:
urlParts, err := sas.ParseURL("https://myaccount.blob.core.windows.net/container/blob.txt?sv=2021-08-06&sr=b&sig=...")
if err != nil {
// handle error
}
fmt.Printf("Container: %s\n", urlParts.ContainerName)
fmt.Printf("Blob: %s\n", urlParts.BlobName)
fmt.Printf("Permissions: %s\n", urlParts.SAS.Permissions())type IPRange struct {
Start string
End string
}
func (ipr IPRange) String() stringExample:
ipRange := sas.IPRange{
Start: "192.168.1.1",
End: "192.168.1.255",
}type IPEndpointStyleInfo struct {
AccountName string
}type Protocol string
const (
ProtocolHTTPS Protocol = "https"
ProtocolHTTPSandHTTP Protocol = "https,http"
)type SharedKeyCredential = exported.SharedKeyCredentialtype UserDelegationCredential = exported.UserDelegationCredentialconst TimeFormat = "2006-01-02T15:04:05Z"
var Version string // Current SAS version