Skip to content
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

Blobs GA Final APIView comments #19906

Merged
merged 10 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 0 deletions sdk/storage/azblob/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* `CpkScopeInfo` -> `CPKScopeInfo`
* `RuleId` -> `RuleID`
* `PolicyId` -> `PolicyID`
* `CorsRule` -> `CORSRule`
* Remove `AccountServices` it is now hardcoded to blobs

### Other Changes

Expand Down
2 changes: 0 additions & 2 deletions sdk/storage/azblob/appendblob/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1771,7 +1771,6 @@ func (s *AppendBlobRecordedTestsSuite) TestAppendBlockPermanentDelete() {
Protocol: sas.ProtocolHTTPS, // Users MUST use HTTPS (not HTTP)
ExpiryTime: time.Now().UTC().Add(48 * time.Hour), // 48-hours before expiration
Permissions: to.Ptr(sas.AccountPermissions{Read: true, List: true, PermanentDelete: true}).String(),
Services: to.Ptr(sas.AccountServices{Blob: true}).String(),
ResourceTypes: to.Ptr(sas.AccountResourceTypes{Container: true, Object: true}).String(),
}.SignWithSharedKey(credential)
_require.Nil(err)
Expand Down Expand Up @@ -1881,7 +1880,6 @@ func (s *AppendBlobRecordedTestsSuite) TestAppendBlockPermanentDeleteWithoutPerm
Protocol: sas.ProtocolHTTPS, // Users MUST use HTTPS (not HTTP)
ExpiryTime: time.Now().UTC().Add(48 * time.Hour), // 48-hours before expiration
Permissions: to.Ptr(sas.AccountPermissions{Read: true, List: true}).String(),
Services: to.Ptr(sas.AccountServices{Blob: true}).String(),
ResourceTypes: to.Ptr(sas.AccountResourceTypes{Container: true, Object: true}).String(),
}.SignWithSharedKey(credential)
_require.Nil(err)
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/azblob/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/azblob",
"Tag": "go/storage/azblob_cf2a55eeaa"
"Tag": "go/storage/azblob_46e572d43a"
}
4 changes: 0 additions & 4 deletions sdk/storage/azblob/blob/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ func (s *BlobUnrecordedTestsSuite) TestCreateBlobClientWithSnapshotAndSAS() {
Protocol: sas.ProtocolHTTPS,
ExpiryTime: currentTime,
Permissions: to.Ptr(sas.AccountPermissions{Read: true, List: true}).String(),
Services: to.Ptr(sas.AccountServices{Blob: true}).String(),
ResourceTypes: to.Ptr(sas.AccountResourceTypes{Container: true, Object: true}).String(),
}.SignWithSharedKey(credential)
_require.Nil(err)
Expand Down Expand Up @@ -159,7 +158,6 @@ func (s *BlobUnrecordedTestsSuite) TestCreateBlobClientWithSnapshotAndSASUsingCo
Protocol: sas.ProtocolHTTPS,
ExpiryTime: currentTime,
Permissions: to.Ptr(sas.AccountPermissions{Read: true, List: true}).String(),
Services: to.Ptr(sas.AccountServices{Blob: true}).String(),
ResourceTypes: to.Ptr(sas.AccountResourceTypes{Container: true, Object: true}).String(),
}.SignWithSharedKey(credential)
_require.Nil(err)
Expand Down Expand Up @@ -3032,7 +3030,6 @@ func (s *BlobRecordedTestsSuite) TestPermanentDelete() {
Protocol: sas.ProtocolHTTPS, // Users MUST use HTTPS (not HTTP)
ExpiryTime: time.Now().UTC().Add(48 * time.Hour), // 48-hours before expiration
Permissions: to.Ptr(sas.AccountPermissions{Read: true, List: true, PermanentDelete: true}).String(),
Services: to.Ptr(sas.AccountServices{Blob: true}).String(),
ResourceTypes: to.Ptr(sas.AccountResourceTypes{Container: true, Object: true}).String(),
}.SignWithSharedKey(credential)
_require.Nil(err)
Expand Down Expand Up @@ -3143,7 +3140,6 @@ func (s *BlobRecordedTestsSuite) TestPermanentDeleteWithoutPermission() {
Protocol: sas.ProtocolHTTPS, // Users MUST use HTTPS (not HTTP)
ExpiryTime: time.Now().UTC().Add(48 * time.Hour), // 48-hours before expiration
Permissions: to.Ptr(sas.AccountPermissions{Read: true, List: true}).String(),
Services: to.Ptr(sas.AccountServices{Blob: true}).String(),
ResourceTypes: to.Ptr(sas.AccountResourceTypes{Container: true, Object: true}).String(),
}.SignWithSharedKey(credential)
_require.Nil(err)
Expand Down
2 changes: 0 additions & 2 deletions sdk/storage/azblob/blockblob/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1316,7 +1316,6 @@ func (s *BlockBlobUnrecordedTestsSuite) TestSetTierOnCopyBlockBlobFromURL() {
Protocol: sas.ProtocolHTTPS,
ExpiryTime: expiryTime,
Permissions: to.Ptr(sas.AccountPermissions{Read: true, List: true}).String(),
Services: to.Ptr(sas.AccountServices{Blob: true}).String(),
ResourceTypes: to.Ptr(sas.AccountResourceTypes{Container: true, Object: true}).String(),
}.SignWithSharedKey(credential)
_require.Nil(err)
Expand Down Expand Up @@ -2861,7 +2860,6 @@ func (s *BlockBlobUnrecordedTestsSuite) TestFilterBlobsWithTags() {
// Protocol: SASProtocolHTTPS,
// ExpiryTime: time.Now().UTC().Add(48 * time.Hour),
// Permissions: AccountSASPermissions{Read: true, List: true, Write: true, DeletePreviousVersion: true, Tag: true, FilterByTags: true, Create: true}.String(),
// Services: AccountSASServices{Blob: true}.String(),
// ResourceTypes: AccountSASResourceTypes{Service: true, Container: true, Object: true}.String(),
// }.Sign(credential)
// if err != nil {
Expand Down
23 changes: 23 additions & 0 deletions sdk/storage/azblob/internal/generated/autorest.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,34 @@ directive:
```

### Change CPK acronym to be all caps

``` yaml
directive:
- from: source-file-go
where: $
transform: >-
return $.
replace(/Cpk/g, "CPK");
```

### Change CORS acronym to be all caps

``` yaml
directive:
- from: source-file-go
where: $
transform: >-
return $.
replace(/Cors/g, "CORS");
```

### Change cors xml to be correct

``` yaml
directive:
- from: source-file-go
where: $
transform: >-
return $.
replace(/xml:"CORS>CORSRule"/g, "xml:\"Cors>CorsRule\"");
```
6 changes: 3 additions & 3 deletions sdk/storage/azblob/internal/generated/zz_models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions sdk/storage/azblob/internal/generated/zz_models_serde.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions sdk/storage/azblob/pageblob/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4037,7 +4037,6 @@ func (s *PageBlobRecordedTestsSuite) TestPageBlockPermanentDelete() {
Protocol: sas.ProtocolHTTPS, // Users MUST use HTTPS (not HTTP)
ExpiryTime: time.Now().UTC().Add(48 * time.Hour), // 48-hours before expiration
Permissions: to.Ptr(sas.AccountPermissions{Read: true, List: true, PermanentDelete: true}).String(),
Services: to.Ptr(sas.AccountServices{Blob: true}).String(),
ResourceTypes: to.Ptr(sas.AccountResourceTypes{Container: true, Object: true}).String(),
}.SignWithSharedKey(credential)
_require.Nil(err)
Expand Down Expand Up @@ -4155,7 +4154,6 @@ func (s *PageBlobRecordedTestsSuite) TestPageBlockPermanentDeleteWithoutPermissi
Protocol: sas.ProtocolHTTPS, // Users MUST use HTTPS (not HTTP)
ExpiryTime: time.Now().UTC().Add(48 * time.Hour), // 48-hours before expiration
Permissions: to.Ptr(sas.AccountPermissions{Read: true, List: true}).String(),
Services: to.Ptr(sas.AccountServices{Blob: true}).String(),
ResourceTypes: to.Ptr(sas.AccountResourceTypes{Container: true, Object: true}).String(),
}.SignWithSharedKey(credential)
_require.Nil(err)
Expand Down
30 changes: 4 additions & 26 deletions sdk/storage/azblob/sas/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ type AccountSignatureValues struct {
ExpiryTime time.Time `param:"se"` // Not specified if IsZero
Permissions string `param:"sp"` // Create by initializing a AccountSASPermissions and then call String()
IPRange IPRange `param:"sip"`
Services string `param:"ss"` // Create by initializing AccountSASServices and then call String()
services string `param:"ss"` // will always be "b"
ResourceTypes string `param:"srt"` // Create by initializing AccountSASResourceTypes and then call String()
}

// SignWithSharedKey uses an account's shared key credential to sign this signature values to produce
// the proper SAS query parameters.
func (v AccountSignatureValues) SignWithSharedKey(sharedKeyCredential *SharedKeyCredential) (QueryParameters, error) {
// https://docs.microsoft.com/en-us/rest/api/storageservices/Constructing-an-Account-SAS
if v.ExpiryTime.IsZero() || v.Permissions == "" || v.ResourceTypes == "" || v.Services == "" {
if v.ExpiryTime.IsZero() || v.Permissions == "" || v.ResourceTypes == "" {
return QueryParameters{}, errors.New("account SAS is missing at least one of these: ExpiryTime, Permissions, Service, or ResourceType")
}
if v.Version == "" {
Expand All @@ -56,7 +56,7 @@ func (v AccountSignatureValues) SignWithSharedKey(sharedKeyCredential *SharedKey
stringToSign := strings.Join([]string{
sharedKeyCredential.AccountName(),
v.Permissions,
v.Services,
"b", // blob service
v.ResourceTypes,
startTime,
expiryTime,
Expand All @@ -80,7 +80,7 @@ func (v AccountSignatureValues) SignWithSharedKey(sharedKeyCredential *SharedKey
ipRange: v.IPRange,

// Account-specific SAS parameters
services: v.Services,
services: v.services,
resourceTypes: v.ResourceTypes,

// Calculated SAS signature
Expand Down Expand Up @@ -180,28 +180,6 @@ func parseAccountPermissions(s string) (AccountPermissions, error) {
return p, nil
}

// AccountServices type simplifies creating the services string for an Azure Storage Account SAS.
// Initialize an instance of this type and then call its String method to set AccountSASSignatureValues' Services field.
type AccountServices struct {
Blob, Queue, File bool
}

// String produces the SAS services string for an Azure Storage account.
// Call this method to set AccountSASSignatureValues' Services field.
func (s *AccountServices) String() string {
var buffer bytes.Buffer
if s.Blob {
buffer.WriteRune('b')
}
if s.Queue {
buffer.WriteRune('q')
}
if s.File {
buffer.WriteRune('f')
}
return buffer.String()
}

// AccountResourceTypes type simplifies creating the resource types string for an Azure Storage Account SAS.
// Initialize an instance of this type and then call its String method to set AccountSASSignatureValues' ResourceTypes field.
type AccountResourceTypes struct {
Expand Down
19 changes: 0 additions & 19 deletions sdk/storage/azblob/sas/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,25 +112,6 @@ func TestAccountPermissions_ParseNegative(t *testing.T) {
require.Contains(t, err.Error(), "122")
}

func TestAccountServices_String(t *testing.T) {
testdata := []struct {
input AccountServices
expected string
}{
{input: AccountServices{Blob: true}, expected: "b"},
{input: AccountServices{Queue: true}, expected: "q"},
{input: AccountServices{File: true}, expected: "f"},
{input: AccountServices{
Blob: true,
Queue: true,
File: true,
}, expected: "bqf"},
}
for _, c := range testdata {
require.Equal(t, c.expected, c.input.String())
}
}

func TestAccountResourceTypes_String(t *testing.T) {
testdata := []struct {
input AccountResourceTypes
Expand Down
3 changes: 1 addition & 2 deletions sdk/storage/azblob/service/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func (s *Client) GetStatistics(ctx context.Context, o *GetStatisticsOptions) (Ge

// 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 (s *Client) GetSASURL(resources sas.AccountResourceTypes, permissions sas.AccountPermissions, services sas.AccountServices, expiry time.Time, o *GetSASURLOptions) (string, error) {
func (s *Client) GetSASURL(resources sas.AccountResourceTypes, permissions sas.AccountPermissions, expiry time.Time, o *GetSASURLOptions) (string, error) {
if s.sharedKey() == nil {
return "", bloberror.MissingSharedKeyCredential
}
Expand All @@ -252,7 +252,6 @@ func (s *Client) GetSASURL(resources sas.AccountResourceTypes, permissions sas.A
Version: sas.Version,
Protocol: sas.ProtocolHTTPS,
Permissions: permissions.String(),
Services: services.String(),
ResourceTypes: resources.String(),
StartTime: st,
ExpiryTime: expiry.UTC(),
Expand Down
45 changes: 20 additions & 25 deletions sdk/storage/azblob/service/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func (s *ServiceRecordedTestsSuite) TestSetPropertiesMinuteMetrics() {
_require.Equal(resp1.MinuteMetrics.RetentionPolicy.Enabled, enabled)
}

func (s *ServiceRecordedTestsSuite) TestSetPropertiesSetCors() {
func (s *ServiceRecordedTestsSuite) TestSetPropertiesSetCORSMultiple() {
_require := require.New(s.T())
svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil)
_require.NoError(err)
Expand All @@ -238,37 +238,37 @@ func (s *ServiceRecordedTestsSuite) TestSetPropertiesSetCors() {

allowedOrigins1 := "www.xyz.com"
allowedMethods1 := "GET"
corsOpts1 := &service.CorsRule{AllowedOrigins: &allowedOrigins1, AllowedMethods: &allowedMethods1}
CORSOpts1 := &service.CORSRule{AllowedOrigins: &allowedOrigins1, AllowedMethods: &allowedMethods1}

allowedOrigins2 := "www.xyz.com,www.ab.com,www.bc.com"
allowedMethods2 := "GET, PUT"
maxAge2 := to.Ptr[int32](500)
exposedHeaders2 := "x-ms-meta-data*,x-ms-meta-source*,x-ms-meta-abc,x-ms-meta-bcd"
allowedHeaders2 := "x-ms-meta-data*,x-ms-meta-target*,x-ms-meta-xyz,x-ms-meta-foo"

corsOpts2 := &service.CorsRule{
CORSOpts2 := &service.CORSRule{
AllowedOrigins: &allowedOrigins2, AllowedMethods: &allowedMethods2,
MaxAgeInSeconds: maxAge2, ExposedHeaders: &exposedHeaders2, AllowedHeaders: &allowedHeaders2}

corsRules := []*service.CorsRule{corsOpts1, corsOpts2}
CORSRules := []*service.CORSRule{CORSOpts1, CORSOpts2}

opts := service.SetPropertiesOptions{Cors: corsRules}
opts := service.SetPropertiesOptions{CORS: CORSRules}
_, err = svcClient.SetProperties(context.Background(), &opts)

_require.Nil(err)
resp, err := svcClient.GetProperties(context.Background(), nil)
for i := 0; i < len(resp.Cors); i++ {
if resp.Cors[i].AllowedOrigins == &allowedOrigins1 {
_require.Equal(resp.Cors[i].AllowedMethods, &allowedMethods1)
_require.Equal(resp.Cors[i].MaxAgeInSeconds, defaultAge)
_require.Equal(resp.Cors[i].ExposedHeaders, defaultStr)
_require.Equal(resp.Cors[i].AllowedHeaders, defaultStr)

} else if resp.Cors[i].AllowedOrigins == &allowedOrigins2 {
_require.Equal(resp.Cors[i].AllowedMethods, &allowedMethods2)
_require.Equal(resp.Cors[i].MaxAgeInSeconds, &maxAge2)
_require.Equal(resp.Cors[i].ExposedHeaders, &exposedHeaders2)
_require.Equal(resp.Cors[i].AllowedHeaders, &allowedHeaders2)
for i := 0; i < len(resp.CORS); i++ {
if resp.CORS[i].AllowedOrigins == &allowedOrigins1 {
_require.Equal(resp.CORS[i].AllowedMethods, &allowedMethods1)
_require.Equal(resp.CORS[i].MaxAgeInSeconds, defaultAge)
_require.Equal(resp.CORS[i].ExposedHeaders, defaultStr)
_require.Equal(resp.CORS[i].AllowedHeaders, defaultStr)

} else if resp.CORS[i].AllowedOrigins == &allowedOrigins2 {
_require.Equal(resp.CORS[i].AllowedMethods, &allowedMethods2)
_require.Equal(resp.CORS[i].MaxAgeInSeconds, &maxAge2)
_require.Equal(resp.CORS[i].ExposedHeaders, &exposedHeaders2)
_require.Equal(resp.CORS[i].AllowedHeaders, &allowedHeaders2)
}
}
_require.Nil(err)
Expand Down Expand Up @@ -692,14 +692,12 @@ func (s *ServiceUnrecordedTestsSuite) TestSASServiceClient() {
Update: true,
Delete: true,
}
services := sas.AccountServices{
Blob: true,
}

start := time.Now().Add(-time.Hour)
expiry := start.Add(time.Hour)

opts := service.GetSASURLOptions{StartTime: &start}
sasUrl, err := serviceClient.GetSASURL(resources, permissions, services, expiry, &opts)
sasUrl, err := serviceClient.GetSASURL(resources, permissions, expiry, &opts)
_require.Nil(err)

svcClient, err := service.NewClientWithNoCredential(sasUrl, nil)
Expand Down Expand Up @@ -733,15 +731,12 @@ func (s *ServiceUnrecordedTestsSuite) TestNoSharedKeyCredError() {
Update: true,
Delete: true,
}
services := sas.AccountServices{
Blob: true,
}
start := time.Now().Add(-time.Hour)
expiry := start.Add(time.Hour)
opts := service.GetSASURLOptions{StartTime: &start}

// GetSASURL fails (with MissingSharedKeyCredential) because service client is created without credentials
_, err = serviceClient.GetSASURL(resources, permissions, services, expiry, &opts)
_, err = serviceClient.GetSASURL(resources, permissions, expiry, &opts)
_require.Equal(err, bloberror.MissingSharedKeyCredential)

}
Expand Down
3 changes: 1 addition & 2 deletions sdk/storage/azblob/service/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func Example_service_Client_GetSASURL() {
start := time.Now()
expiry := start.AddDate(1, 0, 0)
options := service.GetSASURLOptions{StartTime: &start}
sasURL, err := serviceClient.GetSASURL(resources, permission, sas.AccountServices{Blob: true}, expiry, &options)
sasURL, err := serviceClient.GetSASURL(resources, permission, expiry, &options)
handleError(err)

serviceURL := fmt.Sprintf("https://<myAccountName>.blob.core.windows.net/?%s", sasURL)
Expand Down Expand Up @@ -267,7 +267,6 @@ func Example_service_SASSignatureValues_Sign() {
Protocol: sas.ProtocolHTTPS,
ExpiryTime: time.Now().UTC().Add(48 * time.Hour),
Permissions: to.Ptr(sas.AccountPermissions{Read: true, List: true}).String(),
Services: to.Ptr(sas.AccountServices{Blob: true}).String(),
ResourceTypes: to.Ptr(sas.AccountResourceTypes{Container: true, Object: true}).String(),
}.SignWithSharedKey(credential)
handleError(err)
Expand Down
Loading