sas

package
v1.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 10 Imported by: 4

Documentation

Index

Constants

View Source
const (
	SnapshotTimeFormat = "2006-01-02T15:04:05.0000000Z07:00"
)

timeFormat represents the format of a SAS start or expiry time. Use it when formatting/parsing a time.Time.

Variables

View Source
var (
	// Version is the default version encoded in the SAS token.
	Version = generated.ServiceVersion
)

Functions

This section is empty.

Types

type AccountPermissions

type AccountPermissions struct {
	Read, Write, Delete, List, Create bool
}

AccountPermissions type simplifies creating the permissions string for an Azure Storage Account SAS. Initialize an instance of this type and then call its String method to set AccountSignatureValues' Permissions field.

func (*AccountPermissions) String

func (p *AccountPermissions) String() string

String produces the SAS permissions string for an Azure Storage account. Call this method to set AccountSignatureValues' Permissions field.

type AccountResourceTypes

type AccountResourceTypes struct {
	Service, Container, Object bool
}

AccountResourceTypes type simplifies creating the resource types string for an Azure Storage Account SAS. Initialize an instance of this type and then call its String method to set AccountSignatureValues' ResourceTypes field.

func (*AccountResourceTypes) String

func (rt *AccountResourceTypes) String() string

String produces the SAS resource types string for an Azure Storage account. Call this method to set AccountSignatureValues' ResourceTypes field.

type AccountSignatureValues

type AccountSignatureValues struct {
	Version         string    `param:"sv"`  // If not specified, this format to SASVersion
	Protocol        Protocol  `param:"spr"` // See the SASProtocol* constants
	StartTime       time.Time `param:"st"`  // Not specified if IsZero
	ExpiryTime      time.Time `param:"se"`  // Not specified if IsZero
	Permissions     string    `param:"sp"`  // Create by initializing AccountPermissions and then call String()
	IPRange         IPRange   `param:"sip"`
	ResourceTypes   string    `param:"srt"` // Create by initializing AccountResourceTypes and then call String()
	EncryptionScope string    `param:"ses"`
}

AccountSignatureValues is used to generate a Shared Access Signature (SAS) for an Azure Storage account. For more information, see https://docs.microsoft.com/rest/api/storageservices/constructing-an-account-sas

func (AccountSignatureValues) SignWithSharedKey

func (v AccountSignatureValues) SignWithSharedKey(sharedKeyCredential *SharedKeyCredential) (QueryParameters, error)

SignWithSharedKey uses an account's shared key credential to sign this signature values to produce the proper SAS query parameters.

type FilePermissions

type FilePermissions struct {
	Read, Create, Write, Delete bool
}

FilePermissions type simplifies creating the permissions string for an Azure Storage file SAS. Initialize an instance of this type and then call its String method to set SignatureValues' Permissions field. All permissions descriptions can be found here: https://docs.microsoft.com/en-us/rest/api/storageservices/create-service-sas#permissions-for-a-file

func (*FilePermissions) String

func (p *FilePermissions) String() string

String produces the SAS permissions string for an Azure Storage file. Call this method to set SignatureValues' Permissions field.

type IPEndpointStyleInfo

type IPEndpointStyleInfo struct {
	AccountName string // "" if not using IP endpoint style
}

IPEndpointStyleInfo is used for IP endpoint style URL when working with Azure storage emulator. Ex: "https://10.132.141.33/accountname/sharename"

type IPRange

type IPRange struct {
	Start net.IP // Not specified if length = 0
	End   net.IP // Not specified if length = 0
}

IPRange represents a SAS IP range's start IP and (optionally) end IP.

func (*IPRange) String

func (ipr *IPRange) String() string

String returns a string representation of an IPRange.

type Protocol

type Protocol string

Protocol indicates the http/https.

const (
	// ProtocolHTTPS can be specified for a SAS protocol.
	ProtocolHTTPS Protocol = "https"

	// ProtocolHTTPSandHTTP can be specified for a SAS protocol.
	ProtocolHTTPSandHTTP Protocol = "https,http"
)

type QueryParameters

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

QueryParameters object represents the components that make up an Azure Storage SAS' query parameters. You parse a map of query parameters into its fields by calling NewQueryParameters(). You add the components to a query parameter map by calling AddToValues(). NOTE: Changing any field requires computing a new SAS signature using a XxxSASSignatureValues type. This type defines the components used by all Azure Storage resources (Containers, Blobs, Files, & Queues).

func NewQueryParameters

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

NewQueryParameters creates and initializes a QueryParameters object based on the query parameter map's passed-in values. If deleteSASParametersFromValues is true, all SAS-related query parameters are removed from the passed-in map. If deleteSASParametersFromValues is false, the map passed-in map is unaltered.

func (*QueryParameters) CacheControl

func (p *QueryParameters) CacheControl() string

CacheControl returns cacheControl.

func (*QueryParameters) ContentDisposition

func (p *QueryParameters) ContentDisposition() string

ContentDisposition returns contentDisposition.

func (*QueryParameters) ContentEncoding

func (p *QueryParameters) ContentEncoding() string

ContentEncoding returns contentEncoding.

func (*QueryParameters) ContentLanguage

func (p *QueryParameters) ContentLanguage() string

