Documentation ¶
Overview ¶
Example (Service_Client_GetProperties) ¶
package main import ( "context" "fmt" "github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/service" "log" "os" ) func handleError(err error) { if err != nil { log.Fatal(err.Error()) } } func main() { accountName, ok := os.LookupEnv("AZURE_STORAGE_ACCOUNT_NAME") if !ok { panic("AZURE_STORAGE_ACCOUNT_NAME could not be found") } accountKey, ok := os.LookupEnv("AZURE_STORAGE_ACCOUNT_KEY") if !ok { panic("AZURE_STORAGE_ACCOUNT_KEY could not be found") } serviceURL := fmt.Sprintf("https://%s.file.core.windows.net/", accountName) cred, err := service.NewSharedKeyCredential(accountName, accountKey) handleError(err) svcClient, err := service.NewClientWithSharedKeyCredential(serviceURL, cred, nil) handleError(err) _, err = svcClient.GetProperties(context.TODO(), nil) handleError(err) }
Output:
Example (Service_Client_GetSASURL) ¶
package main import ( "context" "fmt" "github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/sas" "github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/service" "log" "os" "time" ) func handleError(err error) { if err != nil { log.Fatal(err.Error()) } } func main() { accountName, ok := os.LookupEnv("AZURE_STORAGE_ACCOUNT_NAME") if !ok { panic("AZURE_STORAGE_ACCOUNT_NAME could not be found") } accountKey, ok := os.LookupEnv("AZURE_STORAGE_ACCOUNT_KEY") if !ok { panic("AZURE_STORAGE_ACCOUNT_KEY could not be found") } serviceURL := fmt.Sprintf("https://%s.file.core.windows.net/", accountName) cred, err := service.NewSharedKeyCredential(accountName, accountKey) handleError(err) svcClient, err := service.NewClientWithSharedKeyCredential(serviceURL, cred, nil) handleError(err) resources := sas.AccountResourceTypes{ Object: true, Service: true, Container: true, } permissions := sas.AccountPermissions{ Read: true, Write: true, Delete: true, List: true, Create: true, } expiry := time.Now().Add(time.Hour) sasUrl, err := svcClient.GetSASURL(resources, permissions, expiry, nil) handleError(err) fmt.Println("SAS URL: ", sasUrl) svcSASClient, err := service.NewClientWithNoCredential(sasUrl, nil) handleError(err) _, err = svcSASClient.GetProperties(context.TODO(), nil) handleError(err) }
Output:
Example (Service_Client_NewClient) ¶
package main import ( "fmt" "github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/service" "log" "os" ) func handleError(err error) { if err != nil { log.Fatal(err.Error()) } } func main() { accountName, ok := os.LookupEnv("AZURE_STORAGE_ACCOUNT_NAME") if !ok { panic("AZURE_STORAGE_ACCOUNT_NAME could not be found") } accountKey, ok := os.LookupEnv("AZURE_STORAGE_ACCOUNT_KEY") if !ok { panic("AZURE_STORAGE_ACCOUNT_KEY could not be found") } serviceURL := fmt.Sprintf("https://%s.file.core.windows.net/", accountName) cred, err := service.NewSharedKeyCredential(accountName, accountKey) handleError(err) svcClient, err := service.NewClientWithSharedKeyCredential(serviceURL, cred, nil) handleError(err) fmt.Println(svcClient.URL()) }
Output:
Example (Service_Client_SetProperties) ¶
package main import ( "context" "fmt" "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" "github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/service" "log" "os" ) func handleError(err error) { if err != nil { log.Fatal(err.Error()) } } func main() { accountName, ok := os.LookupEnv("AZURE_STORAGE_ACCOUNT_NAME") if !ok { panic("AZURE_STORAGE_ACCOUNT_NAME could not be found") } accountKey, ok := os.LookupEnv("AZURE_STORAGE_ACCOUNT_KEY") if !ok { panic("AZURE_STORAGE_ACCOUNT_KEY could not be found") } serviceURL := fmt.Sprintf("https://%s.file.core.windows.net/", accountName) cred, err := service.NewSharedKeyCredential(accountName, accountKey) handleError(err) svcClient, err := service.NewClientWithSharedKeyCredential(serviceURL, cred, nil) handleError(err) setPropertiesOpts := service.SetPropertiesOptions{ HourMetrics: &service.Metrics{ Enabled: to.Ptr(true), IncludeAPIs: to.Ptr(true), RetentionPolicy: &service.RetentionPolicy{ Enabled: to.Ptr(true), Days: to.Ptr(int32(2)), }, }, MinuteMetrics: &service.Metrics{ Enabled: to.Ptr(true), IncludeAPIs: to.Ptr(false), RetentionPolicy: &service.RetentionPolicy{ Enabled: to.Ptr(true), Days: to.Ptr(int32(2)), }, }, CORS: []*service.CORSRule{ { AllowedOrigins: to.Ptr("*"), AllowedMethods: to.Ptr("PUT"), AllowedHeaders: to.Ptr("x-ms-client-request-id"), ExposedHeaders: to.Ptr("x-ms-*"), MaxAgeInSeconds: to.Ptr(int32(2)), }, }, } _, err = svcClient.SetProperties(context.TODO(), &setPropertiesOpts) handleError(err) }
Output:
Example (Service_NewClientFromConnectionString) ¶
package main import ( "fmt" "github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/service" "log" "os" ) func handleError(err error) { if err != nil { log.Fatal(err.Error()) } } func main() { // Your connection string can be obtained from the Azure Portal. connectionString, ok := os.LookupEnv("AZURE_STORAGE_CONNECTION_STRING") if !ok { log.Fatal("the environment variable 'AZURE_STORAGE_CONNECTION_STRING' could not be found") } svcClient, err := service.NewClientFromConnectionString(connectionString, nil) handleError(err) fmt.Println(svcClient.URL()) }
Output:
Index ¶
- type CORSRule
- type Client
- func NewClient(serviceURL string, cred azcore.TokenCredential, options *ClientOptions) (*Client, error)
- func NewClientFromConnectionString(connectionString string, options *ClientOptions) (*Client, error)
- func NewClientWithNoCredential(serviceURL string, options *ClientOptions) (*Client, error)
- func NewClientWithSharedKeyCredential(serviceURL string, cred *SharedKeyCredential, options *ClientOptions) (*Client, error)
- func (s *Client) CreateShare(ctx context.Context, shareName string, options *CreateShareOptions) (CreateShareResponse, error)
- func (s *Client) DeleteShare(ctx context.Context, shareName string, options *DeleteShareOptions) (DeleteShareResponse, error)
- func (s *Client) GetProperties(ctx context.Context, options *GetPropertiesOptions) (GetPropertiesResponse, error)
- func (s *Client) GetSASURL(resources sas.AccountResourceTypes, permissions sas.AccountPermissions, ...) (string, error)
- func (s *Client) NewListSharesPager(options *ListSharesOptions) *runtime.Pager[ListSharesSegmentResponse]
- func (s *Client) NewShareClient(shareName string) *share.Client
- func (s *Client) RestoreShare(ctx context.Context, deletedShareName string, deletedShareVersion string, ...) (RestoreShareResponse, error)
- func (s *Client) SetProperties(ctx context.Context, options *SetPropertiesOptions) (SetPropertiesResponse, error)
- func (s *Client) URL() string
- type ClientOptions
- type CreateShareOptions
- type CreateShareResponse
- type DeleteShareOptions
- type DeleteShareResponse
- type GetPropertiesOptions
- type GetPropertiesResponse
- type GetSASURLOptions
- type ListSharesInclude
- type ListSharesIncludeType
- type ListSharesOptions
- type ListSharesResponse
- type ListSharesSegmentResponse
- type Metrics
- type ProtocolSettings
- type RestoreShareOptions
- type RestoreShareResponse
- type RetentionPolicy
- type SMBMultichannel
- type SMBSettings
- type SetPropertiesOptions
- type SetPropertiesResponse
- type Share
- type ShareProperties
- type ShareRootSquash
- type ShareTokenIntent
- type SharedKeyCredential
- type StorageServiceProperties
Examples ¶
- Package (Service_Client_CreateShare)
- Package (Service_Client_DeleteShare)
- Package (Service_Client_GetProperties)
- Package (Service_Client_GetSASURL)
- Package (Service_Client_ListShares)
- Package (Service_Client_NewClient)
- Package (Service_Client_NewShareClient)
- Package (Service_Client_RestoreShare)
- Package (Service_Client_SetProperties)
- Package (Service_NewClientFromConnectionString)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CORSRule ¶
CORSRule - CORS is an HTTP feature that enables a web application running under one domain to access resources in another domain. Web browsers implement a security restriction known as same-origin policy that prevents a web page from calling APIs in a different domain; CORS provides a secure way to allow one domain (the origin domain) to call APIs in another domain.
type Client ¶
type Client base.Client[generated.ServiceClient]
Client represents a URL to the Azure File Storage service allowing you to manipulate file shares.
func NewClient ¶
func NewClient(serviceURL string, cred azcore.TokenCredential, options *ClientOptions) (*Client, error)
NewClient creates an instance of Client with the specified values.
- serviceURL - the URL of the storage account e.g. https://<account>.file.core.windows.net/
- cred - an Azure AD credential, typically obtained via the azidentity module
- options - client options; pass nil to accept the default values
Note that service-level operations do not support token credential authentication. This constructor exists to allow the construction of a share.Client that has token credential authentication. Also note that ClientOptions.FileRequestIntent is currently required for token authentication.
func NewClientFromConnectionString ¶
func NewClientFromConnectionString(connectionString string, options *ClientOptions) (*Client, error)
NewClientFromConnectionString creates an instance of Client with the specified values.
- connectionString - a connection string for the desired storage account
- options - client options; pass nil to accept the default values
func NewClientWithNoCredential ¶
func NewClientWithNoCredential(serviceURL string, options *ClientOptions) (*Client, error)
NewClientWithNoCredential creates an instance of Client with the specified values. This is used to anonymously access a storage account or with a shared access signature (SAS) token.
- serviceURL - the URL of the storage account e.g. https://<account>.file.core.windows.net/?<sas token>
- options - client options; pass nil to accept the default values
func NewClientWithSharedKeyCredential ¶
func NewClientWithSharedKeyCredential(serviceURL string, cred *SharedKeyCredential, options *ClientOptions) (*Client, error)
NewClientWithSharedKeyCredential creates an instance of Client with the specified values.
- serviceURL - the URL of the storage account e.g. https://<account>.file.core.windows.net/
- cred - a SharedKeyCredential created with the matching storage account and access key
- options - client options; pass nil to accept the default values
func (*Client) CreateShare ¶
func (s *Client) CreateShare(ctx context.Context, shareName string, options *CreateShareOptions) (CreateShareResponse, error)
CreateShare is a lifecycle method to creates a new share under the specified account. If the share with the same name already exists, a ResourceExistsError will be raised. This method returns a client with which to interact with the newly created share. For more information see, https://learn.microsoft.com/en-us/rest/api/storageservices/create-share.
func (*Client) DeleteShare ¶
func (s *Client) DeleteShare(ctx context.Context, shareName string, options *DeleteShareOptions) (DeleteShareResponse, error)
DeleteShare is a lifecycle method that marks the specified share for deletion. The share and any files contained within it are later deleted during garbage collection. If the share is not found, a ResourceNotFoundError will be raised. For more information see, https://learn.microsoft.com/en-us/rest/api/storageservices/delete-share.
func (*Client) GetProperties ¶
func (s *Client) GetProperties(ctx context.Context, options *GetPropertiesOptions) (GetPropertiesResponse, error)
GetProperties operation gets the properties of a storage account's File service. For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/get-file-service-properties.
func (*Client) GetSASURL ¶
func (s *Client) GetSASURL(resources sas.AccountResourceTypes, permissions sas.AccountPermissions, expiry time.Time, o *GetSASURLOptions) (string, error)
GetSASURL is a convenience method for generating a SAS token for the currently pointed at account. It can only be used if the credential supplied during creation was a SharedKeyCredential.
func (*Client) NewListSharesPager ¶
func (s *Client) NewListSharesPager(options *ListSharesOptions) *runtime.Pager[ListSharesSegmentResponse]
NewListSharesPager operation returns a pager of the shares under the specified account. For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/list-shares
func (*Client) NewShareClient ¶
NewShareClient creates a new share.Client object by concatenating shareName to the end of this Client's URL. The new share.Client uses the same request policy pipeline as the Client.
func (*Client) RestoreShare ¶
func (s *Client) RestoreShare(ctx context.Context, deletedShareName string, deletedShareVersion string, options *RestoreShareOptions) (RestoreShareResponse, error)
RestoreShare restores soft-deleted share. Operation will only be successful if used within the specified number of days set in the delete retention policy. For more information see, https://learn.microsoft.com/en-us/rest/api/storageservices/restore-share.
func (*Client) SetProperties ¶
func (s *Client) SetProperties(ctx context.Context, options *SetPropertiesOptions) (SetPropertiesResponse, error)
SetProperties operation sets properties for a storage account's File service endpoint. For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/set-file-service-properties.
type ClientOptions ¶
type ClientOptions base.ClientOptions
ClientOptions contains the optional parameters when creating a Client.
type CreateShareOptions ¶
type CreateShareOptions = share.CreateOptions
CreateShareOptions contains the optional parameters for the share.Client.Create method.
type CreateShareResponse ¶
type CreateShareResponse = generated.ShareClientCreateResponse
CreateShareResponse contains the response from method share.Client.Create.
type DeleteShareOptions ¶
type DeleteShareOptions = share.DeleteOptions
DeleteShareOptions contains the optional parameters for the share.Client.Delete method.
type DeleteShareResponse ¶
type DeleteShareResponse = generated.ShareClientDeleteResponse
DeleteShareResponse contains the response from method share.Client.Delete.
type GetPropertiesOptions ¶
type GetPropertiesOptions struct { }
GetPropertiesOptions provides set of options for Client.GetProperties
type GetPropertiesResponse ¶
type GetPropertiesResponse = generated.ServiceClientGetPropertiesResponse
GetPropertiesResponse contains the response from method Client.GetProperties.
type GetSASURLOptions ¶
GetSASURLOptions contains the optional parameters for the Client.GetSASURL method.
type ListSharesInclude ¶
ListSharesInclude indicates what additional information the service should return with each share.
type ListSharesIncludeType ¶
type ListSharesIncludeType = generated.ListSharesIncludeType
ListSharesIncludeType defines values for ListSharesIncludeType
const ()
func PossibleListSharesIncludeTypeValues ¶
func PossibleListSharesIncludeTypeValues() []ListSharesIncludeType
PossibleListSharesIncludeTypeValues returns the possible values for the ListSharesIncludeType const type.
type ListSharesOptions ¶
type ListSharesOptions struct { ListSharesInclude // a marker value within the responseBody body if the list returned was not complete. // The marker value may then be used in a subsequent call to request the next set of list items. The marker value is opaque // to the client. Marker *string // than 5,000, the server will return up to 5,000 items. MaxResults *int32 Prefix *string }Include
ListSharesOptions contains the optional parameters for the Client.NewListSharesPager method.
type ListSharesResponse ¶
type ListSharesResponse = generated.ListSharesResponse
ListSharesResponse - An enumeration of shares.
type ListSharesSegmentResponse ¶
type ListSharesSegmentResponse = generated.ServiceClientListSharesSegmentResponse
ListSharesSegmentResponse contains the response from method Client.NewListSharesPager.
type ProtocolSettings ¶
type ProtocolSettings = generated.ProtocolSettings
ProtocolSettings - Protocol settings
type RestoreShareOptions ¶
type RestoreShareOptions = share.RestoreOptions
RestoreShareOptions contains the optional parameters for the share.Client.Restore method.
type RestoreShareResponse ¶
type RestoreShareResponse = generated.ShareClientRestoreResponse
RestoreShareResponse contains the response from method share.Client.Restore.
type RetentionPolicy ¶
type RetentionPolicy = generated.RetentionPolicy
RetentionPolicy - The retention policy.
type SMBMultichannel ¶
type SMBMultichannel = generated.SMBMultichannel
SMBMultichannel - Settings for SMB multichannel
type SMBSettings ¶
type SMBSettings = generated.SMBSettings
SMBSettings - Settings for SMB protocol.
type SetPropertiesOptions ¶
type SetPropertiesOptions struct { // The set of CORS rules. CORS []*CORSRule // A summary of request statistics grouped by API in hourly aggregates for files. HourMetrics *Metrics // A summary of request statistics grouped by API in minute aggregates for files. MinuteMetrics *Metrics // Protocol settings Protocol *ProtocolSettings }
SetPropertiesOptions provides set of options for Client.SetProperties
type SetPropertiesResponse ¶
type SetPropertiesResponse = generated.ServiceClientSetPropertiesResponse
SetPropertiesResponse contains the response from method Client.SetProperties.
type ShareProperties ¶
type ShareProperties = generated.ShareProperties
ShareProperties - Properties of a share.
type ShareRootSquash ¶
type ShareRootSquash = generated.ShareRootSquash
ShareRootSquash defines values for the root squashing behavior on the share when NFS is enabled. If it's not specified, the default is NoRootSquash.
const ( RootSquashNoRootSquash ShareRootSquash = generated.ShareRootSquashNoRootSquash RootSquashRootSquash ShareRootSquash = generated.ShareRootSquashRootSquash RootSquashAllSquash ShareRootSquash = generated.ShareRootSquashAllSquash )
func PossibleShareRootSquashValues ¶
func PossibleShareRootSquashValues() []ShareRootSquash
PossibleShareRootSquashValues returns the possible values for the RootSquash const type.
type ShareTokenIntent ¶
type ShareTokenIntent = generated.ShareTokenIntent
ShareTokenIntent is required if authorization header specifies an OAuth token.
const (
)func PossibleShareTokenIntentValues ¶
func PossibleShareTokenIntentValues() []ShareTokenIntent
PossibleShareTokenIntentValues returns the possible values for the ShareTokenIntent const type.
type SharedKeyCredential ¶
type SharedKeyCredential = exported.SharedKeyCredential
SharedKeyCredential contains an account's name and its primary or secondary key.
func NewSharedKeyCredential ¶
func NewSharedKeyCredential(accountName, accountKey string) (*SharedKeyCredential, error)
NewSharedKeyCredential creates an immutable SharedKeyCredential containing the storage account's name and either its primary or secondary key.
type StorageServiceProperties ¶
type StorageServiceProperties = generated.StorageServiceProperties
StorageServiceProperties - Storage service properties.