Skip to content

Commit

Permalink
[Secrets] Remove RawResponse (#17224)
Browse files Browse the repository at this point in the history
* bump azcore, remove RawResponse, add example and Readme docs

* code formatting in readme

* removing example from example_test

* improving readme
  • Loading branch information
seankane-msft committed Mar 4, 2022
1 parent 7f9c0b7 commit 085ea93
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 58 deletions.
1 change: 1 addition & 0 deletions sdk/keyvault/azsecrets/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* Changed pager APIs for `ListSecretVersionsPager`, `ListDeletedSecretsPager`, and `ListSecretsPager`
* Use the `More()` method to determine if there are more pages to fetch
* Use the `NextPage(context.Context)` to fetch the next page of results
* Removed all `RawResponse *http.Response` fields from response structs.

## 0.5.0 (2022-02-08)

Expand Down
20 changes: 19 additions & 1 deletion sdk/keyvault/azsecrets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ if err != nil {

### Logging

This module uses the classification based logging implementation in azcore. To turn on logging set `AZURE_SDK_GO_LOGGING` to `all`. If you only want to include logs for `azsecrets`, you must create your own logger and set the log classification as `LogCredential`.
This module uses the classification based logging implementation in `azcore`. To turn on logging set `AZURE_SDK_GO_LOGGING` to `all`. If you only want to include logs for `azsecrets`, you must create your own logger and set the log classification as `LogCredential`.

To obtain more detailed logging, including request/response bodies and header values, make sure to leave the logger as default or enable the `LogRequest` and/or `LogResponse` classificatons. A logger that only includes credential logs can be like the following:

Expand All @@ -248,6 +248,24 @@ azlog.SetEvents(azlog.EventRequest, azlog.EventResponse)
> CAUTION: logs from credentials contain sensitive information.
> These logs must be protected to avoid compromising account security.
### Accessing `http.Response`
You can access the raw `*http.Response` returned by the service using the `runtime.WithCaptureResponse` method and a context passed to any client method.

```go
import "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"

func GetHTTPResponse() {
var respFromCtx *http.Response
ctx := runtime.WithCaptureResponse(context.Background(), &respFromCtx)
_, err = client.GetSecret(ctx, "mySecretName", nil)
if err != nil {
panic(err)
}
// Do something with *http.Response
fmt.Println(respFromCtx.StatusCode)
}
```

### Additional Documentation
For more extensive documentation on Azure Key Vault, see the [API reference documentation][reference_docs].

Expand Down
59 changes: 5 additions & 54 deletions sdk/keyvault/azsecrets/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,10 @@ func (g *GetSecretOptions) toGenerated() *internal.KeyVaultClientGetSecretOption
// GetSecretResponse is the response object for the Client.GetSecret operation
type GetSecretResponse struct {
Secret

// RawResponse contains the underlying HTTP response
RawResponse *http.Response
}

func getSecretResponseFromGenerated(i internal.KeyVaultClientGetSecretResponse) *GetSecretResponse {
return &GetSecretResponse{
RawResponse: i.RawResponse,
Secret: Secret{
Properties: secretPropertiesFromGenerated(i.Attributes),
ContentType: i.ContentType,
Expand Down Expand Up @@ -136,15 +132,11 @@ func (s *SetSecretOptions) toGenerated() *internal.KeyVaultClientSetSecretOption
// SetSecretResponse is the response struct for the Client.SetSecret operation.
type SetSecretResponse struct {
Secret

// RawResponse holds the underlying HTTP response
RawResponse *http.Response
}

// convert generated response to publicly exposed response.
func setSecretResponseFromGenerated(i internal.KeyVaultClientSetSecretResponse) SetSecretResponse {
return SetSecretResponse{
RawResponse: i.RawResponse,
Secret: Secret{
Properties: secretPropertiesFromGenerated(i.Attributes),
ContentType: i.ContentType,
Expand Down Expand Up @@ -179,9 +171,6 @@ func (c *Client) SetSecret(ctx context.Context, secretName string, value string,
// DeletedSecretResponse contains the response for a Client.DeleteSecret operation.
type DeleteSecretResponse struct {
DeletedSecret

// RawResponse holds the underlying HTTP response
RawResponse *http.Response
}

func deleteSecretResponseFromGenerated(i *internal.KeyVaultClientDeleteSecretResponse) *DeleteSecretResponse {
Expand Down Expand Up @@ -209,7 +198,6 @@ func deleteSecretResponseFromGenerated(i *internal.KeyVaultClientDeleteSecretRes
DeletedOn: i.DeletedDate,
ScheduledPurgeDate: i.ScheduledPurgeDate,
},
RawResponse: i.RawResponse,
}
}

Expand Down Expand Up @@ -286,9 +274,6 @@ type DeleteSecretPollerResponse struct {

// Poller contains an initialized WidgetPoller
Poller DeleteSecretPoller

// RawResponse contains the underlying HTTP response.
RawResponse *http.Response
}

// BeginDeleteSecret deletes a secret from the keyvault. Delete cannot be applied to an individual version of a secret. This operation
Expand Down Expand Up @@ -322,7 +307,6 @@ func (c *Client) BeginDeleteSecret(ctx context.Context, secretName string, optio

return DeleteSecretPollerResponse{
Poller: s,
RawResponse: resp.RawResponse,
PollUntilDone: s.pollUntilDone,
}, nil
}
Expand All @@ -339,15 +323,11 @@ func (g *GetDeletedSecretOptions) toGenerated() *internal.KeyVaultClientGetDelet
// GetDeletedSecretResponse contains the response struct for the Client.GetDeletedSecret operation.
type GetDeletedSecretResponse struct {
DeletedSecret

// RawResponse contains the underlying HTTP response.
RawResponse *http.Response
}

// Convert the generated response to the publicly exposed version
func getDeletedSecretResponseFromGenerated(i internal.KeyVaultClientGetDeletedSecretResponse) GetDeletedSecretResponse {
return GetDeletedSecretResponse{
RawResponse: i.RawResponse,
DeletedSecret: DeletedSecret{
Properties: secretPropertiesFromGenerated(i.Attributes),
ContentType: i.ContentType,
Expand Down Expand Up @@ -403,13 +383,10 @@ func (u UpdateSecretPropertiesOptions) toGeneratedProperties() internal.SecretUp
// UpdateSecretPropertiesResponse contains the underlying response object for the UpdateSecretProperties method
type UpdateSecretPropertiesResponse struct {
Secret
// RawResponse contains the underlying HTTP response.
RawResponse *http.Response
}

func updateSecretPropertiesResponseFromGenerated(i internal.KeyVaultClientUpdateSecretResponse) UpdateSecretPropertiesResponse {
return UpdateSecretPropertiesResponse{
RawResponse: i.RawResponse,
Secret: Secret{
Properties: secretPropertiesFromGenerated(i.Attributes),
ContentType: i.ContentType,
Expand Down Expand Up @@ -458,16 +435,12 @@ func (b *BackupSecretOptions) toGenerated() *internal.KeyVaultClientBackupSecret
type BackupSecretResponse struct {
// READ-ONLY; The backup blob containing the backed up secret.
Value []byte `json:"value,omitempty" azure:"ro"`

// RawResponse contains the underlying HTTP response.
RawResponse *http.Response
}

// convert generated response to the publicly exposed version.
func backupSecretResponseFromGenerated(i internal.KeyVaultClientBackupSecretResponse) BackupSecretResponse {
return BackupSecretResponse{
RawResponse: i.RawResponse,
Value: i.Value,
Value: i.Value,
}
}

Expand Down Expand Up @@ -498,15 +471,11 @@ func (r RestoreSecretBackupOptions) toGenerated() *internal.KeyVaultClientRestor
// RestoreSecretBackupResponse contains the response object for the Client.RestoreSecretBackup operation.
type RestoreSecretBackupResponse struct {
Secret

// RawResponse contains the underlying HTTP response.
RawResponse *http.Response
}

// converts the generated response to the publicly exposed version.
func restoreSecretBackupResponseFromGenerated(i internal.KeyVaultClientRestoreSecretResponse) RestoreSecretBackupResponse {
return RestoreSecretBackupResponse{
RawResponse: i.RawResponse,
Secret: Secret{
ContentType: i.ContentType,
ID: i.ID,
Expand Down Expand Up @@ -553,15 +522,12 @@ func (p *PurgeDeletedSecretOptions) toGenerated() *internal.KeyVaultClientPurgeD

// PurgeDeletedSecretResponse contains the response from method Client.PurgeDeletedSecret.
type PurgeDeletedSecretResponse struct {
// RawResponse contains the underlying HTTP response.
RawResponse *http.Response
// placeholder for future response fields
}

// Converts the generated response to the publicly exposed version.
func purgeDeletedSecretResponseFromGenerated(i internal.KeyVaultClientPurgeDeletedSecretResponse) PurgeDeletedSecretResponse {
return PurgeDeletedSecretResponse{
RawResponse: i.RawResponse,
}
return PurgeDeletedSecretResponse{}
}

// PurgeDeletedSecret deletes the specified secret. The purge deleted secret operation removes the secret permanently, without the possibility of recovery.
Expand Down Expand Up @@ -634,8 +600,6 @@ func (b BeginRecoverDeletedSecretOptions) toGenerated() *internal.KeyVaultClient
// RecoverDeletedSecretResponse is the response object for the Client.RecoverDeletedSecret operation.
type RecoverDeletedSecretResponse struct {
Secret
// RawResponse contains the underlying HTTP response.
RawResponse *http.Response
}

// change recover deleted secret reponse to the generated version.
Expand All @@ -653,7 +617,6 @@ func recoverDeletedSecretResponseFromGenerated(i internal.KeyVaultClientRecoverD
}
}
return RecoverDeletedSecretResponse{
RawResponse: i.RawResponse,
Secret: Secret{
Properties: a,
ContentType: i.ContentType,
Expand All @@ -673,9 +636,6 @@ type RecoverDeletedSecretPollerResponse struct {

// Poller contains an initialized RecoverDeletedSecretPoller
Poller RecoverDeletedSecretPoller

// RawResponse cotains the underlying HTTP response
RawResponse *http.Response
}

// BeginRecoverDeletedSecret recovers the deleted secret in the specified vault to the latest version.
Expand Down Expand Up @@ -709,7 +669,6 @@ func (c *Client) BeginRecoverDeletedSecret(ctx context.Context, secretName strin
return RecoverDeletedSecretPollerResponse{
PollUntilDone: b.pollUntilDone,
Poller: b,
RawResponse: getResp.RawResponse,
}, nil
}

Expand Down Expand Up @@ -774,9 +733,6 @@ func (l *ListDeletedSecretsPager) NextPage(ctx context.Context) (ListDeletedSecr

// ListDeletedSecretsPageResponse holds the data for a single page.
type ListDeletedSecretsPageResponse struct {
// RawResponse contains the underlying HTTP response.
RawResponse *http.Response

// READ-ONLY; The URL to get the next set of deleted secrets.
NextLink *string `json:"nextLink,omitempty" azure:"ro"`

Expand All @@ -795,7 +751,6 @@ func listDeletedSecretsPageFromGenerated(g internal.KeyVaultClientGetDeletedSecr
}

return ListDeletedSecretsPageResponse{
RawResponse: g.RawResponse,
NextLink: g.NextLink,
DeletedSecrets: items,
}
Expand Down Expand Up @@ -985,9 +940,6 @@ type ListSecretsOptions struct {

// ListSecretsPageResponse contains the current page of results for the Client.ListSecrets operation.
type ListSecretsPageResponse struct {
// RawResponse contains the underlying HTTP response.
RawResponse *http.Response

// READ-ONLY; The URL to get the next set of secrets.
NextLink *string `json:"nextLink,omitempty" azure:"ro"`

Expand All @@ -1002,9 +954,8 @@ func listSecretsPageFromGenerated(i internal.KeyVaultClientGetSecretsResponse) L
secrets = append(secrets, secretItemFromGenerated(s))
}
return ListSecretsPageResponse{
RawResponse: i.RawResponse,
NextLink: i.NextLink,
Secrets: secrets,
NextLink: i.NextLink,
Secrets: secrets,
}
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/keyvault/azsecrets/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/Azure/azure-sdk-for-go/sdk/keyvault/azsecrets
go 1.16

require (
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.1
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.22.0
github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.13.0
github.com/Azure/azure-sdk-for-go/sdk/internal v0.9.1
github.com/Azure/azure-sdk-for-go/sdk/keyvault/internal v0.2.1
Expand Down
4 changes: 2 additions & 2 deletions sdk/keyvault/azsecrets/go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.20.0/go.mod h1:ZPW/Z0kLCTdDZaDbYTetxc9Cxl/2lNqxYHYNOF2bti0=
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.0/go.mod h1:fBF9PQNqB8scdgpZ3ufzaLntG0AG7C1WjPMsiFOmfHM=
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.1 h1:qoVeMsc9/fh/yhxVaA0obYjVH/oI/ihrOoMwsLS9KSA=
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.1/go.mod h1:fBF9PQNqB8scdgpZ3ufzaLntG0AG7C1WjPMsiFOmfHM=
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.22.0 h1:zBJcBJwte0x6PcPK7XaWDMvK2o2ZM2f1sMaqNNavQ5g=
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.22.0/go.mod h1:fBF9PQNqB8scdgpZ3ufzaLntG0AG7C1WjPMsiFOmfHM=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.13.0 h1:bLRntPH25SkY1uZ/YZW+dmxNky9r1fAHvDFrzluo+4Q=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.13.0/go.mod h1:TmXReXZ9yPp5D5TBRMTAtyz+UyOl15Py4hL5E5p6igQ=
github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.1/go.mod h1:KLF4gFr6DcKFZwSuH8w8yEK6DpFl3LP5rhdvAb7Yz5I=
Expand Down

0 comments on commit 085ea93

Please sign in to comment.