directory

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: MIT Imports: 20 Imported by: 6

Documentation

Overview

Example (Dir_Client_SetMetadata)

make sure you create the filesystem and directory before running this example

package main

import (
	"context"
	"fmt"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azdatalake"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azdatalake/directory"
	"log"
	"os"
)

func handleError(err error) {
	if err != nil {
		log.Fatal(err.Error())
	}
}

func main() {
	accountName, accountKey := os.Getenv("AZURE_STORAGE_ACCOUNT_NAME"), os.Getenv("AZURE_STORAGE_ACCOUNT_KEY")
	// Create a dir client
	u := fmt.Sprintf("https://%s.dfs.core.windows.net/fs/dir1", accountName)
	credential, err := azdatalake.NewSharedKeyCredential(accountName, accountKey)
	handleError(err)

	dirClient, err := directory.NewClientWithSharedKeyCredential(u, credential, nil)
	handleError(err)

	_, err = dirClient.SetMetadata(context.TODO(), map[string]*string{"author": to.Ptr("Tamer")}, nil)
	handleError(err)

	// Query the directory's properties and metadata
	get, err := dirClient.GetProperties(context.TODO(), nil)
	handleError(err)

	// Show the directory's metadata
	if get.Metadata == nil {
		log.Fatal("No metadata returned")
	}

	for k, v := range get.Metadata {
		fmt.Print(k + "=" + *v + "\n")
	}
}
Output:

Example (Directory_CreateAndDelete)

make sure you create the filesystem before running this example

package main

import (
	"context"
	"fmt"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azdatalake"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azdatalake/directory"
	"log"
	"os"
)

func handleError(err error) {
	if err != nil {
		log.Fatal(err.Error())
	}
}

func main() {
	accountName, accountKey := os.Getenv("AZURE_STORAGE_ACCOUNT_NAME"), os.Getenv("AZURE_STORAGE_ACCOUNT_KEY")

	// Create a directory client
	u := fmt.Sprintf("https://%s.dfs.core.windows.net/fs/dir1", accountName)
	credential, err := azdatalake.NewSharedKeyCredential(accountName, accountKey)
	handleError(err)
	dirClient, err := directory.NewClientWithSharedKeyCredential(u, credential, nil)
	handleError(err)

	_, err = dirClient.Create(context.Background(), nil)
	handleError(err)

	_, err = dirClient.Delete(context.Background(), nil)
	handleError(err)
}
Output:

Example (Directory_HTTPHeaders)

This examples shows how to set a directory HTTP Headers, how to read, and how to update the directory's HTTP headers.

package main

import (
	"context"
	"fmt"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azdatalake"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azdatalake/directory"
	"log"
	"os"
)

func handleError(err error) {
	if err != nil {
		log.Fatal(err.Error())
	}
}

func main() {
	// make sure you create the filesystem and directory before running this example
	accountName, accountKey := os.Getenv("AZURE_STORAGE_ACCOUNT_NAME"), os.Getenv("AZURE_STORAGE_ACCOUNT_KEY")

	// Create a dir client
	u := fmt.Sprintf("https://%s.dfs.core.windows.net/fs/dir1", accountName)
	credential, err := azdatalake.NewSharedKeyCredential(accountName, accountKey)
	handleError(err)
	dirClient, err := directory.NewClientWithSharedKeyCredential(u, credential, nil)
	handleError(err)

	// Create a directory with HTTP headers
	_, err = dirClient.SetHTTPHeaders(context.TODO(), directory.HTTPHeaders{
		ContentType:        to.Ptr("text/html; charset=utf-8"),
		ContentDisposition: to.Ptr("attachment"),
	}, nil)
	handleError(err)

	get, err := dirClient.GetProperties(context.TODO(), nil)
	handleError(err)

	fmt.Println(get.ContentType)
	fmt.Println(get.ContentDisposition)
}
Output:

Example (Directory_Rename)

make sure you create the filesystem before running this example

package main

import (
	"context"
	"fmt"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azdatalake"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azdatalake/directory"
	"log"
	"os"
)

func handleError(err error) {
	if err != nil {
		log.Fatal(err.Error())
	}
}

func main() {
	accountName, accountKey := os.Getenv("AZURE_STORAGE_ACCOUNT_NAME"), os.Getenv("AZURE_STORAGE_ACCOUNT_KEY")

	// Create a directory client
	u := fmt.Sprintf("https://%s.dfs.core.windows.net/fs/dir1", accountName)
	credential, err := azdatalake.NewSharedKeyCredential(accountName, accountKey)
	handleError(err)
	dirClient, err := directory.NewClientWithSharedKeyCredential(u, credential, nil)
	handleError(err)

	_, err = dirClient.Create(context.Background(), nil)
	handleError(err)

	_, err = dirClient.Rename(context.Background(), "renameDir", nil)
	handleError(err)
}
Output:

Example (Directory_SetACLRecursive)

for this example make sure to create paths within the dir so you can recursively set the ACL on them

package main

import (
	"context"
	"fmt"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azdatalake"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azdatalake/directory"
	"log"
	"os"
)

func handleError(err error) {
	if err != nil {
		log.Fatal(err.Error())
	}
}

func main() {
	accountName, accountKey := os.Getenv("AZURE_STORAGE_ACCOUNT_NAME"), os.Getenv("AZURE_STORAGE_ACCOUNT_KEY")

	// Create a directory client
	acl := "user::rwx,group::r-x,other::rwx"
	u := fmt.Sprintf("https://%s.dfs.core.windows.net/fs/dir1", accountName)
	credential, err := azdatalake.NewSharedKeyCredential(accountName, accountKey)
	handleError(err)
	dirClient, err := directory.NewClientWithSharedKeyCredential(u, credential, nil)
	handleError(err)

	_, err = dirClient.SetAccessControlRecursive(context.Background(), acl, &directory.SetAccessControlRecursiveOptions{
		BatchSize: to.Ptr(int32(2)), MaxBatches: to.Ptr(int32(1)), ContinueOnFailure: to.Ptr(true), Marker: nil})
	handleError(err)
}
Output:

Example (Directory_SetAccessControlIfUnmodifiedSinceTrue)

make sure you create the filesystem before running this example

package main

import (
	"context"
	"fmt"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azdatalake"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azdatalake/directory"
	"log"
	"os"
	"time"
)

func handleError(err error) {
	if err != nil {
		log.Fatal(err.Error())
	}
}

func getRelativeTimeFromAnchor(anchorTime *time.Time, amount time.Duration) time.Time {
	return anchorTime.Add(amount * time.Second)
}

