share

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: 14 Imported by: 7

Documentation

Overview

Example (Share_Client_AccessPolicy)
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"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share"
	"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")
	}

	shareName := "testshare"
	shareURL := fmt.Sprintf("https://%s.file.core.windows.net/%s", accountName, shareName)

	cred, err := service.NewSharedKeyCredential(accountName, accountKey)
	handleError(err)

	shareClient, err := share.NewClientWithSharedKeyCredential(shareURL, cred, nil)
	handleError(err)

	permission := share.AccessPolicyPermission{Read: true, Write: true, Create: true, Delete: true, List: true}.String()
	permissions := []*share.SignedIdentifier{
		{
			ID: to.Ptr("1"),
			AccessPolicy: &share.AccessPolicy{
				Start:      to.Ptr(time.Now()),
				Expiry:     to.Ptr(time.Now().Add(time.Hour)),
				Permission: &permission,
			},
		}}

	_, err = shareClient.SetAccessPolicy(context.TODO(), &share.SetAccessPolicyOptions{
		ShareACL: permissions,
	})
	handleError(err)

	resp, err := shareClient.GetAccessPolicy(context.TODO(), nil)
	handleError(err)

	fmt.Println(*resp.SignedIdentifiers[0].AccessPolicy.Permission)
}
Output:

Example (Share_Client_Create)
package main

import (
	"context"
	"fmt"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/service"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share"
	"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")
	}

	shareName := "testshare"
	shareURL := fmt.Sprintf("https://%s.file.core.windows.net/%s", accountName, shareName)

	cred, err := service.NewSharedKeyCredential(accountName, accountKey)
	handleError(err)

	shareClient, err := share.NewClientWithSharedKeyCredential(shareURL, cred, nil)
	handleError(err)

	_, err = shareClient.Create(context.TODO(), nil)
	handleError(err)
}
Output:

Example (Share_Client_CreateAndGetPermissionOAuth)
package main

import (
	"context"
	"fmt"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
	"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share"
	"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")
	}

	shareName := "testshare"
	shareURL := fmt.Sprintf("https://%s.file.core.windows.net/%s", accountName, shareName)

	cred, err := azidentity.NewDefaultAzureCredential(nil)
	handleError(err)

	// FileRequestintent is required if authorization header specifies an OAuth token.
	options := &share.ClientOptions{FileRequestIntent: to.Ptr(share.TokenIntentBackup)}
	shareClient, err := share.NewClient(shareURL, cred, options)
	handleError(err)

	// Create, Delete, GetProperties, SetProperties, etc. operations does not work when share client is created using OAuth credentials
	// Operations supported are: CreatePermission and GetPermission
	// Below GetProperties operation results in an error
	_, err = shareClient.GetProperties(context.TODO(), nil)
	fmt.Println(err.Error())

	testSDDL := `O:S-1-5-32-548G:S-1-5-21-397955417-626881126-188441444-512D:(A;;RPWPCCDCLCSWRCWDWOGA;;;S-1-0-0)`
	createResp, err := shareClient.CreatePermission(context.TODO(), testSDDL, nil)
	handleError(err)

	getResp, err := shareClient.GetPermission(context.TODO(), *createResp.FilePermissionKey, nil)
	handleError(err)
	fmt.Println(*getResp.Permission)
}
Output:

Example (Share_Client_CreateGetPermission)
package main

import (
	"context"
	"fmt"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/service"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share"
	"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")
	}

	shareName := "testshare"
	shareURL := fmt.Sprintf("https://%s.file.core.windows.net/%s", accountName, shareName)

	cred, err := service.NewSharedKeyCredential(accountName, accountKey)
	handleError(err)

	shareClient, err := share.NewClientWithSharedKeyCredential(shareURL, cred, nil)
	handleError(err)

	testSDDL := `O:S-1-5-32-548G:S-1-5-21-397955417-626881126-188441444-512D:(A;;RPWPCCDCLCSWRCWDWOGA;;;S-1-0-0)`
	createResp, err := shareClient.CreatePermission(context.TODO(), testSDDL, nil)
	handleError(err)

	getResp, err := shareClient.GetPermission(context.TODO(), *createResp.FilePermissionKey, nil)
	handleError(err)
	fmt.Println(*getResp.Permission)
}
Output:

