Skip to content

Commit

Permalink
azfile: Service Client (#20035)
Browse files Browse the repository at this point in the history
Service Client
  • Loading branch information
souravgupta-msft authored Feb 23, 2023
1 parent eed7403 commit 573013e
Show file tree
Hide file tree
Showing 22 changed files with 1,078 additions and 77 deletions.
6 changes: 6 additions & 0 deletions sdk/storage/azfile/assets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "go",
"TagPrefix": "go/storage/azfile",
"Tag": "go/storage/azfile_33b8efd383"
}
10 changes: 1 addition & 9 deletions sdk/storage/azfile/directory/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ type ClientOptions struct {
// Client represents a URL to the Azure Storage directory allowing you to manipulate its directories and files.
type Client base.Client[generated.DirectoryClient]

// NewClient creates an instance of Client with the specified values.
// - directoryURL - the URL of the directory e.g. https://<account>.file.core.windows.net/share/directory
// - cred - an Azure AD credential, typically obtained via the azidentity module
// - options - client options; pass nil to accept the default values
func NewClient(directoryURL string, cred azcore.TokenCredential, options *ClientOptions) (*Client, error) {
return nil, nil
}

// NewClientWithNoCredential creates an instance of Client with the specified values.
// This is used to anonymously access a directory or with a shared access signature (SAS) token.
// - directoryURL - the URL of the directory e.g. https://<account>.file.core.windows.net/share/directory?<sas token>
Expand Down Expand Up @@ -66,7 +58,7 @@ func (d *Client) sharedKey() *SharedKeyCredential {

// URL returns the URL endpoint used by the Client object.
func (d *Client) URL() string {
return "s.generated().Endpoint()"
return d.generated().Endpoint()
}

// NewSubdirectoryClient creates a new Client object by concatenating subDirectoryName to the end of this Client's URL.
Expand Down
14 changes: 3 additions & 11 deletions sdk/storage/azfile/file/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ type ClientOptions struct {
// Client represents a URL to the Azure Storage file.
type Client base.Client[generated.FileClient]

// NewClient creates an instance of Client with the specified values.
// - fileURL - the URL of the file e.g. https://<account>.file.core.windows.net/share/directoryPath/file
// - cred - an Azure AD credential, typically obtained via the azidentity module
// - options - client options; pass nil to accept the default values
func NewClient(fileURL string, cred azcore.TokenCredential, options *ClientOptions) (*Client, error) {
return nil, nil
}

// NewClientWithNoCredential creates an instance of Client with the specified values.
// This is used to anonymously access a file or with a shared access signature (SAS) token.
// - fileURL - the URL of the file e.g. https://<account>.file.core.windows.net/share/directoryPath/file?<sas token>
Expand Down Expand Up @@ -67,7 +59,7 @@ func (f *Client) sharedKey() *SharedKeyCredential {

// URL returns the URL endpoint used by the Client object.
func (f *Client) URL() string {
return "s.generated().Endpoint()"
return f.generated().Endpoint()
}

// Create operation creates a new file or replaces a file. Note it only initializes the file with no content.
Expand Down Expand Up @@ -124,12 +116,12 @@ func (f *Client) DownloadStream(ctx context.Context, options *DownloadStreamOpti
return DownloadStreamResponse{}, nil
}

// DownloadBuffer downloads an Azure blob to a buffer with parallel.
// DownloadBuffer downloads an Azure file to a buffer with parallel.
func (f *Client) DownloadBuffer(ctx context.Context, buffer []byte, o *DownloadBufferOptions) (int64, error) {
return 0, nil
}

// DownloadFile downloads an Azure blob to a local file.
// DownloadFile downloads an Azure file to a local file.
// The file would be truncated if the size doesn't match.
func (f *Client) DownloadFile(ctx context.Context, file *os.File, o *DownloadFileOptions) (int64, error) {
return 0, nil
Expand Down
102 changes: 102 additions & 0 deletions sdk/storage/azfile/fileerror/error_codes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
//go:build go1.18
// +build go1.18

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

package fileerror

import (
"errors"

"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/internal/generated"
)

// HasCode returns true if the provided error is an *azcore.ResponseError
// with its ErrorCode field equal to one of the specified Codes.
func HasCode(err error, codes ...Code) bool {
var respErr *azcore.ResponseError
if !errors.As(err, &respErr) {
return false
}

for _, code := range codes {
if respErr.ErrorCode == string(code) {
return true
}
}

return false
}

// Code - Error codes returned by the service
type Code = generated.StorageErrorCode

const (
AccountAlreadyExists Code = "AccountAlreadyExists"
AccountBeingCreated Code = "AccountBeingCreated"
AccountIsDisabled Code = "AccountIsDisabled"
AuthenticationFailed Code = "AuthenticationFailed"
AuthorizationFailure Code = "AuthorizationFailure"
AuthorizationPermissionMismatch Code = "AuthorizationPermissionMismatch"
AuthorizationProtocolMismatch Code = "AuthorizationProtocolMismatch"
AuthorizationResourceTypeMismatch Code = "AuthorizationResourceTypeMismatch"
AuthorizationServiceMismatch Code = "AuthorizationServiceMismatch"
AuthorizationSourceIPMismatch Code = "AuthorizationSourceIPMismatch"
CannotDeleteFileOrDirectory Code = "CannotDeleteFileOrDirectory"
ClientCacheFlushDelay Code = "ClientCacheFlushDelay"
ConditionHeadersNotSupported Code = "ConditionHeadersNotSupported"
ConditionNotMet Code = "ConditionNotMet"
DeletePending Code = "DeletePending"
DirectoryNotEmpty Code = "DirectoryNotEmpty"
EmptyMetadataKey Code = "EmptyMetadataKey"
FeatureVersionMismatch Code = "FeatureVersionMismatch"
FileLockConflict Code = "FileLockConflict"
InsufficientAccountPermissions Code = "InsufficientAccountPermissions"
InternalError Code = "InternalError"
InvalidAuthenticationInfo Code = "InvalidAuthenticationInfo"
InvalidFileOrDirectoryPathName Code = "InvalidFileOrDirectoryPathName"
InvalidHTTPVerb Code = "InvalidHttpVerb"
InvalidHeaderValue Code = "InvalidHeaderValue"
InvalidInput Code = "InvalidInput"
InvalidMD5 Code = "InvalidMd5"
InvalidMetadata Code = "InvalidMetadata"
InvalidQueryParameterValue Code = "InvalidQueryParameterValue"
InvalidRange Code = "InvalidRange"
InvalidResourceName Code = "InvalidResourceName"
InvalidURI Code = "InvalidUri"
InvalidXMLDocument Code = "InvalidXmlDocument"
InvalidXMLNodeValue Code = "InvalidXmlNodeValue"
MD5Mismatch Code = "Md5Mismatch"
MetadataTooLarge Code = "MetadataTooLarge"
MissingContentLengthHeader Code = "MissingContentLengthHeader"
MissingRequiredHeader Code = "MissingRequiredHeader"
MissingRequiredQueryParameter Code = "MissingRequiredQueryParameter"
MissingRequiredXMLNode Code = "MissingRequiredXmlNode"
MultipleConditionHeadersNotSupported Code = "MultipleConditionHeadersNotSupported"
OperationTimedOut Code = "OperationTimedOut"
OutOfRangeInput Code = "OutOfRangeInput"
OutOfRangeQueryParameterValue Code = "OutOfRangeQueryParameterValue"
ParentNotFound Code = "ParentNotFound"
ReadOnlyAttribute Code = "ReadOnlyAttribute"
RequestBodyTooLarge Code = "RequestBodyTooLarge"
RequestURLFailedToParse Code = "RequestUrlFailedToParse"
ResourceAlreadyExists Code = "ResourceAlreadyExists"
ResourceNotFound Code = "ResourceNotFound"
ResourceTypeMismatch Code = "ResourceTypeMismatch"
ServerBusy Code = "ServerBusy"
ShareAlreadyExists Code = "ShareAlreadyExists"
ShareBeingDeleted Code = "ShareBeingDeleted"
ShareDisabled Code = "ShareDisabled"
ShareHasSnapshots Code = "ShareHasSnapshots"
ShareNotFound Code = "ShareNotFound"
ShareSnapshotCountExceeded Code = "ShareSnapshotCountExceeded"
ShareSnapshotInProgress Code = "ShareSnapshotInProgress"
ShareSnapshotOperationNotSupported Code = "ShareSnapshotOperationNotSupported"
SharingViolation Code = "SharingViolation"
UnsupportedHTTPVerb Code = "UnsupportedHttpVerb"
UnsupportedHeader Code = "UnsupportedHeader"
UnsupportedQueryParameter Code = "UnsupportedQueryParameter"
UnsupportedXMLNode Code = "UnsupportedXmlNode"
)
12 changes: 10 additions & 2 deletions sdk/storage/azfile/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@ module github.com/Azure/azure-sdk-for-go/sdk/storage/azfile

go 1.18

require github.com/Azure/azure-sdk-for-go/sdk/azcore v1.3.0
require (
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.3.0
github.com/Azure/azure-sdk-for-go/sdk/internal v1.1.1
github.com/stretchr/testify v1.7.0
)

require (
github.com/Azure/azure-sdk-for-go/sdk/internal v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/dnaeon/go-vcr v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
13 changes: 13 additions & 0 deletions sdk/storage/azfile/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,23 @@ github.com/Azure/azure-sdk-for-go/sdk/azcore v1.3.0/go.mod h1:tZoQYdDZNOiIjdSn0d
github.com/Azure/azure-sdk-for-go/sdk/internal v1.1.1 h1:Oj853U9kG+RLTCQXpjvOnrv0WaZHxgmZz1TlLywgOPY=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.1.1/go.mod h1:eWRD7oawr1Mu1sLCawqVc0CUiF43ia3qQMxLscsKQ9w=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dnaeon/go-vcr v1.1.0 h1:ReYa/UBrRyQdant9B4fNHGoCNKw6qh6P0fsdGmZpR7c=
github.com/dnaeon/go-vcr v1.1.0/go.mod h1:M7tiix8f0r6mKKJ3Yq/kqU1OYf3MnfmBWVbPx/yU9ko=
github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 h1:HVyaeDAYux4pnY+D/SiwmLOR36ewZ4iGQIIrtnuCjFA=
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
30 changes: 30 additions & 0 deletions sdk/storage/azfile/internal/base/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
package base

import (
"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/internal/exported"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/internal/generated"
)

type Client[T any] struct {
Expand All @@ -22,3 +24,31 @@ func InnerClient[T any](client *Client[T]) *T {
func SharedKey[T any](client *Client[T]) *exported.SharedKeyCredential {
return client.sharedKey
}

func NewServiceClient(serviceURL string, pipeline runtime.Pipeline, sharedKey *exported.SharedKeyCredential) *Client[generated.ServiceClient] {
return &Client[generated.ServiceClient]{
inner: generated.NewServiceClient(serviceURL, pipeline),
sharedKey: sharedKey,
}
}

func NewShareClient(shareURL string, pipeline runtime.Pipeline, sharedKey *exported.SharedKeyCredential) *Client[generated.ShareClient] {
return &Client[generated.ShareClient]{
inner: generated.NewShareClient(shareURL, pipeline),
sharedKey: sharedKey,
}
}

func NewDirectoryClient(directoryURL string, pipeline runtime.Pipeline, sharedKey *exported.SharedKeyCredential) *Client[generated.DirectoryClient] {
return &Client[generated.DirectoryClient]{
inner: generated.NewDirectoryClient(directoryURL, pipeline),
sharedKey: sharedKey,
}
}

func NewFileClient(fileURL string, pipeline runtime.Pipeline, sharedKey *exported.SharedKeyCredential) *Client[generated.FileClient] {
return &Client[generated.FileClient]{
inner: generated.NewFileClient(fileURL, pipeline),
sharedKey: sharedKey,
}
}
Loading

0 comments on commit 573013e

Please sign in to comment.