Skip to content

Commit

Permalink
Merge pull request #118 from tombuildsstuff/bugfix/response-error-clo…
Browse files Browse the repository at this point in the history
…bbering

bugfix: avoid clobbering response errors
  • Loading branch information
manicminer authored Apr 22, 2024
2 parents 41801b9 + 16f1fbd commit 1f01155
Show file tree
Hide file tree
Showing 44 changed files with 454 additions and 358 deletions.
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/google/uuid v1.4.0
github.com/hashicorp/go-azure-helpers v0.66.2
github.com/hashicorp/go-azure-sdk/resource-manager v0.20240227.1172434
github.com/hashicorp/go-azure-sdk/sdk v0.20240227.1172434
github.com/hashicorp/go-azure-sdk/sdk v0.20240422.1112441
github.com/stretchr/testify v1.8.4
)

Expand Down Expand Up @@ -44,10 +44,10 @@ require (
github.com/vmihailenco/msgpack/v4 v4.3.12 // indirect
github.com/vmihailenco/tagparser v0.1.1 // indirect
github.com/zclconf/go-cty v1.13.1 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/oauth2 v0.16.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.33.0 // indirect
Expand Down
12 changes: 12 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ github.com/hashicorp/go-azure-sdk/resource-manager v0.20240227.1172434 h1:UNp65k
github.com/hashicorp/go-azure-sdk/resource-manager v0.20240227.1172434/go.mod h1:8Pmp8Bg+FDUjkbuuiLLqysKrKUu5dOIf1dX3KFKNSU8=
github.com/hashicorp/go-azure-sdk/sdk v0.20240227.1172434 h1:IX9e6DRUYl+1skjZPpfdhnEV3cx8dNX1qECYSVcD288=
github.com/hashicorp/go-azure-sdk/sdk v0.20240227.1172434/go.mod h1:IKIPyL+hfFWBHABKT0NOWlIEzlusiUBG0SxIfaiv278=
github.com/hashicorp/go-azure-sdk/sdk v0.20240417.1084634-0.20240417084653-773ed908fb40 h1:TNLaQy51sD/Sjj2lpSSVVVg2/RrbVZPYH9tdAWuQ+hQ=
github.com/hashicorp/go-azure-sdk/sdk v0.20240417.1084634-0.20240417084653-773ed908fb40/go.mod h1:POOjeoqNp+mvlLBuibJTziUAkBZ7FxXGeGestwemL/w=
github.com/hashicorp/go-azure-sdk/sdk v0.20240417.1084634-0.20240419120035-390da9deb824 h1:wbQB3CLwpi7QB8hZP3YedB8UZy/ZVJWFW2GYg3SyqHY=
github.com/hashicorp/go-azure-sdk/sdk v0.20240417.1084634-0.20240419120035-390da9deb824/go.mod h1:POOjeoqNp+mvlLBuibJTziUAkBZ7FxXGeGestwemL/w=
github.com/hashicorp/go-azure-sdk/sdk v0.20240422.1112441 h1:BGDyjzyjD+NhcL9cd+WhMIgAzY+/wKB30nD4h34sEPg=
github.com/hashicorp/go-azure-sdk/sdk v0.20240422.1112441/go.mod h1:Ts5vRL3KPw8iLit+4WSi1hOWlRCx++wJrCkMGj69xBY=
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 h1:1/D3zfFHttUKaCaGKZ/dR2roBXv0vKbSCnssIldfQdI=
Expand Down Expand Up @@ -100,11 +106,15 @@ github.com/zclconf/go-cty v1.13.1/go.mod h1:YKQzy/7pZ7iq2jNFzy5go57xdxdWoLLpaEp4
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/oauth2 v0.16.0 h1:aDkGMBSYxElaoP81NpoUoz2oo2R2wHdZpGToUxfyQrQ=
golang.org/x/oauth2 v0.16.0/go.mod h1:hqZ+0LWXsiVoZpeld6jVt06P3adbS2Uu911W1SsJv2o=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -116,6 +126,8 @@ golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
Expand Down
10 changes: 6 additions & 4 deletions storage/2023-11-03/blob/accounts/get_service_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ func (c Client) GetServiceProperties(ctx context.Context, accountName string) (r
if resp != nil && resp.Response != nil {
result.HttpResponse = resp.Response

err = resp.Unmarshal(&result)
if err != nil {
err = fmt.Errorf("unmarshalling response: %+v", err)
return
if err == nil {
err = resp.Unmarshal(&result)
if err != nil {
err = fmt.Errorf("unmarshalling response: %+v", err)
return
}
}
}
if err != nil {
Expand Down
26 changes: 14 additions & 12 deletions storage/2023-11-03/blob/blobs/append_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,21 @@ func (c Client) AppendBlock(ctx context.Context, containerName, blobName string,
if resp != nil && resp.Response != nil {
result.HttpResponse = resp.Response

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.Header.Get("x-ms-blob-committed-block-count"); v != "" {
i, innerErr := strconv.Atoi(v)
if innerErr != nil {
err = fmt.Errorf("parsing `x-ms-blob-committed-block-count` header value %q: %+v", v, innerErr)
return
if err == nil {
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.Header.Get("x-ms-blob-committed-block-count"); v != "" {
i, innerErr := strconv.Atoi(v)
if innerErr != nil {
err = fmt.Errorf("parsing `x-ms-blob-committed-block-count` header value %q: %+v", v, innerErr)
return
}
result.BlobCommittedBlockCount = int64(i)
}
result.BlobCommittedBlockCount = int64(i)
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions storage/2023-11-03/blob/blobs/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,11 @@ func (c Client) Copy(ctx context.Context, containerName, blobName string, input
if resp != nil && resp.Response != 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 {
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 {
Expand Down
16 changes: 9 additions & 7 deletions storage/2023-11-03/blob/blobs/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,16 @@ func (c Client) Get(ctx context.Context, containerName, blobName string, input G
if resp != nil && resp.Response != nil {
result.HttpResponse = resp.Response

if resp.Body != nil {
defer resp.Body.Close()
respBody, err := io.ReadAll(resp.Body)
if err != nil {
return result, fmt.Errorf("could not parse response body")
if err == nil {
if resp.Body != nil {
defer resp.Body.Close()
respBody, err := io.ReadAll(resp.Body)
if err != nil {
return result, fmt.Errorf("could not parse response body")
}

result.Contents = &respBody
}

result.Contents = &respBody
}
}
if err != nil {
Expand Down
36 changes: 19 additions & 17 deletions storage/2023-11-03/blob/blobs/get_block_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,28 @@ func (c Client) GetBlockList(ctx context.Context, containerName, blobName string
if resp != nil && resp.Response != nil {
result.HttpResponse = resp.Response

if resp.Header != nil {
result.ContentType = resp.Header.Get("Content-Type")
result.ETag = resp.Header.Get("ETag")

if v := resp.Header.Get("x-ms-blob-content-length"); v != "" {
i, innerErr := strconv.Atoi(v)
if innerErr != nil {
err = fmt.Errorf("parsing `x-ms-blob-content-length` header value %q: %s", v, innerErr)
return
if err == nil {
if resp.Header != nil {
result.ContentType = resp.Header.Get("Content-Type")
result.ETag = resp.Header.Get("ETag")

if v := resp.Header.Get("x-ms-blob-content-length"); v != "" {
i, innerErr := strconv.Atoi(v)
if innerErr != nil {
err = fmt.Errorf("parsing `x-ms-blob-content-length` header value %q: %s", v, innerErr)
return
}

i64 := int64(i)
result.BlobContentLength = &i64
}

i64 := int64(i)
result.BlobContentLength = &i64
}
}

err = resp.Unmarshal(&result)
if err != nil {
err = fmt.Errorf("unmarshalling response: %+v", err)
return
err = resp.Unmarshal(&result)
if err != nil {
err = fmt.Errorf("unmarshalling response: %+v", err)
return
}
}
}
if err != nil {
Expand Down
36 changes: 19 additions & 17 deletions storage/2023-11-03/blob/blobs/get_page_ranges.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,28 @@ func (c Client) GetPageRanges(ctx context.Context, containerName, blobName strin
if resp != nil && resp.Response != nil {
result.HttpResponse = resp.Response

if resp.Header != nil {
result.ContentType = resp.Header.Get("Content-Type")
result.ETag = resp.Header.Get("ETag")

if v := resp.Header.Get("x-ms-blob-content-length"); v != "" {
i, innerErr := strconv.Atoi(v)
if innerErr != nil {
err = fmt.Errorf("parsing `x-ms-blob-content-length` header value %q: %+v", v, innerErr)
return
if err == nil {
if resp.Header != nil {
result.ContentType = resp.Header.Get("Content-Type")
result.ETag = resp.Header.Get("ETag")

if v := resp.Header.Get("x-ms-blob-content-length"); v != "" {
i, innerErr := strconv.Atoi(v)
if innerErr != nil {
err = fmt.Errorf("parsing `x-ms-blob-content-length` header value %q: %+v", v, innerErr)
return
}

i64 := int64(i)
result.ContentLength = &i64
}

i64 := int64(i)
result.ContentLength = &i64
}
}

err = resp.Unmarshal(&result)
if err != nil {
err = fmt.Errorf("unmarshalling response: %+v", err)
return
err = resp.Unmarshal(&result)
if err != nil {
err = fmt.Errorf("unmarshalling response: %+v", err)
return
}
}
}
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions storage/2023-11-03/blob/blobs/lease_acquire.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ func (c Client) AcquireLease(ctx context.Context, containerName, blobName string
if resp != nil && resp.Response != nil {
result.HttpResponse = resp.Response

if resp.Response != nil && resp.Header != nil {
result.LeaseID = resp.Header.Get("x-ms-lease-id")
if err == nil {
if resp.Response != nil && resp.Header != nil {
result.LeaseID = resp.Header.Get("x-ms-lease-id")
}
}
}
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions storage/2023-11-03/blob/blobs/lease_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ func (c Client) ChangeLease(ctx context.Context, containerName, blobName string,
if resp != nil && resp.Response != nil {
result.HttpResponse = resp.Response

if resp.Response != nil && resp.Header != nil {
result.LeaseID = resp.Header.Get("x-ms-lease-id")
if err == nil {
if resp.Response != nil && resp.Header != nil {
result.LeaseID = resp.Header.Get("x-ms-lease-id")
}
}
}
if err != nil {
Expand Down
112 changes: 57 additions & 55 deletions storage/2023-11-03/blob/blobs/properties_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,68 +200,70 @@ func (c Client) GetProperties(ctx context.Context, containerName, blobName strin
if resp != nil && resp.Response != nil {
result.HttpResponse = resp.Response

if resp.Header != nil {
result.AccessTier = AccessTier(resp.Header.Get("x-ms-access-tier"))
result.AccessTierChangeTime = resp.Header.Get("x-ms-access-tier-change-time")
result.ArchiveStatus = ArchiveStatus(resp.Header.Get("x-ms-archive-status"))
result.BlobCommittedBlockCount = resp.Header.Get("x-ms-blob-committed-block-count")
result.BlobSequenceNumber = resp.Header.Get("x-ms-blob-sequence-number")
result.BlobType = BlobType(resp.Header.Get("x-ms-blob-type"))
result.CacheControl = resp.Header.Get("Cache-Control")
result.ContentDisposition = resp.Header.Get("Content-Disposition")
result.ContentEncoding = resp.Header.Get("Content-Encoding")
result.ContentLanguage = resp.Header.Get("Content-Language")
result.ContentMD5 = resp.Header.Get("Content-MD5")
result.ContentType = resp.Header.Get("Content-Type")
result.CopyCompletionTime = resp.Header.Get("x-ms-copy-completion-time")
result.CopyDestinationSnapshot = resp.Header.Get("x-ms-copy-destination-snapshot")
result.CopyID = resp.Header.Get("x-ms-copy-id")
result.CopyProgress = resp.Header.Get("x-ms-copy-progress")
result.CopySource = resp.Header.Get("x-ms-copy-source")
result.CopyStatus = CopyStatus(resp.Header.Get("x-ms-copy-status"))
result.CopyStatusDescription = resp.Header.Get("x-ms-copy-status-description")
result.CreationTime = resp.Header.Get("x-ms-creation-time")
result.ETag = resp.Header.Get("Etag")
result.LastModified = resp.Header.Get("Last-Modified")
result.LeaseDuration = LeaseDuration(resp.Header.Get("x-ms-lease-duration"))
result.LeaseState = LeaseState(resp.Header.Get("x-ms-lease-state"))
result.LeaseStatus = LeaseStatus(resp.Header.Get("x-ms-lease-status"))
result.EncryptionScope = resp.Header.Get("x-ms-encryption-scope")
result.MetaData = metadata.ParseFromHeaders(resp.Header)

if v := resp.Header.Get("x-ms-access-tier-inferred"); v != "" {
b, innerErr := strconv.ParseBool(v)
if innerErr != nil {
err = fmt.Errorf("parsing `x-ms-access-tier-inferred` header value %q: %s", v, innerErr)
return
if err == nil {
if resp.Header != nil {
result.AccessTier = AccessTier(resp.Header.Get("x-ms-access-tier"))
result.AccessTierChangeTime = resp.Header.Get("x-ms-access-tier-change-time")
result.ArchiveStatus = ArchiveStatus(resp.Header.Get("x-ms-archive-status"))
result.BlobCommittedBlockCount = resp.Header.Get("x-ms-blob-committed-block-count")
result.BlobSequenceNumber = resp.Header.Get("x-ms-blob-sequence-number")
result.BlobType = BlobType(resp.Header.Get("x-ms-blob-type"))
result.CacheControl = resp.Header.Get("Cache-Control")
result.ContentDisposition = resp.Header.Get("Content-Disposition")
result.ContentEncoding = resp.Header.Get("Content-Encoding")
result.ContentLanguage = resp.Header.Get("Content-Language")
result.ContentMD5 = resp.Header.Get("Content-MD5")
result.ContentType = resp.Header.Get("Content-Type")
result.CopyCompletionTime = resp.Header.Get("x-ms-copy-completion-time")
result.CopyDestinationSnapshot = resp.Header.Get("x-ms-copy-destination-snapshot")
result.CopyID = resp.Header.Get("x-ms-copy-id")
result.CopyProgress = resp.Header.Get("x-ms-copy-progress")
result.CopySource = resp.Header.Get("x-ms-copy-source")
result.CopyStatus = CopyStatus(resp.Header.Get("x-ms-copy-status"))
result.CopyStatusDescription = resp.Header.Get("x-ms-copy-status-description")
result.CreationTime = resp.Header.Get("x-ms-creation-time")
result.ETag = resp.Header.Get("Etag")
result.LastModified = resp.Header.Get("Last-Modified")
result.LeaseDuration = LeaseDuration(resp.Header.Get("x-ms-lease-duration"))
result.LeaseState = LeaseState(resp.Header.Get("x-ms-lease-state"))
result.LeaseStatus = LeaseStatus(resp.Header.Get("x-ms-lease-status"))
result.EncryptionScope = resp.Header.Get("x-ms-encryption-scope")
result.MetaData = metadata.ParseFromHeaders(resp.Header)

if v := resp.Header.Get("x-ms-access-tier-inferred"); v != "" {
b, innerErr := strconv.ParseBool(v)
if innerErr != nil {
err = fmt.Errorf("parsing `x-ms-access-tier-inferred` header value %q: %s", v, innerErr)
return
}
result.AccessTierInferred = b
}
result.AccessTierInferred = b
}

if v := resp.Header.Get("Content-Length"); v != "" {
i, innerErr := strconv.Atoi(v)
if innerErr != nil {
err = fmt.Errorf("parsing `Content-Length` header value %q: %s", v, innerErr)
if v := resp.Header.Get("Content-Length"); v != "" {
i, innerErr := strconv.Atoi(v)
if innerErr != nil {
err = fmt.Errorf("parsing `Content-Length` header value %q: %s", v, innerErr)
}
result.ContentLength = int64(i)
}
result.ContentLength = int64(i)
}

if v := resp.Header.Get("x-ms-incremental-copy"); v != "" {
b, innerErr := strconv.ParseBool(v)
if innerErr != nil {
err = fmt.Errorf("parsing `x-ms-incremental-copy` header value %q: %s", v, innerErr)
return
if v := resp.Header.Get("x-ms-incremental-copy"); v != "" {
b, innerErr := strconv.ParseBool(v)
if innerErr != nil {
err = fmt.Errorf("parsing `x-ms-incremental-copy` header value %q: %s", v, innerErr)
return
}
result.IncrementalCopy = b
}
result.IncrementalCopy = b
}

if v := resp.Header.Get("x-ms-server-encrypted"); v != "" {
b, innerErr := strconv.ParseBool(v)
if innerErr != nil {
err = fmt.Errorf("parsing `x-ms-server-encrypted` header value %q: %s", v, innerErr)
return
if v := resp.Header.Get("x-ms-server-encrypted"); v != "" {
b, innerErr := strconv.ParseBool(v)
if innerErr != nil {
err = fmt.Errorf("parsing `x-ms-server-encrypted` header value %q: %s", v, innerErr)
return
}
result.ServerEncrypted = b
}
result.ServerEncrypted = b
}
}
}
Expand Down
Loading

0 comments on commit 1f01155

Please sign in to comment.