diff --git a/sdk/containers/azcontainerregistry/CHANGELOG.md b/sdk/containers/azcontainerregistry/CHANGELOG.md index db876da499da..e544357e66ae 100644 --- a/sdk/containers/azcontainerregistry/CHANGELOG.md +++ b/sdk/containers/azcontainerregistry/CHANGELOG.md @@ -4,9 +4,11 @@ ### Features Added * Add `ConfigMediaType` and `MediaType` properties to `ManifestAttributes` +* Enabled spans for distributed tracing ### Other Changes * Refine some logics and comments +* Updated to latest version of azcore ## 0.2.0 (2023-06-06) diff --git a/sdk/containers/azcontainerregistry/authentication_client.go b/sdk/containers/azcontainerregistry/authentication_client.go index de75e60e1fb0..72cf8301a127 100644 --- a/sdk/containers/azcontainerregistry/authentication_client.go +++ b/sdk/containers/azcontainerregistry/authentication_client.go @@ -3,14 +3,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package azcontainerregistry import ( "context" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" "github.com/Azure/azure-sdk-for-go/sdk/azcore/streaming" @@ -20,10 +20,10 @@ import ( ) // authenticationClient contains the methods for the Authentication group. -// Don't use this type directly, use newAuthenticationClient() instead. +// Don't use this type directly, use a constructor function instead. type authenticationClient struct { + internal *azcore.Client endpoint string - pl runtime.Pipeline } // ExchangeAADAccessTokenForACRRefreshToken - Exchange AAD tokens for an ACR refresh Token @@ -35,18 +35,23 @@ type authenticationClient struct { // - options - authenticationClientExchangeAADAccessTokenForACRRefreshTokenOptions contains the optional parameters for the // authenticationClient.ExchangeAADAccessTokenForACRRefreshToken method. func (client *authenticationClient) ExchangeAADAccessTokenForACRRefreshToken(ctx context.Context, grantType postContentSchemaGrantType, service string, options *authenticationClientExchangeAADAccessTokenForACRRefreshTokenOptions) (authenticationClientExchangeAADAccessTokenForACRRefreshTokenResponse, error) { + var err error + ctx, endSpan := runtime.StartSpan(ctx, "AuthenticationClient.ExchangeAADAccessTokenForACRRefreshToken", client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.exchangeAADAccessTokenForACRRefreshTokenCreateRequest(ctx, grantType, service, options) if err != nil { return authenticationClientExchangeAADAccessTokenForACRRefreshTokenResponse{}, err } - resp, err := client.pl.Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return authenticationClientExchangeAADAccessTokenForACRRefreshTokenResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return authenticationClientExchangeAADAccessTokenForACRRefreshTokenResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return authenticationClientExchangeAADAccessTokenForACRRefreshTokenResponse{}, err } - return client.exchangeAADAccessTokenForACRRefreshTokenHandleResponse(resp) + resp, err := client.exchangeAADAccessTokenForACRRefreshTokenHandleResponse(httpResp) + return resp, err } // exchangeAADAccessTokenForACRRefreshTokenCreateRequest creates the ExchangeAADAccessTokenForACRRefreshToken request. @@ -73,7 +78,10 @@ func (client *authenticationClient) exchangeAADAccessTokenForACRRefreshTokenCrea formData.Set("access_token", *options.AccessToken) } body := streaming.NopCloser(strings.NewReader(formData.Encode())) - return req, req.SetBody(body, "application/x-www-form-urlencoded") + if err := req.SetBody(body, "application/x-www-form-urlencoded"); err != nil { + return nil, err + } + return req, nil } // exchangeAADAccessTokenForACRRefreshTokenHandleResponse handles the ExchangeAADAccessTokenForACRRefreshToken response. @@ -96,18 +104,23 @@ func (client *authenticationClient) exchangeAADAccessTokenForACRRefreshTokenHand // - options - authenticationClientExchangeACRRefreshTokenForACRAccessTokenOptions contains the optional parameters for the // authenticationClient.ExchangeACRRefreshTokenForACRAccessToken method. func (client *authenticationClient) ExchangeACRRefreshTokenForACRAccessToken(ctx context.Context, service string, scope string, refreshToken string, options *authenticationClientExchangeACRRefreshTokenForACRAccessTokenOptions) (authenticationClientExchangeACRRefreshTokenForACRAccessTokenResponse, error) { + var err error + ctx, endSpan := runtime.StartSpan(ctx, "AuthenticationClient.ExchangeACRRefreshTokenForACRAccessToken", client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.exchangeACRRefreshTokenForACRAccessTokenCreateRequest(ctx, service, scope, refreshToken, options) if err != nil { return authenticationClientExchangeACRRefreshTokenForACRAccessTokenResponse{}, err } - resp, err := client.pl.Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return authenticationClientExchangeACRRefreshTokenForACRAccessTokenResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return authenticationClientExchangeACRRefreshTokenForACRAccessTokenResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return authenticationClientExchangeACRRefreshTokenForACRAccessTokenResponse{}, err } - return client.exchangeACRRefreshTokenForACRAccessTokenHandleResponse(resp) + resp, err := client.exchangeACRRefreshTokenForACRAccessTokenHandleResponse(httpResp) + return resp, err } // exchangeACRRefreshTokenForACRAccessTokenCreateRequest creates the ExchangeACRRefreshTokenForACRAccessToken request. @@ -129,7 +142,10 @@ func (client *authenticationClient) exchangeACRRefreshTokenForACRAccessTokenCrea formData.Set("grant_type", string(*options.GrantType)) } body := streaming.NopCloser(strings.NewReader(formData.Encode())) - return req, req.SetBody(body, "application/x-www-form-urlencoded") + if err := req.SetBody(body, "application/x-www-form-urlencoded"); err != nil { + return nil, err + } + return req, nil } // exchangeACRRefreshTokenForACRAccessTokenHandleResponse handles the ExchangeACRRefreshTokenForACRAccessToken response. diff --git a/sdk/containers/azcontainerregistry/authentication_client_test.go b/sdk/containers/azcontainerregistry/authentication_client_test.go index 8dc02f2b20dd..fc77da0b1a7d 100644 --- a/sdk/containers/azcontainerregistry/authentication_client_test.go +++ b/sdk/containers/azcontainerregistry/authentication_client_test.go @@ -23,7 +23,8 @@ import ( func Test_authenticationClient_ExchangeAADAccessTokenForACRRefreshToken(t *testing.T) { startRecording(t) endpoint, cred, options := getEndpointCredAndClientOptions(t) - client := newAuthenticationClient(endpoint, &authenticationClientOptions{ClientOptions: options}) + client, err := newAuthenticationClient(endpoint, &authenticationClientOptions{ClientOptions: options}) + require.NoError(t, err) ctx := context.Background() if reflect.ValueOf(options.Cloud).IsZero() { options.Cloud = cloud.AzurePublic @@ -44,9 +45,10 @@ func Test_authenticationClient_ExchangeAADAccessTokenForACRRefreshToken(t *testi func Test_authenticationClient_ExchangeAADAccessTokenForACRRefreshToken_fail(t *testing.T) { startRecording(t) endpoint, _, options := getEndpointCredAndClientOptions(t) - client := newAuthenticationClient(endpoint, &authenticationClientOptions{ClientOptions: options}) + client, err := newAuthenticationClient(endpoint, &authenticationClientOptions{ClientOptions: options}) + require.NoError(t, err) ctx := context.Background() - _, err := client.ExchangeAADAccessTokenForACRRefreshToken(ctx, postContentSchemaGrantTypeAccessToken, strings.TrimPrefix(endpoint, "https://"), &authenticationClientExchangeAADAccessTokenForACRRefreshTokenOptions{ + _, err = client.ExchangeAADAccessTokenForACRRefreshToken(ctx, postContentSchemaGrantTypeAccessToken, strings.TrimPrefix(endpoint, "https://"), &authenticationClientExchangeAADAccessTokenForACRRefreshTokenOptions{ Tenant: to.Ptr("wrong tenant"), RefreshToken: to.Ptr("wrong token"), AccessToken: to.Ptr("wrong token"), @@ -58,16 +60,18 @@ func Test_authenticationClient_ExchangeAADAccessTokenForACRRefreshToken_error(t srv, closeServer := mock.NewServer() defer closeServer() srv.AppendResponse(mock.WithStatusCode(http.StatusOK), mock.WithBody([]byte("wrong response"))) - client := newAuthenticationClient(srv.URL(), &authenticationClientOptions{ClientOptions: azcore.ClientOptions{Transport: srv}}) + client, err := newAuthenticationClient(srv.URL(), &authenticationClientOptions{ClientOptions: azcore.ClientOptions{Transport: srv}}) + require.NoError(t, err) ctx := context.Background() - _, err := client.ExchangeAADAccessTokenForACRRefreshToken(ctx, "grantType", "service", nil) + _, err = client.ExchangeAADAccessTokenForACRRefreshToken(ctx, "grantType", "service", nil) require.Error(t, err) } func Test_authenticationClient_ExchangeACRRefreshTokenForACRAccessToken(t *testing.T) { startRecording(t) endpoint, cred, options := getEndpointCredAndClientOptions(t) - client := newAuthenticationClient(endpoint, &authenticationClientOptions{ClientOptions: options}) + client, err := newAuthenticationClient(endpoint, &authenticationClientOptions{ClientOptions: options}) + require.NoError(t, err) ctx := context.Background() if reflect.ValueOf(options.Cloud).IsZero() { options.Cloud = cloud.AzurePublic @@ -91,9 +95,10 @@ func Test_authenticationClient_ExchangeACRRefreshTokenForACRAccessToken(t *testi func Test_authenticationClient_ExchangeACRRefreshTokenForACRAccessToken_fail(t *testing.T) { startRecording(t) endpoint, _, options := getEndpointCredAndClientOptions(t) - client := newAuthenticationClient(endpoint, &authenticationClientOptions{ClientOptions: options}) + client, err := newAuthenticationClient(endpoint, &authenticationClientOptions{ClientOptions: options}) + require.NoError(t, err) ctx := context.Background() - _, err := client.ExchangeACRRefreshTokenForACRAccessToken(ctx, strings.TrimPrefix(endpoint, "https://"), "registry:catalog:*", "wrong token", &authenticationClientExchangeACRRefreshTokenForACRAccessTokenOptions{GrantType: to.Ptr(tokenGrantTypeRefreshToken)}) + _, err = client.ExchangeACRRefreshTokenForACRAccessToken(ctx, strings.TrimPrefix(endpoint, "https://"), "registry:catalog:*", "wrong token", &authenticationClientExchangeACRRefreshTokenForACRAccessTokenOptions{GrantType: to.Ptr(tokenGrantTypeRefreshToken)}) require.Error(t, err) } @@ -101,8 +106,9 @@ func Test_authenticationClient_ExchangeACRRefreshTokenForACRAccessToken_error(t srv, closeServer := mock.NewServer() defer closeServer() srv.AppendResponse(mock.WithStatusCode(http.StatusOK), mock.WithBody([]byte("wrong response"))) - client := newAuthenticationClient(srv.URL(), &authenticationClientOptions{ClientOptions: azcore.ClientOptions{Transport: srv}}) + client, err := newAuthenticationClient(srv.URL(), &authenticationClientOptions{ClientOptions: azcore.ClientOptions{Transport: srv}}) + require.NoError(t, err) ctx := context.Background() - _, err := client.ExchangeACRRefreshTokenForACRAccessToken(ctx, "service", "scope", "refresh token", nil) + _, err = client.ExchangeACRRefreshTokenForACRAccessToken(ctx, "service", "scope", "refresh token", nil) require.Error(t, err) } diff --git a/sdk/containers/azcontainerregistry/authentication_custom_client.go b/sdk/containers/azcontainerregistry/authentication_custom_client.go index 6083d6afa54f..f8bf0fa80b1a 100644 --- a/sdk/containers/azcontainerregistry/authentication_custom_client.go +++ b/sdk/containers/azcontainerregistry/authentication_custom_client.go @@ -19,16 +19,19 @@ type authenticationClientOptions struct { // newAuthenticationClient creates a new instance of AuthenticationClient with the specified values. // - endpoint - Registry login URL // - options - Client options, pass nil to accept the default values. -func newAuthenticationClient(endpoint string, options *authenticationClientOptions) *authenticationClient { +func newAuthenticationClient(endpoint string, options *authenticationClientOptions) (*authenticationClient, error) { if options == nil { options = &authenticationClientOptions{} } - pipeline := runtime.NewPipeline(moduleName, moduleVersion, runtime.PipelineOptions{}, &options.ClientOptions) + azcoreClient, err := azcore.NewClient(moduleName, moduleVersion, runtime.PipelineOptions{}, &options.ClientOptions) + if err != nil { + return nil, err + } client := &authenticationClient{ + internal: azcoreClient, endpoint: endpoint, - pl: pipeline, } - return client + return client, nil } diff --git a/sdk/containers/azcontainerregistry/authentication_custom_client_test.go b/sdk/containers/azcontainerregistry/authentication_custom_client_test.go index 133cfac0c60d..a1ce580b9c89 100644 --- a/sdk/containers/azcontainerregistry/authentication_custom_client_test.go +++ b/sdk/containers/azcontainerregistry/authentication_custom_client_test.go @@ -12,6 +12,7 @@ import ( ) func Test_newAuthenticationClient(t *testing.T) { - client := newAuthenticationClient("test", nil) + client, err := newAuthenticationClient("test", nil) + require.NoError(t, err) require.NotNil(t, client) } diff --git a/sdk/containers/azcontainerregistry/authentication_policy_test.go b/sdk/containers/azcontainerregistry/authentication_policy_test.go index dcf5f79dcfda..5847558422cd 100644 --- a/sdk/containers/azcontainerregistry/authentication_policy_test.go +++ b/sdk/containers/azcontainerregistry/authentication_policy_test.go @@ -131,7 +131,8 @@ func Test_authenticationPolicy_getAccessToken_live(t *testing.T) { if reflect.ValueOf(options.Cloud).IsZero() { options.Cloud = cloud.AzurePublic } - authClient := newAuthenticationClient(endpoint, &authenticationClientOptions{options}) + authClient, err := newAuthenticationClient(endpoint, &authenticationClientOptions{options}) + require.NoError(t, err) p := &authenticationPolicy{ temporal.NewResource(acquireRefreshToken), atomic.Value{}, @@ -154,7 +155,8 @@ func Test_authenticationPolicy_getAccessToken_error(t *testing.T) { srv.AppendResponse(mock.WithStatusCode(http.StatusOK), mock.WithBody([]byte("{\"refresh_token\": \".eyJqdGkiOiIwMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMDAiLCJzdWIiOiIwMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMDAiLCJuYmYiOjQ2NzA0MTEyMTIsImV4cCI6NDY3MDQyMjkxMiwiaWF0Ijo0NjcwNDExMjEyLCJpc3MiOiJBenVyZSBDb250YWluZXIgUmVnaXN0cnkiLCJhdWQiOiJhemFjcmxpdmV0ZXN0LmF6dXJlY3IuaW8iLCJ2ZXJzaW9uIjoiMS4wIiwicmlkIjoiMDAwMCIsImdyYW50X3R5cGUiOiJyZWZyZXNoX3Rva2VuIiwiYXBwaWQiOiIwMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMDAiLCJwZXJtaXNzaW9ucyI6eyJBY3Rpb25zIjpbInJlYWQiLCJ3cml0ZSIsImRlbGV0ZSIsImRlbGV0ZWQvcmVhZCIsImRlbGV0ZWQvcmVzdG9yZS9hY3Rpb24iXSwiTm90QWN0aW9ucyI6bnVsbH0sInJvbGVzIjpbXX0.\"}"))) srv.AppendResponse(mock.WithStatusCode(http.StatusOK), mock.WithBody([]byte("wrong response"))) srv.AppendResponse(mock.WithStatusCode(http.StatusOK), mock.WithBody([]byte("wrong response"))) - authClient := newAuthenticationClient(srv.URL(), &authenticationClientOptions{ClientOptions: azcore.ClientOptions{Transport: srv}}) + authClient, err := newAuthenticationClient(srv.URL(), &authenticationClientOptions{ClientOptions: azcore.ClientOptions{Transport: srv}}) + require.NoError(t, err) p := &authenticationPolicy{ temporal.NewResource(acquireRefreshToken), @@ -179,7 +181,8 @@ func Test_authenticationPolicy_getAccessToken_error(t *testing.T) { func Test_authenticationPolicy_getAccessToken_live_anonymous(t *testing.T) { startRecording(t) endpoint, _, options := getEndpointCredAndClientOptions(t) - authClient := newAuthenticationClient(endpoint, &authenticationClientOptions{options}) + authClient, err := newAuthenticationClient(endpoint, &authenticationClientOptions{options}) + require.NoError(t, err) p := &authenticationPolicy{ refreshTokenCache: temporal.NewResource(acquireRefreshToken), authClient: authClient, @@ -237,7 +240,8 @@ func Test_authenticationPolicy(t *testing.T) { srv.AppendResponse(mock.WithStatusCode(http.StatusOK), mock.WithBody([]byte("{\"access_token\": \"test\"}"))) srv.AppendResponse(mock.WithStatusCode(http.StatusOK)) - authClient := newAuthenticationClient(srv.URL(), &authenticationClientOptions{ClientOptions: azcore.ClientOptions{Transport: srv}}) + authClient, err := newAuthenticationClient(srv.URL(), &authenticationClientOptions{ClientOptions: azcore.ClientOptions{Transport: srv}}) + require.NoError(t, err) authPolicy := &authenticationPolicy{ temporal.NewResource(acquireRefreshToken), atomic.Value{}, diff --git a/sdk/containers/azcontainerregistry/autorest.md b/sdk/containers/azcontainerregistry/autorest.md index ff1d683e0641..fa2c270a4c86 100644 --- a/sdk/containers/azcontainerregistry/autorest.md +++ b/sdk/containers/azcontainerregistry/autorest.md @@ -12,9 +12,12 @@ clear-output-folder: false export-clients: true openapi-type: "data-plane" output-folder: ../azcontainerregistry -use: "@autorest/go@4.0.0-preview.45" +use: "@autorest/go@4.0.0-preview.60" honor-body-placement: true remove-unreferenced-types: true +module-name: sdk/containers/azcontainerregistry +module: github.com/Azure/azure-sdk-for-go/$(module-name) +inject-spans: true ``` ## Customizations @@ -328,10 +331,11 @@ directive: transform: return $.replaceAll(/AuthenticationClient/g, "authenticationClient").replace(/AcrRefreshToken\n/, "acrRefreshToken\n").replace(/AcrAccessToken\n/, "acrAccessToken\n"); - from: - models.go + - options.go where: $ transform: return $.replaceAll(/AuthenticationClient/g, "authenticationClient").replace(/AcrRefreshToken struct/, "acrRefreshToken struct").replace(/AcrAccessToken struct/, "acrAccessToken struct"); - from: - - models.go + - options.go where: $ transform: return $.replace(/TokenGrantType/, "tokenGrantType"); - from: @@ -444,7 +448,7 @@ directive: }); - from: - blob_client.go - - models.go + - options.go where: $ transform: return $.replaceAll(/BlobClientUploadChunkOptions/g, "blobClientUploadChunkOptions").replace(/BlobClient\.UploadChunk/, "BlobClient.uploadChunk"); ``` diff --git a/sdk/containers/azcontainerregistry/blob_client.go b/sdk/containers/azcontainerregistry/blob_client.go index 5c438d21a74e..6c1d8962862c 100644 --- a/sdk/containers/azcontainerregistry/blob_client.go +++ b/sdk/containers/azcontainerregistry/blob_client.go @@ -3,15 +3,15 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package azcontainerregistry import ( "context" "errors" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" "io" @@ -22,10 +22,10 @@ import ( ) // BlobClient contains the methods for the ContainerRegistryBlob group. -// Don't use this type directly, use NewBlobClient() instead. +// Don't use this type directly, use a constructor function instead. type BlobClient struct { + internal *azcore.Client endpoint string - pl runtime.Pipeline } // CancelUpload - Cancel outstanding upload processes, releasing associated resources. If this is not called, the unfinished @@ -36,16 +36,20 @@ type BlobClient struct { // - location - Link acquired from upload start or previous chunk. Note, do not include initial / (must do substring(1) ) // - options - BlobClientCancelUploadOptions contains the optional parameters for the BlobClient.CancelUpload method. func (client *BlobClient) CancelUpload(ctx context.Context, location string, options *BlobClientCancelUploadOptions) (BlobClientCancelUploadResponse, error) { + var err error + ctx, endSpan := runtime.StartSpan(ctx, "BlobClient.CancelUpload", client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.cancelUploadCreateRequest(ctx, location, options) if err != nil { return BlobClientCancelUploadResponse{}, err } - resp, err := client.pl.Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return BlobClientCancelUploadResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusNoContent) { - return BlobClientCancelUploadResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return BlobClientCancelUploadResponse{}, err } return BlobClientCancelUploadResponse{}, nil } @@ -70,18 +74,23 @@ func (client *BlobClient) cancelUploadCreateRequest(ctx context.Context, locatio // - digest - Digest of a BLOB // - options - BlobClientCheckBlobExistsOptions contains the optional parameters for the BlobClient.CheckBlobExists method. func (client *BlobClient) CheckBlobExists(ctx context.Context, name string, digest string, options *BlobClientCheckBlobExistsOptions) (BlobClientCheckBlobExistsResponse, error) { + var err error + ctx, endSpan := runtime.StartSpan(ctx, "BlobClient.CheckBlobExists", client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.checkBlobExistsCreateRequest(ctx, name, digest, options) if err != nil { return BlobClientCheckBlobExistsResponse{}, err } - resp, err := client.pl.Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return BlobClientCheckBlobExistsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return BlobClientCheckBlobExistsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return BlobClientCheckBlobExistsResponse{}, err } - return client.checkBlobExistsHandleResponse(resp) + resp, err := client.checkBlobExistsHandleResponse(httpResp) + return resp, err } // checkBlobExistsCreateRequest creates the CheckBlobExists request. @@ -128,18 +137,23 @@ func (client *BlobClient) checkBlobExistsHandleResponse(resp *http.Response) (Bl // - rangeParam - Format : bytes=-, HTTP Range header specifying blob chunk. // - options - BlobClientCheckChunkExistsOptions contains the optional parameters for the BlobClient.CheckChunkExists method. func (client *BlobClient) CheckChunkExists(ctx context.Context, name string, digest string, rangeParam string, options *BlobClientCheckChunkExistsOptions) (BlobClientCheckChunkExistsResponse, error) { + var err error + ctx, endSpan := runtime.StartSpan(ctx, "BlobClient.CheckChunkExists", client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.checkChunkExistsCreateRequest(ctx, name, digest, rangeParam, options) if err != nil { return BlobClientCheckChunkExistsResponse{}, err } - resp, err := client.pl.Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return BlobClientCheckChunkExistsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return BlobClientCheckChunkExistsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return BlobClientCheckChunkExistsResponse{}, err } - return client.checkChunkExistsHandleResponse(resp) + resp, err := client.checkChunkExistsHandleResponse(httpResp) + return resp, err } // checkChunkExistsCreateRequest creates the CheckChunkExists request. @@ -187,18 +201,23 @@ func (client *BlobClient) checkChunkExistsHandleResponse(resp *http.Response) (B // - location - Link acquired from upload start or previous chunk. Note, do not include initial / (must do substring(1) ) // - options - BlobClientCompleteUploadOptions contains the optional parameters for the BlobClient.completeUpload method. func (client *BlobClient) completeUpload(ctx context.Context, digest string, location string, options *BlobClientCompleteUploadOptions) (BlobClientCompleteUploadResponse, error) { + var err error + ctx, endSpan := runtime.StartSpan(ctx, "BlobClient.CompleteUpload", client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.completeUploadCreateRequest(ctx, digest, location, options) if err != nil { return BlobClientCompleteUploadResponse{}, err } - resp, err := client.pl.Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return BlobClientCompleteUploadResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusCreated) { - return BlobClientCompleteUploadResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return BlobClientCompleteUploadResponse{}, err } - return client.completeUploadHandleResponse(resp) + resp, err := client.completeUploadHandleResponse(httpResp) + return resp, err } // completeUploadCreateRequest creates the completeUpload request. @@ -219,15 +238,15 @@ func (client *BlobClient) completeUploadCreateRequest(ctx context.Context, diges // completeUploadHandleResponse handles the completeUpload response. func (client *BlobClient) completeUploadHandleResponse(resp *http.Response) (BlobClientCompleteUploadResponse, error) { result := BlobClientCompleteUploadResponse{} + if val := resp.Header.Get("Docker-Content-Digest"); val != "" { + result.DockerContentDigest = &val + } if val := resp.Header.Get("Location"); val != "" { result.Location = &val } if val := resp.Header.Get("Range"); val != "" { result.Range = &val } - if val := resp.Header.Get("Docker-Content-Digest"); val != "" { - result.DockerContentDigest = &val - } return result, nil } @@ -239,18 +258,23 @@ func (client *BlobClient) completeUploadHandleResponse(resp *http.Response) (Blo // - digest - Digest of a BLOB // - options - BlobClientDeleteBlobOptions contains the optional parameters for the BlobClient.DeleteBlob method. func (client *BlobClient) DeleteBlob(ctx context.Context, name string, digest string, options *BlobClientDeleteBlobOptions) (BlobClientDeleteBlobResponse, error) { + var err error + ctx, endSpan := runtime.StartSpan(ctx, "BlobClient.DeleteBlob", client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deleteBlobCreateRequest(ctx, name, digest, options) if err != nil { return BlobClientDeleteBlobResponse{}, err } - resp, err := client.pl.Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return BlobClientDeleteBlobResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusAccepted) { - return BlobClientDeleteBlobResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusAccepted) { + err = runtime.NewResponseError(httpResp) + return BlobClientDeleteBlobResponse{}, err } - return client.deleteBlobHandleResponse(resp) + resp, err := client.deleteBlobHandleResponse(httpResp) + return resp, err } // deleteBlobCreateRequest creates the DeleteBlob request. @@ -288,18 +312,23 @@ func (client *BlobClient) deleteBlobHandleResponse(resp *http.Response) (BlobCli // - digest - Digest of a BLOB // - options - BlobClientGetBlobOptions contains the optional parameters for the BlobClient.GetBlob method. func (client *BlobClient) GetBlob(ctx context.Context, name string, digest string, options *BlobClientGetBlobOptions) (BlobClientGetBlobResponse, error) { + var err error + ctx, endSpan := runtime.StartSpan(ctx, "BlobClient.GetBlob", client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getBlobCreateRequest(ctx, name, digest, options) if err != nil { return BlobClientGetBlobResponse{}, err } - resp, err := client.pl.Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return BlobClientGetBlobResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return BlobClientGetBlobResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return BlobClientGetBlobResponse{}, err } - return client.getBlobHandleResponse(resp) + resp, err := client.getBlobHandleResponse(httpResp) + return resp, err } // getBlobCreateRequest creates the GetBlob request. @@ -349,18 +378,23 @@ func (client *BlobClient) getBlobHandleResponse(resp *http.Response) (BlobClient // - rangeParam - Format : bytes=-, HTTP Range header specifying blob chunk. // - options - BlobClientGetChunkOptions contains the optional parameters for the BlobClient.GetChunk method. func (client *BlobClient) GetChunk(ctx context.Context, name string, digest string, rangeParam string, options *BlobClientGetChunkOptions) (BlobClientGetChunkResponse, error) { + var err error + ctx, endSpan := runtime.StartSpan(ctx, "BlobClient.GetChunk", client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getChunkCreateRequest(ctx, name, digest, rangeParam, options) if err != nil { return BlobClientGetChunkResponse{}, err } - resp, err := client.pl.Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return BlobClientGetChunkResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusPartialContent) { - return BlobClientGetChunkResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusPartialContent) { + err = runtime.NewResponseError(httpResp) + return BlobClientGetChunkResponse{}, err } - return client.getChunkHandleResponse(resp) + resp, err := client.getChunkHandleResponse(httpResp) + return resp, err } // getChunkCreateRequest creates the GetChunk request. @@ -408,18 +442,23 @@ func (client *BlobClient) getChunkHandleResponse(resp *http.Response) (BlobClien // - location - Link acquired from upload start or previous chunk. Note, do not include initial / (must do substring(1) ) // - options - BlobClientGetUploadStatusOptions contains the optional parameters for the BlobClient.GetUploadStatus method. func (client *BlobClient) GetUploadStatus(ctx context.Context, location string, options *BlobClientGetUploadStatusOptions) (BlobClientGetUploadStatusResponse, error) { + var err error + ctx, endSpan := runtime.StartSpan(ctx, "BlobClient.GetUploadStatus", client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getUploadStatusCreateRequest(ctx, location, options) if err != nil { return BlobClientGetUploadStatusResponse{}, err } - resp, err := client.pl.Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return BlobClientGetUploadStatusResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusNoContent) { - return BlobClientGetUploadStatusResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return BlobClientGetUploadStatusResponse{}, err } - return client.getUploadStatusHandleResponse(resp) + resp, err := client.getUploadStatusHandleResponse(httpResp) + return resp, err } // getUploadStatusCreateRequest creates the GetUploadStatus request. @@ -437,12 +476,12 @@ func (client *BlobClient) getUploadStatusCreateRequest(ctx context.Context, loca // getUploadStatusHandleResponse handles the GetUploadStatus response. func (client *BlobClient) getUploadStatusHandleResponse(resp *http.Response) (BlobClientGetUploadStatusResponse, error) { result := BlobClientGetUploadStatusResponse{} - if val := resp.Header.Get("Range"); val != "" { - result.Range = &val - } if val := resp.Header.Get("Docker-Upload-UUID"); val != "" { result.DockerUploadUUID = &val } + if val := resp.Header.Get("Range"); val != "" { + result.Range = &val + } return result, nil } @@ -455,18 +494,23 @@ func (client *BlobClient) getUploadStatusHandleResponse(resp *http.Response) (Bl // - mount - Digest of blob to mount from the source repository. // - options - BlobClientMountBlobOptions contains the optional parameters for the BlobClient.MountBlob method. func (client *BlobClient) MountBlob(ctx context.Context, name string, from string, mount string, options *BlobClientMountBlobOptions) (BlobClientMountBlobResponse, error) { + var err error + ctx, endSpan := runtime.StartSpan(ctx, "BlobClient.MountBlob", client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.mountBlobCreateRequest(ctx, name, from, mount, options) if err != nil { return BlobClientMountBlobResponse{}, err } - resp, err := client.pl.Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return BlobClientMountBlobResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusCreated, http.StatusAccepted) { - return BlobClientMountBlobResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusCreated, http.StatusAccepted) { + err = runtime.NewResponseError(httpResp) + return BlobClientMountBlobResponse{}, err } - return client.mountBlobHandleResponse(resp) + resp, err := client.mountBlobHandleResponse(httpResp) + return resp, err } // mountBlobCreateRequest creates the MountBlob request. @@ -491,14 +535,14 @@ func (client *BlobClient) mountBlobCreateRequest(ctx context.Context, name strin // mountBlobHandleResponse handles the MountBlob response. func (client *BlobClient) mountBlobHandleResponse(resp *http.Response) (BlobClientMountBlobResponse, error) { result := BlobClientMountBlobResponse{} - if val := resp.Header.Get("Location"); val != "" { - result.Location = &val + if val := resp.Header.Get("Docker-Content-Digest"); val != "" { + result.DockerContentDigest = &val } if val := resp.Header.Get("Docker-Upload-UUID"); val != "" { result.DockerUploadUUID = &val } - if val := resp.Header.Get("Docker-Content-Digest"); val != "" { - result.DockerContentDigest = &val + if val := resp.Header.Get("Location"); val != "" { + result.Location = &val } return result, nil } @@ -510,18 +554,23 @@ func (client *BlobClient) mountBlobHandleResponse(resp *http.Response) (BlobClie // - name - Name of the image (including the namespace) // - options - BlobClientStartUploadOptions contains the optional parameters for the BlobClient.StartUpload method. func (client *BlobClient) StartUpload(ctx context.Context, name string, options *BlobClientStartUploadOptions) (BlobClientStartUploadResponse, error) { + var err error + ctx, endSpan := runtime.StartSpan(ctx, "BlobClient.StartUpload", client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.startUploadCreateRequest(ctx, name, options) if err != nil { return BlobClientStartUploadResponse{}, err } - resp, err := client.pl.Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return BlobClientStartUploadResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusAccepted) { - return BlobClientStartUploadResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusAccepted) { + err = runtime.NewResponseError(httpResp) + return BlobClientStartUploadResponse{}, err } - return client.startUploadHandleResponse(resp) + resp, err := client.startUploadHandleResponse(httpResp) + return resp, err } // startUploadCreateRequest creates the StartUpload request. @@ -542,15 +591,15 @@ func (client *BlobClient) startUploadCreateRequest(ctx context.Context, name str // startUploadHandleResponse handles the StartUpload response. func (client *BlobClient) startUploadHandleResponse(resp *http.Response) (BlobClientStartUploadResponse, error) { result := BlobClientStartUploadResponse{} + if val := resp.Header.Get("Docker-Upload-UUID"); val != "" { + result.DockerUploadUUID = &val + } if val := resp.Header.Get("Location"); val != "" { result.Location = &val } if val := resp.Header.Get("Range"); val != "" { result.Range = &val } - if val := resp.Header.Get("Docker-Upload-UUID"); val != "" { - result.DockerUploadUUID = &val - } return result, nil } @@ -562,18 +611,23 @@ func (client *BlobClient) startUploadHandleResponse(resp *http.Response) (BlobCl // - chunkData - Raw data of blob // - options - blobClientUploadChunkOptions contains the optional parameters for the BlobClient.uploadChunk method. func (client *BlobClient) uploadChunk(ctx context.Context, location string, chunkData io.ReadSeekCloser, options *blobClientUploadChunkOptions) (BlobClientUploadChunkResponse, error) { + var err error + ctx, endSpan := runtime.StartSpan(ctx, "BlobClient.uploadChunk", client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.uploadChunkCreateRequest(ctx, location, chunkData, options) if err != nil { return BlobClientUploadChunkResponse{}, err } - resp, err := client.pl.Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return BlobClientUploadChunkResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusAccepted) { - return BlobClientUploadChunkResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusAccepted) { + err = runtime.NewResponseError(httpResp) + return BlobClientUploadChunkResponse{}, err } - return client.uploadChunkHandleResponse(resp) + resp, err := client.uploadChunkHandleResponse(httpResp) + return resp, err } // uploadChunkCreateRequest creates the uploadChunk request. @@ -588,20 +642,23 @@ func (client *BlobClient) uploadChunkCreateRequest(ctx context.Context, location req.Raw().Header["Content-Range"] = []string{*options.ContentRange} } req.Raw().Header["Accept"] = []string{"application/json"} - return req, req.SetBody(chunkData, "application/octet-stream") + if err := req.SetBody(chunkData, "application/octet-stream"); err != nil { + return nil, err + } + return req, nil } // uploadChunkHandleResponse handles the uploadChunk response. func (client *BlobClient) uploadChunkHandleResponse(resp *http.Response) (BlobClientUploadChunkResponse, error) { result := BlobClientUploadChunkResponse{} + if val := resp.Header.Get("Docker-Upload-UUID"); val != "" { + result.DockerUploadUUID = &val + } if val := resp.Header.Get("Location"); val != "" { result.Location = &val } if val := resp.Header.Get("Range"); val != "" { result.Range = &val } - if val := resp.Header.Get("Docker-Upload-UUID"); val != "" { - result.DockerUploadUUID = &val - } return result, nil } diff --git a/sdk/containers/azcontainerregistry/blob_client_test.go b/sdk/containers/azcontainerregistry/blob_client_test.go index 635a446993b5..b4b2e30727a6 100644 --- a/sdk/containers/azcontainerregistry/blob_client_test.go +++ b/sdk/containers/azcontainerregistry/blob_client_test.go @@ -10,6 +10,7 @@ import ( "bytes" "context" "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" "github.com/Azure/azure-sdk-for-go/sdk/azcore/streaming" @@ -176,10 +177,11 @@ func TestBlobClient_GetBlob_wrongDigest(t *testing.T) { defer closeServer() srv.AppendResponse(mock.WithStatusCode(http.StatusOK), mock.WithBody([]byte("test"))) - pl := runtime.NewPipeline(moduleName, moduleVersion, runtime.PipelineOptions{}, &policy.ClientOptions{Transport: srv}) + azcoreClient, err := azcore.NewClient(moduleName, moduleVersion, runtime.PipelineOptions{}, &policy.ClientOptions{Transport: srv}) + require.NoError(t, err) client := &BlobClient{ + azcoreClient, srv.URL(), - pl, } ctx := context.Background() resp, err := client.GetBlob(ctx, "name", "sha256:9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08", nil) @@ -335,13 +337,14 @@ func TestBlobClient_StartUpload_empty(t *testing.T) { } func TestBlobClient_wrongEndpoint(t *testing.T) { - pl := runtime.NewPipeline(moduleName, moduleVersion, runtime.PipelineOptions{}, nil) + azcoreClient, err := azcore.NewClient(moduleName, moduleVersion, runtime.PipelineOptions{}, nil) + require.NoError(t, err) client := &BlobClient{ + azcoreClient, "wrong-endpoint", - pl, } ctx := context.Background() - _, err := client.CancelUpload(ctx, "location", nil) + _, err = client.CancelUpload(ctx, "location", nil) require.Error(t, err) _, err = client.CheckBlobExists(ctx, "name", "digest", nil) require.Error(t, err) diff --git a/sdk/containers/azcontainerregistry/blob_custom_client.go b/sdk/containers/azcontainerregistry/blob_custom_client.go index f7ce95d65c09..fc79bbe43663 100644 --- a/sdk/containers/azcontainerregistry/blob_custom_client.go +++ b/sdk/containers/azcontainerregistry/blob_custom_client.go @@ -41,9 +41,13 @@ func NewBlobClient(endpoint string, credential azcore.TokenCredential, options * return nil, errors.New("provided Cloud field is missing Azure Container Registry configuration") } - authClient := newAuthenticationClient(endpoint, &authenticationClientOptions{ + authClient, err := newAuthenticationClient(endpoint, &authenticationClientOptions{ options.ClientOptions, }) + if err != nil { + return nil, err + } + authPolicy := newAuthenticationPolicy( credential, []string{c.Audience + "/.default"}, @@ -51,10 +55,14 @@ func NewBlobClient(endpoint string, credential azcore.TokenCredential, options * nil, ) - pl := runtime.NewPipeline(moduleName, moduleVersion, runtime.PipelineOptions{PerRetry: []policy.Policy{authPolicy}}, &options.ClientOptions) + azcoreClient, err := azcore.NewClient(moduleName, moduleVersion, runtime.PipelineOptions{PerRetry: []policy.Policy{authPolicy}}, &options.ClientOptions) + if err != nil { + return nil, err + } + return &BlobClient{ + azcoreClient, endpoint, - pl, }, nil } diff --git a/sdk/containers/azcontainerregistry/blob_custom_client_test.go b/sdk/containers/azcontainerregistry/blob_custom_client_test.go index a1721077c132..feab78a9bc1e 100644 --- a/sdk/containers/azcontainerregistry/blob_custom_client_test.go +++ b/sdk/containers/azcontainerregistry/blob_custom_client_test.go @@ -150,15 +150,16 @@ func TestBlobClient_UploadChunk_retry(t *testing.T) { srv.AppendResponse(mock.WithStatusCode(http.StatusGatewayTimeout)) srv.AppendResponse(mock.WithStatusCode(http.StatusAccepted)) - pl := runtime.NewPipeline(moduleName, moduleVersion, runtime.PipelineOptions{}, &policy.ClientOptions{Transport: srv}) + azcoreClient, err := azcore.NewClient(moduleName, moduleVersion, runtime.PipelineOptions{}, &policy.ClientOptions{Transport: srv}) + require.NoError(t, err) client := &BlobClient{ + azcoreClient, srv.URL(), - pl, } ctx := context.Background() chunkData := bytes.NewReader([]byte("test")) calculator := NewBlobDigestCalculator() - _, err := client.UploadChunk(ctx, "location", chunkData, calculator, nil) + _, err = client.UploadChunk(ctx, "location", chunkData, calculator, nil) require.NoError(t, err) require.Equal(t, "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08", fmt.Sprintf("%x", calculator.h.Sum(nil))) } diff --git a/sdk/containers/azcontainerregistry/client.go b/sdk/containers/azcontainerregistry/client.go index 2dd119a1c311..bcc0d067c499 100644 --- a/sdk/containers/azcontainerregistry/client.go +++ b/sdk/containers/azcontainerregistry/client.go @@ -3,15 +3,15 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package azcontainerregistry import ( "context" "errors" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" "io" @@ -22,10 +22,10 @@ import ( ) // Client contains the methods for the ContainerRegistry group. -// Don't use this type directly, use NewClient() instead. +// Don't use this type directly, use a constructor function instead. type Client struct { + internal *azcore.Client endpoint string - pl runtime.Pipeline } // DeleteManifest - Delete the manifest identified by name and reference. Note that a manifest can only be deleted by digest. @@ -36,16 +36,20 @@ type Client struct { // - digest - Digest of a BLOB // - options - ClientDeleteManifestOptions contains the optional parameters for the Client.DeleteManifest method. func (client *Client) DeleteManifest(ctx context.Context, name string, digest string, options *ClientDeleteManifestOptions) (ClientDeleteManifestResponse, error) { + var err error + ctx, endSpan := runtime.StartSpan(ctx, "Client.DeleteManifest", client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deleteManifestCreateRequest(ctx, name, digest, options) if err != nil { return ClientDeleteManifestResponse{}, err } - resp, err := client.pl.Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ClientDeleteManifestResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusAccepted, http.StatusNotFound) { - return ClientDeleteManifestResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusAccepted, http.StatusNotFound) { + err = runtime.NewResponseError(httpResp) + return ClientDeleteManifestResponse{}, err } return ClientDeleteManifestResponse{}, nil } @@ -76,16 +80,20 @@ func (client *Client) deleteManifestCreateRequest(ctx context.Context, name stri // - name - Name of the image (including the namespace) // - options - ClientDeleteRepositoryOptions contains the optional parameters for the Client.DeleteRepository method. func (client *Client) DeleteRepository(ctx context.Context, name string, options *ClientDeleteRepositoryOptions) (ClientDeleteRepositoryResponse, error) { + var err error + ctx, endSpan := runtime.StartSpan(ctx, "Client.DeleteRepository", client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deleteRepositoryCreateRequest(ctx, name, options) if err != nil { return ClientDeleteRepositoryResponse{}, err } - resp, err := client.pl.Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ClientDeleteRepositoryResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusAccepted, http.StatusNotFound) { - return ClientDeleteRepositoryResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusAccepted, http.StatusNotFound) { + err = runtime.NewResponseError(httpResp) + return ClientDeleteRepositoryResponse{}, err } return ClientDeleteRepositoryResponse{}, nil } @@ -116,16 +124,20 @@ func (client *Client) deleteRepositoryCreateRequest(ctx context.Context, name st // - tag - Tag name // - options - ClientDeleteTagOptions contains the optional parameters for the Client.DeleteTag method. func (client *Client) DeleteTag(ctx context.Context, name string, tag string, options *ClientDeleteTagOptions) (ClientDeleteTagResponse, error) { + var err error + ctx, endSpan := runtime.StartSpan(ctx, "Client.DeleteTag", client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deleteTagCreateRequest(ctx, name, tag, options) if err != nil { return ClientDeleteTagResponse{}, err } - resp, err := client.pl.Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ClientDeleteTagResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusAccepted, http.StatusNotFound) { - return ClientDeleteTagResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusAccepted, http.StatusNotFound) { + err = runtime.NewResponseError(httpResp) + return ClientDeleteTagResponse{}, err } return ClientDeleteTagResponse{}, nil } @@ -160,18 +172,23 @@ func (client *Client) deleteTagCreateRequest(ctx context.Context, name string, t // - reference - A tag or a digest, pointing to a specific image // - options - ClientGetManifestOptions contains the optional parameters for the Client.GetManifest method. func (client *Client) GetManifest(ctx context.Context, name string, reference string, options *ClientGetManifestOptions) (ClientGetManifestResponse, error) { + var err error + ctx, endSpan := runtime.StartSpan(ctx, "Client.GetManifest", client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getManifestCreateRequest(ctx, name, reference, options) if err != nil { return ClientGetManifestResponse{}, err } - resp, err := client.pl.Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ClientGetManifestResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientGetManifestResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ClientGetManifestResponse{}, err } - return client.getManifestHandleResponse(resp) + resp, err := client.getManifestHandleResponse(httpResp) + return resp, err } // getManifestCreateRequest creates the GetManifest request. @@ -214,18 +231,23 @@ func (client *Client) getManifestHandleResponse(resp *http.Response) (ClientGetM // - digest - Digest of a BLOB // - options - ClientGetManifestPropertiesOptions contains the optional parameters for the Client.GetManifestProperties method. func (client *Client) GetManifestProperties(ctx context.Context, name string, digest string, options *ClientGetManifestPropertiesOptions) (ClientGetManifestPropertiesResponse, error) { + var err error + ctx, endSpan := runtime.StartSpan(ctx, "Client.GetManifestProperties", client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getManifestPropertiesCreateRequest(ctx, name, digest, options) if err != nil { return ClientGetManifestPropertiesResponse{}, err } - resp, err := client.pl.Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ClientGetManifestPropertiesResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientGetManifestPropertiesResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ClientGetManifestPropertiesResponse{}, err } - return client.getManifestPropertiesHandleResponse(resp) + resp, err := client.getManifestPropertiesHandleResponse(httpResp) + return resp, err } // getManifestPropertiesCreateRequest creates the GetManifestProperties request. @@ -267,18 +289,23 @@ func (client *Client) getManifestPropertiesHandleResponse(resp *http.Response) ( // - options - ClientGetRepositoryPropertiesOptions contains the optional parameters for the Client.GetRepositoryProperties // method. func (client *Client) GetRepositoryProperties(ctx context.Context, name string, options *ClientGetRepositoryPropertiesOptions) (ClientGetRepositoryPropertiesResponse, error) { + var err error + ctx, endSpan := runtime.StartSpan(ctx, "Client.GetRepositoryProperties", client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getRepositoryPropertiesCreateRequest(ctx, name, options) if err != nil { return ClientGetRepositoryPropertiesResponse{}, err } - resp, err := client.pl.Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ClientGetRepositoryPropertiesResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientGetRepositoryPropertiesResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ClientGetRepositoryPropertiesResponse{}, err } - return client.getRepositoryPropertiesHandleResponse(resp) + resp, err := client.getRepositoryPropertiesHandleResponse(httpResp) + return resp, err } // getRepositoryPropertiesCreateRequest creates the GetRepositoryProperties request. @@ -316,18 +343,23 @@ func (client *Client) getRepositoryPropertiesHandleResponse(resp *http.Response) // - tag - Tag name // - options - ClientGetTagPropertiesOptions contains the optional parameters for the Client.GetTagProperties method. func (client *Client) GetTagProperties(ctx context.Context, name string, tag string, options *ClientGetTagPropertiesOptions) (ClientGetTagPropertiesResponse, error) { + var err error + ctx, endSpan := runtime.StartSpan(ctx, "Client.GetTagProperties", client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getTagPropertiesCreateRequest(ctx, name, tag, options) if err != nil { return ClientGetTagPropertiesResponse{}, err } - resp, err := client.pl.Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ClientGetTagPropertiesResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientGetTagPropertiesResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ClientGetTagPropertiesResponse{}, err } - return client.getTagPropertiesHandleResponse(resp) + resp, err := client.getTagPropertiesHandleResponse(httpResp) + return resp, err } // getTagPropertiesCreateRequest creates the GetTagProperties request. @@ -372,25 +404,19 @@ func (client *Client) NewListManifestsPager(name string, options *ClientListMani return page.Link != nil && len(*page.Link) > 0 }, Fetcher: func(ctx context.Context, page *ClientListManifestsResponse) (ClientListManifestsResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listManifestsCreateRequest(ctx, name, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.Link) + nextLink := "" + if page != nil { + nextLink = *page.Link } + resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { + return client.listManifestsCreateRequest(ctx, name, options) + }, nil) if err != nil { return ClientListManifestsResponse{}, err } - resp, err := client.pl.Do(req) - if err != nil { - return ClientListManifestsResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientListManifestsResponse{}, runtime.NewResponseError(resp) - } return client.listManifestsHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -444,25 +470,19 @@ func (client *Client) NewListRepositoriesPager(options *ClientListRepositoriesOp return page.Link != nil && len(*page.Link) > 0 }, Fetcher: func(ctx context.Context, page *ClientListRepositoriesResponse) (ClientListRepositoriesResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listRepositoriesCreateRequest(ctx, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.Link) + nextLink := "" + if page != nil { + nextLink = *page.Link } + resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { + return client.listRepositoriesCreateRequest(ctx, options) + }, nil) if err != nil { return ClientListRepositoriesResponse{}, err } - resp, err := client.pl.Do(req) - if err != nil { - return ClientListRepositoriesResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientListRepositoriesResponse{}, runtime.NewResponseError(resp) - } return client.listRepositoriesHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -510,25 +530,19 @@ func (client *Client) NewListTagsPager(name string, options *ClientListTagsOptio return page.Link != nil && len(*page.Link) > 0 }, Fetcher: func(ctx context.Context, page *ClientListTagsResponse) (ClientListTagsResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listTagsCreateRequest(ctx, name, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.Link) - } - if err != nil { - return ClientListTagsResponse{}, err + nextLink := "" + if page != nil { + nextLink = *page.Link } - resp, err := client.pl.Do(req) + resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { + return client.listTagsCreateRequest(ctx, name, options) + }, nil) if err != nil { return ClientListTagsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientListTagsResponse{}, runtime.NewResponseError(resp) - } return client.listTagsHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -584,18 +598,23 @@ func (client *Client) listTagsHandleResponse(resp *http.Response) (ClientListTag // - options - ClientUpdateManifestPropertiesOptions contains the optional parameters for the Client.UpdateManifestProperties // method. func (client *Client) UpdateManifestProperties(ctx context.Context, name string, digest string, options *ClientUpdateManifestPropertiesOptions) (ClientUpdateManifestPropertiesResponse, error) { + var err error + ctx, endSpan := runtime.StartSpan(ctx, "Client.UpdateManifestProperties", client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateManifestPropertiesCreateRequest(ctx, name, digest, options) if err != nil { return ClientUpdateManifestPropertiesResponse{}, err } - resp, err := client.pl.Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ClientUpdateManifestPropertiesResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientUpdateManifestPropertiesResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ClientUpdateManifestPropertiesResponse{}, err } - return client.updateManifestPropertiesHandleResponse(resp) + resp, err := client.updateManifestPropertiesHandleResponse(httpResp) + return resp, err } // updateManifestPropertiesCreateRequest creates the UpdateManifestProperties request. @@ -618,7 +637,10 @@ func (client *Client) updateManifestPropertiesCreateRequest(ctx context.Context, req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} if options != nil && options.Value != nil { - return req, runtime.MarshalAsJSON(req, *options.Value) + if err := runtime.MarshalAsJSON(req, *options.Value); err != nil { + return nil, err + } + return req, nil } return req, nil } @@ -640,18 +662,23 @@ func (client *Client) updateManifestPropertiesHandleResponse(resp *http.Response // - options - ClientUpdateRepositoryPropertiesOptions contains the optional parameters for the Client.UpdateRepositoryProperties // method. func (client *Client) UpdateRepositoryProperties(ctx context.Context, name string, options *ClientUpdateRepositoryPropertiesOptions) (ClientUpdateRepositoryPropertiesResponse, error) { + var err error + ctx, endSpan := runtime.StartSpan(ctx, "Client.UpdateRepositoryProperties", client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateRepositoryPropertiesCreateRequest(ctx, name, options) if err != nil { return ClientUpdateRepositoryPropertiesResponse{}, err } - resp, err := client.pl.Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ClientUpdateRepositoryPropertiesResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientUpdateRepositoryPropertiesResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ClientUpdateRepositoryPropertiesResponse{}, err } - return client.updateRepositoryPropertiesHandleResponse(resp) + resp, err := client.updateRepositoryPropertiesHandleResponse(httpResp) + return resp, err } // updateRepositoryPropertiesCreateRequest creates the UpdateRepositoryProperties request. @@ -670,7 +697,10 @@ func (client *Client) updateRepositoryPropertiesCreateRequest(ctx context.Contex req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} if options != nil && options.Value != nil { - return req, runtime.MarshalAsJSON(req, *options.Value) + if err := runtime.MarshalAsJSON(req, *options.Value); err != nil { + return nil, err + } + return req, nil } return req, nil } @@ -692,18 +722,23 @@ func (client *Client) updateRepositoryPropertiesHandleResponse(resp *http.Respon // - tag - Tag name // - options - ClientUpdateTagPropertiesOptions contains the optional parameters for the Client.UpdateTagProperties method. func (client *Client) UpdateTagProperties(ctx context.Context, name string, tag string, options *ClientUpdateTagPropertiesOptions) (ClientUpdateTagPropertiesResponse, error) { + var err error + ctx, endSpan := runtime.StartSpan(ctx, "Client.UpdateTagProperties", client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagPropertiesCreateRequest(ctx, name, tag, options) if err != nil { return ClientUpdateTagPropertiesResponse{}, err } - resp, err := client.pl.Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ClientUpdateTagPropertiesResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientUpdateTagPropertiesResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ClientUpdateTagPropertiesResponse{}, err } - return client.updateTagPropertiesHandleResponse(resp) + resp, err := client.updateTagPropertiesHandleResponse(httpResp) + return resp, err } // updateTagPropertiesCreateRequest creates the UpdateTagProperties request. @@ -726,7 +761,10 @@ func (client *Client) updateTagPropertiesCreateRequest(ctx context.Context, name req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} if options != nil && options.Value != nil { - return req, runtime.MarshalAsJSON(req, *options.Value) + if err := runtime.MarshalAsJSON(req, *options.Value); err != nil { + return nil, err + } + return req, nil } return req, nil } @@ -750,18 +788,23 @@ func (client *Client) updateTagPropertiesHandleResponse(resp *http.Response) (Cl // - manifestData - Manifest body, can take v1 or v2 values depending on accept header // - options - ClientUploadManifestOptions contains the optional parameters for the Client.UploadManifest method. func (client *Client) UploadManifest(ctx context.Context, name string, reference string, contentType ContentType, manifestData io.ReadSeekCloser, options *ClientUploadManifestOptions) (ClientUploadManifestResponse, error) { + var err error + ctx, endSpan := runtime.StartSpan(ctx, "Client.UploadManifest", client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.uploadManifestCreateRequest(ctx, name, reference, contentType, manifestData, options) if err != nil { return ClientUploadManifestResponse{}, err } - resp, err := client.pl.Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ClientUploadManifestResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusCreated) { - return ClientUploadManifestResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return ClientUploadManifestResponse{}, err } - return client.uploadManifestHandleResponse(resp) + resp, err := client.uploadManifestHandleResponse(httpResp) + return resp, err } // uploadManifestCreateRequest creates the UploadManifest request. @@ -781,18 +824,15 @@ func (client *Client) uploadManifestCreateRequest(ctx context.Context, name stri } req.Raw().Header["Content-Type"] = []string{string(contentType)} req.Raw().Header["Accept"] = []string{"application/json"} - return req, req.SetBody(manifestData, string(contentType)) + if err := req.SetBody(manifestData, string(contentType)); err != nil { + return nil, err + } + return req, nil } // uploadManifestHandleResponse handles the UploadManifest response. func (client *Client) uploadManifestHandleResponse(resp *http.Response) (ClientUploadManifestResponse, error) { result := ClientUploadManifestResponse{} - if val := resp.Header.Get("Docker-Content-Digest"); val != "" { - result.DockerContentDigest = &val - } - if val := resp.Header.Get("Location"); val != "" { - result.Location = &val - } if val := resp.Header.Get("Content-Length"); val != "" { contentLength, err := strconv.ParseInt(val, 10, 64) if err != nil { @@ -800,5 +840,11 @@ func (client *Client) uploadManifestHandleResponse(resp *http.Response) (ClientU } result.ContentLength = &contentLength } + if val := resp.Header.Get("Docker-Content-Digest"); val != "" { + result.DockerContentDigest = &val + } + if val := resp.Header.Get("Location"); val != "" { + result.Location = &val + } return result, nil } diff --git a/sdk/containers/azcontainerregistry/client_test.go b/sdk/containers/azcontainerregistry/client_test.go index b43fe8345733..dff2ae5ee51b 100644 --- a/sdk/containers/azcontainerregistry/client_test.go +++ b/sdk/containers/azcontainerregistry/client_test.go @@ -10,6 +10,7 @@ import ( "bytes" "context" "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" "github.com/Azure/azure-sdk-for-go/sdk/azcore/streaming" @@ -80,13 +81,14 @@ func TestClient_DeleteRepository_error(t *testing.T) { defer closeServer() srv.AppendResponse(mock.WithStatusCode(http.StatusBadRequest)) - pl := runtime.NewPipeline(moduleName, moduleVersion, runtime.PipelineOptions{}, &policy.ClientOptions{Transport: srv}) + azcoreClient, err := azcore.NewClient(moduleName, moduleVersion, runtime.PipelineOptions{}, &policy.ClientOptions{Transport: srv}) + require.NoError(t, err) client := &Client{ + azcoreClient, srv.URL(), - pl, } ctx := context.Background() - _, err := client.DeleteRepository(ctx, "test", nil) + _, err = client.DeleteRepository(ctx, "test", nil) require.Error(t, err) } @@ -115,13 +117,14 @@ func TestClient_DeleteTag_error(t *testing.T) { defer closeServer() srv.AppendResponse(mock.WithStatusCode(http.StatusBadRequest)) - pl := runtime.NewPipeline(moduleName, moduleVersion, runtime.PipelineOptions{}, &policy.ClientOptions{Transport: srv}) + azcoreClient, err := azcore.NewClient(moduleName, moduleVersion, runtime.PipelineOptions{}, &policy.ClientOptions{Transport: srv}) + require.NoError(t, err) client := &Client{ + azcoreClient, srv.URL(), - pl, } ctx := context.Background() - _, err := client.DeleteTag(ctx, "name", "tag", nil) + _, err = client.DeleteTag(ctx, "name", "tag", nil) require.Error(t, err) } @@ -146,10 +149,11 @@ func TestClient_GetManifest_wrongServerDigest(t *testing.T) { defer closeServer() srv.AppendResponse(mock.WithStatusCode(http.StatusOK), mock.WithBody([]byte("test")), mock.WithHeader("Docker-Content-Digest", "sha256:wrong")) - pl := runtime.NewPipeline(moduleName, moduleVersion, runtime.PipelineOptions{}, &policy.ClientOptions{Transport: srv}) + azcoreClient, err := azcore.NewClient(moduleName, moduleVersion, runtime.PipelineOptions{}, &policy.ClientOptions{Transport: srv}) + require.NoError(t, err) client := &Client{ + azcoreClient, srv.URL(), - pl, } ctx := context.Background() resp, err := client.GetManifest(ctx, "name", "sha256:9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08", nil) @@ -395,10 +399,11 @@ func TestClient_NewListRepositoriesPager_error(t *testing.T) { defer closeServer() srv.AppendResponse(mock.WithStatusCode(http.StatusBadRequest)) - pl := runtime.NewPipeline(moduleName, moduleVersion, runtime.PipelineOptions{}, &policy.ClientOptions{Transport: srv}) + azcoreClient, err := azcore.NewClient(moduleName, moduleVersion, runtime.PipelineOptions{}, &policy.ClientOptions{Transport: srv}) + require.NoError(t, err) client := &Client{ + azcoreClient, srv.URL(), - pl, } ctx := context.Background() pager := client.NewListRepositoriesPager(nil) @@ -655,24 +660,26 @@ func TestClient_UploadManifest_error(t *testing.T) { defer closeServer() srv.AppendResponse(mock.WithStatusCode(http.StatusBadRequest)) - pl := runtime.NewPipeline(moduleName, moduleVersion, runtime.PipelineOptions{}, &policy.ClientOptions{Transport: srv}) + azcoreClient, err := azcore.NewClient(moduleName, moduleVersion, runtime.PipelineOptions{}, &policy.ClientOptions{Transport: srv}) + require.NoError(t, err) client := &Client{ + azcoreClient, srv.URL(), - pl, } ctx := context.Background() - _, err := client.UploadManifest(ctx, "name", "reference", "contentType", nil, nil) + _, err = client.UploadManifest(ctx, "name", "reference", "contentType", nil, nil) require.Error(t, err) } func TestClient_wrongEndpoint(t *testing.T) { - pl := runtime.NewPipeline(moduleName, moduleVersion, runtime.PipelineOptions{}, nil) + azcoreClient, err := azcore.NewClient(moduleName, moduleVersion, runtime.PipelineOptions{}, nil) + require.NoError(t, err) client := &Client{ + azcoreClient, "wrong-endpoint", - pl, } ctx := context.Background() - _, err := client.DeleteManifest(ctx, "name", "digest", nil) + _, err = client.DeleteManifest(ctx, "name", "digest", nil) require.Error(t, err) _, err = client.DeleteRepository(ctx, "name", nil) require.Error(t, err) diff --git a/sdk/containers/azcontainerregistry/constants.go b/sdk/containers/azcontainerregistry/constants.go index 304df483ffd1..8dcf5c0b1e85 100644 --- a/sdk/containers/azcontainerregistry/constants.go +++ b/sdk/containers/azcontainerregistry/constants.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package azcontainerregistry @@ -64,22 +63,22 @@ func PossibleArtifactArchitectureValues() []ArtifactArchitecture { type ArtifactManifestOrderBy string const ( - // ArtifactManifestOrderByNone - Do not provide an orderby value in the request. - ArtifactManifestOrderByNone ArtifactManifestOrderBy = "none" - // ArtifactManifestOrderByLastUpdatedOnDescending - Order manifests by LastUpdatedOn field, from most recently updated to - // least recently updated. - ArtifactManifestOrderByLastUpdatedOnDescending ArtifactManifestOrderBy = "timedesc" // ArtifactManifestOrderByLastUpdatedOnAscending - Order manifest by LastUpdatedOn field, from least recently updated to most // recently updated. ArtifactManifestOrderByLastUpdatedOnAscending ArtifactManifestOrderBy = "timeasc" + // ArtifactManifestOrderByLastUpdatedOnDescending - Order manifests by LastUpdatedOn field, from most recently updated to + // least recently updated. + ArtifactManifestOrderByLastUpdatedOnDescending ArtifactManifestOrderBy = "timedesc" + // ArtifactManifestOrderByNone - Do not provide an orderby value in the request. + ArtifactManifestOrderByNone ArtifactManifestOrderBy = "none" ) // PossibleArtifactManifestOrderByValues returns the possible values for the ArtifactManifestOrderBy const type. func PossibleArtifactManifestOrderByValues() []ArtifactManifestOrderBy { return []ArtifactManifestOrderBy{ - ArtifactManifestOrderByNone, - ArtifactManifestOrderByLastUpdatedOnDescending, ArtifactManifestOrderByLastUpdatedOnAscending, + ArtifactManifestOrderByLastUpdatedOnDescending, + ArtifactManifestOrderByNone, } } @@ -127,22 +126,22 @@ func PossibleArtifactOperatingSystemValues() []ArtifactOperatingSystem { type ArtifactTagOrderBy string const ( - // ArtifactTagOrderByNone - Do not provide an orderby value in the request. - ArtifactTagOrderByNone ArtifactTagOrderBy = "none" - // ArtifactTagOrderByLastUpdatedOnDescending - Order tags by LastUpdatedOn field, from most recently updated to least recently - // updated. - ArtifactTagOrderByLastUpdatedOnDescending ArtifactTagOrderBy = "timedesc" // ArtifactTagOrderByLastUpdatedOnAscending - Order tags by LastUpdatedOn field, from least recently updated to most recently // updated. ArtifactTagOrderByLastUpdatedOnAscending ArtifactTagOrderBy = "timeasc" + // ArtifactTagOrderByLastUpdatedOnDescending - Order tags by LastUpdatedOn field, from most recently updated to least recently + // updated. + ArtifactTagOrderByLastUpdatedOnDescending ArtifactTagOrderBy = "timedesc" + // ArtifactTagOrderByNone - Do not provide an orderby value in the request. + ArtifactTagOrderByNone ArtifactTagOrderBy = "none" ) // PossibleArtifactTagOrderByValues returns the possible values for the ArtifactTagOrderBy const type. func PossibleArtifactTagOrderByValues() []ArtifactTagOrderBy { return []ArtifactTagOrderBy{ - ArtifactTagOrderByNone, - ArtifactTagOrderByLastUpdatedOnDescending, ArtifactTagOrderByLastUpdatedOnAscending, + ArtifactTagOrderByLastUpdatedOnDescending, + ArtifactTagOrderByNone, } } @@ -186,14 +185,14 @@ func possiblePostContentSchemaGrantTypeValues() []postContentSchemaGrantType { type tokenGrantType string const ( - tokenGrantTypeRefreshToken tokenGrantType = "refresh_token" tokenGrantTypePassword tokenGrantType = "password" + tokenGrantTypeRefreshToken tokenGrantType = "refresh_token" ) // possibleTokenGrantTypeValues returns the possible values for the tokenGrantType const type. func possibleTokenGrantTypeValues() []tokenGrantType { return []tokenGrantType{ - tokenGrantTypeRefreshToken, tokenGrantTypePassword, + tokenGrantTypeRefreshToken, } } diff --git a/sdk/containers/azcontainerregistry/custom_client.go b/sdk/containers/azcontainerregistry/custom_client.go index 6719e63494a4..ed9fdbad4246 100644 --- a/sdk/containers/azcontainerregistry/custom_client.go +++ b/sdk/containers/azcontainerregistry/custom_client.go @@ -37,9 +37,13 @@ func NewClient(endpoint string, credential azcore.TokenCredential, options *Clie return nil, errors.New("provided Cloud field is missing Azure Container Registry configuration") } - authClient := newAuthenticationClient(endpoint, &authenticationClientOptions{ + authClient, err := newAuthenticationClient(endpoint, &authenticationClientOptions{ options.ClientOptions, }) + if err != nil { + return nil, err + } + authPolicy := newAuthenticationPolicy( credential, []string{c.Audience + "/.default"}, @@ -47,10 +51,14 @@ func NewClient(endpoint string, credential azcore.TokenCredential, options *Clie nil, ) - pl := runtime.NewPipeline(moduleName, moduleVersion, runtime.PipelineOptions{PerRetry: []policy.Policy{authPolicy}}, &options.ClientOptions) + azcoreClient, err := azcore.NewClient(moduleName, moduleVersion, runtime.PipelineOptions{PerRetry: []policy.Policy{authPolicy}}, &options.ClientOptions) + if err != nil { + return nil, err + } + return &Client{ + azcoreClient, endpoint, - pl, }, nil } diff --git a/sdk/containers/azcontainerregistry/custom_constants.go b/sdk/containers/azcontainerregistry/custom_constants.go index 6755645e6f8a..43d030b4c155 100644 --- a/sdk/containers/azcontainerregistry/custom_constants.go +++ b/sdk/containers/azcontainerregistry/custom_constants.go @@ -7,7 +7,7 @@ package azcontainerregistry const ( - moduleName = "azcontainerregistry" + moduleName = "github.com/Azure/azure-sdk-for-go/sdk/containers/azcontainerregistry" moduleVersion = "v0.2.1" defaultAudience = "https://containerregistry.azure.net" ) diff --git a/sdk/containers/azcontainerregistry/models.go b/sdk/containers/azcontainerregistry/models.go index d9bf10a50405..cb37a1fe1655 100644 --- a/sdk/containers/azcontainerregistry/models.go +++ b/sdk/containers/azcontainerregistry/models.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package azcontainerregistry @@ -13,369 +12,204 @@ import "time" type acrAccessToken struct { // The access token for performing authenticated requests - AccessToken *string `json:"access_token,omitempty"` + AccessToken *string } type acrRefreshToken struct { // The refresh token to be used for generating access tokens - RefreshToken *string `json:"refresh_token,omitempty"` + RefreshToken *string } // ArtifactManifestPlatform - The artifact's platform, consisting of operating system and architecture. type ArtifactManifestPlatform struct { // READ-ONLY; Manifest digest - Digest *string `json:"digest,omitempty" azure:"ro"` + Digest *string // READ-ONLY; CPU architecture - Architecture *ArtifactArchitecture `json:"architecture,omitempty" azure:"ro"` + Architecture *ArtifactArchitecture // READ-ONLY; Operating system - OperatingSystem *ArtifactOperatingSystem `json:"os,omitempty" azure:"ro"` + OperatingSystem *ArtifactOperatingSystem } // ArtifactManifestProperties - Manifest attributes details type ArtifactManifestProperties struct { // READ-ONLY; Manifest attributes - Manifest *ManifestAttributes `json:"manifest,omitempty" azure:"ro"` + Manifest *ManifestAttributes // READ-ONLY; Registry login server name. This is likely to be similar to {registry-name}.azurecr.io. - RegistryLoginServer *string `json:"registry,omitempty" azure:"ro"` + RegistryLoginServer *string // READ-ONLY; Repository name - RepositoryName *string `json:"imageName,omitempty" azure:"ro"` + RepositoryName *string } // ArtifactTagProperties - Tag attributes type ArtifactTagProperties struct { // READ-ONLY; Registry login server name. This is likely to be similar to {registry-name}.azurecr.io. - RegistryLoginServer *string `json:"registry,omitempty" azure:"ro"` + RegistryLoginServer *string // READ-ONLY; Image name - RepositoryName *string `json:"imageName,omitempty" azure:"ro"` + RepositoryName *string // READ-ONLY; List of tag attribute details - Tag *TagAttributes `json:"tag,omitempty" azure:"ro"` -} - -// authenticationClientExchangeAADAccessTokenForACRRefreshTokenOptions contains the optional parameters for the authenticationClient.ExchangeAADAccessTokenForACRRefreshToken -// method. -type authenticationClientExchangeAADAccessTokenForACRRefreshTokenOptions struct { - // AAD access token, mandatory when granttype is accesstokenrefreshtoken or access_token. - AccessToken *string - // AAD refresh token, mandatory when granttype is accesstokenrefreshtoken or refresh_token - RefreshToken *string - // AAD tenant associated to the AAD credentials. - Tenant *string -} - -// authenticationClientExchangeACRRefreshTokenForACRAccessTokenOptions contains the optional parameters for the authenticationClient.ExchangeACRRefreshTokenForACRAccessToken -// method. -type authenticationClientExchangeACRRefreshTokenForACRAccessTokenOptions struct { - // Grant type is expected to be refresh_token - GrantType *tokenGrantType -} - -// BlobClientCancelUploadOptions contains the optional parameters for the BlobClient.CancelUpload method. -type BlobClientCancelUploadOptions struct { - // placeholder for future optional parameters -} - -// BlobClientCheckBlobExistsOptions contains the optional parameters for the BlobClient.CheckBlobExists method. -type BlobClientCheckBlobExistsOptions struct { - // placeholder for future optional parameters -} - -// BlobClientCheckChunkExistsOptions contains the optional parameters for the BlobClient.CheckChunkExists method. -type BlobClientCheckChunkExistsOptions struct { - // placeholder for future optional parameters -} - -// BlobClientCompleteUploadOptions contains the optional parameters for the BlobClient.CompleteUpload method. -type BlobClientCompleteUploadOptions struct { - // placeholder for future optional parameters -} - -// BlobClientDeleteBlobOptions contains the optional parameters for the BlobClient.DeleteBlob method. -type BlobClientDeleteBlobOptions struct { - // placeholder for future optional parameters -} - -// BlobClientGetBlobOptions contains the optional parameters for the BlobClient.GetBlob method. -type BlobClientGetBlobOptions struct { - // placeholder for future optional parameters -} - -// BlobClientGetChunkOptions contains the optional parameters for the BlobClient.GetChunk method. -type BlobClientGetChunkOptions struct { - // placeholder for future optional parameters -} - -// BlobClientGetUploadStatusOptions contains the optional parameters for the BlobClient.GetUploadStatus method. -type BlobClientGetUploadStatusOptions struct { - // placeholder for future optional parameters -} - -// BlobClientMountBlobOptions contains the optional parameters for the BlobClient.MountBlob method. -type BlobClientMountBlobOptions struct { - // placeholder for future optional parameters -} - -// BlobClientStartUploadOptions contains the optional parameters for the BlobClient.StartUpload method. -type BlobClientStartUploadOptions struct { - // placeholder for future optional parameters -} - -// blobClientUploadChunkOptions contains the optional parameters for the BlobClient.uploadChunk method. -type blobClientUploadChunkOptions struct { - // Range of bytes identifying the desired block of content represented by the body. Start must the end offset retrieved via - // status check plus one. Note that this is a non-standard use of the - // Content-Range header. - ContentRange *string -} - -// ClientDeleteManifestOptions contains the optional parameters for the Client.DeleteManifest method. -type ClientDeleteManifestOptions struct { - // placeholder for future optional parameters -} - -// ClientDeleteRepositoryOptions contains the optional parameters for the Client.DeleteRepository method. -type ClientDeleteRepositoryOptions struct { - // placeholder for future optional parameters -} - -// ClientDeleteTagOptions contains the optional parameters for the Client.DeleteTag method. -type ClientDeleteTagOptions struct { - // placeholder for future optional parameters -} - -// ClientGetManifestOptions contains the optional parameters for the Client.GetManifest method. -type ClientGetManifestOptions struct { - // Accept header string delimited by comma. For example, application/vnd.docker.distribution.manifest.v2+json - Accept *string -} - -// ClientGetManifestPropertiesOptions contains the optional parameters for the Client.GetManifestProperties method. -type ClientGetManifestPropertiesOptions struct { - // placeholder for future optional parameters -} - -// ClientGetRepositoryPropertiesOptions contains the optional parameters for the Client.GetRepositoryProperties method. -type ClientGetRepositoryPropertiesOptions struct { - // placeholder for future optional parameters -} - -// ClientGetTagPropertiesOptions contains the optional parameters for the Client.GetTagProperties method. -type ClientGetTagPropertiesOptions struct { - // placeholder for future optional parameters -} - -// ClientListManifestsOptions contains the optional parameters for the Client.NewListManifestsPager method. -type ClientListManifestsOptions struct { - // Query parameter for the last item in previous query. Result set will include values lexically after last. - Last *string - // query parameter for max number of items - MaxNum *int32 - // Sort options for ordering manifests in a collection. - OrderBy *ArtifactManifestOrderBy -} - -// ClientListRepositoriesOptions contains the optional parameters for the Client.NewListRepositoriesPager method. -type ClientListRepositoriesOptions struct { - // Query parameter for the last item in previous query. Result set will include values lexically after last. - Last *string - // query parameter for max number of items - MaxNum *int32 -} - -// ClientListTagsOptions contains the optional parameters for the Client.NewListTagsPager method. -type ClientListTagsOptions struct { - // filter by digest - Digest *string - // Query parameter for the last item in previous query. Result set will include values lexically after last. - Last *string - // query parameter for max number of items - MaxNum *int32 - // Sort options for ordering tags in a collection. - OrderBy *ArtifactTagOrderBy -} - -// ClientUpdateManifestPropertiesOptions contains the optional parameters for the Client.UpdateManifestProperties method. -type ClientUpdateManifestPropertiesOptions struct { - // Manifest attribute value - Value *ManifestWriteableProperties -} - -// ClientUpdateRepositoryPropertiesOptions contains the optional parameters for the Client.UpdateRepositoryProperties method. -type ClientUpdateRepositoryPropertiesOptions struct { - // Repository attribute value - Value *RepositoryWriteableProperties -} - -// ClientUpdateTagPropertiesOptions contains the optional parameters for the Client.UpdateTagProperties method. -type ClientUpdateTagPropertiesOptions struct { - // Tag attribute value - Value *TagWriteableProperties -} - -// ClientUploadManifestOptions contains the optional parameters for the Client.UploadManifest method. -type ClientUploadManifestOptions struct { - // placeholder for future optional parameters + Tag *TagAttributes } // ContainerRepositoryProperties - Properties of this repository. type ContainerRepositoryProperties struct { // REQUIRED; Writeable properties of the resource - ChangeableAttributes *RepositoryWriteableProperties `json:"changeableAttributes,omitempty"` + ChangeableAttributes *RepositoryWriteableProperties // READ-ONLY; Image created time - CreatedOn *time.Time `json:"createdTime,omitempty" azure:"ro"` + CreatedOn *time.Time // READ-ONLY; Image last update time - LastUpdatedOn *time.Time `json:"lastUpdateTime,omitempty" azure:"ro"` + LastUpdatedOn *time.Time // READ-ONLY; Number of the manifests - ManifestCount *int32 `json:"manifestCount,omitempty" azure:"ro"` + ManifestCount *int32 // READ-ONLY; Image name - Name *string `json:"imageName,omitempty" azure:"ro"` + Name *string // READ-ONLY; Registry login server name. This is likely to be similar to {registry-name}.azurecr.io. - RegistryLoginServer *string `json:"registry,omitempty" azure:"ro"` + RegistryLoginServer *string // READ-ONLY; Number of the tags - TagCount *int32 `json:"tagCount,omitempty" azure:"ro"` + TagCount *int32 } // ManifestAttributes - Manifest details type ManifestAttributes struct { // READ-ONLY; Created time - CreatedOn *time.Time `json:"createdTime,omitempty" azure:"ro"` + CreatedOn *time.Time // READ-ONLY; Manifest - Digest *string `json:"digest,omitempty" azure:"ro"` + Digest *string // READ-ONLY; Last update time - LastUpdatedOn *time.Time `json:"lastUpdateTime,omitempty" azure:"ro"` + LastUpdatedOn *time.Time // Writeable properties of the resource - ChangeableAttributes *ManifestWriteableProperties `json:"changeableAttributes,omitempty"` + ChangeableAttributes *ManifestWriteableProperties // Config blob media type - ConfigMediaType *string `json:"configMediaType,omitempty"` + ConfigMediaType *string // Media type for this Manifest - MediaType *string `json:"mediaType,omitempty"` + MediaType *string // READ-ONLY; CPU architecture - Architecture *ArtifactArchitecture `json:"architecture,omitempty" azure:"ro"` + Architecture *ArtifactArchitecture // READ-ONLY; Operating system - OperatingSystem *ArtifactOperatingSystem `json:"os,omitempty" azure:"ro"` + OperatingSystem *ArtifactOperatingSystem // READ-ONLY; List of artifacts that are referenced by this manifest list, with information about the platform each supports. // This list will be empty if this is a leaf manifest and not a manifest list. - RelatedArtifacts []*ArtifactManifestPlatform `json:"references,omitempty" azure:"ro"` + RelatedArtifacts []*ArtifactManifestPlatform // READ-ONLY; Image size - Size *int64 `json:"imageSize,omitempty" azure:"ro"` + Size *int64 // READ-ONLY; List of tags - Tags []*string `json:"tags,omitempty" azure:"ro"` + Tags []*string } // ManifestWriteableProperties - Changeable attributes type ManifestWriteableProperties struct { // Delete enabled - CanDelete *bool `json:"deleteEnabled,omitempty"` + CanDelete *bool // List enabled - CanList *bool `json:"listEnabled,omitempty"` + CanList *bool // Read enabled - CanRead *bool `json:"readEnabled,omitempty"` + CanRead *bool // Write enabled - CanWrite *bool `json:"writeEnabled,omitempty"` + CanWrite *bool } // Manifests - Manifest attributes type Manifests struct { // List of manifests - Attributes []*ManifestAttributes `json:"manifests,omitempty"` - Link *string `json:"link,omitempty"` + Attributes []*ManifestAttributes + Link *string // Registry login server name. This is likely to be similar to {registry-name}.azurecr.io. - RegistryLoginServer *string `json:"registry,omitempty"` + RegistryLoginServer *string // Image name - Repository *string `json:"imageName,omitempty"` + Repository *string } // Repositories - List of repositories type Repositories struct { - Link *string `json:"link,omitempty"` + Link *string // Repository names - Names []*string `json:"repositories,omitempty"` + Names []*string } // RepositoryWriteableProperties - Changeable attributes for Repository type RepositoryWriteableProperties struct { // Delete enabled - CanDelete *bool `json:"deleteEnabled,omitempty"` + CanDelete *bool // List enabled - CanList *bool `json:"listEnabled,omitempty"` + CanList *bool // Read enabled - CanRead *bool `json:"readEnabled,omitempty"` + CanRead *bool // Write enabled - CanWrite *bool `json:"writeEnabled,omitempty"` + CanWrite *bool } // TagAttributes - Tag attribute details type TagAttributes struct { // REQUIRED; Writeable properties of the resource - ChangeableAttributes *TagWriteableProperties `json:"changeableAttributes,omitempty"` + ChangeableAttributes *TagWriteableProperties // READ-ONLY; Tag created time - CreatedOn *time.Time `json:"createdTime,omitempty" azure:"ro"` + CreatedOn *time.Time // READ-ONLY; Tag digest - Digest *string `json:"digest,omitempty" azure:"ro"` + Digest *string // READ-ONLY; Tag last update time - LastUpdatedOn *time.Time `json:"lastUpdateTime,omitempty" azure:"ro"` + LastUpdatedOn *time.Time // READ-ONLY; Tag name - Name *string `json:"name,omitempty" azure:"ro"` + Name *string } // TagList - List of tag details type TagList struct { // REQUIRED; Registry login server name. This is likely to be similar to {registry-name}.azurecr.io. - RegistryLoginServer *string `json:"registry,omitempty"` + RegistryLoginServer *string // REQUIRED; Image name - Repository *string `json:"imageName,omitempty"` + Repository *string // REQUIRED; List of tag attribute details - Tags []*TagAttributes `json:"tags,omitempty"` - Link *string `json:"link,omitempty"` + Tags []*TagAttributes + Link *string } // TagWriteableProperties - Changeable attributes type TagWriteableProperties struct { // Delete enabled - CanDelete *bool `json:"deleteEnabled,omitempty"` + CanDelete *bool // List enabled - CanList *bool `json:"listEnabled,omitempty"` + CanList *bool // Read enabled - CanRead *bool `json:"readEnabled,omitempty"` + CanRead *bool // Write enabled - CanWrite *bool `json:"writeEnabled,omitempty"` + CanWrite *bool } diff --git a/sdk/containers/azcontainerregistry/models_serde.go b/sdk/containers/azcontainerregistry/models_serde.go index a063ae11fb02..0a3ab4bc99cd 100644 --- a/sdk/containers/azcontainerregistry/models_serde.go +++ b/sdk/containers/azcontainerregistry/models_serde.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package azcontainerregistry @@ -147,10 +146,10 @@ func (c *ContainerRepositoryProperties) UnmarshalJSON(data []byte) error { err = unpopulate(val, "ChangeableAttributes", &c.ChangeableAttributes) delete(rawMsg, key) case "createdTime": - err = unpopulateTimeRFC3339(val, "CreatedOn", &c.CreatedOn) + err = unpopulateDateTimeRFC3339(val, "CreatedOn", &c.CreatedOn) delete(rawMsg, key) case "lastUpdateTime": - err = unpopulateTimeRFC3339(val, "LastUpdatedOn", &c.LastUpdatedOn) + err = unpopulateDateTimeRFC3339(val, "LastUpdatedOn", &c.LastUpdatedOn) delete(rawMsg, key) case "manifestCount": err = unpopulate(val, "ManifestCount", &c.ManifestCount) @@ -191,13 +190,13 @@ func (m *ManifestAttributes) UnmarshalJSON(data []byte) error { err = unpopulate(val, "ConfigMediaType", &m.ConfigMediaType) delete(rawMsg, key) case "createdTime": - err = unpopulateTimeRFC3339(val, "CreatedOn", &m.CreatedOn) + err = unpopulateDateTimeRFC3339(val, "CreatedOn", &m.CreatedOn) delete(rawMsg, key) case "digest": err = unpopulate(val, "Digest", &m.Digest) delete(rawMsg, key) case "lastUpdateTime": - err = unpopulateTimeRFC3339(val, "LastUpdatedOn", &m.LastUpdatedOn) + err = unpopulateDateTimeRFC3339(val, "LastUpdatedOn", &m.LastUpdatedOn) delete(rawMsg, key) case "mediaType": err = unpopulate(val, "MediaType", &m.MediaType) @@ -365,13 +364,13 @@ func (t *TagAttributes) UnmarshalJSON(data []byte) error { err = unpopulate(val, "ChangeableAttributes", &t.ChangeableAttributes) delete(rawMsg, key) case "createdTime": - err = unpopulateTimeRFC3339(val, "CreatedOn", &t.CreatedOn) + err = unpopulateDateTimeRFC3339(val, "CreatedOn", &t.CreatedOn) delete(rawMsg, key) case "digest": err = unpopulate(val, "Digest", &t.Digest) delete(rawMsg, key) case "lastUpdateTime": - err = unpopulateTimeRFC3339(val, "LastUpdatedOn", &t.LastUpdatedOn) + err = unpopulateDateTimeRFC3339(val, "LastUpdatedOn", &t.LastUpdatedOn) delete(rawMsg, key) case "name": err = unpopulate(val, "Name", &t.Name) diff --git a/sdk/containers/azcontainerregistry/options.go b/sdk/containers/azcontainerregistry/options.go new file mode 100644 index 000000000000..f1a7ebc2dc4e --- /dev/null +++ b/sdk/containers/azcontainerregistry/options.go @@ -0,0 +1,182 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package azcontainerregistry + +// authenticationClientExchangeAADAccessTokenForACRRefreshTokenOptions contains the optional parameters for the authenticationClient.ExchangeAADAccessTokenForACRRefreshToken +// method. +type authenticationClientExchangeAADAccessTokenForACRRefreshTokenOptions struct { + // AAD access token, mandatory when granttype is accesstokenrefreshtoken or access_token. + AccessToken *string + + // AAD refresh token, mandatory when granttype is accesstokenrefreshtoken or refresh_token + RefreshToken *string + + // AAD tenant associated to the AAD credentials. + Tenant *string +} + +// authenticationClientExchangeACRRefreshTokenForACRAccessTokenOptions contains the optional parameters for the authenticationClient.ExchangeACRRefreshTokenForACRAccessToken +// method. +type authenticationClientExchangeACRRefreshTokenForACRAccessTokenOptions struct { + // Grant type is expected to be refresh_token + GrantType *tokenGrantType +} + +// BlobClientCancelUploadOptions contains the optional parameters for the BlobClient.CancelUpload method. +type BlobClientCancelUploadOptions struct { + // placeholder for future optional parameters +} + +// BlobClientCheckBlobExistsOptions contains the optional parameters for the BlobClient.CheckBlobExists method. +type BlobClientCheckBlobExistsOptions struct { + // placeholder for future optional parameters +} + +// BlobClientCheckChunkExistsOptions contains the optional parameters for the BlobClient.CheckChunkExists method. +type BlobClientCheckChunkExistsOptions struct { + // placeholder for future optional parameters +} + +// BlobClientCompleteUploadOptions contains the optional parameters for the BlobClient.CompleteUpload method. +type BlobClientCompleteUploadOptions struct { + // placeholder for future optional parameters +} + +// BlobClientDeleteBlobOptions contains the optional parameters for the BlobClient.DeleteBlob method. +type BlobClientDeleteBlobOptions struct { + // placeholder for future optional parameters +} + +// BlobClientGetBlobOptions contains the optional parameters for the BlobClient.GetBlob method. +type BlobClientGetBlobOptions struct { + // placeholder for future optional parameters +} + +// BlobClientGetChunkOptions contains the optional parameters for the BlobClient.GetChunk method. +type BlobClientGetChunkOptions struct { + // placeholder for future optional parameters +} + +// BlobClientGetUploadStatusOptions contains the optional parameters for the BlobClient.GetUploadStatus method. +type BlobClientGetUploadStatusOptions struct { + // placeholder for future optional parameters +} + +// BlobClientMountBlobOptions contains the optional parameters for the BlobClient.MountBlob method. +type BlobClientMountBlobOptions struct { + // placeholder for future optional parameters +} + +// BlobClientStartUploadOptions contains the optional parameters for the BlobClient.StartUpload method. +type BlobClientStartUploadOptions struct { + // placeholder for future optional parameters +} + +// blobClientUploadChunkOptions contains the optional parameters for the BlobClient.uploadChunk method. +type blobClientUploadChunkOptions struct { + // Range of bytes identifying the desired block of content represented by the body. Start must the end offset retrieved via + // status check plus one. Note that this is a non-standard use of the + // Content-Range header. + ContentRange *string +} + +// ClientDeleteManifestOptions contains the optional parameters for the Client.DeleteManifest method. +type ClientDeleteManifestOptions struct { + // placeholder for future optional parameters +} + +// ClientDeleteRepositoryOptions contains the optional parameters for the Client.DeleteRepository method. +type ClientDeleteRepositoryOptions struct { + // placeholder for future optional parameters +} + +// ClientDeleteTagOptions contains the optional parameters for the Client.DeleteTag method. +type ClientDeleteTagOptions struct { + // placeholder for future optional parameters +} + +// ClientGetManifestOptions contains the optional parameters for the Client.GetManifest method. +type ClientGetManifestOptions struct { + // Accept header string delimited by comma. For example, application/vnd.docker.distribution.manifest.v2+json + Accept *string +} + +// ClientGetManifestPropertiesOptions contains the optional parameters for the Client.GetManifestProperties method. +type ClientGetManifestPropertiesOptions struct { + // placeholder for future optional parameters +} + +// ClientGetRepositoryPropertiesOptions contains the optional parameters for the Client.GetRepositoryProperties method. +type ClientGetRepositoryPropertiesOptions struct { + // placeholder for future optional parameters +} + +// ClientGetTagPropertiesOptions contains the optional parameters for the Client.GetTagProperties method. +type ClientGetTagPropertiesOptions struct { + // placeholder for future optional parameters +} + +// ClientListManifestsOptions contains the optional parameters for the Client.NewListManifestsPager method. +type ClientListManifestsOptions struct { + // Query parameter for the last item in previous query. Result set will include values lexically after last. + Last *string + + // query parameter for max number of items + MaxNum *int32 + + // Sort options for ordering manifests in a collection. + OrderBy *ArtifactManifestOrderBy +} + +// ClientListRepositoriesOptions contains the optional parameters for the Client.NewListRepositoriesPager method. +type ClientListRepositoriesOptions struct { + // Query parameter for the last item in previous query. Result set will include values lexically after last. + Last *string + + // query parameter for max number of items + MaxNum *int32 +} + +// ClientListTagsOptions contains the optional parameters for the Client.NewListTagsPager method. +type ClientListTagsOptions struct { + // filter by digest + Digest *string + + // Query parameter for the last item in previous query. Result set will include values lexically after last. + Last *string + + // query parameter for max number of items + MaxNum *int32 + + // Sort options for ordering tags in a collection. + OrderBy *ArtifactTagOrderBy +} + +// ClientUpdateManifestPropertiesOptions contains the optional parameters for the Client.UpdateManifestProperties method. +type ClientUpdateManifestPropertiesOptions struct { + // Manifest attribute value + Value *ManifestWriteableProperties +} + +// ClientUpdateRepositoryPropertiesOptions contains the optional parameters for the Client.UpdateRepositoryProperties method. +type ClientUpdateRepositoryPropertiesOptions struct { + // Repository attribute value + Value *RepositoryWriteableProperties +} + +// ClientUpdateTagPropertiesOptions contains the optional parameters for the Client.UpdateTagProperties method. +type ClientUpdateTagPropertiesOptions struct { + // Tag attribute value + Value *TagWriteableProperties +} + +// ClientUploadManifestOptions contains the optional parameters for the Client.UploadManifest method. +type ClientUploadManifestOptions struct { + // placeholder for future optional parameters +} diff --git a/sdk/containers/azcontainerregistry/response_types.go b/sdk/containers/azcontainerregistry/response_types.go index 8227369e5fdf..ed310e0c02be 100644 --- a/sdk/containers/azcontainerregistry/response_types.go +++ b/sdk/containers/azcontainerregistry/response_types.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package azcontainerregistry @@ -148,6 +147,7 @@ type ClientDeleteTagResponse struct { // ClientGetManifestPropertiesResponse contains the response from method Client.GetManifestProperties. type ClientGetManifestPropertiesResponse struct { + // Manifest attributes details ArtifactManifestProperties } @@ -162,47 +162,58 @@ type ClientGetManifestResponse struct { // ClientGetRepositoryPropertiesResponse contains the response from method Client.GetRepositoryProperties. type ClientGetRepositoryPropertiesResponse struct { + // Properties of this repository. ContainerRepositoryProperties } // ClientGetTagPropertiesResponse contains the response from method Client.GetTagProperties. type ClientGetTagPropertiesResponse struct { + // Tag attributes ArtifactTagProperties } // ClientListManifestsResponse contains the response from method Client.NewListManifestsPager. type ClientListManifestsResponse struct { + // Manifest attributes Manifests + // Link contains the information returned from the Link header response. Link *string } // ClientListRepositoriesResponse contains the response from method Client.NewListRepositoriesPager. type ClientListRepositoriesResponse struct { + // List of repositories Repositories + // Link contains the information returned from the Link header response. Link *string } // ClientListTagsResponse contains the response from method Client.NewListTagsPager. type ClientListTagsResponse struct { + // List of tag details TagList + // Link contains the information returned from the Link header response. Link *string } // ClientUpdateManifestPropertiesResponse contains the response from method Client.UpdateManifestProperties. type ClientUpdateManifestPropertiesResponse struct { + // Manifest attributes details ArtifactManifestProperties } // ClientUpdateRepositoryPropertiesResponse contains the response from method Client.UpdateRepositoryProperties. type ClientUpdateRepositoryPropertiesResponse struct { + // Properties of this repository. ContainerRepositoryProperties } // ClientUpdateTagPropertiesResponse contains the response from method Client.UpdateTagProperties. type ClientUpdateTagPropertiesResponse struct { + // Tag attributes ArtifactTagProperties } diff --git a/sdk/containers/azcontainerregistry/time_rfc3339.go b/sdk/containers/azcontainerregistry/time_rfc3339.go index 8ef526fa064c..a594fec3aab8 100644 --- a/sdk/containers/azcontainerregistry/time_rfc3339.go +++ b/sdk/containers/azcontainerregistry/time_rfc3339.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package azcontainerregistry @@ -19,50 +18,50 @@ import ( "time" ) -const ( - utcLayoutJSON = `"2006-01-02T15:04:05.999999999"` - utcLayout = "2006-01-02T15:04:05.999999999" - rfc3339JSON = `"` + time.RFC3339Nano + `"` -) - // Azure reports time in UTC but it doesn't include the 'Z' time zone suffix in some cases. var tzOffsetRegex = regexp.MustCompile(`(Z|z|\+|-)(\d+:\d+)*"*$`) -type timeRFC3339 time.Time +const ( + utcDateTimeJSON = `"2006-01-02T15:04:05.999999999"` + utcDateTime = "2006-01-02T15:04:05.999999999" + dateTimeJSON = `"` + time.RFC3339Nano + `"` +) + +type dateTimeRFC3339 time.Time -func (t timeRFC3339) MarshalJSON() (json []byte, err error) { +func (t dateTimeRFC3339) MarshalJSON() ([]byte, error) { tt := time.Time(t) return tt.MarshalJSON() } -func (t timeRFC3339) MarshalText() (text []byte, err error) { +func (t dateTimeRFC3339) MarshalText() ([]byte, error) { tt := time.Time(t) return tt.MarshalText() } -func (t *timeRFC3339) UnmarshalJSON(data []byte) error { - layout := utcLayoutJSON +func (t *dateTimeRFC3339) UnmarshalJSON(data []byte) error { + layout := utcDateTimeJSON if tzOffsetRegex.Match(data) { - layout = rfc3339JSON + layout = dateTimeJSON } return t.Parse(layout, string(data)) } -func (t *timeRFC3339) UnmarshalText(data []byte) (err error) { - layout := utcLayout +func (t *dateTimeRFC3339) UnmarshalText(data []byte) error { + layout := utcDateTime if tzOffsetRegex.Match(data) { layout = time.RFC3339Nano } return t.Parse(layout, string(data)) } -func (t *timeRFC3339) Parse(layout, value string) error { +func (t *dateTimeRFC3339) Parse(layout, value string) error { p, err := time.Parse(layout, strings.ToUpper(value)) - *t = timeRFC3339(p) + *t = dateTimeRFC3339(p) return err } -func populateTimeRFC3339(m map[string]any, k string, t *time.Time) { +func populateDateTimeRFC3339(m map[string]any, k string, t *time.Time) { if t == nil { return } else if azcore.IsNullValue(t) { @@ -71,14 +70,14 @@ func populateTimeRFC3339(m map[string]any, k string, t *time.Time) { } else if reflect.ValueOf(t).IsNil() { return } - m[k] = (*timeRFC3339)(t) + m[k] = (*dateTimeRFC3339)(t) } -func unpopulateTimeRFC3339(data json.RawMessage, fn string, t **time.Time) error { +func unpopulateDateTimeRFC3339(data json.RawMessage, fn string, t **time.Time) error { if data == nil || strings.EqualFold(string(data), "null") { return nil } - var aux timeRFC3339 + var aux dateTimeRFC3339 if err := json.Unmarshal(data, &aux); err != nil { return fmt.Errorf("struct field %s: %v", fn, err) } diff --git a/sdk/containers/azcontainerregistry/time_rfc3339_test.go b/sdk/containers/azcontainerregistry/time_rfc3339_test.go index fa8f02222746..acc378b3ce3c 100644 --- a/sdk/containers/azcontainerregistry/time_rfc3339_test.go +++ b/sdk/containers/azcontainerregistry/time_rfc3339_test.go @@ -14,62 +14,62 @@ import ( "time" ) -func Test_timeRFC3339_MarshalJSON(t *testing.T) { - t1 := timeRFC3339(time.Date(2023, 5, 6, 10, 23, 15, 123456789, time.UTC)) +func Test_dateTimeRFC3339_MarshalJSON(t *testing.T) { + t1 := dateTimeRFC3339(time.Date(2023, 5, 6, 10, 23, 15, 123456789, time.UTC)) b, err := t1.MarshalJSON() require.NoError(t, err) require.Equal(t, `"2023-05-06T10:23:15.123456789Z"`, string(b)) } -func Test_timeRFC3339_MarshalText(t *testing.T) { - t1 := timeRFC3339(time.Date(2023, 5, 6, 10, 23, 15, 123456789, time.UTC)) +func Test_dateTimeRFC3339_MarshalText(t *testing.T) { + t1 := dateTimeRFC3339(time.Date(2023, 5, 6, 10, 23, 15, 123456789, time.UTC)) b, err := t1.MarshalText() require.NoError(t, err) require.Equal(t, "2023-05-06T10:23:15.123456789Z", string(b)) } -func Test_timeRFC3339_UnmarshalJSON(t *testing.T) { - var t1 timeRFC3339 +func Test_dateTimeRFC3339_UnmarshalJSON(t *testing.T) { + var t1 dateTimeRFC3339 err := t1.UnmarshalJSON([]byte(`"2023-05-06T10:23:15.123456789Z"`)) require.NoError(t, err) - require.Equal(t, timeRFC3339(time.Date(2023, 5, 6, 10, 23, 15, 123456789, time.UTC)), t1) + require.Equal(t, dateTimeRFC3339(time.Date(2023, 5, 6, 10, 23, 15, 123456789, time.UTC)), t1) } -func Test_timeRFC3339_UnmarshalText(t *testing.T) { - var t1 timeRFC3339 +func Test_dateTimeRFC3339_UnmarshalText(t *testing.T) { + var t1 dateTimeRFC3339 err := t1.UnmarshalText([]byte("2023-05-06T10:23:15.123456789Z")) require.NoError(t, err) - require.Equal(t, timeRFC3339(time.Date(2023, 5, 6, 10, 23, 15, 123456789, time.UTC)), t1) + require.Equal(t, dateTimeRFC3339(time.Date(2023, 5, 6, 10, 23, 15, 123456789, time.UTC)), t1) } -func Test_populateTimeRFC3339(t *testing.T) { +func Test_populateDateTimeRFC3339(t *testing.T) { m := map[string]any{} - populateTimeRFC3339(m, "test", nil) + populateDateTimeRFC3339(m, "test", nil) require.Equal(t, map[string]any{}, m) - populateTimeRFC3339(m, "test", azcore.NullValue[*time.Time]()) + populateDateTimeRFC3339(m, "test", azcore.NullValue[*time.Time]()) require.Equal(t, map[string]any{"test": nil}, m) t1 := time.Date(2023, 5, 6, 10, 23, 15, 123456789, time.UTC) - populateTimeRFC3339(m, "test", &t1) - tt1 := timeRFC3339(t1) + populateDateTimeRFC3339(m, "test", &t1) + tt1 := dateTimeRFC3339(t1) require.Equal(t, map[string]any{"test": &tt1}, m) } -func Test_unpopulateTimeRFC3339(t *testing.T) { +func Test_unpopulateDateTimeRFC3339(t *testing.T) { var t1 *time.Time var data json.RawMessage - err := unpopulateTimeRFC3339(data, "test", &t1) + err := unpopulateDateTimeRFC3339(data, "test", &t1) require.NoError(t, err) var tt1 *time.Time require.Equal(t, tt1, t1) data = json.RawMessage("null") - err = unpopulateTimeRFC3339(data, "test", &t1) + err = unpopulateDateTimeRFC3339(data, "test", &t1) require.NoError(t, err) require.Equal(t, tt1, t1) data = json.RawMessage("wrong value") - err = unpopulateTimeRFC3339(data, "test", &t1) + err = unpopulateDateTimeRFC3339(data, "test", &t1) require.Error(t, err) data = json.RawMessage(`"2023-05-06T10:23:15.123456789Z"`) - err = unpopulateTimeRFC3339(data, "test", &t1) + err = unpopulateDateTimeRFC3339(data, "test", &t1) require.NoError(t, err) tt2 := time.Date(2023, 5, 6, 10, 23, 15, 123456789, time.UTC) require.Equal(t, &tt2, t1)