From 121da8b8fe2909dd4a9d40385cc269b0bcd28d9f Mon Sep 17 00:00:00 2001 From: Azure SDK for Python bot Date: Mon, 23 Apr 2018 12:59:22 -0700 Subject: [PATCH] Generated from 8c306b9774829c9683c09365e29ff4265e655bcf (#1679) (#1680) add a copy image operation to Azure Container Registry - adds an operation to support copying a Docker image from one registry to another - supports copying to multiple places in the target registry - only one source and one target registry are supported --- .../mgmt/containerregistry/models.go | 13 +++ .../mgmt/containerregistry/models.go | 13 +++ .../2017-10-01/containerregistry/models.go | 87 +++++++++++++++++++ .../containerregistry/registries.go | 84 ++++++++++++++++++ 4 files changed, 197 insertions(+) diff --git a/profiles/latest/containerregistry/mgmt/containerregistry/models.go b/profiles/latest/containerregistry/mgmt/containerregistry/models.go index 8eaf48648bab..d360569dd15b 100644 --- a/profiles/latest/containerregistry/mgmt/containerregistry/models.go +++ b/profiles/latest/containerregistry/mgmt/containerregistry/models.go @@ -26,6 +26,13 @@ const ( ) type BaseClient = original.BaseClient +type ImportMode = original.ImportMode + +const ( + Force ImportMode = original.Force + NoForce ImportMode = original.NoForce +) + type PasswordName = original.PasswordName const ( @@ -93,6 +100,8 @@ type EventListResultIterator = original.EventListResultIterator type EventListResultPage = original.EventListResultPage type EventRequestMessage = original.EventRequestMessage type EventResponseMessage = original.EventResponseMessage +type ImportImageParameters = original.ImportImageParameters +type ImportSource = original.ImportSource type OperationDefinition = original.OperationDefinition type OperationDisplayDefinition = original.OperationDisplayDefinition type OperationListResult = original.OperationListResult @@ -101,6 +110,7 @@ type OperationListResultPage = original.OperationListResultPage type RegenerateCredentialParameters = original.RegenerateCredentialParameters type RegistriesCreateFuture = original.RegistriesCreateFuture type RegistriesDeleteFuture = original.RegistriesDeleteFuture +type RegistriesImportImageFuture = original.RegistriesImportImageFuture type RegistriesUpdateFuture = original.RegistriesUpdateFuture type Registry = original.Registry type RegistryListCredentialsResult = original.RegistryListCredentialsResult @@ -154,6 +164,9 @@ func New(subscriptionID string) BaseClient { func NewWithBaseURI(baseURI string, subscriptionID string) BaseClient { return original.NewWithBaseURI(baseURI, subscriptionID) } +func PossibleImportModeValues() []ImportMode { + return original.PossibleImportModeValues() +} func PossiblePasswordNameValues() []PasswordName { return original.PossiblePasswordNameValues() } diff --git a/profiles/preview/containerregistry/mgmt/containerregistry/models.go b/profiles/preview/containerregistry/mgmt/containerregistry/models.go index 6b54722934d3..dde7cc88062f 100644 --- a/profiles/preview/containerregistry/mgmt/containerregistry/models.go +++ b/profiles/preview/containerregistry/mgmt/containerregistry/models.go @@ -26,6 +26,13 @@ const ( ) type BaseClient = original.BaseClient +type ImportMode = original.ImportMode + +const ( + Force ImportMode = original.Force + NoForce ImportMode = original.NoForce +) + type PasswordName = original.PasswordName const ( @@ -93,6 +100,8 @@ type EventListResultIterator = original.EventListResultIterator type EventListResultPage = original.EventListResultPage type EventRequestMessage = original.EventRequestMessage type EventResponseMessage = original.EventResponseMessage +type ImportImageParameters = original.ImportImageParameters +type ImportSource = original.ImportSource type OperationDefinition = original.OperationDefinition type OperationDisplayDefinition = original.OperationDisplayDefinition type OperationListResult = original.OperationListResult @@ -101,6 +110,7 @@ type OperationListResultPage = original.OperationListResultPage type RegenerateCredentialParameters = original.RegenerateCredentialParameters type RegistriesCreateFuture = original.RegistriesCreateFuture type RegistriesDeleteFuture = original.RegistriesDeleteFuture +type RegistriesImportImageFuture = original.RegistriesImportImageFuture type RegistriesUpdateFuture = original.RegistriesUpdateFuture type Registry = original.Registry type RegistryListCredentialsResult = original.RegistryListCredentialsResult @@ -154,6 +164,9 @@ func New(subscriptionID string) BaseClient { func NewWithBaseURI(baseURI string, subscriptionID string) BaseClient { return original.NewWithBaseURI(baseURI, subscriptionID) } +func PossibleImportModeValues() []ImportMode { + return original.PossibleImportModeValues() +} func PossiblePasswordNameValues() []PasswordName { return original.PossiblePasswordNameValues() } diff --git a/services/containerregistry/mgmt/2017-10-01/containerregistry/models.go b/services/containerregistry/mgmt/2017-10-01/containerregistry/models.go index 61c6cd67b3ce..4b16260110a6 100644 --- a/services/containerregistry/mgmt/2017-10-01/containerregistry/models.go +++ b/services/containerregistry/mgmt/2017-10-01/containerregistry/models.go @@ -26,6 +26,21 @@ import ( "net/http" ) +// ImportMode enumerates the values for import mode. +type ImportMode string + +const ( + // Force ... + Force ImportMode = "Force" + // NoForce ... + NoForce ImportMode = "NoForce" +) + +// PossibleImportModeValues returns an array of possible values for the ImportMode const type. +func PossibleImportModeValues() []ImportMode { + return []ImportMode{Force, NoForce} +} + // PasswordName enumerates the values for password name. type PasswordName string @@ -382,6 +397,29 @@ func (erm EventResponseMessage) MarshalJSON() ([]byte, error) { return json.Marshal(objectMap) } +// ImportImageParameters ... +type ImportImageParameters struct { + // Source - The source of the image. + Source *ImportSource `json:"source,omitempty"` + // TargetTags - List of strings of the form repo[:tag]. When tag is omitted the source will be used (or 'latest' if source tag is also omitted). + TargetTags *[]string `json:"targetTags,omitempty"` + // UntaggedTargetRepositories - List of strings of repository names to do a manifest only copy. No tag will be created. + UntaggedTargetRepositories *[]string `json:"untaggedTargetRepositories,omitempty"` + // Mode - When Force, any existing target tags will be overwritten. When NoForce, any existing target tags will fail the operation before any copying begins. Possible values include: 'NoForce', 'Force' + Mode ImportMode `json:"mode,omitempty"` +} + +// ImportSource ... +type ImportSource struct { + // ResourceID - The resource identifier of the target Azure Container Registry. + ResourceID *string `json:"resourceId,omitempty"` + // SourceImage - Repository name of the source image. + // Specify an image by repository ('hello-world'). This will use the 'latest' tag. + // Specify an image by tag ('hello-world:latest'). + // Specify an image by sha256-based manifest digest ('hello-world@sha256:abc123'). + SourceImage *string `json:"sourceImage,omitempty"` +} + // OperationDefinition the definition of a container registry operation. type OperationDefinition struct { // Name - Operation name: {provider}/{resource}/{operation}. @@ -606,6 +644,55 @@ func (future RegistriesDeleteFuture) Result(client RegistriesClient) (ar autores return } +// RegistriesImportImageFuture an abstraction for monitoring and retrieving the results of a long-running +// operation. +type RegistriesImportImageFuture struct { + azure.Future + req *http.Request +} + +// Result returns the result of the asynchronous operation. +// If the operation has not completed it will return an error. +func (future RegistriesImportImageFuture) Result(client RegistriesClient) (ar autorest.Response, err error) { + var done bool + done, err = future.Done(client) + if err != nil { + err = autorest.NewErrorWithError(err, "containerregistry.RegistriesImportImageFuture", "Result", future.Response(), "Polling failure") + return + } + if !done { + return ar, azure.NewAsyncOpIncompleteError("containerregistry.RegistriesImportImageFuture") + } + if future.PollingMethod() == azure.PollingLocation { + ar, err = client.ImportImageResponder(future.Response()) + if err != nil { + err = autorest.NewErrorWithError(err, "containerregistry.RegistriesImportImageFuture", "Result", future.Response(), "Failure responding to request") + } + return + } + var req *http.Request + var resp *http.Response + if future.PollingURL() != "" { + req, err = http.NewRequest(http.MethodGet, future.PollingURL(), nil) + if err != nil { + return + } + } else { + req = autorest.ChangeToGet(future.req) + } + resp, err = autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) + if err != nil { + err = autorest.NewErrorWithError(err, "containerregistry.RegistriesImportImageFuture", "Result", resp, "Failure sending request") + return + } + ar, err = client.ImportImageResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "containerregistry.RegistriesImportImageFuture", "Result", resp, "Failure responding to request") + } + return +} + // RegistriesUpdateFuture an abstraction for monitoring and retrieving the results of a long-running operation. type RegistriesUpdateFuture struct { azure.Future diff --git a/services/containerregistry/mgmt/2017-10-01/containerregistry/registries.go b/services/containerregistry/mgmt/2017-10-01/containerregistry/registries.go index 2157367e5390..b1bc8db65107 100644 --- a/services/containerregistry/mgmt/2017-10-01/containerregistry/registries.go +++ b/services/containerregistry/mgmt/2017-10-01/containerregistry/registries.go @@ -354,6 +354,90 @@ func (client RegistriesClient) GetResponder(resp *http.Response) (result Registr return } +// ImportImage copies an image to this container registry from the specified container registry. +// +// resourceGroupName is the name of the resource group to which the container registry belongs. registryName is the +// name of the container registry. parameters is the parameters specifying the image to copy and the source +// container registry. +func (client RegistriesClient) ImportImage(ctx context.Context, resourceGroupName string, registryName string, parameters ImportImageParameters) (result RegistriesImportImageFuture, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: registryName, + Constraints: []validation.Constraint{{Target: "registryName", Name: validation.MaxLength, Rule: 50, Chain: nil}, + {Target: "registryName", Name: validation.MinLength, Rule: 5, Chain: nil}, + {Target: "registryName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]*$`, Chain: nil}}}, + {TargetValue: parameters, + Constraints: []validation.Constraint{{Target: "parameters.Source", Name: validation.Null, Rule: true, + Chain: []validation.Constraint{{Target: "parameters.Source.ResourceID", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "parameters.Source.SourceImage", Name: validation.Null, Rule: true, Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("containerregistry.RegistriesClient", "ImportImage", err.Error()) + } + + req, err := client.ImportImagePreparer(ctx, resourceGroupName, registryName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "containerregistry.RegistriesClient", "ImportImage", nil, "Failure preparing request") + return + } + + result, err = client.ImportImageSender(req) + if err != nil { + err = autorest.NewErrorWithError(err, "containerregistry.RegistriesClient", "ImportImage", result.Response(), "Failure sending request") + return + } + + return +} + +// ImportImagePreparer prepares the ImportImage request. +func (client RegistriesClient) ImportImagePreparer(ctx context.Context, resourceGroupName string, registryName string, parameters ImportImageParameters) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "registryName": autorest.Encode("path", registryName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-10-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerRegistry/registries/{registryName}/importImage", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ImportImageSender sends the ImportImage request. The method will close the +// http.Response Body if it receives an error. +func (client RegistriesClient) ImportImageSender(req *http.Request) (future RegistriesImportImageFuture, err error) { + sender := autorest.DecorateSender(client, azure.DoRetryWithRegistration(client.Client)) + future.Future = azure.NewFuture(req) + future.req = req + _, err = future.Done(sender) + if err != nil { + return + } + err = autorest.Respond(future.Response(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted)) + return +} + +// ImportImageResponder handles the response to the ImportImage request. The method always +// closes the http.Response Body. +func (client RegistriesClient) ImportImageResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), + autorest.ByClosing()) + result.Response = resp + return +} + // List lists all the container registries under the specified subscription. func (client RegistriesClient) List(ctx context.Context) (result RegistryListResultPage, err error) { result.fn = client.listNextResults