Example (Share_Client_CreateSnapshot)
package main

import (
	"context"
	"fmt"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/service"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share"
	"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")
	}

	shareName := "testshare"
	shareURL := fmt.Sprintf("https://%s.file.core.windows.net/%s", accountName, shareName)

	cred, err := service.NewSharedKeyCredential(accountName, accountKey)
	handleError(err)

	shareClient, err := share.NewClientWithSharedKeyCredential(shareURL, cred, nil)
	handleError(err)

	snapResp, err := shareClient.CreateSnapshot(context.TODO(), nil)
	handleError(err)
	shareSnapshot := *snapResp.Snapshot

	snapshotShareClient, err := shareClient.WithSnapshot(shareSnapshot)
	handleError(err)

	fmt.Println(snapshotShareClient.URL())

	_, err = snapshotShareClient.GetProperties(context.TODO(), nil)
	handleError(err)
}
Output:

Example (Share_Client_Delete)
package main

import (
	"context"
	"fmt"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/service"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share"
	"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")
	}

	shareName := "testshare"
	shareURL := fmt.Sprintf("https://%s.file.core.windows.net/%s", accountName, shareName)

	cred, err := service.NewSharedKeyCredential(accountName, accountKey)
	handleError(err)

	shareClient, err := share.NewClientWithSharedKeyCredential(shareURL, cred, nil)
	handleError(err)

	_, err = shareClient.Delete(context.TODO(), nil)
	handleError(err)
}
Output:

Example (Share_Client_GetProperties)
package main

import (
	"context"
	"fmt"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/service"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share"
	"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")
	}

	shareName := "testshare"
	shareURL := fmt.Sprintf("https://%s.file.core.windows.net/%s", accountName, shareName)

	cred, err := service.NewSharedKeyCredential(accountName, accountKey)
	handleError(err)

	shareClient, err := share.NewClientWithSharedKeyCredential(shareURL, cred, nil)
	handleError(err)

	_, err = shareClient.GetProperties(context.TODO(), nil)
	handleError(err)
}
Output:

Example (Share_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"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share"
	"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")
	}

	shareName := "testshare"
	shareURL := fmt.Sprintf("https://%s.file.core.windows.net/%s", accountName, shareName)

	cred, err := service.NewSharedKeyCredential(accountName, accountKey)
	handleError(err)

	shareClient, err := share.NewClientWithSharedKeyCredential(shareURL, cred, nil)
	handleError(err)

	permissions := sas.SharePermissions{
		Read:   true,
		Write:  true,
		Delete: true,
		List:   true,
		Create: true,
	}
	expiry := time.Now().Add(time.Hour)

	shareSASURL, err := shareClient.GetSASURL(permissions, expiry, nil)
	handleError(err)

	fmt.Println("SAS URL: ", shareSASURL)

	shareSASClient, err := share.NewClientWithNoCredential(shareSASURL, nil)
	handleError(err)

	var dirs, files []string
	pager := shareSASClient.NewRootDirectoryClient().NewListFilesAndDirectoriesPager(nil)
	for pager.More() {
		resp, err := pager.NextPage(context.Background())
		handleError(err)

		for _, d := range resp.Segment.Directories {
			dirs = append(dirs, *d.Name)
		}
		for _, f := range resp.Segment.Files {
			files = append(files, *f.Name)
		}
	}

	fmt.Println("Directories:")
	for _, d := range dirs {
		fmt.Println(d)
	}

	fmt.Println("Files:")
	for _, f := range files {
		fmt.Println(f)
	}
}
Output:

Example (Share_Client_GetStatistics)
package main