func main() {
	accountName, accountKey := os.Getenv("AZURE_STORAGE_ACCOUNT_NAME"), os.Getenv("AZURE_STORAGE_ACCOUNT_KEY")

	// Create a directory client
	owner := "4cf4e284-f6a8-4540-b53e-c3469af032dc"
	group := owner
	acl := "user::rwx,group::r-x,other::rwx"
	u := fmt.Sprintf("https://%s.dfs.core.windows.net/fs/dir1", accountName)
	credential, err := azdatalake.NewSharedKeyCredential(accountName, accountKey)
	handleError(err)
	dirClient, err := directory.NewClientWithSharedKeyCredential(u, credential, nil)
	handleError(err)
	resp, err := dirClient.Create(context.Background(), nil)
	handleError(err)

	currentTime := getRelativeTimeFromAnchor(resp.Date, 10)
	opts := &directory.SetAccessControlOptions{
		Owner: &owner,
		Group: &group,
		ACL:   &acl,
		AccessConditions: &directory.AccessConditions{
			ModifiedAccessConditions: &directory.ModifiedAccessConditions{
				IfUnmodifiedSince: &currentTime,
			},
		}}

	_, err = dirClient.SetAccessControl(context.Background(), opts)
	handleError(err)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ACLFailedEntry

type ACLFailedEntry = path.ACLFailedEntry

ACLFailedEntry contains the failed ACL entry (response model).

type AccessConditions

type AccessConditions = path.AccessConditions

AccessConditions identifies path-specific access conditions which you optionally set.

type CPKInfo

type CPKInfo = path.CPKInfo

CPKInfo contains a group of parameters for client provided encryption key.

type CPKScopeInfo

type CPKScopeInfo path.CPKScopeInfo

CPKScopeInfo contains a group of parameters for client provided encryption scope.

type Client

Client represents a URL to the Azure Datalake Storage service.

func NewClient

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

NewClient creates an instance of Client with the specified values.

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

func NewClientFromConnectionString

func NewClientFromConnectionString(connectionString string, dirPath, fsName 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(directoryURL 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.

  • directoryURL - the URL of the storage account e.g. https://<account>.dfs.core.windows.net/fs/dir?<sas token>
  • options - client options; pass nil to accept the default values

func NewClientWithSharedKeyCredential

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

NewClientWithSharedKeyCredential creates an instance of Client with the specified values.

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

func (*Client) BlobURL

func (d *Client) BlobURL() string

BlobURL returns the URL endpoint used by the Client object.

func (*Client) Create

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

Create creates a new directory.

func (*Client) DFSURL

func (d *Client) DFSURL() string

DFSURL returns the URL endpoint used by the Client object.

func (*Client) Delete

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

Delete deletes directory and any path under it.

func (*Client) GetAccessControl

func (d *Client) GetAccessControl(ctx context.Context, options *GetAccessControlOptions) (GetAccessControlResponse, error)

GetAccessControl gets the owner, owning group, and permissions for a directory.

func (*Client) GetProperties

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

GetProperties gets the properties of a directory.

func (*Client) GetSASURL

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

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

func (*Client) NewFileClient

func (d *Client) NewFileClient(fileName string) (*file.Client, error)

NewFileClient 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) NewSubdirectoryClient added in v1.1.0

func (d *Client) NewSubdirectoryClient(subdirectoryName string) (*Client, error)

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

func (*Client) RemoveAccessControlRecursive

func (d *Client) RemoveAccessControlRecursive(ctx context.Context, ACL string, options *RemoveAccessControlRecursiveOptions) (SetAccessControlRecursiveResponse, error)

RemoveAccessControlRecursive removes the owner, owning group, and permissions for a directory.

func (*Client) Rename

func (d *Client) Rename(ctx context.Context, destinationPath string, options *RenameOptions) (RenameResponse, error)

Rename renames a directory. The original directory will no longer exist and the client will be stale.

func (*Client) SetAccessControl

func (d *Client) SetAccessControl(ctx context.Context, options *SetAccessControlOptions) (SetAccessControlResponse, error)

SetAccessControl sets the owner, owning group, and permissions for a directory.

func (*Client) SetAccessControlRecursive

func (d *Client) SetAccessControlRecursive(ctx context.Context, ACL string, options *SetAccessControlRecursiveOptions) (SetAccessControlRecursiveResponse, error)

SetAccessControlRecursive sets the owner, owning group, and permissions for a directory.

func (*Client) SetHTTPHeaders

func (d *Client) SetHTTPHeaders(ctx context.Context, httpHeaders HTTPHeaders, options *SetHTTPHeadersOptions) (SetHTTPHeadersResponse, error)

SetHTTPHeaders sets the HTTP headers for a directory.

func (*Client) SetMetadata

func (d *Client) SetMetadata(ctx context.Context, metadata map[string]*string, options *SetMetadataOptions) (SetMetadataResponse, error)

SetMetadata sets the metadata for a directory.

func (*Client) UpdateAccessControlRecursive

func (d *Client) UpdateAccessControlRecursive(ctx context.Context, ACL string, options *UpdateAccessControlRecursiveOptions) (SetAccessControlRecursiveResponse, error)

UpdateAccessControlRecursive updates the owner, owning group, and permissions for a directory.

type ClientOptions

type ClientOptions base.ClientOptions

ClientOptions contains the optional parameters when creating a Client.

type CreateOptions

type CreateOptions struct {
	// AccessConditions contains parameters for accessing the file.
	AccessConditions *AccessConditions
	// CPKInfo contains a group of parameters for client provided encryption key.
	CPKInfo *CPKInfo
	// HTTPHeaders contains the HTTP headers for path operations.
	HTTPHeaders *HTTPHeaders
	// LeaseDuration specifies the duration of the lease, in seconds, or negative one
	// (-1) for a lease that never expires. A non-infinite lease can be
	// between 15 and 60 seconds.
	LeaseDuration *int64
	// ProposedLeaseID specifies the proposed lease ID for the file.
	ProposedLeaseID *string
	// Permissions is the octal representation of the permissions for user, group and mask.
	Permissions *string
	// Umask is the umask for the file.
	Umask *string
	// Owner is the owner of the file.
	Owner *string
	// Group is the owning group of the file.
	Group *string
	// ACL is the access control list for the file.
	ACL *string
}

CreateOptions contains the optional parameters when calling the Create operation.

type CreateResponse

type CreateResponse = path.CreateResponse

CreateResponse contains the response fields for the Create operation.

type DeleteOptions

type DeleteOptions = path.DeleteOptions

DeleteOptions contains the optional parameters when calling the Delete operation.

type DeleteResponse

type DeleteResponse = path.DeleteResponse

DeleteResponse contains the response fields for the Delete operation.

type EncryptionAlgorithmType

type EncryptionAlgorithmType = path.EncryptionAlgorithmType

EncryptionAlgorithmType defines values for EncryptionAlgorithmType.

const (
	EncryptionAlgorithmTypeNone   EncryptionAlgorithmType = path.EncryptionAlgorithmTypeNone
	EncryptionAlgorithmTypeAES256 EncryptionAlgorithmType = path.EncryptionAlgorithmTypeAES256
)

type GetAccessControlOptions

type GetAccessControlOptions = path.GetAccessControlOptions

GetAccessControlOptions contains the optional parameters when calling the GetAccessControl operation.

type GetAccessControlResponse

type GetAccessControlResponse = path.GetAccessControlResponse

GetAccessControlResponse contains the response fields for the GetAccessControl operation.

type GetPropertiesOptions

type GetPropertiesOptions = path.GetPropertiesOptions

GetPropertiesOptions contains the optional parameters for the GetProperties method.

type GetPropertiesResponse

type GetPropertiesResponse = path.GetPropertiesResponse

GetPropertiesResponse contains the response fields for the GetProperties operation.

type GetSASURLOptions

type GetSASURLOptions = path.GetSASURLOptions

GetSASURLOptions contains the optional parameters for the GetSASURL method.

type HTTPHeaders

type HTTPHeaders = path.HTTPHeaders

HTTPHeaders contains the HTTP headers for path operations.

type LeaseAccessConditions

type LeaseAccessConditions = path.LeaseAccessConditions

LeaseAccessConditions contains optional parameters to access leased entity.

type ModifiedAccessConditions

type ModifiedAccessConditions = path.ModifiedAccessConditions

ModifiedAccessConditions contains a group of parameters for specifying access conditions.

type RemoveAccessControlRecursiveOptions

type RemoveAccessControlRecursiveOptions = accessControlRecursiveOptions

RemoveAccessControlRecursiveOptions contains the optional parameters when calling the RemoveAccessControlRecursive operation.

type RemoveAccessControlRecursiveResponse

type RemoveAccessControlRecursiveResponse = setAccessControlRecursiveResponse

RemoveAccessControlRecursiveResponse contains the response fields for the RemoveAccessControlRecursive operation.

type RenameOptions

type RenameOptions = path.RenameOptions

RenameOptions contains the optional parameters when calling the Rename operation.

type RenameResponse

type RenameResponse = path.RenameResponse

RenameResponse contains the response fields for the Rename operation.

type SetAccessControlOptions

type SetAccessControlOptions = path.SetAccessControlOptions

SetAccessControlOptions contains the optional parameters when calling the SetAccessControl operation.

type SetAccessControlRecursiveOptions

type SetAccessControlRecursiveOptions = accessControlRecursiveOptions

SetAccessControlRecursiveOptions contains the optional parameters when calling the UpdateAccessControlRecursive operation.

type SetAccessControlRecursiveResponse

type SetAccessControlRecursiveResponse = setAccessControlRecursiveResponse

SetAccessControlRecursiveResponse contains the response fields for the SetAccessControlRecursive operation.

type SetAccessControlResponse

type SetAccessControlResponse = path.SetAccessControlResponse

SetAccessControlResponse contains the response fields for the SetAccessControl operation.

type SetHTTPHeadersOptions

type SetHTTPHeadersOptions = path.SetHTTPHeadersOptions

SetHTTPHeadersOptions contains the optional parameters for the SetHTTPHeaders method.

type SetHTTPHeadersResponse

type SetHTTPHeadersResponse = path.SetHTTPHeadersResponse

SetHTTPHeadersResponse contains the response from method Client.SetHTTPHeaders.

type SetMetadataOptions

type SetMetadataOptions = path.SetMetadataOptions

SetMetadataOptions provides set of configurations for SetMetadata.

type SetMetadataResponse

type SetMetadataResponse = path.SetMetadataResponse

SetMetadataResponse contains the response fields for the SetMetadata operation.

type SharedKeyCredential

type SharedKeyCredential = path.SharedKeyCredential

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

type SourceAccessConditions

type SourceAccessConditions = path.SourceAccessConditions

SourceAccessConditions identifies source path-specific access conditions which you optionally set.

type SourceModifiedAccessConditions

type SourceModifiedAccessConditions = path.SourceModifiedAccessConditions

SourceModifiedAccessConditions contains a group of parameters for specifying source access conditions.

type UpdateAccessControlRecursiveOptions

type UpdateAccessControlRecursiveOptions = accessControlRecursiveOptions

UpdateAccessControlRecursiveOptions contains the optional parameters when calling the UpdateAccessControlRecursive operation.

type UpdateAccessControlRecursiveResponse

type UpdateAccessControlRecursiveResponse = setAccessControlRecursiveResponse

UpdateAccessControlRecursiveResponse contains the response fields for the UpdateAccessControlRecursive operation.

Jump to

Keyboard shortcuts

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