Skip to content

Commit

Permalink
2023-11-03: making the Response parsing consistent
Browse files Browse the repository at this point in the history
Now when deserializing the Response we're checking if `resp` and `resp.Response` are both != nil before trying
to unmarshal.

See hashicorp/terraform-provider-azurerm#25521 for an example of where this manifests
by being done inconsistently - as such doing this across the board means this'll take effect everywhere, plus be
included in any new operations which are based on the existing one
  • Loading branch information
tombuildsstuff committed Apr 5, 2024
1 parent a1ba466 commit 21ae81a
Show file tree
Hide file tree
Showing 103 changed files with 129 additions and 145 deletions.
2 changes: 1 addition & 1 deletion storage/2023-11-03/blob/accounts/get_service_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (c Client) GetServiceProperties(ctx context.Context, accountName string) (r

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

err = resp.Unmarshal(&result)
Expand Down
2 changes: 1 addition & 1 deletion storage/2023-11-03/blob/accounts/set_service_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (c Client) SetServiceProperties(ctx context.Context, accountName string, in

var resp *client.Response
resp, err = req.Execute(ctx)
if resp != nil {
if resp != nil && resp.Response != nil {
result.HttpResponse = resp.Response
}
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions storage/2023-11-03/blob/blobs/append_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ func (c Client) AppendBlock(ctx context.Context, containerName, blobName string,

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

if resp.Response != nil && resp.Header != 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")
Expand Down
4 changes: 2 additions & 2 deletions storage/2023-11-03/blob/blobs/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ func (c Client) Copy(ctx context.Context, containerName, blobName string, input

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

if resp.Response != nil && resp.Header != nil {
if resp.Header != nil {
result.CopyID = resp.Header.Get("x-ms-copy-id")
result.CopyStatus = resp.Header.Get("x-ms-copy-status")
}
Expand Down
2 changes: 1 addition & 1 deletion storage/2023-11-03/blob/blobs/copy_abort.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (c Client) AbortCopy(ctx context.Context, containerName, blobName string, i

var resp *client.Response
resp, err = req.Execute(ctx)
if resp != nil {
if resp != nil && resp.Response != nil {
result.HttpResponse = resp.Response
}
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion storage/2023-11-03/blob/blobs/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (c Client) Delete(ctx context.Context, containerName, blobName string, inpu

var resp *client.Response
resp, err = req.Execute(ctx)
if resp != nil {
if resp != nil && resp.Response != nil {
result.HttpResponse = resp.Response
}
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion storage/2023-11-03/blob/blobs/delete_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (c Client) DeleteSnapshot(ctx context.Context, containerName, blobName stri

var resp *client.Response
resp, err = req.Execute(ctx)
if resp != nil {
if resp != nil && resp.Response != nil {
result.HttpResponse = resp.Response
}
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion storage/2023-11-03/blob/blobs/delete_snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (c Client) DeleteSnapshots(ctx context.Context, containerName, blobName str

var resp *client.Response
resp, err = req.Execute(ctx)
if resp != nil {
if resp != nil && resp.Response != nil {
result.HttpResponse = resp.Response
}
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion storage/2023-11-03/blob/blobs/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (c Client) Get(ctx context.Context, containerName, blobName string, input G

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

if resp.Body != nil {
Expand Down
4 changes: 2 additions & 2 deletions storage/2023-11-03/blob/blobs/get_block_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ func (c Client) GetBlockList(ctx context.Context, containerName, blobName string

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

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

Expand Down
4 changes: 2 additions & 2 deletions storage/2023-11-03/blob/blobs/get_page_ranges.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ func (c Client) GetPageRanges(ctx context.Context, containerName, blobName strin

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

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

Expand Down
2 changes: 1 addition & 1 deletion storage/2023-11-03/blob/blobs/incremental_copy_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (c Client) IncrementalCopyBlob(ctx context.Context, containerName, blobName

var resp *client.Response
resp, err = req.Execute(ctx)
if resp != nil {
if resp != nil && resp.Response != nil {
result.HttpResponse = resp.Response
}
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion storage/2023-11-03/blob/blobs/lease_acquire.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (c Client) AcquireLease(ctx context.Context, containerName, blobName string

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

if resp.Response != nil && resp.Header != nil {
Expand Down
2 changes: 1 addition & 1 deletion storage/2023-11-03/blob/blobs/lease_break.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (c Client) BreakLease(ctx context.Context, containerName, blobName string,

var resp *client.Response
resp, err = req.Execute(ctx)
if resp != nil {
if resp != nil && resp.Response != nil {
result.HttpResponse = resp.Response
}
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion storage/2023-11-03/blob/blobs/lease_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (c Client) ChangeLease(ctx context.Context, containerName, blobName string,

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

if resp.Response != nil && resp.Header != nil {
Expand Down
2 changes: 1 addition & 1 deletion storage/2023-11-03/blob/blobs/lease_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (c Client) ReleaseLease(ctx context.Context, containerName, blobName string

var resp *client.Response
resp, err = req.Execute(ctx)
if resp != nil {
if resp != nil && resp.Response != nil {
result.HttpResponse = resp.Response
}
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion storage/2023-11-03/blob/blobs/lease_renew.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (c Client) RenewLease(ctx context.Context, containerName, blobName string,

var resp *client.Response
resp, err = req.Execute(ctx)
if resp != nil {
if resp != nil && resp.Response != nil {
result.HttpResponse = resp.Response
}
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion storage/2023-11-03/blob/blobs/metadata_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (c Client) SetMetaData(ctx context.Context, containerName, blobName string,

var resp *client.Response
resp, err = req.Execute(ctx)
if resp != nil {
if resp != nil && resp.Response != nil {
result.HttpResponse = resp.Response
}
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions storage/2023-11-03/blob/blobs/properties_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ func (c Client) GetProperties(ctx context.Context, containerName, blobName strin

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

if resp.Response != nil && resp.Header != 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"))
Expand Down
2 changes: 1 addition & 1 deletion storage/2023-11-03/blob/blobs/properties_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (c Client) SetProperties(ctx context.Context, containerName, blobName strin

var resp *client.Response
resp, err = req.Execute(ctx)
if resp != nil {
if resp != nil && resp.Response != nil {
result.HttpResponse = resp.Response
}
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion storage/2023-11-03/blob/blobs/put_append_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (c Client) PutAppendBlob(ctx context.Context, containerName, blobName strin

var resp *client.Response
resp, err = req.Execute(ctx)
if resp != nil {
if resp != nil && resp.Response != nil {
result.HttpResponse = resp.Response
}
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion storage/2023-11-03/blob/blobs/put_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (c Client) PutBlock(ctx context.Context, containerName, blobName string, in

var resp *client.Response
resp, err = req.Execute(ctx)
if resp != nil {
if resp != nil && resp.Response != nil {
result.HttpResponse = resp.Response
}
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion storage/2023-11-03/blob/blobs/put_block_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (c Client) PutBlockBlob(ctx context.Context, containerName, blobName string

var resp *client.Response
resp, err = req.Execute(ctx)
if resp != nil {
if resp != nil && resp.Response != nil {
result.HttpResponse = resp.Response
}
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions storage/2023-11-03/blob/blobs/put_block_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ func (c Client) PutBlockList(ctx context.Context, containerName, blobName string

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

if resp.Response != nil && resp.Header != nil {
if resp.Header != nil {
result.ContentMD5 = resp.Header.Get("Content-MD5")
result.ETag = resp.Header.Get("ETag")
result.LastModified = resp.Header.Get("Last-Modified")
Expand Down
4 changes: 2 additions & 2 deletions storage/2023-11-03/blob/blobs/put_block_url.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ func (c Client) PutBlockFromURL(ctx context.Context, containerName, blobName str

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

if resp.Response != nil && resp.Header != nil {
if resp.Header != nil {
result.ContentMD5 = resp.Header.Get("Content-MD5")
}
}
Expand Down
2 changes: 1 addition & 1 deletion storage/2023-11-03/blob/blobs/put_page_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (c Client) PutPageBlob(ctx context.Context, containerName, blobName string,

var resp *client.Response
resp, err = req.Execute(ctx)
if resp != nil {
if resp != nil && resp.Response != nil {
result.HttpResponse = resp.Response
}
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion storage/2023-11-03/blob/blobs/put_page_clear.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (c Client) PutPageClear(ctx context.Context, containerName, blobName string

var resp *client.Response
resp, err = req.Execute(ctx)
if resp != nil {
if resp != nil && resp.Response != nil {
result.HttpResponse = resp.Response
}
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions storage/2023-11-03/blob/blobs/put_page_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ func (c Client) PutPageUpdate(ctx context.Context, containerName, blobName strin

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

if resp.Response != nil && resp.Header != nil {
if resp.Header != nil {
result.BlobSequenceNumber = resp.Header.Get("x-ms-blob-sequence-number")
result.ContentMD5 = resp.Header.Get("Content-MD5")
result.LastModified = resp.Header.Get("Last-Modified")
Expand Down
2 changes: 1 addition & 1 deletion storage/2023-11-03/blob/blobs/set_tier.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (c Client) SetTier(ctx context.Context, containerName, blobName string, inp

var resp *client.Response
resp, err = req.Execute(ctx)
if resp != nil {
if resp != nil && resp.Response != nil {
result.HttpResponse = resp.Response
}
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions storage/2023-11-03/blob/blobs/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ func (c Client) Snapshot(ctx context.Context, containerName, blobName string, in

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

if resp.Response != nil && resp.Header != nil {
if resp.Header != nil {
result.ETag = resp.Header.Get("ETag")
result.SnapshotDateTime = resp.Header.Get("x-ms-snapshot")
}
Expand Down
4 changes: 2 additions & 2 deletions storage/2023-11-03/blob/blobs/snapshot_get_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ func (c Client) GetSnapshotProperties(ctx context.Context, containerName, blobNa

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

if resp.Response != nil && resp.Header != 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"))
Expand Down
2 changes: 1 addition & 1 deletion storage/2023-11-03/blob/blobs/undelete.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (c Client) Undelete(ctx context.Context, containerName, blobName string) (r

var resp *client.Response
resp, err = req.Execute(ctx)
if resp != nil {
if resp != nil && resp.Response != nil {
result.HttpResponse = resp.Response
}
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion storage/2023-11-03/blob/containers/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (c Client) Create(ctx context.Context, containerName string, input CreateIn

var resp *client.Response
resp, err = req.Execute(ctx)
if resp != nil {
if resp != nil && resp.Response != nil {
result.HttpResponse = resp.Response
}
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion storage/2023-11-03/blob/containers/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (c Client) Delete(ctx context.Context, containerName string) (result Delete

var resp *client.Response
resp, err = req.Execute(ctx)
if resp != nil {
if resp != nil && resp.Response != nil {
result.HttpResponse = resp.Response
}
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions storage/2023-11-03/blob/containers/get_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ func (c Client) GetProperties(ctx context.Context, containerName string, input G

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

if resp.Response != nil && resp.Header != nil {
if resp.Header != nil {
result.DefaultEncryptionScope = resp.Header.Get("x-ms-default-encryption-scope")
result.LeaseStatus = LeaseStatus(resp.Header.Get("x-ms-lease-status"))
result.LeaseState = LeaseState(resp.Header.Get("x-ms-lease-state"))
Expand Down
4 changes: 2 additions & 2 deletions storage/2023-11-03/blob/containers/lease_acquire.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ func (c Client) AcquireLease(ctx context.Context, containerName string, input Ac

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

if resp.Response != nil && resp.Header != nil {
if resp.Header != nil {
result.LeaseID = resp.Header.Get("x-ms-lease-id")
}
}
Expand Down
4 changes: 2 additions & 2 deletions storage/2023-11-03/blob/containers/lease_break.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ func (c Client) BreakLease(ctx context.Context, containerName string, input Brea

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

if resp.Response != nil && resp.Header != nil {
if resp.Header != nil {
if leaseTimeRaw := resp.Header.Get("x-ms-lease-time"); leaseTimeRaw != "" {
if leaseTime, err := strconv.Atoi(leaseTimeRaw); err == nil {
result.LeaseTime = leaseTime
Expand Down
4 changes: 2 additions & 2 deletions storage/2023-11-03/blob/containers/lease_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ func (c Client) ChangeLease(ctx context.Context, containerName string, input Cha

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

if resp.Response != nil && resp.Header != nil {
if resp.Header != nil {
result.LeaseID = resp.Header.Get("x-ms-lease-id")
}
}
Expand Down
Loading

0 comments on commit 21ae81a

Please sign in to comment.