import (
	"context"
	"fmt"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/service"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share"
	"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")
	}

	shareName := "testshare"
	shareURL := fmt.Sprintf("https://%s.file.core.windows.net/%s", accountName, shareName)

	cred, err := service.NewSharedKeyCredential(accountName, accountKey)
	handleError(err)

	shareClient, err := share.NewClientWithSharedKeyCredential(shareURL, cred, nil)
	handleError(err)

	getStats, err := shareClient.GetStatistics(context.Background(), nil)
	handleError(err)
	fmt.Println(*getStats.ShareUsageBytes)
}
Output:

Example (Share_Client_NewClient)
package main

import (
	"fmt"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/service"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share"
	"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")
	}

	shareName := "testshare"
	shareURL := fmt.Sprintf("https://%s.file.core.windows.net/%s", accountName, shareName)

	cred, err := service.NewSharedKeyCredential(accountName, accountKey)
	handleError(err)

	shareClient, err := share.NewClientWithSharedKeyCredential(shareURL, cred, nil)
	handleError(err)

	fmt.Println(shareClient.URL())
}
Output:

Example (Share_Client_NewClientFromConnectionString)
package main

import (
	"fmt"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share"
	"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")
	}

	shareName := "testshare"
	shareClient, err := share.NewClientFromConnectionString(connectionString, shareName, nil)
	handleError(err)

	fmt.Println(shareClient.URL())
}
Output:

Example (Share_Client_NewDirectoryClient)
package main

import (
	"fmt"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/service"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share"
	"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")
	}

	shareName := "testshare"
	shareURL := fmt.Sprintf("https://%s.file.core.windows.net/%s", accountName, shareName)

	cred, err := service.NewSharedKeyCredential(accountName, accountKey)
	handleError(err)

	shareClient, err := share.NewClientWithSharedKeyCredential(shareURL, cred, nil)
	handleError(err)

	dirName := "testdirectory"
	dirClient := shareClient.NewDirectoryClient(dirName)

	fmt.Println(dirClient.URL())
}
Output:

Example (Share_Client_NewRootDirectoryClient)
package main

import (
	"fmt"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/service"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share"
	"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")
	}

	shareName := "testshare"
	shareURL := fmt.Sprintf("https://%s.file.core.windows.net/%s", accountName, shareName)

	cred, err := service.NewSharedKeyCredential(accountName, accountKey)
	handleError(err)

	shareClient, err := share.NewClientWithSharedKeyCredential(shareURL, cred, nil)
	handleError(err)

	dirClient := shareClient.NewRootDirectoryClient()

	fmt.Println(dirClient.URL())
}
Output:

Example (Share_Client_Restore)
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")
	}

	shareName := "testshare"
	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)

	shareClient := svcClient.NewShareClient(shareName)

	// get share version for restore operation
	pager := svcClient.NewListSharesPager(&service.ListSharesOptions{
		Include: service.ListSharesInclude{Deleted: true}, // Include deleted shares in the result
	})

	for pager.More() {
		resp, err := pager.NextPage(context.Background())
		handleError(err)
		for _, s := range resp.Shares {
			if s.Deleted != nil && *s.Deleted {
				_, err = shareClient.Restore(context.TODO(), *s.Version, nil)
				handleError(err)
			}
		}
	}
}
Output:

Example (Share_Client_SetMetadata)
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"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share"
	"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")
	}

	shareName := "testshare"
	shareURL := fmt.Sprintf("https://%s.file.core.windows.net/%s", accountName, shareName)

	cred, err := service.NewSharedKeyCredential(accountName, accountKey)
	handleError(err)

	shareClient, err := share.NewClientWithSharedKeyCredential(shareURL, cred, nil)
	handleError(err)

	md := map[string]*string{
		"Foo": to.Ptr("FooValuE"),
		"Bar": to.Ptr("bArvaLue"),
	}
	_, err = shareClient.SetMetadata(context.TODO(), &share.SetMetadataOptions{
		Metadata: md,
	})
	handleError(err)

	resp, err := shareClient.GetProperties(context.TODO(), nil)
	handleError(err)
	for k, v := range resp.Metadata {
		fmt.Printf("%v : %v\n", k, *v)
	}
}
Output:

Example (Share_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"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share"
	"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")
	}

	shareName := "testshare"
	shareURL := fmt.Sprintf("https://%s.file.core.windows.net/%s", accountName, shareName)

	cred, err := service.NewSharedKeyCredential(accountName, accountKey)
	handleError(err)

	shareClient, err := share.NewClientWithSharedKeyCredential(shareURL, cred, nil)
	handleError(err)

	_, err = shareClient.SetProperties(context.TODO(), &share.SetPropertiesOptions{
		Quota:      to.Ptr(int32(1000)),
		AccessTier: to.Ptr(share.AccessTierHot),
	})
	handleError(err)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessPolicy

type AccessPolicy = generated.AccessPolicy

AccessPolicy - An Access policy.

type AccessPolicyPermission

type AccessPolicyPermission = exported.AccessPolicyPermission

AccessPolicyPermission type simplifies creating the permissions string for a share's access policy. Initialize an instance of this type and then call its String method to set AccessPolicy's permission field.

type AccessTier

type AccessTier = generated.ShareAccessTier

AccessTier defines values for the access tier of the share.

const (
	AccessTierCool                 AccessTier = generated.ShareAccessTierCool
	AccessTierHot                  AccessTier = generated.ShareAccessTierHot
	AccessTierTransactionOptimized AccessTier = generated.ShareAccessTierTransactionOptimized
)

func PossibleAccessTierValues

func PossibleAccessTierValues() []AccessTier

PossibleAccessTierValues returns the possible values for the AccessTier const type.

type Client

Client represents a URL to the Azure Storage share allowing you to manipulate its directories and files.

func NewClient added in v1.1.0

func NewClient(shareURL string, cred azcore.TokenCredential, options *ClientOptions) (*Client, error)

NewClient creates an instance of Client with the specified values.

  • shareURL - the URL of the share e.g. https://<account>.file.core.windows.net/share
  • cred - an Azure AD credential, typically obtained via the azidentity module
  • options - client options; pass nil to accept the default values

Note that the only share-level operations that support token credential authentication are CreatePermission and GetPermission. Also note that ClientOptions.FileRequestIntent is currently required for token authentication.

func NewClientFromConnectionString

func NewClientFromConnectionString(connectionString string, shareName string, options *ClientOptions) (*Client, error)

NewClientFromConnectionString creates an instance of Client with the specified values.

  • connectionString - a connection string for the desired storage account
  • shareName - the name of the share within the storage account
  • options - client options; pass nil to accept the default values

func NewClientWithNoCredential

func NewClientWithNoCredential(shareURL string, options *ClientOptions) (*Client, error)

NewClientWithNoCredential creates an instance of Client with the specified values. This is used to anonymously access a share or with a shared access signature (SAS) token.

  • shareURL - the URL of the share e.g. https://<account>.file.core.windows.net/share?<sas token>
  • options - client options; pass nil to accept the default values

func NewClientWithSharedKeyCredential

func NewClientWithSharedKeyCredential(shareURL string, cred *SharedKeyCredential, options *ClientOptions) (*Client, error)

NewClientWithSharedKeyCredential creates an instance of Client with the specified values.

  • shareURL - the URL of the share e.g. https://<account>.file.core.windows.net/share
  • cred - a SharedKeyCredential created with the matching share's storage account and access key
  • options - client options; pass nil to accept the default values

func (*Client) Create

func (s *Client) Create(ctx context.Context, options *CreateOptions) (CreateResponse, error)

Create operation creates a new share within a storage account. If a share with the same name already exists, the operation fails. For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/create-share.

func (*Client) CreatePermission

func (s *Client) CreatePermission(ctx context.Context, sharePermission string, options *CreatePermissionOptions) (CreatePermissionResponse, error)

CreatePermission operation creates a permission (a security descriptor) at the share level. The created security descriptor can be used for the files and directories in the share. For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/create-permission.

func (*Client) CreateSnapshot

func (s *Client) CreateSnapshot(ctx context.Context, options *CreateSnapshotOptions) (CreateSnapshotResponse, error)

CreateSnapshot operation creates a read-only snapshot of a share. For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/snapshot-share.

func (*Client) Delete

func (s *Client) Delete(ctx context.Context, options *DeleteOptions) (DeleteResponse, error)

Delete operation marks the specified share for deletion. The share and any files contained within it are later deleted during garbage collection. For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/delete-share.

func (*Client) GetAccessPolicy

func (s *Client) GetAccessPolicy(ctx context.Context, options *GetAccessPolicyOptions) (GetAccessPolicyResponse, error)

GetAccessPolicy operation returns information about stored access policies specified on the share. For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/get-share-acl.

func (*Client) GetPermission

func (s *Client) GetPermission(ctx context.Context, filePermissionKey string, options *GetPermissionOptions) (GetPermissionResponse, error)

GetPermission operation gets the SDDL permission string from the service using a known permission key. For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/get-permission.

func (*Client) GetProperties

func (s *Client) GetProperties(ctx context.Context, options *GetPropertiesOptions) (GetPropertiesResponse, error)

GetProperties operation returns all user-defined metadata and system properties for the specified share or share snapshot. For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/get-share-properties.

func (*Client) GetSASURL

func (s *Client) GetSASURL(permissions sas.SharePermissions, expiry time.Time, o *GetSASURLOptions) (string, error)

GetSASURL is a convenience method for generating a SAS token for the currently pointed at share. It can only be used if the credential supplied during creation was a SharedKeyCredential.

func (*Client) GetStatistics

func (s *Client) GetStatistics(ctx context.Context, options *GetStatisticsOptions) (GetStatisticsResponse, error)

GetStatistics operation retrieves statistics related to the share. For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/get-share-stats.

func (*Client) NewDirectoryClient

func (s *Client) NewDirectoryClient(directoryName string) *directory.Client

NewDirectoryClient creates a new directory.Client object by concatenating directoryName to the end of this Client's URL. The new directory.Client uses the same request policy pipeline as the Client.

func (*Client) NewRootDirectoryClient

func (s *Client) NewRootDirectoryClient() *directory.Client

NewRootDirectoryClient creates a new directory.Client object for the root of the share using the Client's URL. The new directory.Client uses the same request policy pipeline as the Client.

func (*Client) Restore

func (s *Client) Restore(ctx context.Context, deletedShareVersion string, options *RestoreOptions) (RestoreResponse, error)

Restore operation restores a share that had previously been soft-deleted. For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/restore-share.

func (*Client) SetAccessPolicy

func (s *Client) SetAccessPolicy(ctx context.Context, options *SetAccessPolicyOptions) (SetAccessPolicyResponse, error)

SetAccessPolicy operation sets a stored access policy for use with shared access signatures. For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/set-share-acl.

func (*Client) SetMetadata

func (s *Client) SetMetadata(ctx context.Context, options *SetMetadataOptions) (SetMetadataResponse, error)

SetMetadata operation sets one or more user-defined name-value pairs for the specified share. For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/set-share-metadata.

func (*Client) SetProperties

func (s *Client) SetProperties(ctx context.Context, options *SetPropertiesOptions) (SetPropertiesResponse, error)

SetProperties operation sets properties for the specified share. For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/set-share-properties.

func (*Client) URL

func (s *Client) URL() string

URL returns the URL endpoint used by the Client object.

func (*Client) WithSnapshot

func (s *Client) WithSnapshot(shareSnapshot string) (*Client, error)

WithSnapshot creates a new Client object identical to the source but with the specified share snapshot timestamp. Pass "" to remove the snapshot returning a URL to the base share.

type ClientOptions

type ClientOptions base.ClientOptions

ClientOptions contains the optional parameters when creating a Client.

type CreateOptions

type CreateOptions struct {
	// Specifies the access tier of the share.
	AccessTier *AccessTier
	// Protocols to enable on the share.
	EnabledProtocols *string
	// A name-value pair to associate with a file storage object.
	Metadata map[string]*string
	// Specifies the maximum size of the share, in gigabytes.
	Quota *int32
	// Root squash to set on the share. Only valid for NFS shares.
	RootSquash *RootSquash
}