ContentLanguage returns contentLanguage.

func (*QueryParameters) ContentType

func (p *QueryParameters) ContentType() string

ContentType returns contentType.

func (*QueryParameters) Encode

func (p *QueryParameters) Encode() string

Encode encodes the SAS query parameters into URL encoded form sorted by key.

func (*QueryParameters) EncryptionScope added in v1.1.0

func (p *QueryParameters) EncryptionScope() string

EncryptionScope returns encryption scope.

func (*QueryParameters) ExpiryTime

func (p *QueryParameters) ExpiryTime() time.Time

ExpiryTime returns expiryTime.

func (*QueryParameters) IPRange

func (p *QueryParameters) IPRange() IPRange

IPRange returns ipRange.

func (*QueryParameters) Identifier

func (p *QueryParameters) Identifier() string

Identifier returns identifier.

func (*QueryParameters) Permissions

func (p *QueryParameters) Permissions() string

Permissions returns permissions.

func (*QueryParameters) Protocol

func (p *QueryParameters) Protocol() Protocol

Protocol returns protocol.

func (*QueryParameters) Resource

func (p *QueryParameters) Resource() string

Resource returns resource.

func (*QueryParameters) ResourceTypes

func (p *QueryParameters) ResourceTypes() string

ResourceTypes returns resourceTypes.

func (*QueryParameters) Services

func (p *QueryParameters) Services() string

Services returns services.

func (*QueryParameters) ShareSnapshotTime

func (p *QueryParameters) ShareSnapshotTime() time.Time

ShareSnapshotTime returns shareSnapshotTime.

func (*QueryParameters) Signature

func (p *QueryParameters) Signature() string

Signature returns signature.

func (*QueryParameters) StartTime

func (p *QueryParameters) StartTime() time.Time

StartTime returns startTime.

func (*QueryParameters) Version

func (p *QueryParameters) Version() string

Version returns version.

type SharePermissions

type SharePermissions struct {
	Read, Create, Write, Delete, List bool
}

SharePermissions type simplifies creating the permissions string for an Azure Storage share SAS. Initialize an instance of this type and then call its String method to set SignatureValues' Permissions field. All permissions descriptions can be found here: https://docs.microsoft.com/en-us/rest/api/storageservices/create-service-sas#permissions-for-a-share

func (*SharePermissions) String

func (p *SharePermissions) String() string

String produces the SAS permissions string for an Azure Storage share. Call this method to set SignatureValues' Permissions field.

type SharedKeyCredential

type SharedKeyCredential = exported.SharedKeyCredential

SharedKeyCredential contains an account's name and its primary or secondary key.

type SignatureValues

type SignatureValues struct {
	Version            string    `param:"sv"`  // If not specified, this defaults to Version
	Protocol           Protocol  `param:"spr"` // See the Protocol* constants
	StartTime          time.Time `param:"st"`  // Not specified if IsZero
	ExpiryTime         time.Time `param:"se"`  // Not specified if IsZero
	SnapshotTime       time.Time
	Permissions        string  `param:"sp"` // Create by initializing SharePermissions or FilePermissions and then call String()
	IPRange            IPRange `param:"sip"`
	Identifier         string  `param:"si"`
	ShareName          string
	FilePath           string // Ex: "directory/FileName". Use "" to create a Share SAS and file path for File SAS.
	CacheControl       string // rscc
	ContentDisposition string // rscd
	ContentEncoding    string // rsce
	ContentLanguage    string // rscl
	ContentType        string // rsct
}

SignatureValues is used to generate a Shared Access Signature (SAS) for an Azure Storage file or share. For more information on creating service sas, see https://docs.microsoft.com/rest/api/storageservices/constructing-a-service-sas User Delegation SAS not supported for files service

func (SignatureValues) SignWithSharedKey

func (v SignatureValues) SignWithSharedKey(sharedKeyCredential *SharedKeyCredential) (QueryParameters, error)

SignWithSharedKey uses an account's SharedKeyCredential to sign this signature values to produce the proper SAS query parameters.

type URLParts

type URLParts struct {
	Scheme              string              // Ex: "https://"
	Host                string              // Ex: "account.share.core.windows.net", "10.132.141.33", "10.132.141.33:80"
	IPEndpointStyleInfo IPEndpointStyleInfo // Useful Parts for IP endpoint style URL.
	ShareName           string              // Share name, Ex: "myshare"
	DirectoryOrFilePath string              // Path of directory or file, Ex: "mydirectory/myfile"
	ShareSnapshot       string              // IsZero is true if not a snapshot
	SAS                 QueryParameters
	UnparsedParams      string
}

URLParts object represents the components that make up an Azure Storage Share/Directory/File URL. You parse an existing URL into its parts by calling NewFileURLParts(). You construct a URL from parts by calling URL(). NOTE: Changing any SAS-related field requires computing a new SAS signature.

func ParseURL

func ParseURL(u string) (URLParts, error)

ParseURL parses a URL initializing URLParts' fields including any SAS-related & sharesnapshot query parameters. Any other query parameters remain in the UnparsedParams field.

func (URLParts) String

func (up URLParts) String() string

String returns a URL object whose fields are initialized from the URLParts fields. The URL's RawQuery field contains the SAS, snapshot, and unparsed query parameters.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL