Skip to content

azfile: File download methods #20670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 66 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from 62 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
964e4d2
Adding share client
souravgupta-msft Feb 27, 2023
69446ae
More share client methods
souravgupta-msft Feb 28, 2023
bf3d82f
Adding tests for share client
souravgupta-msft Mar 3, 2023
0f48bdc
More tests
souravgupta-msft Mar 6, 2023
1456741
lint
souravgupta-msft Mar 6, 2023
dc37bbd
More tests
souravgupta-msft Mar 7, 2023
99256a6
Few changes
souravgupta-msft Mar 9, 2023
ecbd69b
directory client ctors
souravgupta-msft Mar 9, 2023
25aa885
Removing check for shared key
souravgupta-msft Mar 10, 2023
b3785f0
Merge branch 'sourav/shareClient' of https://github.com/Azure/azure-s…
souravgupta-msft Mar 10, 2023
4759643
Adding directory client apis
souravgupta-msft Mar 10, 2023
a72172b
Adding list files and directories api
souravgupta-msft Mar 14, 2023
fe3bfd7
Adding generate SAS method in directory client
souravgupta-msft Mar 14, 2023
a37d5d3
List and force close handles api
souravgupta-msft Mar 14, 2023
4e508c9
Adding tests for directory client
souravgupta-msft Mar 15, 2023
207f205
More tests
souravgupta-msft Mar 15, 2023
72fb334
Format check
souravgupta-msft Mar 16, 2023
03de239
Merge branch 'feature/azfile' of https://github.com/Azure/azure-sdk-f…
souravgupta-msft Mar 17, 2023
5dadfaf
FileSignatureValues to SignatureValues
souravgupta-msft Mar 17, 2023
c4f769a
Merge branch 'sourav/shareClient' of https://github.com/Azure/azure-s…
souravgupta-msft Mar 17, 2023
560e382
updating GetSASURL()
souravgupta-msft Mar 17, 2023
6df4890
Merge from feature branch
souravgupta-msft Mar 20, 2023
7ae34f5
file client ctors
souravgupta-msft Mar 20, 2023
a202b9a
Adding file client apis
souravgupta-msft Mar 20, 2023
97a0fe4
List and force close handles
souravgupta-msft Mar 21, 2023
d515768
File lease client
souravgupta-msft Mar 21, 2023
26df11e
Share lease client
souravgupta-msft Mar 21, 2023
49f3814
Adding tests
souravgupta-msft Mar 24, 2023
af21402
More tests
souravgupta-msft Mar 27, 2023
e0181a2
More tests
souravgupta-msft Mar 27, 2023
d620cd9
Few changes
souravgupta-msft Mar 28, 2023
cb306cd
Pull from feature branch
souravgupta-msft Mar 29, 2023
1e842b6
Lease client tests
souravgupta-msft Mar 29, 2023
32f9add
More lease client tests
souravgupta-msft Mar 29, 2023
d21f82f
Adding recordings
souravgupta-msft Mar 30, 2023
3d10edb
More recordings
souravgupta-msft Mar 30, 2023
d4da5b0
Update recordings
souravgupta-msft Mar 30, 2023
6913872
Adding recordings for directory client
souravgupta-msft Mar 30, 2023
530b8c7
Updating assets.json
souravgupta-msft Mar 30, 2023
c9a2aec
Adding recordings for share client
souravgupta-msft Mar 31, 2023
3207b8f
Adding recordings for service client
souravgupta-msft Mar 31, 2023
eece2da
Modifying options for CopyFileSMBInfo
souravgupta-msft Apr 4, 2023
293d84b
Adding recordings
souravgupta-msft Apr 4, 2023
65fd26e
Adding upload methods
souravgupta-msft Apr 5, 2023
209791c
Tests
souravgupta-msft Apr 11, 2023
279d149
UploadBuffer and UploadFile methods
souravgupta-msft Apr 11, 2023
7b36269
sync with feature branch
souravgupta-msft Apr 11, 2023
af73603
Adding UploadStream
souravgupta-msft Apr 13, 2023
f2963ea
source crc64 type update
souravgupta-msft Apr 13, 2023
fef6da8
PR comments
souravgupta-msft Apr 17, 2023
dec587e
Adding DownloadBuffer and DownloadStream methods
souravgupta-msft Apr 17, 2023
2947c04
Updating recordings
souravgupta-msft Apr 17, 2023
923b38f
Merge branch 'sourav/fileUpload' of https://github.com/Azure/azure-sd…
souravgupta-msft Apr 17, 2023
4d45e07
Adding tests
souravgupta-msft Apr 18, 2023
1a721b5
Adding tests
souravgupta-msft Apr 18, 2023
2e51d32
More tests
souravgupta-msft Apr 20, 2023
3318754
Adding recordings
souravgupta-msft Apr 20, 2023
a0b6a9d
Lint fix
souravgupta-msft Apr 20, 2023
15dd5a4
More tests
souravgupta-msft Apr 24, 2023
8bca640
tests
souravgupta-msft Apr 24, 2023
60797ea
tests
souravgupta-msft Apr 24, 2023
84f7d49
Removing SAS generation from directory client
souravgupta-msft Apr 24, 2023
a83cda0
sync with feature branch
souravgupta-msft Apr 25, 2023
a55b038
more tests for directory client
souravgupta-msft Apr 25, 2023
bb097d8
More tests
souravgupta-msft Apr 25, 2023
703e18a
Merge branch 'feature/azfile' of https://github.com/Azure/azure-sdk-f…
souravgupta-msft Apr 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/storage/azfile/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "go",
"TagPrefix": "go/storage/azfile",
"Tag": "go/storage/azfile_413a85db89"
"Tag": "go/storage/azfile_41f00dcea9"
}
34 changes: 0 additions & 34 deletions sdk/storage/azfile/directory/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/file"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/fileerror"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/internal/base"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/internal/exported"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/internal/generated"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/internal/shared"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/sas"
"net/http"
"net/url"
"strings"
"time"
)