CreateOptions contains the optional parameters for the Client.Create method.

type CreatePermissionOptions

type CreatePermissionOptions struct {
}

CreatePermissionOptions contains the optional parameters for the Client.CreatePermission method.

type CreatePermissionResponse

type CreatePermissionResponse = generated.ShareClientCreatePermissionResponse

CreatePermissionResponse contains the response from method Client.CreatePermission.

type CreateResponse

type CreateResponse = generated.ShareClientCreateResponse

CreateResponse contains the response from method Client.Create.

type CreateSnapshotOptions

type CreateSnapshotOptions struct {
	// A name-value pair to associate with a file storage object.
	Metadata map[string]*string
}

CreateSnapshotOptions contains the optional parameters for the Client.CreateSnapshot method.

type CreateSnapshotResponse

type CreateSnapshotResponse = generated.ShareClientCreateSnapshotResponse

CreateSnapshotResponse contains the response from method Client.CreateSnapshot.

type DeleteOptions

type DeleteOptions struct {
	// Specifies the option include to delete the base share and all of its snapshots.
	DeleteSnapshots *DeleteSnapshotsOptionType
	// The snapshot parameter is an opaque DateTime value that, when present, specifies the share snapshot to query.
	ShareSnapshot *string
	// LeaseAccessConditions contains optional parameters to access leased entity.
	LeaseAccessConditions *LeaseAccessConditions
}

DeleteOptions contains the optional parameters for the Client.Delete method.

type DeleteResponse

type DeleteResponse = generated.ShareClientDeleteResponse

DeleteResponse contains the response from method Client.Delete.

type DeleteSnapshotsOptionType

type DeleteSnapshotsOptionType = generated.DeleteSnapshotsOptionType

DeleteSnapshotsOptionType defines values for DeleteSnapshotsOptionType

const (
	DeleteSnapshotsOptionTypeInclude       DeleteSnapshotsOptionType = generated.DeleteSnapshotsOptionTypeInclude
	DeleteSnapshotsOptionTypeIncludeLeased DeleteSnapshotsOptionType = generated.DeleteSnapshotsOptionTypeIncludeLeased
)

func PossibleDeleteSnapshotsOptionTypeValues

func PossibleDeleteSnapshotsOptionTypeValues() []DeleteSnapshotsOptionType

PossibleDeleteSnapshotsOptionTypeValues returns the possible values for the DeleteSnapshotsOptionType const type.

type GetAccessPolicyOptions

type GetAccessPolicyOptions struct {
	// LeaseAccessConditions contains optional parameters to access leased entity.
	LeaseAccessConditions *LeaseAccessConditions
}

GetAccessPolicyOptions contains the optional parameters for the Client.GetAccessPolicy method.

type GetAccessPolicyResponse

type GetAccessPolicyResponse = generated.ShareClientGetAccessPolicyResponse

GetAccessPolicyResponse contains the response from method Client.GetAccessPolicy.

type GetPermissionOptions

type GetPermissionOptions struct {
}

GetPermissionOptions contains the optional parameters for the Client.GetPermission method.

type GetPermissionResponse

type GetPermissionResponse = generated.ShareClientGetPermissionResponse

GetPermissionResponse contains the response from method Client.GetPermission.

type GetPropertiesOptions

type GetPropertiesOptions struct {
	// The snapshot parameter is an opaque DateTime value that, when present, specifies the share snapshot to query.
	ShareSnapshot *string
	// LeaseAccessConditions contains optional parameters to access leased entity.
	LeaseAccessConditions *LeaseAccessConditions
}

GetPropertiesOptions contains the optional parameters for the Client.GetProperties method.

type GetPropertiesResponse

type GetPropertiesResponse = generated.ShareClientGetPropertiesResponse

GetPropertiesResponse contains the response from method Client.GetProperties.

type GetSASURLOptions

type GetSASURLOptions struct {
	StartTime *time.Time
}

