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// RunsClient is the client for the Runs methods of the Containerregistry service.
19type RunsClient struct {
20	BaseClient
21}
22
23// NewRunsClient creates an instance of the RunsClient client.
24func NewRunsClient(subscriptionID string) RunsClient {
25	return NewRunsClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewRunsClientWithBaseURI creates an instance of the RunsClient client using a custom endpoint.  Use this when
29// interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
30func NewRunsClientWithBaseURI(baseURI string, subscriptionID string) RunsClient {
31	return RunsClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// Cancel cancel an existing run.
35// Parameters:
36// resourceGroupName - the name of the resource group to which the container registry belongs.
37// registryName - the name of the container registry.
38// runID - the run ID.
39func (client RunsClient) Cancel(ctx context.Context, resourceGroupName string, registryName string, runID string) (result RunsCancelFuture, err error) {
40	if tracing.IsEnabled() {
41		ctx = tracing.StartSpan(ctx, fqdn+"/RunsClient.Cancel")
42		defer func() {
43			sc := -1
44			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
45				sc = result.FutureAPI.Response().StatusCode
46			}
47			tracing.EndSpan(ctx, sc, err)
48		}()
49	}
50	if err := validation.Validate([]validation.Validation{
51		{TargetValue: resourceGroupName,
52			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
53		{TargetValue: registryName,
54			Constraints: []validation.Constraint{{Target: "registryName", Name: validation.MaxLength, Rule: 50, Chain: nil},
55				{Target: "registryName", Name: validation.MinLength, Rule: 5, Chain: nil},
56				{Target: "registryName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]*$`, Chain: nil}}}}); err != nil {
57		return result, validation.NewError("containerregistry.RunsClient", "Cancel", err.Error())
58	}
59
60	req, err := client.CancelPreparer(ctx, resourceGroupName, registryName, runID)
61	if err != nil {
62		err = autorest.NewErrorWithError(err, "containerregistry.RunsClient", "Cancel", nil, "Failure preparing request")
63		return
64	}
65
66	result, err = client.CancelSender(req)
67	if err != nil {
68		err = autorest.NewErrorWithError(err, "containerregistry.RunsClient", "Cancel", nil, "Failure sending request")
69		return
70	}
71
72	return
73}
74
75// CancelPreparer prepares the Cancel request.
76func (client RunsClient) CancelPreparer(ctx context.Context, resourceGroupName string, registryName string, runID string) (*http.Request, error) {
77	pathParameters := map[string]interface{}{
78		"registryName":      autorest.Encode("path", registryName),
79		"resourceGroupName": autorest.Encode("path", resourceGroupName),
80		"runId":             autorest.Encode("path", runID),
81		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
82	}
83
84	const APIVersion = "2019-04-01"
85	queryParameters := map[string]interface{}{
86		"api-version": APIVersion,
87	}
88
89	preparer := autorest.CreatePreparer(
90		autorest.AsPost(),
91		autorest.WithBaseURL(client.BaseURI),
92		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerRegistry/registries/{registryName}/runs/{runId}/cancel", pathParameters),
93		autorest.WithQueryParameters(queryParameters))
94	return preparer.Prepare((&http.Request{}).WithContext(ctx))
95}
96
97// CancelSender sends the Cancel request. The method will close the
98// http.Response Body if it receives an error.
99func (client RunsClient) CancelSender(req *http.Request) (future RunsCancelFuture, err error) {
100	var resp *http.Response
101	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
102	if err != nil {
103		return
104	}
105	var azf azure.Future
106	azf, err = azure.NewFutureFromResponse(resp)
107	future.FutureAPI = &azf
108	future.Result = future.result
109	return
110}
111
112// CancelResponder handles the response to the Cancel request. The method always
113// closes the http.Response Body.
114func (client RunsClient) CancelResponder(resp *http.Response) (result autorest.Response, err error) {
115	err = autorest.Respond(
116		resp,
117		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
118		autorest.ByClosing())
119	result.Response = resp
120	return
121}
122
123// Get gets the detailed information for a given run.
124// Parameters:
125// resourceGroupName - the name of the resource group to which the container registry belongs.
126// registryName - the name of the container registry.
127// runID - the run ID.
128func (client RunsClient) Get(ctx context.Context, resourceGroupName string, registryName string, runID string) (result Run, err error) {
129	if tracing.IsEnabled() {
130		ctx = tracing.StartSpan(ctx, fqdn+"/RunsClient.Get")
131		defer func() {
132			sc := -1
133			if result.Response.Response != nil {
134				sc = result.Response.Response.StatusCode
135			}
136			tracing.EndSpan(ctx, sc, err)
137		}()
138	}
139	if err := validation.Validate([]validation.Validation{
140		{TargetValue: resourceGroupName,
141			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
142		{TargetValue: registryName,
143			Constraints: []validation.Constraint{{Target: "registryName", Name: validation.MaxLength, Rule: 50, Chain: nil},
144				{Target: "registryName", Name: validation.MinLength, Rule: 5, Chain: nil},
145				{Target: "registryName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]*$`, Chain: nil}}}}); err != nil {
146		return result, validation.NewError("containerregistry.RunsClient", "Get", err.Error())
147	}
148
149	req, err := client.GetPreparer(ctx, resourceGroupName, registryName, runID)
150	if err != nil {
151		err = autorest.NewErrorWithError(err, "containerregistry.RunsClient", "Get", nil, "Failure preparing request")
152		return
153	}
154
155	resp, err := client.GetSender(req)
156	if err != nil {
157		result.Response = autorest.Response{Response: resp}
158		err = autorest.NewErrorWithError(err, "containerregistry.RunsClient", "Get", resp, "Failure sending request")
159		return
160	}
161
162	result, err = client.GetResponder(resp)
163	if err != nil {
164		err = autorest.NewErrorWithError(err, "containerregistry.RunsClient", "Get", resp, "Failure responding to request")
165		return
166	}
167
168	return
169}
170
171// GetPreparer prepares the Get request.
172func (client RunsClient) GetPreparer(ctx context.Context, resourceGroupName string, registryName string, runID string) (*http.Request, error) {
173	pathParameters := map[string]interface{}{
174		"registryName":      autorest.Encode("path", registryName),
175		"resourceGroupName": autorest.Encode("path", resourceGroupName),
176		"runId":             autorest.Encode("path", runID),
177		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
178	}
179
180	const APIVersion = "2019-04-01"
181	queryParameters := map[string]interface{}{
182		"api-version": APIVersion,
183	}
184
185	preparer := autorest.CreatePreparer(
186		autorest.AsGet(),
187		autorest.WithBaseURL(client.BaseURI),
188		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerRegistry/registries/{registryName}/runs/{runId}", pathParameters),
189		autorest.WithQueryParameters(queryParameters))
190	return preparer.Prepare((&http.Request{}).WithContext(ctx))
191}
192
193// GetSender sends the Get request. The method will close the
194// http.Response Body if it receives an error.
195func (client RunsClient) GetSender(req *http.Request) (*http.Response, error) {
196	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
197}
198
199// GetResponder handles the response to the Get request. The method always
200// closes the http.Response Body.
201func (client RunsClient) GetResponder(resp *http.Response) (result Run, err error) {
202	err = autorest.Respond(
203		resp,
204		azure.WithErrorUnlessStatusCode(http.StatusOK),
205		autorest.ByUnmarshallingJSON(&result),
206		autorest.ByClosing())
207	result.Response = autorest.Response{Response: resp}
208	return
209}
210
211// GetLogSasURL gets a link to download the run logs.
212// Parameters:
213// resourceGroupName - the name of the resource group to which the container registry belongs.
214// registryName - the name of the container registry.
215// runID - the run ID.
216func (client RunsClient) GetLogSasURL(ctx context.Context, resourceGroupName string, registryName string, runID string) (result RunGetLogResult, err error) {
217	if tracing.IsEnabled() {
218		ctx = tracing.StartSpan(ctx, fqdn+"/RunsClient.GetLogSasURL")
219		defer func() {
220			sc := -1
221			if result.Response.Response != nil {
222				sc = result.Response.Response.StatusCode
223			}
224			tracing.EndSpan(ctx, sc, err)
225		}()
226	}
227	if err := validation.Validate([]validation.Validation{
228		{TargetValue: resourceGroupName,
229			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
230		{TargetValue: registryName,
231			Constraints: []validation.Constraint{{Target: "registryName", Name: validation.MaxLength, Rule: 50, Chain: nil},
232				{Target: "registryName", Name: validation.MinLength, Rule: 5, Chain: nil},
233				{Target: "registryName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]*$`, Chain: nil}}}}); err != nil {
234		return result, validation.NewError("containerregistry.RunsClient", "GetLogSasURL", err.Error())
235	}
236
237	req, err := client.GetLogSasURLPreparer(ctx, resourceGroupName, registryName, runID)
238	if err != nil {
239		err = autorest.NewErrorWithError(err, "containerregistry.RunsClient", "GetLogSasURL", nil, "Failure preparing request")
240		return
241	}
242
243	resp, err := client.GetLogSasURLSender(req)
244	if err != nil {
245		result.Response = autorest.Response{Response: resp}
246		err = autorest.NewErrorWithError(err, "containerregistry.RunsClient", "GetLogSasURL", resp, "Failure sending request")
247		return
248	}
249
250	result, err = client.GetLogSasURLResponder(resp)
251	if err != nil {
252		err = autorest.NewErrorWithError(err, "containerregistry.RunsClient", "GetLogSasURL", resp, "Failure responding to request")
253		return
254	}
255
256	return
257}
258
259// GetLogSasURLPreparer prepares the GetLogSasURL request.
260func (client RunsClient) GetLogSasURLPreparer(ctx context.Context, resourceGroupName string, registryName string, runID string) (*http.Request, error) {
261	pathParameters := map[string]interface{}{
262		"registryName":      autorest.Encode("path", registryName),
263		"resourceGroupName": autorest.Encode("path", resourceGroupName),
264		"runId":             autorest.Encode("path", runID),
265		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
266	}
267
268	const APIVersion = "2019-04-01"
269	queryParameters := map[string]interface{}{
270		"api-version": APIVersion,
271	}
272
273	preparer := autorest.CreatePreparer(
274		autorest.AsPost(),
275		autorest.WithBaseURL(client.BaseURI),
276		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerRegistry/registries/{registryName}/runs/{runId}/listLogSasUrl", pathParameters),
277		autorest.WithQueryParameters(queryParameters))
278	return preparer.Prepare((&http.Request{}).WithContext(ctx))
279}
280
281// GetLogSasURLSender sends the GetLogSasURL request. The method will close the
282// http.Response Body if it receives an error.
283func (client RunsClient) GetLogSasURLSender(req *http.Request) (*http.Response, error) {
284	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
285}
286
287// GetLogSasURLResponder handles the response to the GetLogSasURL request. The method always
288// closes the http.Response Body.
289func (client RunsClient) GetLogSasURLResponder(resp *http.Response) (result RunGetLogResult, err error) {
290	err = autorest.Respond(
291		resp,
292		azure.WithErrorUnlessStatusCode(http.StatusOK),
293		autorest.ByUnmarshallingJSON(&result),
294		autorest.ByClosing())
295	result.Response = autorest.Response{Response: resp}
296	return
297}
298
299// List gets all the runs for a registry.
300// Parameters:
301// resourceGroupName - the name of the resource group to which the container registry belongs.
302// registryName - the name of the container registry.
303// filter - the runs filter to apply on the operation. Arithmetic operators are not supported. The allowed
304// string function is 'contains'. All logical operators except 'Not', 'Has', 'All' are allowed.
305// top - $top is supported for get list of runs, which limits the maximum number of runs to return.
306func (client RunsClient) List(ctx context.Context, resourceGroupName string, registryName string, filter string, top *int32) (result RunListResultPage, err error) {
307	if tracing.IsEnabled() {
308		ctx = tracing.StartSpan(ctx, fqdn+"/RunsClient.List")
309		defer func() {
310			sc := -1
311			if result.rlr.Response.Response != nil {
312				sc = result.rlr.Response.Response.StatusCode
313			}
314			tracing.EndSpan(ctx, sc, err)
315		}()
316	}
317	if err := validation.Validate([]validation.Validation{
318		{TargetValue: resourceGroupName,
319			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
320		{TargetValue: registryName,
321			Constraints: []validation.Constraint{{Target: "registryName", Name: validation.MaxLength, Rule: 50, Chain: nil},
322				{Target: "registryName", Name: validation.MinLength, Rule: 5, Chain: nil},
323				{Target: "registryName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]*$`, Chain: nil}}}}); err != nil {
324		return result, validation.NewError("containerregistry.RunsClient", "List", err.Error())
325	}
326
327	result.fn = client.listNextResults
328	req, err := client.ListPreparer(ctx, resourceGroupName, registryName, filter, top)
329	if err != nil {
330		err = autorest.NewErrorWithError(err, "containerregistry.RunsClient", "List", nil, "Failure preparing request")
331		return
332	}
333
334	resp, err := client.ListSender(req)
335	if err != nil {
336		result.rlr.Response = autorest.Response{Response: resp}
337		err = autorest.NewErrorWithError(err, "containerregistry.RunsClient", "List", resp, "Failure sending request")
338		return
339	}
340
341	result.rlr, err = client.ListResponder(resp)
342	if err != nil {
343		err = autorest.NewErrorWithError(err, "containerregistry.RunsClient", "List", resp, "Failure responding to request")
344		return
345	}
346	if result.rlr.hasNextLink() && result.rlr.IsEmpty() {
347		err = result.NextWithContext(ctx)
348		return
349	}
350
351	return
352}
353
354// ListPreparer prepares the List request.
355func (client RunsClient) ListPreparer(ctx context.Context, resourceGroupName string, registryName string, filter string, top *int32) (*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 = "2019-04-01"
363	queryParameters := map[string]interface{}{
364		"api-version": APIVersion,
365	}
366	if len(filter) > 0 {
367		queryParameters["$filter"] = autorest.Encode("query", filter)
368	}
369	if top != nil {
370		queryParameters["$top"] = autorest.Encode("query", *top)
371	}
372
373	preparer := autorest.CreatePreparer(
374		autorest.AsGet(),
375		autorest.WithBaseURL(client.BaseURI),
376		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerRegistry/registries/{registryName}/runs", pathParameters),
377		autorest.WithQueryParameters(queryParameters))
378	return preparer.Prepare((&http.Request{}).WithContext(ctx))
379}
380
381// ListSender sends the List request. The method will close the
382// http.Response Body if it receives an error.
383func (client RunsClient) ListSender(req *http.Request) (*http.Response, error) {
384	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
385}
386
387// ListResponder handles the response to the List request. The method always
388// closes the http.Response Body.
389func (client RunsClient) ListResponder(resp *http.Response) (result RunListResult, err error) {
390	err = autorest.Respond(
391		resp,
392		azure.WithErrorUnlessStatusCode(http.StatusOK),
393		autorest.ByUnmarshallingJSON(&result),
394		autorest.ByClosing())
395	result.Response = autorest.Response{Response: resp}
396	return
397}
398
399// listNextResults retrieves the next set of results, if any.
400func (client RunsClient) listNextResults(ctx context.Context, lastResults RunListResult) (result RunListResult, err error) {
401	req, err := lastResults.runListResultPreparer(ctx)
402	if err != nil {
403		return result, autorest.NewErrorWithError(err, "containerregistry.RunsClient", "listNextResults", nil, "Failure preparing next results request")
404	}
405	if req == nil {
406		return
407	}
408	resp, err := client.ListSender(req)
409	if err != nil {
410		result.Response = autorest.Response{Response: resp}
411		return result, autorest.NewErrorWithError(err, "containerregistry.RunsClient", "listNextResults", resp, "Failure sending next results request")
412	}
413	result, err = client.ListResponder(resp)
414	if err != nil {
415		err = autorest.NewErrorWithError(err, "containerregistry.RunsClient", "listNextResults", resp, "Failure responding to next results request")
416	}
417	return
418}
419
420// ListComplete enumerates all values, automatically crossing page boundaries as required.
421func (client RunsClient) ListComplete(ctx context.Context, resourceGroupName string, registryName string, filter string, top *int32) (result RunListResultIterator, err error) {
422	if tracing.IsEnabled() {
423		ctx = tracing.StartSpan(ctx, fqdn+"/RunsClient.List")
424		defer func() {
425			sc := -1
426			if result.Response().Response.Response != nil {
427				sc = result.page.Response().Response.Response.StatusCode
428			}
429			tracing.EndSpan(ctx, sc, err)
430		}()
431	}
432	result.page, err = client.List(ctx, resourceGroupName, registryName, filter, top)
433	return
434}
435
436// Update patch the run properties.
437// Parameters:
438// resourceGroupName - the name of the resource group to which the container registry belongs.
439// registryName - the name of the container registry.
440// runID - the run ID.
441// runUpdateParameters - the run update properties.
442func (client RunsClient) Update(ctx context.Context, resourceGroupName string, registryName string, runID string, runUpdateParameters RunUpdateParameters) (result RunsUpdateFuture, err error) {
443	if tracing.IsEnabled() {
444		ctx = tracing.StartSpan(ctx, fqdn+"/RunsClient.Update")
445		defer func() {
446			sc := -1
447			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
448				sc = result.FutureAPI.Response().StatusCode
449			}
450			tracing.EndSpan(ctx, sc, err)
451		}()
452	}
453	if err := validation.Validate([]validation.Validation{
454		{TargetValue: resourceGroupName,
455			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
456		{TargetValue: registryName,
457			Constraints: []validation.Constraint{{Target: "registryName", Name: validation.MaxLength, Rule: 50, Chain: nil},
458				{Target: "registryName", Name: validation.MinLength, Rule: 5, Chain: nil},
459				{Target: "registryName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]*$`, Chain: nil}}}}); err != nil {
460		return result, validation.NewError("containerregistry.RunsClient", "Update", err.Error())
461	}
462
463	req, err := client.UpdatePreparer(ctx, resourceGroupName, registryName, runID, runUpdateParameters)
464	if err != nil {
465		err = autorest.NewErrorWithError(err, "containerregistry.RunsClient", "Update", nil, "Failure preparing request")
466		return
467	}
468
469	result, err = client.UpdateSender(req)
470	if err != nil {
471		err = autorest.NewErrorWithError(err, "containerregistry.RunsClient", "Update", nil, "Failure sending request")
472		return
473	}
474
475	return
476}
477
478// UpdatePreparer prepares the Update request.
479func (client RunsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, registryName string, runID string, runUpdateParameters RunUpdateParameters) (*http.Request, error) {
480	pathParameters := map[string]interface{}{
481		"registryName":      autorest.Encode("path", registryName),
482		"resourceGroupName": autorest.Encode("path", resourceGroupName),
483		"runId":             autorest.Encode("path", runID),
484		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
485	}
486
487	const APIVersion = "2019-04-01"
488	queryParameters := map[string]interface{}{
489		"api-version": APIVersion,
490	}
491
492	preparer := autorest.CreatePreparer(
493		autorest.AsContentType("application/json; charset=utf-8"),
494		autorest.AsPatch(),
495		autorest.WithBaseURL(client.BaseURI),
496		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerRegistry/registries/{registryName}/runs/{runId}", pathParameters),
497		autorest.WithJSON(runUpdateParameters),
498		autorest.WithQueryParameters(queryParameters))
499	return preparer.Prepare((&http.Request{}).WithContext(ctx))
500}
501
502// UpdateSender sends the Update request. The method will close the
503// http.Response Body if it receives an error.
504func (client RunsClient) UpdateSender(req *http.Request) (future RunsUpdateFuture, err error) {
505	var resp *http.Response
506	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
507	if err != nil {
508		return
509	}
510	var azf azure.Future
511	azf, err = azure.NewFutureFromResponse(resp)
512	future.FutureAPI = &azf
513	future.Result = future.result
514	return
515}
516
517// UpdateResponder handles the response to the Update request. The method always
518// closes the http.Response Body.
519func (client RunsClient) UpdateResponder(resp *http.Response) (result Run, err error) {
520	err = autorest.Respond(
521		resp,
522		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
523		autorest.ByUnmarshallingJSON(&result),
524		autorest.ByClosing())
525	result.Response = autorest.Response{Response: resp}
526	return
527}
528