// ClientOptions contains the optional parameters when creating a Client.
Expand Down Expand Up @@ -209,34 +206,3 @@ func (d *Client) NewListFilesAndDirectoriesPager(options *ListFilesAndDirectorie
},
})
}

// 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 (d *Client) GetSASURL(permissions sas.FilePermissions, expiry time.Time, o *GetSASURLOptions) (string, error) {
if d.sharedKey() == nil {
return "", fileerror.MissingSharedKeyCredential
}
st := o.format()

urlParts, err := sas.ParseURL(d.URL())
if err != nil {
return "", err
}

qps, err := sas.SignatureValues{
Version: sas.Version,
Protocol: sas.ProtocolHTTPS,
ShareName: urlParts.ShareName,
DirectoryOrFilePath: urlParts.DirectoryOrFilePath,
Permissions: permissions.String(),
StartTime: st,
ExpiryTime: expiry.UTC(),
}.SignWithSharedKey(d.sharedKey())
if err != nil {
return "", err
}

endpoint := d.URL() + "?" + qps.Encode()

return endpoint, nil
}
110 changes: 0 additions & 110 deletions sdk/storage/azfile/directory/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@ package directory_test

import (
"context"
"fmt"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/internal/recording"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/directory"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/file"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/fileerror"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/internal/testcommon"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/sas"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/service"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"testing"
Expand Down Expand Up @@ -219,63 +216,6 @@ func (d *DirectoryRecordedTestsSuite) TestDirectoryCreateNegativeMultiLevel() {
testcommon.ValidateFileErrorCode(_require, err, fileerror.ParentNotFound)
}

func (d *DirectoryUnrecordedTestsSuite) TestDirectoryClientUsingSAS() {
_require := require.New(d.T())
testName := d.T().Name()

svcClient, err := testcommon.GetServiceClient(d.T(), testcommon.TestAccountDefault, nil)
_require.NoError(err)

shareName := testcommon.GenerateShareName(testName)
shareClient := testcommon.CreateNewShare(context.Background(), _require, shareName, svcClient)
defer testcommon.DeleteShare(context.Background(), _require, shareClient)

dirClient := testcommon.CreateNewDirectory(context.Background(), _require, testcommon.GenerateDirectoryName(testName), shareClient)

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

dirSASURL, err := dirClient.GetSASURL(permissions, expiry, nil)
_require.NoError(err)

dirSASClient, err := directory.NewClientWithNoCredential(dirSASURL, nil)
_require.NoError(err)

_, err = dirSASClient.GetProperties(context.Background(), nil)
_require.Error(err)
testcommon.ValidateFileErrorCode(_require, err, fileerror.AuthenticationFailed)

subDirSASClient := dirSASClient.NewSubdirectoryClient("subdir")
_, err = subDirSASClient.Create(context.Background(), nil)
_require.Error(err)
testcommon.ValidateFileErrorCode(_require, err, fileerror.AuthenticationFailed)

// TODO: directory SAS client unable to do create and get properties on directories.
// Also unable to do create or get properties on files. Validate this behaviour.
fileSASClient := dirSASClient.NewFileClient(testcommon.GenerateFileName(testName))
_, err = fileSASClient.Create(context.Background(), 1024, nil)
_require.Error(err)
testcommon.ValidateFileErrorCode(_require, err, fileerror.AuthenticationFailed)

_, err = fileSASClient.GetProperties(context.Background(), nil)
_require.Error(err)
testcommon.ValidateFileErrorCode(_require, err, fileerror.AuthenticationFailed)

// create file using shared key client
_, err = dirClient.NewFileClient(testcommon.GenerateFileName(testName)).Create(context.Background(), 1024, nil)
_require.NoError(err)

// get properties using SAS client
_, err = fileSASClient.GetProperties(context.Background(), nil)
_require.Error(err)
testcommon.ValidateFileErrorCode(_require, err, fileerror.AuthenticationFailed)
}

func (d *DirectoryRecordedTestsSuite) TestDirCreateDeleteDefault() {
_require := require.New(d.T())
testName := d.T().Name()
Expand Down Expand Up @@ -739,56 +679,6 @@ func (d *DirectoryRecordedTestsSuite) TestDirGetSetMetadataMergeAndReplace() {
_require.EqualValues(gResp.Metadata, md2)
}

func (d *DirectoryRecordedTestsSuite) TestSASDirectoryClientNoKey() {
_require := require.New(d.T())
accountName, _ := testcommon.GetGenericAccountInfo(testcommon.TestAccountDefault)
_require.Greater(len(accountName), 0)

testName := d.T().Name()
shareName := testcommon.GenerateShareName(testName)
dirName := testcommon.GenerateDirectoryName(testName)
dirClient, err := directory.NewClientWithNoCredential(fmt.Sprintf("https://%s.file.core.windows.net/%v/%v", accountName, shareName, dirName), nil)
_require.NoError(err)

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

_, err = dirClient.GetSASURL(permissions, expiry, nil)
_require.Equal(err, fileerror.MissingSharedKeyCredential)
}

func (d *DirectoryRecordedTestsSuite) TestSASDirectoryClientSignNegative() {
_require := require.New(d.T())
accountName, accountKey := testcommon.GetGenericAccountInfo(testcommon.TestAccountDefault)
_require.Greater(len(accountName), 0)
_require.Greater(len(accountKey), 0)

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

testName := d.T().Name()
shareName := testcommon.GenerateShareName(testName)
dirName := testcommon.GenerateDirectoryName(testName)
dirClient, err := directory.NewClientWithSharedKeyCredential(fmt.Sprintf("https://%s.file.core.windows.net/%v%v", accountName, shareName, dirName), cred, nil)
_require.NoError(err)

permissions := sas.FilePermissions{
Read: true,
Write: true,
Delete: true,
Create: true,
}
expiry := time.Time{}

_, err = dirClient.GetSASURL(permissions, expiry, nil)
_require.Equal(err.Error(), "service SAS is missing at least one of these: ExpiryTime or Permissions")
}

// TODO: add tests for listing files and directories after file client is completed

// TODO: add tests for ListHandles and ForceCloseHandles
24 changes: 1 addition & 23 deletions sdk/storage/azfile/directory/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/internal/generated"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/internal/shared"
"reflect"
"time"
)

// SharedKeyCredential contains an account's name and its primary or secondary key.
Expand Down Expand Up @@ -158,7 +157,7 @@ func (l ListFilesInclude) format() []generated.ListFilesIncludeType {
return nil
}

include := []generated.ListFilesIncludeType{}
var include []generated.ListFilesIncludeType

if l.Timestamps {
include = append(include, ListFilesIncludeTypeTimestamps)
Expand Down Expand Up @@ -190,27 +189,6 @@ type FileProperty = generated.FileProperty

// ---------------------------------------------------------------------------------------------------------------------

// GetSASURLOptions contains the optional parameters for the Client.GetSASURL method.
type GetSASURLOptions struct {
StartTime *time.Time
}

func (o *GetSASURLOptions) format() time.Time {
if o == nil {
return time.Time{}
}

var st time.Time
if o.StartTime != nil {
st = o.StartTime.UTC()
} else {
st = time.Time{}
}
return st
}

// ---------------------------------------------------------------------------------------------------------------------

// ListHandlesOptions contains the optional parameters for the Client.ListHandles method.
type ListHandlesOptions struct {
// A string value that identifies the portion of the list to be returned with the next list operation. The operation returns
Expand Down
Loading