GetSASURLOptions contains the optional parameters for the Client.GetSASURL method.

type GetStatisticsOptions

type GetStatisticsOptions struct {
	// LeaseAccessConditions contains optional parameters to access leased entity.
	LeaseAccessConditions *LeaseAccessConditions
}

GetStatisticsOptions contains the optional parameters for the Client.GetStatistics method.

type GetStatisticsResponse

type GetStatisticsResponse = generated.ShareClientGetStatisticsResponse

GetStatisticsResponse contains the response from method Client.GetStatistics.

type LeaseAccessConditions

type LeaseAccessConditions = generated.LeaseAccessConditions

LeaseAccessConditions contains optional parameters to access leased entity.

type Permission

type Permission = generated.SharePermission

Permission - A permission (a security descriptor) at the share level.

type RestoreOptions

type RestoreOptions struct {
}

RestoreOptions contains the optional parameters for the Client.Restore method.

type RestoreResponse

type RestoreResponse = generated.ShareClientRestoreResponse

RestoreResponse contains the response from method Client.Restore.

type RootSquash

type RootSquash = generated.ShareRootSquash

RootSquash 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 RootSquash = generated.ShareRootSquashNoRootSquash
	RootSquashRootSquash   RootSquash = generated.ShareRootSquashRootSquash
	RootSquashAllSquash    RootSquash = generated.ShareRootSquashAllSquash
)

func PossibleRootSquashValues

func PossibleRootSquashValues() []RootSquash

PossibleRootSquashValues returns the possible values for the RootSquash const type.

type SetAccessPolicyOptions

type SetAccessPolicyOptions struct {
	// Specifies the ACL for the share.
	ShareACL []*SignedIdentifier
	// LeaseAccessConditions contains optional parameters to access leased entity.
	LeaseAccessConditions *LeaseAccessConditions
}

SetAccessPolicyOptions contains the optional parameters for the Client.SetAccessPolicy method.

type SetAccessPolicyResponse

type SetAccessPolicyResponse = generated.ShareClientSetAccessPolicyResponse

SetAccessPolicyResponse contains the response from method Client.SetAccessPolicy.

type SetMetadataOptions

type SetMetadataOptions struct {
	// A name-value pair to associate with a file storage object.
	Metadata map[string]*string
	// LeaseAccessConditions contains optional parameters to access leased entity.
	LeaseAccessConditions *LeaseAccessConditions
}

SetMetadataOptions contains the optional parameters for the Client.SetMetadata method.

type SetMetadataResponse

type SetMetadataResponse = generated.ShareClientSetMetadataResponse

SetMetadataResponse contains the response from method Client.SetMetadata.

type SetPropertiesOptions

type SetPropertiesOptions struct {
	// Specifies the access tier of the share.
	AccessTier *AccessTier
	// Specifies the maximum size of the share, in gigabytes.
	Quota *int32
	// Root squash to set on the share. Only valid for NFS shares.
	RootSquash *RootSquash
	// LeaseAccessConditions contains optional parameters to access leased entity.
	LeaseAccessConditions *LeaseAccessConditions
}

SetPropertiesOptions contains the optional parameters for the Client.SetProperties method.

type SetPropertiesResponse

type SetPropertiesResponse = generated.ShareClientSetPropertiesResponse

SetPropertiesResponse contains the response from method Client.SetProperties.

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 SignedIdentifier

type SignedIdentifier = generated.SignedIdentifier

SignedIdentifier - Signed identifier.

type Stats

type Stats = generated.ShareStats

Stats - Stats for the share.

type TokenIntent added in v1.1.0

type TokenIntent = generated.ShareTokenIntent

TokenIntent is required if authorization header specifies an OAuth token.

const (
	TokenIntentBackup TokenIntent = generated.ShareTokenIntentBackup
)

func PossibleTokenIntentValues added in v1.1.0

func PossibleTokenIntentValues() []TokenIntent

PossibleTokenIntentValues returns the possible values for the TokenIntent const type.

Jump to

Keyboard shortcuts

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