1package containerregistry
2
3// Copyright (c) Microsoft Corporation. All rights reserved.
4// Licensed under the MIT License. See License.txt in the project root for license information.
5//
6// Code generated by Microsoft (R) AutoRest Code Generator.
7// Changes may cause incorrect behavior and will be lost if the code is regenerated.
8
9import (
10	"context"
11	"github.com/Azure/go-autorest/autorest"
12	"github.com/Azure/go-autorest/autorest/azure"
13	"github.com/Azure/go-autorest/autorest/validation"
14	"github.com/Azure/go-autorest/tracing"
15	"net/http"
16)
17
18// RegistriesClient is the client for the Registries methods of the Containerregistry service.
19type RegistriesClient struct {
20	BaseClient
21}
22
23// NewRegistriesClient creates an instance of the RegistriesClient client.
24func NewRegistriesClient(subscriptionID string) RegistriesClient {
25	return NewRegistriesClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewRegistriesClientWithBaseURI creates an instance of the RegistriesClient client using a custom endpoint.  Use this
29// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
30func NewRegistriesClientWithBaseURI(baseURI string, subscriptionID string) RegistriesClient {
31	return RegistriesClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// CheckNameAvailability checks whether the container registry name is available for use. The name must contain only
35// alphanumeric characters, be globally unique, and between 5 and 50 characters in length.
36// Parameters:
37// registryNameCheckRequest - the object containing information for the availability request.
38func (client RegistriesClient) CheckNameAvailability(ctx context.Context, registryNameCheckRequest RegistryNameCheckRequest) (result RegistryNameStatus, err error) {
39	if tracing.IsEnabled() {
40		ctx = tracing.StartSpan(ctx, fqdn+"/RegistriesClient.CheckNameAvailability")
41		defer func() {
42			sc := -1
43			if result.Response.Response != nil {
44				sc = result.Response.Response.StatusCode
45			}
46			tracing.EndSpan(ctx, sc, err)
47		}()
48	}
49	if err := validation.Validate([]validation.Validation{
50		{TargetValue: registryNameCheckRequest,
51			Constraints: []validation.Constraint{{Target: "registryNameCheckRequest.Name", Name: validation.Null, Rule: true,
52				Chain: []validation.Constraint{{Target: "registryNameCheckRequest.Name", Name: validation.MaxLength, Rule: 50, Chain: nil},
53					{Target: "registryNameCheckRequest.Name", Name: validation.MinLength, Rule: 5, Chain: nil},
54					{Target: "registryNameCheckRequest.Name", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]*$`, Chain: nil},
55				}},
56				{Target: "registryNameCheckRequest.Type", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
57		return result, validation.NewError("containerregistry.RegistriesClient", "CheckNameAvailability", err.Error())
58	}
59
60	req, err := client.CheckNameAvailabilityPreparer(ctx, registryNameCheckRequest)
61	if err != nil {
62		err = autorest.NewErrorWithError(err, "containerregistry.RegistriesClient", "CheckNameAvailability", nil, "Failure preparing request")
63		return
64	}
65
66	resp, err := client.CheckNameAvailabilitySender(req)
67	if err != nil {
68		result.Response = autorest.Response{Response: resp}
69		err = autorest.NewErrorWithError(err, "containerregistry.RegistriesClient", "CheckNameAvailability", resp, "Failure sending request")
70		return
71	}
72
73	result, err = client.CheckNameAvailabilityResponder(resp)
74	if err != nil {
75		err = autorest.NewErrorWithError(err, "containerregistry.RegistriesClient", "CheckNameAvailability", resp, "Failure responding to request")
76		return
77	}
78
79	return
80}
81
82// CheckNameAvailabilityPreparer prepares the CheckNameAvailability request.
83func (client RegistriesClient) CheckNameAvailabilityPreparer(ctx context.Context, registryNameCheckRequest RegistryNameCheckRequest) (*http.Request, error) {
84	pathParameters := map[string]interface{}{
85		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
86	}
87
88	const APIVersion = "2017-03-01"
89	queryParameters := map[string]interface{}{
90		"api-version": APIVersion,
91	}
92
93	preparer := autorest.CreatePreparer(
94		autorest.AsContentType("application/json; charset=utf-8"),
95		autorest.AsPost(),
96		autorest.WithBaseURL(client.BaseURI),
97		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.ContainerRegistry/checkNameAvailability", pathParameters),
98		autorest.WithJSON(registryNameCheckRequest),
99		autorest.WithQueryParameters(queryParameters))
100	return preparer.Prepare((&http.Request{}).WithContext(ctx))
101}
102
103// CheckNameAvailabilitySender sends the CheckNameAvailability request. The method will close the
104// http.Response Body if it receives an error.
105func (client RegistriesClient) CheckNameAvailabilitySender(req *http.Request) (*http.Response, error) {
106	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
107}
108
109// CheckNameAvailabilityResponder handles the response to the CheckNameAvailability request. The method always
110// closes the http.Response Body.
111func (client RegistriesClient) CheckNameAvailabilityResponder(resp *http.Response) (result RegistryNameStatus, err error) {
112	err = autorest.Respond(
113		resp,
114		azure.WithErrorUnlessStatusCode(http.StatusOK),
115		autorest.ByUnmarshallingJSON(&result),
116		autorest.ByClosing())
117	result.Response = autorest.Response{Response: resp}
118	return
119}
120
121// Create creates a container registry with the specified parameters.
122// Parameters:
123// resourceGroupName - the name of the resource group to which the container registry belongs.
124// registryName - the name of the container registry.
125// registryCreateParameters - the parameters for creating a container registry.
126func (client RegistriesClient) Create(ctx context.Context, resourceGroupName string, registryName string, registryCreateParameters RegistryCreateParameters) (result RegistriesCreateFuture, err error) {
127	if tracing.IsEnabled() {
128		ctx = tracing.StartSpan(ctx, fqdn+"/RegistriesClient.Create")
129		defer func() {
130			sc := -1
131			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
132				sc = result.FutureAPI.Response().StatusCode
133			}
134			tracing.EndSpan(ctx, sc, err)
135		}()
136	}
137	if err := validation.Validate([]validation.Validation{
138		{TargetValue: resourceGroupName,
139			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
140		{TargetValue: registryName,
141			Constraints: []validation.Constraint{{Target: "registryName", Name: validation.MaxLength, Rule: 50, Chain: nil},
142				{Target: "registryName", Name: validation.MinLength, Rule: 5, Chain: nil},
143				{Target: "registryName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]*$`, Chain: nil}}},
144		{TargetValue: registryCreateParameters,
145			Constraints: []validation.Constraint{{Target: "registryCreateParameters.Location", Name: validation.Null, Rule: true, Chain: nil},
146				{Target: "registryCreateParameters.Sku", Name: validation.Null, Rule: true,
147					Chain: []validation.Constraint{{Target: "registryCreateParameters.Sku.Name", Name: validation.Null, Rule: true, Chain: nil}}},
148				{Target: "registryCreateParameters.RegistryPropertiesCreateParameters", Name: validation.Null, Rule: false,
149					Chain: []validation.Constraint{{Target: "registryCreateParameters.RegistryPropertiesCreateParameters.StorageAccount", Name: validation.Null, Rule: true,
150						Chain: []validation.Constraint{{Target: "registryCreateParameters.RegistryPropertiesCreateParameters.StorageAccount.Name", Name: validation.Null, Rule: true, Chain: nil},
151							{Target: "registryCreateParameters.RegistryPropertiesCreateParameters.StorageAccount.AccessKey", Name: validation.Null, Rule: true, Chain: nil},
152						}},
153					}}}}}); err != nil {
154		return result, validation.NewError("containerregistry.RegistriesClient", "Create", err.Error())
155	}
156
157	req, err := client.CreatePreparer(ctx, resourceGroupName, registryName, registryCreateParameters)
158	if err != nil {
159		err = autorest.NewErrorWithError(err, "containerregistry.RegistriesClient", "Create", nil, "Failure preparing request")
160		return
161	}
162
163	result, err = client.CreateSender(req)
164	if err != nil {
165		err = autorest.NewErrorWithError(err, "containerregistry.RegistriesClient", "Create", nil, "Failure sending request")
166		return
167	}
168
169	return
170}
171
172// CreatePreparer prepares the Create request.
173func (client RegistriesClient) CreatePreparer(ctx context.Context, resourceGroupName string, registryName string, registryCreateParameters RegistryCreateParameters) (*http.Request, error) {
174	pathParameters := map[string]interface{}{
175		"registryName":      autorest.Encode("path", registryName),
176		"resourceGroupName": autorest.Encode("path", resourceGroupName),
177		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
178	}
179
180	const APIVersion = "2017-03-01"
181	queryParameters := map[string]interface{}{
182		"api-version": APIVersion,
183	}
184
185	preparer := autorest.CreatePreparer(
186		autorest.AsContentType("application/json; charset=utf-8"),
187		autorest.AsPut(),
188		autorest.WithBaseURL(client.BaseURI),
189		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerRegistry/registries/{registryName}", pathParameters),
190		autorest.WithJSON(registryCreateParameters),
191		autorest.WithQueryParameters(queryParameters))
192	return preparer.Prepare((&http.Request{}).WithContext(ctx))
193}
194
195// CreateSender sends the Create request. The method will close the
196// http.Response Body if it receives an error.
197func (client RegistriesClient) CreateSender(req *http.Request) (future RegistriesCreateFuture, err error) {
198	var resp *http.Response
199	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
200	if err != nil {
201		return
202	}
203	var azf azure.Future
204	azf, err = azure.NewFutureFromResponse(resp)
205	future.FutureAPI = &azf
206	future.Result = future.result
207	return
208}
209
210// CreateResponder handles the response to the Create request. The method always
211// closes the http.Response Body.
212func (client RegistriesClient) CreateResponder(resp *http.Response) (result Registry, err error) {
213	err = autorest.Respond(
214		resp,
215		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
216		autorest.ByUnmarshallingJSON(&result),
217		autorest.ByClosing())
218	result.Response = autorest.Response{Response: resp}
219	return
220}
221
222// Delete deletes a container registry.
223// Parameters:
224// resourceGroupName - the name of the resource group to which the container registry belongs.
225// registryName - the name of the container registry.
226func (client RegistriesClient) Delete(ctx context.Context, resourceGroupName string, registryName string) (result autorest.Response, err error) {
227	if tracing.IsEnabled() {
228		ctx = tracing.StartSpan(ctx, fqdn+"/RegistriesClient.Delete")
229		defer func() {
230			sc := -1
231			if result.Response != nil {
232				sc = result.Response.StatusCode
233			}
234			tracing.EndSpan(ctx, sc, err)
235		}()
236	}
237	if err := validation.Validate([]validation.Validation{
238		{TargetValue: resourceGroupName,
239			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
240		{TargetValue: registryName,
241			Constraints: []validation.Constraint{{Target: "registryName", Name: validation.MaxLength, Rule: 50, Chain: nil},
242				{Target: "registryName", Name: validation.MinLength, Rule: 5, Chain: nil},
243				{Target: "registryName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]*$`, Chain: nil}}}}); err != nil {
244		return result, validation.NewError("containerregistry.RegistriesClient", "Delete", err.Error())
245	}
246
247	req, err := client.DeletePreparer(ctx, resourceGroupName, registryName)
248	if err != nil {
249		err = autorest.NewErrorWithError(err, "containerregistry.RegistriesClient", "Delete", nil, "Failure preparing request")
250		return
251	}
252
253	resp, err := client.DeleteSender(req)
254	if err != nil {
255		result.Response = resp
256		err = autorest.NewErrorWithError(err, "containerregistry.RegistriesClient", "Delete", resp, "Failure sending request")
257		return
258	}
259
260	result, err = client.DeleteResponder(resp)
261	if err != nil {
262		err = autorest.NewErrorWithError(err, "containerregistry.RegistriesClient", "Delete", resp, "Failure responding to request")
263		return
264	}
265
266	return
267}
268
269// DeletePreparer prepares the Delete request.
270func (client RegistriesClient) DeletePreparer(ctx context.Context, resourceGroupName string, registryName string) (*http.Request, error) {
271	pathParameters := map[string]interface{}{
272		"registryName":      autorest.Encode("path", registryName),
273		"resourceGroupName": autorest.Encode("path", resourceGroupName),
274		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
275	}
276
277	const APIVersion = "2017-03-01"
278	queryParameters := map[string]interface{}{
279		"api-version": APIVersion,
280	}
281
282	preparer := autorest.CreatePreparer(
283		autorest.AsDelete(),
284		autorest.WithBaseURL(client.BaseURI),
285		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerRegistry/registries/{registryName}", pathParameters),
286		autorest.WithQueryParameters(queryParameters))
287	return preparer.Prepare((&http.Request{}).WithContext(ctx))
288}
289
290// DeleteSender sends the Delete request. The method will close the
291// http.Response Body if it receives an error.
292func (client RegistriesClient) DeleteSender(req *http.Request) (*http.Response, error) {
293	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
294}
295
296// DeleteResponder handles the response to the Delete request. The method always
297// closes the http.Response Body.
298func (client RegistriesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
299	err = autorest.Respond(
300		resp,
301		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
302		autorest.ByClosing())
303	result.Response = resp
304	return
305}
306
307// Get gets the properties of the specified container registry.
308// Parameters:
309// resourceGroupName - the name of the resource group to which the container registry belongs.
310// registryName - the name of the container registry.
311func (client RegistriesClient) Get(ctx context.Context, resourceGroupName string, registryName string) (result Registry, err error) {
312	if tracing.IsEnabled() {
313		ctx = tracing.StartSpan(ctx, fqdn+"/RegistriesClient.Get")
314		defer func() {
315			sc := -1
316			if result.Response.Response != nil {
317				sc = result.Response.Response.StatusCode
318			}
319			tracing.EndSpan(ctx, sc, err)
320		}()
321	}
322	if err := validation.Validate([]validation.Validation{
323		{TargetValue: resourceGroupName,
324			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
325		{TargetValue: registryName,
326			Constraints: []validation.Constraint{{Target: "registryName", Name: validation.MaxLength, Rule: 50, Chain: nil},
327				{Target: "registryName", Name: validation.MinLength, Rule: 5, Chain: nil},
328				{Target: "registryName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]*$`, Chain: nil}}}}); err != nil {
329		return result, validation.NewError("containerregistry.RegistriesClient", "Get", err.Error())
330	}
331
332	req, err := client.GetPreparer(ctx, resourceGroupName, registryName)
333	if err != nil {
334		err = autorest.NewErrorWithError(err, "containerregistry.RegistriesClient", "Get", nil, "Failure preparing request")
335		return
336	}
337
338	resp, err := client.GetSender(req)
339	if err != nil {
340		result.Response = autorest.Response{Response: resp}
341		err = autorest.NewErrorWithError(err, "containerregistry.RegistriesClient", "Get", resp, "Failure sending request")
342		return
343	}
344
345	result, err = client.GetResponder(resp)
346	if err != nil {
347		err = autorest.NewErrorWithError(err, "containerregistry.RegistriesClient", "Get", resp, "Failure responding to request")
348		return
349	}
350
351	return
352}
353
354// GetPreparer prepares the Get request.
355func (client RegistriesClient) GetPreparer(ctx context.Context, resourceGroupName string, registryName string) (*http.Request, error) {
356	pathParameters := map[string]interface{}{
357		"registryName":      autorest.Encode("path", registryName),
358		"resourceGroupName": autorest.Encode("path", resourceGroupName),
359		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
360	}
361
362	const APIVersion = "2017-03-01"
363	queryParameters := map[string]interface{}{
364		"api-version": APIVersion,
365	}
366
367	preparer := autorest.CreatePreparer(
368		autorest.AsGet(),
369		autorest.WithBaseURL(client.BaseURI),
370		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerRegistry/registries/{registryName}", pathParameters),
371		autorest.WithQueryParameters(queryParameters))
372	return preparer.Prepare((&http.Request{}).WithContext(ctx))
373}
374
375// GetSender sends the Get request. The method will close the
376// http.Response Body if it receives an error.
377func (client RegistriesClient) GetSender(req *http.Request) (*http.Response, error) {
378	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
379}
380
381// GetResponder handles the response to the Get request. The method always
382// closes the http.Response Body.
383func (client RegistriesClient) GetResponder(resp *http.Response) (result Registry, err error) {
384	err = autorest.Respond(
385		resp,
386		azure.WithErrorUnlessStatusCode(http.StatusOK),
387		autorest.ByUnmarshallingJSON(&result),
388		autorest.ByClosing())
389	result.Response = autorest.Response{Response: resp}
390	return
391}
392
393// List lists all the container registries under the specified subscription.
394func (client RegistriesClient) List(ctx context.Context) (result RegistryListResultPage, err error) {
395	if tracing.IsEnabled() {
396		ctx = tracing.StartSpan(ctx, fqdn+"/RegistriesClient.List")
397		defer func() {
398			sc := -1
399			if result.rlr.Response.Response != nil {
400				sc = result.rlr.Response.Response.StatusCode
401			}
402			tracing.EndSpan(ctx, sc, err)
403		}()
404	}
405	result.fn = client.listNextResults
406	req, err := client.ListPreparer(ctx)
407	if err != nil {
408		err = autorest.NewErrorWithError(err, "containerregistry.RegistriesClient", "List", nil, "Failure preparing request")
409		return
410	}
411
412	resp, err := client.ListSender(req)
413	if err != nil {
414		result.rlr.Response = autorest.Response{Response: resp}
415		err = autorest.NewErrorWithError(err, "containerregistry.RegistriesClient", "List", resp, "Failure sending request")
416		return
417	}
418
419	result.rlr, err = client.ListResponder(resp)
420	if err != nil {
421		err = autorest.NewErrorWithError(err, "containerregistry.RegistriesClient", "List", resp, "Failure responding to request")
422		return
423	}
424	if result.rlr.hasNextLink() && result.rlr.IsEmpty() {
425		err = result.NextWithContext(ctx)
426		return
427	}
428
429	return
430}
431
432// ListPreparer prepares the List request.
433func (client RegistriesClient) ListPreparer(ctx context.Context) (*http.Request, error) {
434	pathParameters := map[string]interface{}{
435		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
436	}
437
438	const APIVersion = "2017-03-01"
439	queryParameters := map[string]interface{}{
440		"api-version": APIVersion,
441	}
442
443	preparer := autorest.CreatePreparer(
444		autorest.AsGet(),
445		autorest.WithBaseURL(client.BaseURI),
446		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.ContainerRegistry/registries", pathParameters),
447		autorest.WithQueryParameters(queryParameters))
448	return preparer.Prepare((&http.Request{}).WithContext(ctx))
449}
450
451// ListSender sends the List request. The method will close the
452// http.Response Body if it receives an error.
453func (client RegistriesClient) ListSender(req *http.Request) (*http.Response, error) {
454	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
455}
456
457// ListResponder handles the response to the List request. The method always
458// closes the http.Response Body.
459func (client RegistriesClient) ListResponder(resp *http.Response) (result RegistryListResult, err error) {
460	err = autorest.Respond(
461		resp,
462		azure.WithErrorUnlessStatusCode(http.StatusOK),
463		autorest.ByUnmarshallingJSON(&result),
464		autorest.ByClosing())
465	result.Response = autorest.Response{Response: resp}
466	return
467}
468
469// listNextResults retrieves the next set of results, if any.
470func (client RegistriesClient) listNextResults(ctx context.Context, lastResults RegistryListResult) (result RegistryListResult, err error) {
471	req, err := lastResults.registryListResultPreparer(ctx)
472	if err != nil {
473		return result, autorest.NewErrorWithError(err, "containerregistry.RegistriesClient", "listNextResults", nil, "Failure preparing next results request")
474	}
475	if req == nil {
476		return
477	}
478	resp, err := client.ListSender(req)
479	if err != nil {
480		result.Response = autorest.Response{Response: resp}
481		return result, autorest.NewErrorWithError(err, "containerregistry.RegistriesClient", "listNextResults", resp, "Failure sending next results request")
482	}
483	result, err = client.ListResponder(resp)
484	if err != nil {
485		err = autorest.NewErrorWithError(err, "containerregistry.RegistriesClient", "listNextResults", resp, "Failure responding to next results request")
486	}
487	return
488}
489
490// ListComplete enumerates all values, automatically crossing page boundaries as required.
491func (client RegistriesClient) ListComplete(ctx context.Context) (result RegistryListResultIterator, err error) {
492	if tracing.IsEnabled() {
493		ctx = tracing.StartSpan(ctx, fqdn+"/RegistriesClient.List")
494		defer func() {
495			sc := -1
496			if result.Response().Response.Response != nil {
497				sc = result.page.Response().Response.Response.StatusCode
498			}
499			tracing.EndSpan(ctx, sc, err)
500		}()
501	}
502	result.page, err = client.List(ctx)
503	return
504}
505
506// ListByResourceGroup lists all the container registries under the specified resource group.
507// Parameters:
508// resourceGroupName - the name of the resource group to which the container registry belongs.
509func (client RegistriesClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result RegistryListResultPage, err error) {
510	if tracing.IsEnabled() {
511		ctx = tracing.StartSpan(ctx, fqdn+"/RegistriesClient.ListByResourceGroup")
512		defer func() {
513			sc := -1
514			if result.rlr.Response.Response != nil {
515				sc = result.rlr.Response.Response.StatusCode
516			}
517			tracing.EndSpan(ctx, sc, err)
518		}()
519	}
520	if err := validation.Validate([]validation.Validation{
521		{TargetValue: resourceGroupName,
522			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
523		return result, validation.NewError("containerregistry.RegistriesClient", "ListByResourceGroup", err.Error())
524	}
525
526	result.fn = client.listByResourceGroupNextResults
527	req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName)
528	if err != nil {
529		err = autorest.NewErrorWithError(err, "containerregistry.RegistriesClient", "ListByResourceGroup", nil, "Failure preparing request")
530		return
531	}
532
533	resp, err := client.ListByResourceGroupSender(req)
534	if err != nil {
535		result.rlr.Response = autorest.Response{Response: resp}
536		err = autorest.NewErrorWithError(err, "containerregistry.RegistriesClient", "ListByResourceGroup", resp, "Failure sending request")
537		return
538	}
539
540	result.rlr, err = client.ListByResourceGroupResponder(resp)
541	if err != nil {
542		err = autorest.NewErrorWithError(err, "containerregistry.RegistriesClient", "ListByResourceGroup", resp, "Failure responding to request")
543		return
544	}
545	if result.rlr.hasNextLink() && result.rlr.IsEmpty() {
546		err = result.NextWithContext(ctx)
547		return
548	}
549
550	return
551}
552
553// ListByResourceGroupPreparer prepares the ListByResourceGroup request.
554func (client RegistriesClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) {
555	pathParameters := map[string]interface{}{
556		"resourceGroupName": autorest.Encode("path", resourceGroupName),
557		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
558	}
559
560	const APIVersion = "2017-03-01"
561	queryParameters := map[string]interface{}{
562		"api-version": APIVersion,
563	}
564
565	preparer := autorest.CreatePreparer(
566		autorest.AsGet(),
567		autorest.WithBaseURL(client.BaseURI),
568		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerRegistry/registries", pathParameters),
569		autorest.WithQueryParameters(queryParameters))
570	return preparer.Prepare((&http.Request{}).WithContext(ctx))
571}
572
573// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the
574// http.Response Body if it receives an error.
575func (client RegistriesClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) {
576	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
577}
578
579// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always
580// closes the http.Response Body.
581func (client RegistriesClient) ListByResourceGroupResponder(resp *http.Response) (result RegistryListResult, err error) {
582	err = autorest.Respond(
583		resp,
584		azure.WithErrorUnlessStatusCode(http.StatusOK),
585		autorest.ByUnmarshallingJSON(&result),
586		autorest.ByClosing())
587	result.Response = autorest.Response{Response: resp}
588	return
589}
590
591// listByResourceGroupNextResults retrieves the next set of results, if any.
592func (client RegistriesClient) listByResourceGroupNextResults(ctx context.Context, lastResults RegistryListResult) (result RegistryListResult, err error) {
593	req, err := lastResults.registryListResultPreparer(ctx)
594	if err != nil {
595		return result, autorest.NewErrorWithError(err, "containerregistry.RegistriesClient", "listByResourceGroupNextResults", nil, "Failure preparing next results request")
596	}
597	if req == nil {
598		return
599	}
600	resp, err := client.ListByResourceGroupSender(req)
601	if err != nil {
602		result.Response = autorest.Response{Response: resp}
603		return result, autorest.NewErrorWithError(err, "containerregistry.RegistriesClient", "listByResourceGroupNextResults", resp, "Failure sending next results request")
604	}
605	result, err = client.ListByResourceGroupResponder(resp)
606	if err != nil {
607		err = autorest.NewErrorWithError(err, "containerregistry.RegistriesClient", "listByResourceGroupNextResults", resp, "Failure responding to next results request")
608	}
609	return
610}
611
612// ListByResourceGroupComplete enumerates all values, automatically crossing page boundaries as required.
613func (client RegistriesClient) ListByResourceGroupComplete(ctx context.Context, resourceGroupName string) (result RegistryListResultIterator, err error) {
614	if tracing.IsEnabled() {
615		ctx = tracing.StartSpan(ctx, fqdn+"/RegistriesClient.ListByResourceGroup")
616		defer func() {
617			sc := -1
618			if result.Response().Response.Response != nil {
619				sc = result.page.Response().Response.Response.StatusCode
620			}
621			tracing.EndSpan(ctx, sc, err)
622		}()
623	}
624	result.page, err = client.ListByResourceGroup(ctx, resourceGroupName)
625	return
626}
627
628// ListCredentials lists the login credentials for the specified container registry.
629// Parameters:
630// resourceGroupName - the name of the resource group to which the container registry belongs.
631// registryName - the name of the container registry.
632func (client RegistriesClient) ListCredentials(ctx context.Context, resourceGroupName string, registryName string) (result RegistryListCredentialsResult, err error) {
633	if tracing.IsEnabled() {
634		ctx = tracing.StartSpan(ctx, fqdn+"/RegistriesClient.ListCredentials")
635		defer func() {
636			sc := -1
637			if result.Response.Response != nil {
638				sc = result.Response.Response.StatusCode
639			}
640			tracing.EndSpan(ctx, sc, err)
641		}()
642	}
643	if err := validation.Validate([]validation.Validation{
644		{TargetValue: resourceGroupName,
645			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
646		{TargetValue: registryName,
647			Constraints: []validation.Constraint{{Target: "registryName", Name: validation.MaxLength, Rule: 50, Chain: nil},
648				{Target: "registryName", Name: validation.MinLength, Rule: 5, Chain: nil},
649				{Target: "registryName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]*$`, Chain: nil}}}}); err != nil {
650		return result, validation.NewError("containerregistry.RegistriesClient", "ListCredentials", err.Error())
651	}
652
653	req, err := client.ListCredentialsPreparer(ctx, resourceGroupName, registryName)
654	if err != nil {
655		err = autorest.NewErrorWithError(err, "containerregistry.RegistriesClient", "ListCredentials", nil, "Failure preparing request")
656		return
657	}
658
659	resp, err := client.ListCredentialsSender(req)
660	if err != nil {
661		result.Response = autorest.Response{Response: resp}
662		err = autorest.NewErrorWithError(err, "containerregistry.RegistriesClient", "ListCredentials", resp, "Failure sending request")
663		return
664	}
665
666	result, err = client.ListCredentialsResponder(resp)
667	if err != nil {
668		err = autorest.NewErrorWithError(err, "containerregistry.RegistriesClient", "ListCredentials", resp, "Failure responding to request")
669		return
670	}
671
672	return
673}
674
675// ListCredentialsPreparer prepares the ListCredentials request.
676func (client RegistriesClient) ListCredentialsPreparer(ctx context.Context, resourceGroupName string, registryName string) (*http.Request, error) {
677	pathParameters := map[string]interface{}{
678		"registryName":      autorest.Encode("path", registryName),
679		"resourceGroupName": autorest.Encode("path", resourceGroupName),
680		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
681	}
682
683	const APIVersion = "2017-03-01"
684	queryParameters := map[string]interface{}{
685		"api-version": APIVersion,
686	}
687
688	preparer := autorest.CreatePreparer(
689		autorest.AsPost(),
690		autorest.WithBaseURL(client.BaseURI),
691		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerRegistry/registries/{registryName}/listCredentials", pathParameters),
692		autorest.WithQueryParameters(queryParameters))
693	return preparer.Prepare((&http.Request{}).WithContext(ctx))
694}
695
696// ListCredentialsSender sends the ListCredentials request. The method will close the
697// http.Response Body if it receives an error.
698func (client RegistriesClient) ListCredentialsSender(req *http.Request) (*http.Response, error) {
699	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
700}
701
702// ListCredentialsResponder handles the response to the ListCredentials request. The method always
703// closes the http.Response Body.
704func (client RegistriesClient) ListCredentialsResponder(resp *http.Response) (result RegistryListCredentialsResult, err error) {
705	err = autorest.Respond(
706		resp,
707		azure.WithErrorUnlessStatusCode(http.StatusOK),
708		autorest.ByUnmarshallingJSON(&result),
709		autorest.ByClosing())
710	result.Response = autorest.Response{Response: resp}
711	return
712}
713
714// RegenerateCredential regenerates one of the login credentials for the specified container registry.
715// Parameters:
716// resourceGroupName - the name of the resource group to which the container registry belongs.
717// registryName - the name of the container registry.
718// regenerateCredentialParameters - specifies name of the password which should be regenerated -- password or
719// password2.
720func (client RegistriesClient) RegenerateCredential(ctx context.Context, resourceGroupName string, registryName string, regenerateCredentialParameters RegenerateCredentialParameters) (result RegistryListCredentialsResult, err error) {
721	if tracing.IsEnabled() {
722		ctx = tracing.StartSpan(ctx, fqdn+"/RegistriesClient.RegenerateCredential")
723		defer func() {
724			sc := -1
725			if result.Response.Response != nil {
726				sc = result.Response.Response.StatusCode
727			}
728			tracing.EndSpan(ctx, sc, err)
729		}()
730	}
731	if err := validation.Validate([]validation.Validation{
732		{TargetValue: resourceGroupName,
733			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
734		{TargetValue: registryName,
735			Constraints: []validation.Constraint{{Target: "registryName", Name: validation.MaxLength, Rule: 50, Chain: nil},
736				{Target: "registryName", Name: validation.MinLength, Rule: 5, Chain: nil},
737				{Target: "registryName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]*$`, Chain: nil}}}}); err != nil {
738		return result, validation.NewError("containerregistry.RegistriesClient", "RegenerateCredential", err.Error())
739	}
740
741	req, err := client.RegenerateCredentialPreparer(ctx, resourceGroupName, registryName, regenerateCredentialParameters)
742	if err != nil {
743		err = autorest.NewErrorWithError(err, "containerregistry.RegistriesClient", "RegenerateCredential", nil, "Failure preparing request")
744		return
745	}
746
747	resp, err := client.RegenerateCredentialSender(req)
748	if err != nil {
749		result.Response = autorest.Response{Response: resp}
750		err = autorest.NewErrorWithError(err, "containerregistry.RegistriesClient", "RegenerateCredential", resp, "Failure sending request")
751		return
752	}
753
754	result, err = client.RegenerateCredentialResponder(resp)
755	if err != nil {
756		err = autorest.NewErrorWithError(err, "containerregistry.RegistriesClient", "RegenerateCredential", resp, "Failure responding to request")
757		return
758	}
759
760	return
761}
762
763// RegenerateCredentialPreparer prepares the RegenerateCredential request.
764func (client RegistriesClient) RegenerateCredentialPreparer(ctx context.Context, resourceGroupName string, registryName string, regenerateCredentialParameters RegenerateCredentialParameters) (*http.Request, error) {
765	pathParameters := map[string]interface{}{
766		"registryName":      autorest.Encode("path", registryName),
767		"resourceGroupName": autorest.Encode("path", resourceGroupName),
768		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
769	}
770
771	const APIVersion = "2017-03-01"
772	queryParameters := map[string]interface{}{
773		"api-version": APIVersion,
774	}
775
776	preparer := autorest.CreatePreparer(
777		autorest.AsContentType("application/json; charset=utf-8"),
778		autorest.AsPost(),
779		autorest.WithBaseURL(client.BaseURI),
780		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerRegistry/registries/{registryName}/regenerateCredential", pathParameters),
781		autorest.WithJSON(regenerateCredentialParameters),
782		autorest.WithQueryParameters(queryParameters))
783	return preparer.Prepare((&http.Request{}).WithContext(ctx))
784}
785
786// RegenerateCredentialSender sends the RegenerateCredential request. The method will close the
787// http.Response Body if it receives an error.
788func (client RegistriesClient) RegenerateCredentialSender(req *http.Request) (*http.Response, error) {
789	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
790}
791
792// RegenerateCredentialResponder handles the response to the RegenerateCredential request. The method always
793// closes the http.Response Body.
794func (client RegistriesClient) RegenerateCredentialResponder(resp *http.Response) (result RegistryListCredentialsResult, err error) {
795	err = autorest.Respond(
796		resp,
797		azure.WithErrorUnlessStatusCode(http.StatusOK),
798		autorest.ByUnmarshallingJSON(&result),
799		autorest.ByClosing())
800	result.Response = autorest.Response{Response: resp}
801	return
802}
803
804// Update updates a container registry with the specified parameters.
805// Parameters:
806// resourceGroupName - the name of the resource group to which the container registry belongs.
807// registryName - the name of the container registry.
808// registryUpdateParameters - the parameters for updating a container registry.
809func (client RegistriesClient) Update(ctx context.Context, resourceGroupName string, registryName string, registryUpdateParameters RegistryUpdateParameters) (result Registry, err error) {
810	if tracing.IsEnabled() {
811		ctx = tracing.StartSpan(ctx, fqdn+"/RegistriesClient.Update")
812		defer func() {
813			sc := -1
814			if result.Response.Response != nil {
815				sc = result.Response.Response.StatusCode
816			}
817			tracing.EndSpan(ctx, sc, err)
818		}()
819	}
820	if err := validation.Validate([]validation.Validation{
821		{TargetValue: resourceGroupName,
822			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
823		{TargetValue: registryName,
824			Constraints: []validation.Constraint{{Target: "registryName", Name: validation.MaxLength, Rule: 50, Chain: nil},
825				{Target: "registryName", Name: validation.MinLength, Rule: 5, Chain: nil},
826				{Target: "registryName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]*$`, Chain: nil}}}}); err != nil {
827		return result, validation.NewError("containerregistry.RegistriesClient", "Update", err.Error())
828	}
829
830	req, err := client.UpdatePreparer(ctx, resourceGroupName, registryName, registryUpdateParameters)
831	if err != nil {
832		err = autorest.NewErrorWithError(err, "containerregistry.RegistriesClient", "Update", nil, "Failure preparing request")
833		return
834	}
835
836	resp, err := client.UpdateSender(req)
837	if err != nil {
838		result.Response = autorest.Response{Response: resp}
839		err = autorest.NewErrorWithError(err, "containerregistry.RegistriesClient", "Update", resp, "Failure sending request")
840		return
841	}
842
843	result, err = client.UpdateResponder(resp)
844	if err != nil {
845		err = autorest.NewErrorWithError(err, "containerregistry.RegistriesClient", "Update", resp, "Failure responding to request")
846		return
847	}
848
849	return
850}
851
852// UpdatePreparer prepares the Update request.
853func (client RegistriesClient) UpdatePreparer(ctx context.Context, resourceGroupName string, registryName string, registryUpdateParameters RegistryUpdateParameters) (*http.Request, error) {
854	pathParameters := map[string]interface{}{
855		"registryName":      autorest.Encode("path", registryName),
856		"resourceGroupName": autorest.Encode("path", resourceGroupName),
857		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
858	}
859
860	const APIVersion = "2017-03-01"
861	queryParameters := map[string]interface{}{
862		"api-version": APIVersion,
863	}
864
865	preparer := autorest.CreatePreparer(
866		autorest.AsContentType("application/json; charset=utf-8"),
867		autorest.AsPatch(),
868		autorest.WithBaseURL(client.BaseURI),
869		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerRegistry/registries/{registryName}", pathParameters),
870		autorest.WithJSON(registryUpdateParameters),
871		autorest.WithQueryParameters(queryParameters))
872	return preparer.Prepare((&http.Request{}).WithContext(ctx))
873}
874
875// UpdateSender sends the Update request. The method will close the
876// http.Response Body if it receives an error.
877func (client RegistriesClient) UpdateSender(req *http.Request) (*http.Response, error) {
878	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
879}
880
881// UpdateResponder handles the response to the Update request. The method always
882// closes the http.Response Body.
883func (client RegistriesClient) UpdateResponder(resp *http.Response) (result Registry, err error) {
884	err = autorest.Respond(
885		resp,
886		azure.WithErrorUnlessStatusCode(http.StatusOK),
887		autorest.ByUnmarshallingJSON(&result),
888		autorest.ByClosing())
889	result.Response = autorest.Response{Response: resp}
890	return
891}
892