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

Fixups for 2023-11-03 SDK #101

Merged
merged 2 commits into from
Feb 8, 2024
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: 1 addition & 1 deletion storage/2020-08-04/queue/queues/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Cors struct {
type CorsRule struct {
AllowedOrigins string `xml:"AllowedOrigins"`
AllowedMethods string `xml:"AllowedMethods"`
AllowedHeaders string `xml:"AllowedHeaders`
AllowedHeaders string `xml:"AllowedHeaders"`
ExposedHeaders string `xml:"ExposedHeaders"`
MaxAgeInSeconds int `xml:"MaxAgeInSeconds"`
}
29 changes: 17 additions & 12 deletions storage/2023-11-03/blob/accounts/get_service_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (
)

type GetServicePropertiesResult struct {
HttpResponse *client.Response
Model *StorageServiceProperties
StorageServiceProperties
HttpResponse *http.Response
}

func (c Client) GetServiceProperties(ctx context.Context, accountName string) (resp GetServicePropertiesResult, err error) {
func (c Client) GetServiceProperties(ctx context.Context, accountName string) (result GetServicePropertiesResult, err error) {
if accountName == "" {
return resp, fmt.Errorf("`accountName` cannot be an empty string")
return result, fmt.Errorf("`accountName` cannot be an empty string")
}

opts := client.RequestOptions{
Expand All @@ -27,23 +27,28 @@ func (c Client) GetServiceProperties(ctx context.Context, accountName string) (r
OptionsObject: servicePropertiesOptions{},
Path: "/",
}

req, err := c.Client.NewRequest(ctx, opts)
if err != nil {
err = fmt.Errorf("building request: %+v", err)
return
}
resp.HttpResponse, err = req.Execute(ctx)
if err != nil {
err = fmt.Errorf("executing request: %+v", err)
return
}

if resp.HttpResponse != nil {
if err = resp.HttpResponse.Unmarshal(&resp.Model); err != nil {
err = fmt.Errorf("unmarshaling response: %+v", err)
var resp *client.Response
resp, err = req.Execute(ctx)
if resp != nil {
result.HttpResponse = resp.Response

err = resp.Unmarshal(&result)
if err != nil {
err = fmt.Errorf("unmarshalling response: %+v", err)
return
}
}
if err != nil {
err = fmt.Errorf("executing request: %+v", err)
return
}

return
}
15 changes: 11 additions & 4 deletions storage/2023-11-03/blob/accounts/set_service_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
)

type SetServicePropertiesResult struct {
HttpResponse *client.Response
HttpResponse *http.Response
}

func (c Client) SetServiceProperties(ctx context.Context, accountName string, input StorageServiceProperties) (resp SetServicePropertiesResult, err error) {
func (c Client) SetServiceProperties(ctx context.Context, accountName string, input StorageServiceProperties) (result SetServicePropertiesResult, err error) {
if accountName == "" {
return resp, fmt.Errorf("`accountName` cannot be an empty string")
return result, fmt.Errorf("`accountName` cannot be an empty string")
}

opts := client.RequestOptions{
Expand All @@ -26,16 +26,23 @@ func (c Client) SetServiceProperties(ctx context.Context, accountName string, in
OptionsObject: servicePropertiesOptions{},
Path: "/",
}

req, err := c.Client.NewRequest(ctx, opts)
if err != nil {
err = fmt.Errorf("building request: %+v", err)
return
}

if err = req.Marshal(&input); err != nil {
err = fmt.Errorf("marshaling request: %+v", err)
return
}
resp.HttpResponse, err = req.Execute(ctx)

var resp *client.Response
resp, err = req.Execute(ctx)
if resp != nil {
result.HttpResponse = resp.Response
}
if err != nil {
err = fmt.Errorf("executing request: %+v", err)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ func TestContainerLifecycle(t *testing.T) {
t.Fatal(fmt.Errorf("error getting properties: %s", err))
}

website := result.Model.StaticWebsite
website := result.StaticWebsite
if website.Enabled != true {
t.Fatalf("Expected the StaticWebsite %t but got %t", true, website.Enabled)
}

logging := result.Model.Logging
logging := result.Logging
if logging.Version != "2.0" {
t.Fatalf("Expected the Logging Version %s but got %s", "2.0", logging.Version)
}
Expand Down
2 changes: 1 addition & 1 deletion storage/2023-11-03/blob/blobs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func Example() error {

blobClient, err := blobs.NewWithBaseUri(fmt.Sprintf("https://%s.blob.%s", accountName, domainSuffix))
if err != nil {
return fmt.Errorf("building client for environment: %+v", err)
return fmt.Errorf("building client for environment: %v", err)
}

auth, err := auth.NewSharedKeyAuthorizer(accountName, storageAccountKey, auth.SharedKey)
Expand Down
48 changes: 26 additions & 22 deletions storage/2023-11-03/blob/blobs/append_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type AppendBlockInput struct {
}

type AppendBlockResponse struct {
HttpResponse *client.Response
HttpResponse *http.Response

BlobAppendOffset string
BlobCommittedBlockCount int64
Expand All @@ -56,22 +56,25 @@ type AppendBlockResponse struct {
}

// AppendBlock commits a new block of data to the end of an existing append blob.
func (c Client) AppendBlock(ctx context.Context, containerName, blobName string, input AppendBlockInput) (resp AppendBlockResponse, err error) {

func (c Client) AppendBlock(ctx context.Context, containerName, blobName string, input AppendBlockInput) (result AppendBlockResponse, err error) {
if containerName == "" {
return resp, fmt.Errorf("`containerName` cannot be an empty string")
err = fmt.Errorf("`containerName` cannot be an empty string")
return
}

if strings.ToLower(containerName) != containerName {
return resp, fmt.Errorf("`containerName` must be a lower-cased string")
err = fmt.Errorf("`containerName` must be a lower-cased string")
return
}

if blobName == "" {
return resp, fmt.Errorf("`blobName` cannot be an empty string")
err = fmt.Errorf("`blobName` cannot be an empty string")
return
}

if input.Content != nil && len(*input.Content) > (4*1024*1024) {
return resp, fmt.Errorf("`input.Content` must be at most 4MB")
err = fmt.Errorf("`input.Content` must be at most 4MB")
return
}

opts := client.RequestOptions{
Expand All @@ -97,30 +100,31 @@ func (c Client) AppendBlock(ctx context.Context, containerName, blobName string,

req.ContentLength = int64(len(*input.Content))

resp.HttpResponse, err = req.Execute(ctx)
if err != nil {
err = fmt.Errorf("executing request: %+v", err)
return
}
var resp *client.Response
resp, err = req.Execute(ctx)
if resp != nil {
result.HttpResponse = resp.Response

if resp.HttpResponse != nil {
if resp.HttpResponse.Header != nil {
resp.BlobAppendOffset = resp.HttpResponse.Header.Get("x-ms-blob-append-offset")
resp.ContentMD5 = resp.HttpResponse.Header.Get("Content-MD5")
resp.ETag = resp.HttpResponse.Header.Get("ETag")
resp.LastModified = resp.HttpResponse.Header.Get("Last-Modified")
if resp.Header != nil {
result.BlobAppendOffset = resp.Header.Get("x-ms-blob-append-offset")
result.ContentMD5 = resp.Header.Get("Content-MD5")
result.ETag = resp.Header.Get("ETag")
result.LastModified = resp.Header.Get("Last-Modified")

if v := resp.HttpResponse.Header.Get("x-ms-blob-committed-block-count"); v != "" {
if v := resp.Header.Get("x-ms-blob-committed-block-count"); v != "" {
i, innerErr := strconv.Atoi(v)
if innerErr != nil {
err = fmt.Errorf("error parsing %q as an integer: %s", v, innerErr)
err = fmt.Errorf("parsing `x-ms-blob-committed-block-count` header value %q: %+v", v, innerErr)
return
}
resp.BlobCommittedBlockCount = int64(i)
result.BlobCommittedBlockCount = int64(i)
}

}
}
if err != nil {
err = fmt.Errorf("executing request: %+v", err)
return
}

return
}
Expand Down
4 changes: 2 additions & 2 deletions storage/2023-11-03/blob/blobs/blob_page_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestPageBlobLifecycle(t *testing.T) {
t.Fatalf("building client for environment: %+v", err)
}

if err := client.PrepareWithSharedKeyAuth(containersClient.Client, testData, auth.SharedKey); err != nil {
if err = client.PrepareWithSharedKeyAuth(containersClient.Client, testData, auth.SharedKey); err != nil {
t.Fatalf("adding authorizer to client: %+v", err)
}

Expand All @@ -57,7 +57,7 @@ func TestPageBlobLifecycle(t *testing.T) {
t.Fatalf("building client for environment: %+v", err)
}

if err := client.PrepareWithSharedKeyAuth(blobClient.Client, testData, auth.SharedKey); err != nil {
if err = client.PrepareWithSharedKeyAuth(blobClient.Client, testData, auth.SharedKey); err != nil {
t.Fatalf("adding authorizer to client: %+v", err)
}

Expand Down
31 changes: 16 additions & 15 deletions storage/2023-11-03/blob/blobs/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,29 +106,28 @@ type CopyInput struct {
}

type CopyResponse struct {
HttpResponse *client.Response
HttpResponse *http.Response

CopyID string
CopyStatus string
}

// Copy copies a blob to a destination within the storage account asynchronously.
func (c Client) Copy(ctx context.Context, containerName, blobName string, input CopyInput) (resp CopyResponse, err error) {

func (c Client) Copy(ctx context.Context, containerName, blobName string, input CopyInput) (result CopyResponse, err error) {
if containerName == "" {
return resp, fmt.Errorf("`containerName` cannot be an empty string")
return result, fmt.Errorf("`containerName` cannot be an empty string")
}

if strings.ToLower(containerName) != containerName {
return resp, fmt.Errorf("`containerName` must be a lower-cased string")
return result, fmt.Errorf("`containerName` must be a lower-cased string")
}

if blobName == "" {
return resp, fmt.Errorf("`blobName` cannot be an empty string")
return result, fmt.Errorf("`blobName` cannot be an empty string")
}

if input.CopySource == "" {
return resp, fmt.Errorf("`input.CopySource` cannot be an empty string")
return result, fmt.Errorf("`input.CopySource` cannot be an empty string")
}

opts := client.RequestOptions{
Expand All @@ -148,19 +147,21 @@ func (c Client) Copy(ctx context.Context, containerName, blobName string, input
return
}

resp.HttpResponse, err = req.Execute(ctx)
var resp *client.Response
resp, err = req.Execute(ctx)
if resp != nil {
result.HttpResponse = resp.Response

if resp.Header != nil {
result.CopyID = resp.Header.Get("x-ms-copy-id")
result.CopyStatus = resp.Header.Get("x-ms-copy-status")
}
}
if err != nil {
err = fmt.Errorf("executing request: %+v", err)
return
}

if resp.HttpResponse != nil {
if resp.HttpResponse.Header != nil {
resp.CopyID = resp.HttpResponse.Header.Get("x-ms-copy-id")
resp.CopyStatus = resp.HttpResponse.Header.Get("x-ms-copy-status")
}
}

return
}

Expand Down
23 changes: 15 additions & 8 deletions storage/2023-11-03/blob/blobs/copy_abort.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,29 @@ type AbortCopyInput struct {
}

type CopyAbortResponse struct {
HttpResponse *client.Response
HttpResponse *http.Response
}

// AbortCopy aborts a pending Copy Blob operation, and leaves a destination blob with zero length and full metadata.
func (c Client) AbortCopy(ctx context.Context, containerName, blobName string, input AbortCopyInput) (resp CopyAbortResponse, err error) {

func (c Client) AbortCopy(ctx context.Context, containerName, blobName string, input AbortCopyInput) (result CopyAbortResponse, err error) {
if containerName == "" {
return resp, fmt.Errorf("`containerName` cannot be an empty string")
err = fmt.Errorf("`containerName` cannot be an empty string")
return
}

if strings.ToLower(containerName) != containerName {
return resp, fmt.Errorf("`containerName` must be a lower-cased string")
err = fmt.Errorf("`containerName` must be a lower-cased string")
return
}

if blobName == "" {
return resp, fmt.Errorf("`blobName` cannot be an empty string")
err = fmt.Errorf("`blobName` cannot be an empty string")
return
}

if input.CopyID == "" {
return resp, fmt.Errorf("`input.CopyID` cannot be an empty string")
err = fmt.Errorf("`input.CopyID` cannot be an empty string")
return
}

opts := client.RequestOptions{
Expand All @@ -59,7 +62,11 @@ func (c Client) AbortCopy(ctx context.Context, containerName, blobName string, i
return
}

resp.HttpResponse, err = req.Execute(ctx)
var resp *client.Response
resp, err = req.Execute(ctx)
if resp != nil {
result.HttpResponse = resp.Response
}
if err != nil {
err = fmt.Errorf("executing request: %+v", err)
return
Expand Down
8 changes: 4 additions & 4 deletions storage/2023-11-03/blob/blobs/copy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestCopyFromExistingFile(t *testing.T) {
t.Fatalf("building client for environment: %+v", err)
}

if err := client.PrepareWithSharedKeyAuth(containersClient.Client, testData, auth.SharedKey); err != nil {
if err = client.PrepareWithSharedKeyAuth(containersClient.Client, testData, auth.SharedKey); err != nil {
t.Fatalf("adding authorizer to client: %+v", err)
}

Expand All @@ -59,7 +59,7 @@ func TestCopyFromExistingFile(t *testing.T) {
t.Fatalf("building client for environment: %+v", err)
}

if err := client.PrepareWithSharedKeyAuth(blobClient.Client, testData, auth.SharedKey); err != nil {
if err = client.PrepareWithSharedKeyAuth(blobClient.Client, testData, auth.SharedKey); err != nil {
t.Fatalf("adding authorizer to client: %+v", err)
}

Expand Down Expand Up @@ -137,7 +137,7 @@ func TestCopyFromURL(t *testing.T) {
t.Fatalf("building client for environment: %+v", err)
}

if err := client.PrepareWithSharedKeyAuth(containersClient.Client, testData, auth.SharedKey); err != nil {
if err = client.PrepareWithSharedKeyAuth(containersClient.Client, testData, auth.SharedKey); err != nil {
t.Fatalf("adding authorizer to client: %+v", err)
}

Expand All @@ -152,7 +152,7 @@ func TestCopyFromURL(t *testing.T) {
t.Fatalf("building client for environment: %+v", err)
}

if err := client.PrepareWithSharedKeyAuth(blobClient.Client, testData, auth.SharedKey); err != nil {
if err = client.PrepareWithSharedKeyAuth(blobClient.Client, testData, auth.SharedKey); err != nil {
t.Fatalf("adding authorizer to client: %+v", err)
}

Expand Down
Loading
Loading