or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
golangpkg:golang/github.com/Azure/azure-sdk-for-go/sdk/storage/azblob@v1.6.4

docs

appendblob.mdblob.mdblockblob.mdclient.mdcontainer.mderrors.mdindex.mdlease.mdpageblob.mdsas.mdservice.md
tile.json

tessl/golang-github-com--azure--azure-sdk-for-go--sdk--storage--azblob

tessl install tessl/golang-github-com--azure--azure-sdk-for-go--sdk--storage--azblob@1.6.0

Azure Blob Storage SDK for Go providing comprehensive blob storage operations including uploads, downloads, container management, and advanced features like leases and SAS generation

sas.mddocs/

Shared Access Signatures (sas package)

The SAS package provides functionality to generate and parse Shared Access Signature tokens for delegated access to Azure Storage resources.

Package Import

import "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/sas"

Account SAS

AccountSignatureValues

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()

AccountPermissions

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

AccountResourceTypes

type AccountResourceTypes struct {
    Service   bool
    Container bool
    Object    bool
}

func (rt *AccountResourceTypes) String() string

Resource types string format: sco

Blob and Container SAS

BlobSignatureValues

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)

BlobPermissions

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

ContainerPermissions

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

SAS Query Parameters

QueryParameters

type QueryParameters struct {
    // contains filtered or unexported fields
}

func NewQueryParameters(values url.Values, deleteSASParametersFromValues bool) QueryParameters

Methods

func (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() string

URL Parsing

ParseURL

func ParseURL(u string) (URLParts, error)

Parses a blob URL into its component parts.

URLParts

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() string

Example:

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())

Helper Types

IPRange

type IPRange struct {
    Start string
    End   string
}

func (ipr IPRange) String() string

Example:

ipRange := sas.IPRange{
    Start: "192.168.1.1",
    End:   "192.168.1.255",
}

IPEndpointStyleInfo

type IPEndpointStyleInfo struct {
    AccountName string
}

Protocol

type Protocol string

const (
    ProtocolHTTPS        Protocol = "https"
    ProtocolHTTPSandHTTP Protocol = "https,http"
)

Credentials

SharedKeyCredential

type SharedKeyCredential = exported.SharedKeyCredential

UserDelegationCredential

type UserDelegationCredential = exported.UserDelegationCredential

Constants

const TimeFormat = "2006-01-02T15:04:05Z"

var Version string // Current SAS version