1package databox
2
3// Copyright (c) Microsoft and contributors.  All rights reserved.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13//
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17// Code generated by Microsoft (R) AutoRest Code Generator.
18// Changes may cause incorrect behavior and will be lost if the code is regenerated.
19
20import (
21	"context"
22	"github.com/Azure/go-autorest/autorest"
23	"github.com/Azure/go-autorest/autorest/azure"
24	"github.com/Azure/go-autorest/autorest/validation"
25	"github.com/Azure/go-autorest/tracing"
26	"net/http"
27)
28
29// JobsClient is the client for the Jobs methods of the Databox service.
30type JobsClient struct {
31	BaseClient
32}
33
34// NewJobsClient creates an instance of the JobsClient client.
35func NewJobsClient(subscriptionID string) JobsClient {
36	return NewJobsClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewJobsClientWithBaseURI creates an instance of the JobsClient client using a custom endpoint.  Use this when
40// interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
41func NewJobsClientWithBaseURI(baseURI string, subscriptionID string) JobsClient {
42	return JobsClient{NewWithBaseURI(baseURI, subscriptionID)}
43}
44
45// BookShipmentPickUp book shipment pick up.
46// Parameters:
47// resourceGroupName - the Resource Group Name
48// jobName - the name of the job Resource within the specified resource group. job names must be between 3 and
49// 24 characters in length and use any alphanumeric and underscore only
50// shipmentPickUpRequest - details of shipment pick up request.
51func (client JobsClient) BookShipmentPickUp(ctx context.Context, resourceGroupName string, jobName string, shipmentPickUpRequest ShipmentPickUpRequest) (result ShipmentPickUpResponse, err error) {
52	if tracing.IsEnabled() {
53		ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.BookShipmentPickUp")
54		defer func() {
55			sc := -1
56			if result.Response.Response != nil {
57				sc = result.Response.Response.StatusCode
58			}
59			tracing.EndSpan(ctx, sc, err)
60		}()
61	}
62	if err := validation.Validate([]validation.Validation{
63		{TargetValue: jobName,
64			Constraints: []validation.Constraint{{Target: "jobName", Name: validation.MaxLength, Rule: 24, Chain: nil},
65				{Target: "jobName", Name: validation.MinLength, Rule: 3, Chain: nil},
66				{Target: "jobName", Name: validation.Pattern, Rule: `^[-\w\.]+$`, Chain: nil}}},
67		{TargetValue: shipmentPickUpRequest,
68			Constraints: []validation.Constraint{{Target: "shipmentPickUpRequest.StartTime", Name: validation.Null, Rule: true, Chain: nil},
69				{Target: "shipmentPickUpRequest.EndTime", Name: validation.Null, Rule: true, Chain: nil},
70				{Target: "shipmentPickUpRequest.ShipmentLocation", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
71		return result, validation.NewError("databox.JobsClient", "BookShipmentPickUp", err.Error())
72	}
73
74	req, err := client.BookShipmentPickUpPreparer(ctx, resourceGroupName, jobName, shipmentPickUpRequest)
75	if err != nil {
76		err = autorest.NewErrorWithError(err, "databox.JobsClient", "BookShipmentPickUp", nil, "Failure preparing request")
77		return
78	}
79
80	resp, err := client.BookShipmentPickUpSender(req)
81	if err != nil {
82		result.Response = autorest.Response{Response: resp}
83		err = autorest.NewErrorWithError(err, "databox.JobsClient", "BookShipmentPickUp", resp, "Failure sending request")
84		return
85	}
86
87	result, err = client.BookShipmentPickUpResponder(resp)
88	if err != nil {
89		err = autorest.NewErrorWithError(err, "databox.JobsClient", "BookShipmentPickUp", resp, "Failure responding to request")
90		return
91	}
92
93	return
94}
95
96// BookShipmentPickUpPreparer prepares the BookShipmentPickUp request.
97func (client JobsClient) BookShipmentPickUpPreparer(ctx context.Context, resourceGroupName string, jobName string, shipmentPickUpRequest ShipmentPickUpRequest) (*http.Request, error) {
98	pathParameters := map[string]interface{}{
99		"jobName":           autorest.Encode("path", jobName),
100		"resourceGroupName": autorest.Encode("path", resourceGroupName),
101		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
102	}
103
104	const APIVersion = "2020-04-01"
105	queryParameters := map[string]interface{}{
106		"api-version": APIVersion,
107	}
108
109	preparer := autorest.CreatePreparer(
110		autorest.AsContentType("application/json; charset=utf-8"),
111		autorest.AsPost(),
112		autorest.WithBaseURL(client.BaseURI),
113		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataBox/jobs/{jobName}/bookShipmentPickUp", pathParameters),
114		autorest.WithJSON(shipmentPickUpRequest),
115		autorest.WithQueryParameters(queryParameters))
116	return preparer.Prepare((&http.Request{}).WithContext(ctx))
117}
118
119// BookShipmentPickUpSender sends the BookShipmentPickUp request. The method will close the
120// http.Response Body if it receives an error.
121func (client JobsClient) BookShipmentPickUpSender(req *http.Request) (*http.Response, error) {
122	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
123}
124
125// BookShipmentPickUpResponder handles the response to the BookShipmentPickUp request. The method always
126// closes the http.Response Body.
127func (client JobsClient) BookShipmentPickUpResponder(resp *http.Response) (result ShipmentPickUpResponse, err error) {
128	err = autorest.Respond(
129		resp,
130		azure.WithErrorUnlessStatusCode(http.StatusOK),
131		autorest.ByUnmarshallingJSON(&result),
132		autorest.ByClosing())
133	result.Response = autorest.Response{Response: resp}
134	return
135}
136
137// Cancel cancelJob.
138// Parameters:
139// resourceGroupName - the Resource Group Name
140// jobName - the name of the job Resource within the specified resource group. job names must be between 3 and
141// 24 characters in length and use any alphanumeric and underscore only
142// cancellationReason - reason for cancellation.
143func (client JobsClient) Cancel(ctx context.Context, resourceGroupName string, jobName string, cancellationReason CancellationReason) (result autorest.Response, err error) {
144	if tracing.IsEnabled() {
145		ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.Cancel")
146		defer func() {
147			sc := -1
148			if result.Response != nil {
149				sc = result.Response.StatusCode
150			}
151			tracing.EndSpan(ctx, sc, err)
152		}()
153	}
154	if err := validation.Validate([]validation.Validation{
155		{TargetValue: jobName,
156			Constraints: []validation.Constraint{{Target: "jobName", Name: validation.MaxLength, Rule: 24, Chain: nil},
157				{Target: "jobName", Name: validation.MinLength, Rule: 3, Chain: nil},
158				{Target: "jobName", Name: validation.Pattern, Rule: `^[-\w\.]+$`, Chain: nil}}},
159		{TargetValue: cancellationReason,
160			Constraints: []validation.Constraint{{Target: "cancellationReason.Reason", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
161		return result, validation.NewError("databox.JobsClient", "Cancel", err.Error())
162	}
163
164	req, err := client.CancelPreparer(ctx, resourceGroupName, jobName, cancellationReason)
165	if err != nil {
166		err = autorest.NewErrorWithError(err, "databox.JobsClient", "Cancel", nil, "Failure preparing request")
167		return
168	}
169
170	resp, err := client.CancelSender(req)
171	if err != nil {
172		result.Response = resp
173		err = autorest.NewErrorWithError(err, "databox.JobsClient", "Cancel", resp, "Failure sending request")
174		return
175	}
176
177	result, err = client.CancelResponder(resp)
178	if err != nil {
179		err = autorest.NewErrorWithError(err, "databox.JobsClient", "Cancel", resp, "Failure responding to request")
180		return
181	}
182
183	return
184}
185
186// CancelPreparer prepares the Cancel request.
187func (client JobsClient) CancelPreparer(ctx context.Context, resourceGroupName string, jobName string, cancellationReason CancellationReason) (*http.Request, error) {
188	pathParameters := map[string]interface{}{
189		"jobName":           autorest.Encode("path", jobName),
190		"resourceGroupName": autorest.Encode("path", resourceGroupName),
191		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
192	}
193
194	const APIVersion = "2020-04-01"
195	queryParameters := map[string]interface{}{
196		"api-version": APIVersion,
197	}
198
199	preparer := autorest.CreatePreparer(
200		autorest.AsContentType("application/json; charset=utf-8"),
201		autorest.AsPost(),
202		autorest.WithBaseURL(client.BaseURI),
203		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataBox/jobs/{jobName}/cancel", pathParameters),
204		autorest.WithJSON(cancellationReason),
205		autorest.WithQueryParameters(queryParameters))
206	return preparer.Prepare((&http.Request{}).WithContext(ctx))
207}
208
209// CancelSender sends the Cancel request. The method will close the
210// http.Response Body if it receives an error.
211func (client JobsClient) CancelSender(req *http.Request) (*http.Response, error) {
212	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
213}
214
215// CancelResponder handles the response to the Cancel request. The method always
216// closes the http.Response Body.
217func (client JobsClient) CancelResponder(resp *http.Response) (result autorest.Response, err error) {
218	err = autorest.Respond(
219		resp,
220		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
221		autorest.ByClosing())
222	result.Response = resp
223	return
224}
225
226// Create creates a new job with the specified parameters. Existing job cannot be updated with this API and should
227// instead be updated with the Update job API.
228// Parameters:
229// resourceGroupName - the Resource Group Name
230// jobName - the name of the job Resource within the specified resource group. job names must be between 3 and
231// 24 characters in length and use any alphanumeric and underscore only
232// jobResource - job details from request body.
233func (client JobsClient) Create(ctx context.Context, resourceGroupName string, jobName string, jobResource JobResource) (result JobsCreateFuture, err error) {
234	if tracing.IsEnabled() {
235		ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.Create")
236		defer func() {
237			sc := -1
238			if result.Response() != nil {
239				sc = result.Response().StatusCode
240			}
241			tracing.EndSpan(ctx, sc, err)
242		}()
243	}
244	if err := validation.Validate([]validation.Validation{
245		{TargetValue: jobName,
246			Constraints: []validation.Constraint{{Target: "jobName", Name: validation.MaxLength, Rule: 24, Chain: nil},
247				{Target: "jobName", Name: validation.MinLength, Rule: 3, Chain: nil},
248				{Target: "jobName", Name: validation.Pattern, Rule: `^[-\w\.]+$`, Chain: nil}}},
249		{TargetValue: jobResource,
250			Constraints: []validation.Constraint{{Target: "jobResource.JobProperties", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
251		return result, validation.NewError("databox.JobsClient", "Create", err.Error())
252	}
253
254	req, err := client.CreatePreparer(ctx, resourceGroupName, jobName, jobResource)
255	if err != nil {
256		err = autorest.NewErrorWithError(err, "databox.JobsClient", "Create", nil, "Failure preparing request")
257		return
258	}
259
260	result, err = client.CreateSender(req)
261	if err != nil {
262		err = autorest.NewErrorWithError(err, "databox.JobsClient", "Create", nil, "Failure sending request")
263		return
264	}
265
266	return
267}
268
269// CreatePreparer prepares the Create request.
270func (client JobsClient) CreatePreparer(ctx context.Context, resourceGroupName string, jobName string, jobResource JobResource) (*http.Request, error) {
271	pathParameters := map[string]interface{}{
272		"jobName":           autorest.Encode("path", jobName),
273		"resourceGroupName": autorest.Encode("path", resourceGroupName),
274		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
275	}
276
277	const APIVersion = "2020-04-01"
278	queryParameters := map[string]interface{}{
279		"api-version": APIVersion,
280	}
281
282	jobResource.Name = nil
283	jobResource.ID = nil
284	jobResource.Type = nil
285	preparer := autorest.CreatePreparer(
286		autorest.AsContentType("application/json; charset=utf-8"),
287		autorest.AsPut(),
288		autorest.WithBaseURL(client.BaseURI),
289		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataBox/jobs/{jobName}", pathParameters),
290		autorest.WithJSON(jobResource),
291		autorest.WithQueryParameters(queryParameters))
292	return preparer.Prepare((&http.Request{}).WithContext(ctx))
293}
294
295// CreateSender sends the Create request. The method will close the
296// http.Response Body if it receives an error.
297func (client JobsClient) CreateSender(req *http.Request) (future JobsCreateFuture, err error) {
298	var resp *http.Response
299	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
300	if err != nil {
301		return
302	}
303	var azf azure.Future
304	azf, err = azure.NewFutureFromResponse(resp)
305	future.FutureAPI = &azf
306	future.Result = func(client JobsClient) (jr JobResource, err error) {
307		var done bool
308		done, err = future.DoneWithContext(context.Background(), client)
309		if err != nil {
310			err = autorest.NewErrorWithError(err, "databox.JobsCreateFuture", "Result", future.Response(), "Polling failure")
311			return
312		}
313		if !done {
314			err = azure.NewAsyncOpIncompleteError("databox.JobsCreateFuture")
315			return
316		}
317		sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
318		if jr.Response.Response, err = future.GetResult(sender); err == nil && jr.Response.Response.StatusCode != http.StatusNoContent {
319			jr, err = client.CreateResponder(jr.Response.Response)
320			if err != nil {
321				err = autorest.NewErrorWithError(err, "databox.JobsCreateFuture", "Result", jr.Response.Response, "Failure responding to request")
322			}
323		}
324		return
325	}
326	return
327}
328
329// CreateResponder handles the response to the Create request. The method always
330// closes the http.Response Body.
331func (client JobsClient) CreateResponder(resp *http.Response) (result JobResource, err error) {
332	err = autorest.Respond(
333		resp,
334		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
335		autorest.ByUnmarshallingJSON(&result),
336		autorest.ByClosing())
337	result.Response = autorest.Response{Response: resp}
338	return
339}
340
341// Delete deletes a job.
342// Parameters:
343// resourceGroupName - the Resource Group Name
344// jobName - the name of the job Resource within the specified resource group. job names must be between 3 and
345// 24 characters in length and use any alphanumeric and underscore only
346func (client JobsClient) Delete(ctx context.Context, resourceGroupName string, jobName string) (result JobsDeleteFuture, err error) {
347	if tracing.IsEnabled() {
348		ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.Delete")
349		defer func() {
350			sc := -1
351			if result.Response() != nil {
352				sc = result.Response().StatusCode
353			}
354			tracing.EndSpan(ctx, sc, err)
355		}()
356	}
357	if err := validation.Validate([]validation.Validation{
358		{TargetValue: jobName,
359			Constraints: []validation.Constraint{{Target: "jobName", Name: validation.MaxLength, Rule: 24, Chain: nil},
360				{Target: "jobName", Name: validation.MinLength, Rule: 3, Chain: nil},
361				{Target: "jobName", Name: validation.Pattern, Rule: `^[-\w\.]+$`, Chain: nil}}}}); err != nil {
362		return result, validation.NewError("databox.JobsClient", "Delete", err.Error())
363	}
364
365	req, err := client.DeletePreparer(ctx, resourceGroupName, jobName)
366	if err != nil {
367		err = autorest.NewErrorWithError(err, "databox.JobsClient", "Delete", nil, "Failure preparing request")
368		return
369	}
370
371	result, err = client.DeleteSender(req)
372	if err != nil {
373		err = autorest.NewErrorWithError(err, "databox.JobsClient", "Delete", nil, "Failure sending request")
374		return
375	}
376
377	return
378}
379
380// DeletePreparer prepares the Delete request.
381func (client JobsClient) DeletePreparer(ctx context.Context, resourceGroupName string, jobName string) (*http.Request, error) {
382	pathParameters := map[string]interface{}{
383		"jobName":           autorest.Encode("path", jobName),
384		"resourceGroupName": autorest.Encode("path", resourceGroupName),
385		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
386	}
387
388	const APIVersion = "2020-04-01"
389	queryParameters := map[string]interface{}{
390		"api-version": APIVersion,
391	}
392
393	preparer := autorest.CreatePreparer(
394		autorest.AsDelete(),
395		autorest.WithBaseURL(client.BaseURI),
396		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataBox/jobs/{jobName}", pathParameters),
397		autorest.WithQueryParameters(queryParameters))
398	return preparer.Prepare((&http.Request{}).WithContext(ctx))
399}
400
401// DeleteSender sends the Delete request. The method will close the
402// http.Response Body if it receives an error.
403func (client JobsClient) DeleteSender(req *http.Request) (future JobsDeleteFuture, err error) {
404	var resp *http.Response
405	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
406	if err != nil {
407		return
408	}
409	var azf azure.Future
410	azf, err = azure.NewFutureFromResponse(resp)
411	future.FutureAPI = &azf
412	future.Result = func(client JobsClient) (ar autorest.Response, err error) {
413		var done bool
414		done, err = future.DoneWithContext(context.Background(), client)
415		if err != nil {
416			err = autorest.NewErrorWithError(err, "databox.JobsDeleteFuture", "Result", future.Response(), "Polling failure")
417			return
418		}
419		if !done {
420			err = azure.NewAsyncOpIncompleteError("databox.JobsDeleteFuture")
421			return
422		}
423		ar.Response = future.Response()
424		return
425	}
426	return
427}
428
429// DeleteResponder handles the response to the Delete request. The method always
430// closes the http.Response Body.
431func (client JobsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
432	err = autorest.Respond(
433		resp,
434		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
435		autorest.ByClosing())
436	result.Response = resp
437	return
438}
439
440// Get gets information about the specified job.
441// Parameters:
442// resourceGroupName - the Resource Group Name
443// jobName - the name of the job Resource within the specified resource group. job names must be between 3 and
444// 24 characters in length and use any alphanumeric and underscore only
445// expand - $expand is supported on details parameter for job, which provides details on the job stages.
446func (client JobsClient) Get(ctx context.Context, resourceGroupName string, jobName string, expand string) (result JobResource, err error) {
447	if tracing.IsEnabled() {
448		ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.Get")
449		defer func() {
450			sc := -1
451			if result.Response.Response != nil {
452				sc = result.Response.Response.StatusCode
453			}
454			tracing.EndSpan(ctx, sc, err)
455		}()
456	}
457	if err := validation.Validate([]validation.Validation{
458		{TargetValue: jobName,
459			Constraints: []validation.Constraint{{Target: "jobName", Name: validation.MaxLength, Rule: 24, Chain: nil},
460				{Target: "jobName", Name: validation.MinLength, Rule: 3, Chain: nil},
461				{Target: "jobName", Name: validation.Pattern, Rule: `^[-\w\.]+$`, Chain: nil}}}}); err != nil {
462		return result, validation.NewError("databox.JobsClient", "Get", err.Error())
463	}
464
465	req, err := client.GetPreparer(ctx, resourceGroupName, jobName, expand)
466	if err != nil {
467		err = autorest.NewErrorWithError(err, "databox.JobsClient", "Get", nil, "Failure preparing request")
468		return
469	}
470
471	resp, err := client.GetSender(req)
472	if err != nil {
473		result.Response = autorest.Response{Response: resp}
474		err = autorest.NewErrorWithError(err, "databox.JobsClient", "Get", resp, "Failure sending request")
475		return
476	}
477
478	result, err = client.GetResponder(resp)
479	if err != nil {
480		err = autorest.NewErrorWithError(err, "databox.JobsClient", "Get", resp, "Failure responding to request")
481		return
482	}
483
484	return
485}
486
487// GetPreparer prepares the Get request.
488func (client JobsClient) GetPreparer(ctx context.Context, resourceGroupName string, jobName string, expand string) (*http.Request, error) {
489	pathParameters := map[string]interface{}{
490		"jobName":           autorest.Encode("path", jobName),
491		"resourceGroupName": autorest.Encode("path", resourceGroupName),
492		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
493	}
494
495	const APIVersion = "2020-04-01"
496	queryParameters := map[string]interface{}{
497		"api-version": APIVersion,
498	}
499	if len(expand) > 0 {
500		queryParameters["$expand"] = autorest.Encode("query", expand)
501	}
502
503	preparer := autorest.CreatePreparer(
504		autorest.AsGet(),
505		autorest.WithBaseURL(client.BaseURI),
506		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataBox/jobs/{jobName}", pathParameters),
507		autorest.WithQueryParameters(queryParameters))
508	return preparer.Prepare((&http.Request{}).WithContext(ctx))
509}
510
511// GetSender sends the Get request. The method will close the
512// http.Response Body if it receives an error.
513func (client JobsClient) GetSender(req *http.Request) (*http.Response, error) {
514	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
515}
516
517// GetResponder handles the response to the Get request. The method always
518// closes the http.Response Body.
519func (client JobsClient) GetResponder(resp *http.Response) (result JobResource, err error) {
520	err = autorest.Respond(
521		resp,
522		azure.WithErrorUnlessStatusCode(http.StatusOK),
523		autorest.ByUnmarshallingJSON(&result),
524		autorest.ByClosing())
525	result.Response = autorest.Response{Response: resp}
526	return
527}
528
529// List lists all the jobs available under the subscription.
530// Parameters:
531// skipToken - $skipToken is supported on Get list of jobs, which provides the next page in the list of jobs.
532func (client JobsClient) List(ctx context.Context, skipToken string) (result JobResourceListPage, err error) {
533	if tracing.IsEnabled() {
534		ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.List")
535		defer func() {
536			sc := -1
537			if result.jrl.Response.Response != nil {
538				sc = result.jrl.Response.Response.StatusCode
539			}
540			tracing.EndSpan(ctx, sc, err)
541		}()
542	}
543	result.fn = client.listNextResults
544	req, err := client.ListPreparer(ctx, skipToken)
545	if err != nil {
546		err = autorest.NewErrorWithError(err, "databox.JobsClient", "List", nil, "Failure preparing request")
547		return
548	}
549
550	resp, err := client.ListSender(req)
551	if err != nil {
552		result.jrl.Response = autorest.Response{Response: resp}
553		err = autorest.NewErrorWithError(err, "databox.JobsClient", "List", resp, "Failure sending request")
554		return
555	}
556
557	result.jrl, err = client.ListResponder(resp)
558	if err != nil {
559		err = autorest.NewErrorWithError(err, "databox.JobsClient", "List", resp, "Failure responding to request")
560		return
561	}
562	if result.jrl.hasNextLink() && result.jrl.IsEmpty() {
563		err = result.NextWithContext(ctx)
564		return
565	}
566
567	return
568}
569
570// ListPreparer prepares the List request.
571func (client JobsClient) ListPreparer(ctx context.Context, skipToken string) (*http.Request, error) {
572	pathParameters := map[string]interface{}{
573		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
574	}
575
576	const APIVersion = "2020-04-01"
577	queryParameters := map[string]interface{}{
578		"api-version": APIVersion,
579	}
580	if len(skipToken) > 0 {
581		queryParameters["$skipToken"] = autorest.Encode("query", skipToken)
582	}
583
584	preparer := autorest.CreatePreparer(
585		autorest.AsGet(),
586		autorest.WithBaseURL(client.BaseURI),
587		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.DataBox/jobs", pathParameters),
588		autorest.WithQueryParameters(queryParameters))
589	return preparer.Prepare((&http.Request{}).WithContext(ctx))
590}
591
592// ListSender sends the List request. The method will close the
593// http.Response Body if it receives an error.
594func (client JobsClient) ListSender(req *http.Request) (*http.Response, error) {
595	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
596}
597
598// ListResponder handles the response to the List request. The method always
599// closes the http.Response Body.
600func (client JobsClient) ListResponder(resp *http.Response) (result JobResourceList, err error) {
601	err = autorest.Respond(
602		resp,
603		azure.WithErrorUnlessStatusCode(http.StatusOK),
604		autorest.ByUnmarshallingJSON(&result),
605		autorest.ByClosing())
606	result.Response = autorest.Response{Response: resp}
607	return
608}
609
610// listNextResults retrieves the next set of results, if any.
611func (client JobsClient) listNextResults(ctx context.Context, lastResults JobResourceList) (result JobResourceList, err error) {
612	req, err := lastResults.jobResourceListPreparer(ctx)
613	if err != nil {
614		return result, autorest.NewErrorWithError(err, "databox.JobsClient", "listNextResults", nil, "Failure preparing next results request")
615	}
616	if req == nil {
617		return
618	}
619	resp, err := client.ListSender(req)
620	if err != nil {
621		result.Response = autorest.Response{Response: resp}
622		return result, autorest.NewErrorWithError(err, "databox.JobsClient", "listNextResults", resp, "Failure sending next results request")
623	}
624	result, err = client.ListResponder(resp)
625	if err != nil {
626		err = autorest.NewErrorWithError(err, "databox.JobsClient", "listNextResults", resp, "Failure responding to next results request")
627	}
628	return
629}
630
631// ListComplete enumerates all values, automatically crossing page boundaries as required.
632func (client JobsClient) ListComplete(ctx context.Context, skipToken string) (result JobResourceListIterator, err error) {
633	if tracing.IsEnabled() {
634		ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.List")
635		defer func() {
636			sc := -1
637			if result.Response().Response.Response != nil {
638				sc = result.page.Response().Response.Response.StatusCode
639			}
640			tracing.EndSpan(ctx, sc, err)
641		}()
642	}
643	result.page, err = client.List(ctx, skipToken)
644	return
645}
646
647// ListByResourceGroup lists all the jobs available under the given resource group.
648// Parameters:
649// resourceGroupName - the Resource Group Name
650// skipToken - $skipToken is supported on Get list of jobs, which provides the next page in the list of jobs.
651func (client JobsClient) ListByResourceGroup(ctx context.Context, resourceGroupName string, skipToken string) (result JobResourceListPage, err error) {
652	if tracing.IsEnabled() {
653		ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.ListByResourceGroup")
654		defer func() {
655			sc := -1
656			if result.jrl.Response.Response != nil {
657				sc = result.jrl.Response.Response.StatusCode
658			}
659			tracing.EndSpan(ctx, sc, err)
660		}()
661	}
662	result.fn = client.listByResourceGroupNextResults
663	req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName, skipToken)
664	if err != nil {
665		err = autorest.NewErrorWithError(err, "databox.JobsClient", "ListByResourceGroup", nil, "Failure preparing request")
666		return
667	}
668
669	resp, err := client.ListByResourceGroupSender(req)
670	if err != nil {
671		result.jrl.Response = autorest.Response{Response: resp}
672		err = autorest.NewErrorWithError(err, "databox.JobsClient", "ListByResourceGroup", resp, "Failure sending request")
673		return
674	}
675
676	result.jrl, err = client.ListByResourceGroupResponder(resp)
677	if err != nil {
678		err = autorest.NewErrorWithError(err, "databox.JobsClient", "ListByResourceGroup", resp, "Failure responding to request")
679		return
680	}
681	if result.jrl.hasNextLink() && result.jrl.IsEmpty() {
682		err = result.NextWithContext(ctx)
683		return
684	}
685
686	return
687}
688
689// ListByResourceGroupPreparer prepares the ListByResourceGroup request.
690func (client JobsClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string, skipToken string) (*http.Request, error) {
691	pathParameters := map[string]interface{}{
692		"resourceGroupName": autorest.Encode("path", resourceGroupName),
693		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
694	}
695
696	const APIVersion = "2020-04-01"
697	queryParameters := map[string]interface{}{
698		"api-version": APIVersion,
699	}
700	if len(skipToken) > 0 {
701		queryParameters["$skipToken"] = autorest.Encode("query", skipToken)
702	}
703
704	preparer := autorest.CreatePreparer(
705		autorest.AsGet(),
706		autorest.WithBaseURL(client.BaseURI),
707		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataBox/jobs", pathParameters),
708		autorest.WithQueryParameters(queryParameters))
709	return preparer.Prepare((&http.Request{}).WithContext(ctx))
710}
711
712// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the
713// http.Response Body if it receives an error.
714func (client JobsClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) {
715	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
716}
717
718// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always
719// closes the http.Response Body.
720func (client JobsClient) ListByResourceGroupResponder(resp *http.Response) (result JobResourceList, err error) {
721	err = autorest.Respond(
722		resp,
723		azure.WithErrorUnlessStatusCode(http.StatusOK),
724		autorest.ByUnmarshallingJSON(&result),
725		autorest.ByClosing())
726	result.Response = autorest.Response{Response: resp}
727	return
728}
729
730// listByResourceGroupNextResults retrieves the next set of results, if any.
731func (client JobsClient) listByResourceGroupNextResults(ctx context.Context, lastResults JobResourceList) (result JobResourceList, err error) {
732	req, err := lastResults.jobResourceListPreparer(ctx)
733	if err != nil {
734		return result, autorest.NewErrorWithError(err, "databox.JobsClient", "listByResourceGroupNextResults", nil, "Failure preparing next results request")
735	}
736	if req == nil {
737		return
738	}
739	resp, err := client.ListByResourceGroupSender(req)
740	if err != nil {
741		result.Response = autorest.Response{Response: resp}
742		return result, autorest.NewErrorWithError(err, "databox.JobsClient", "listByResourceGroupNextResults", resp, "Failure sending next results request")
743	}
744	result, err = client.ListByResourceGroupResponder(resp)
745	if err != nil {
746		err = autorest.NewErrorWithError(err, "databox.JobsClient", "listByResourceGroupNextResults", resp, "Failure responding to next results request")
747	}
748	return
749}
750
751// ListByResourceGroupComplete enumerates all values, automatically crossing page boundaries as required.
752func (client JobsClient) ListByResourceGroupComplete(ctx context.Context, resourceGroupName string, skipToken string) (result JobResourceListIterator, err error) {
753	if tracing.IsEnabled() {
754		ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.ListByResourceGroup")
755		defer func() {
756			sc := -1
757			if result.Response().Response.Response != nil {
758				sc = result.page.Response().Response.Response.StatusCode
759			}
760			tracing.EndSpan(ctx, sc, err)
761		}()
762	}
763	result.page, err = client.ListByResourceGroup(ctx, resourceGroupName, skipToken)
764	return
765}
766
767// ListCredentials this method gets the unencrypted secrets related to the job.
768// Parameters:
769// resourceGroupName - the Resource Group Name
770// jobName - the name of the job Resource within the specified resource group. job names must be between 3 and
771// 24 characters in length and use any alphanumeric and underscore only
772func (client JobsClient) ListCredentials(ctx context.Context, resourceGroupName string, jobName string) (result UnencryptedCredentialsList, err error) {
773	if tracing.IsEnabled() {
774		ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.ListCredentials")
775		defer func() {
776			sc := -1
777			if result.Response.Response != nil {
778				sc = result.Response.Response.StatusCode
779			}
780			tracing.EndSpan(ctx, sc, err)
781		}()
782	}
783	if err := validation.Validate([]validation.Validation{
784		{TargetValue: jobName,
785			Constraints: []validation.Constraint{{Target: "jobName", Name: validation.MaxLength, Rule: 24, Chain: nil},
786				{Target: "jobName", Name: validation.MinLength, Rule: 3, Chain: nil},
787				{Target: "jobName", Name: validation.Pattern, Rule: `^[-\w\.]+$`, Chain: nil}}}}); err != nil {
788		return result, validation.NewError("databox.JobsClient", "ListCredentials", err.Error())
789	}
790
791	req, err := client.ListCredentialsPreparer(ctx, resourceGroupName, jobName)
792	if err != nil {
793		err = autorest.NewErrorWithError(err, "databox.JobsClient", "ListCredentials", nil, "Failure preparing request")
794		return
795	}
796
797	resp, err := client.ListCredentialsSender(req)
798	if err != nil {
799		result.Response = autorest.Response{Response: resp}
800		err = autorest.NewErrorWithError(err, "databox.JobsClient", "ListCredentials", resp, "Failure sending request")
801		return
802	}
803
804	result, err = client.ListCredentialsResponder(resp)
805	if err != nil {
806		err = autorest.NewErrorWithError(err, "databox.JobsClient", "ListCredentials", resp, "Failure responding to request")
807		return
808	}
809
810	return
811}
812
813// ListCredentialsPreparer prepares the ListCredentials request.
814func (client JobsClient) ListCredentialsPreparer(ctx context.Context, resourceGroupName string, jobName string) (*http.Request, error) {
815	pathParameters := map[string]interface{}{
816		"jobName":           autorest.Encode("path", jobName),
817		"resourceGroupName": autorest.Encode("path", resourceGroupName),
818		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
819	}
820
821	const APIVersion = "2020-04-01"
822	queryParameters := map[string]interface{}{
823		"api-version": APIVersion,
824	}
825
826	preparer := autorest.CreatePreparer(
827		autorest.AsPost(),
828		autorest.WithBaseURL(client.BaseURI),
829		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataBox/jobs/{jobName}/listCredentials", pathParameters),
830		autorest.WithQueryParameters(queryParameters))
831	return preparer.Prepare((&http.Request{}).WithContext(ctx))
832}
833
834// ListCredentialsSender sends the ListCredentials request. The method will close the
835// http.Response Body if it receives an error.
836func (client JobsClient) ListCredentialsSender(req *http.Request) (*http.Response, error) {
837	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
838}
839
840// ListCredentialsResponder handles the response to the ListCredentials request. The method always
841// closes the http.Response Body.
842func (client JobsClient) ListCredentialsResponder(resp *http.Response) (result UnencryptedCredentialsList, err error) {
843	err = autorest.Respond(
844		resp,
845		azure.WithErrorUnlessStatusCode(http.StatusOK),
846		autorest.ByUnmarshallingJSON(&result),
847		autorest.ByClosing())
848	result.Response = autorest.Response{Response: resp}
849	return
850}
851
852// Update updates the properties of an existing job.
853// Parameters:
854// resourceGroupName - the Resource Group Name
855// jobName - the name of the job Resource within the specified resource group. job names must be between 3 and
856// 24 characters in length and use any alphanumeric and underscore only
857// jobResourceUpdateParameter - job update parameters from request body.
858// ifMatch - defines the If-Match condition. The patch will be performed only if the ETag of the job on the
859// server matches this value.
860func (client JobsClient) Update(ctx context.Context, resourceGroupName string, jobName string, jobResourceUpdateParameter JobResourceUpdateParameter, ifMatch string) (result JobsUpdateFuture, err error) {
861	if tracing.IsEnabled() {
862		ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.Update")
863		defer func() {
864			sc := -1
865			if result.Response() != nil {
866				sc = result.Response().StatusCode
867			}
868			tracing.EndSpan(ctx, sc, err)
869		}()
870	}
871	if err := validation.Validate([]validation.Validation{
872		{TargetValue: jobName,
873			Constraints: []validation.Constraint{{Target: "jobName", Name: validation.MaxLength, Rule: 24, Chain: nil},
874				{Target: "jobName", Name: validation.MinLength, Rule: 3, Chain: nil},
875				{Target: "jobName", Name: validation.Pattern, Rule: `^[-\w\.]+$`, Chain: nil}}}}); err != nil {
876		return result, validation.NewError("databox.JobsClient", "Update", err.Error())
877	}
878
879	req, err := client.UpdatePreparer(ctx, resourceGroupName, jobName, jobResourceUpdateParameter, ifMatch)
880	if err != nil {
881		err = autorest.NewErrorWithError(err, "databox.JobsClient", "Update", nil, "Failure preparing request")
882		return
883	}
884
885	result, err = client.UpdateSender(req)
886	if err != nil {
887		err = autorest.NewErrorWithError(err, "databox.JobsClient", "Update", nil, "Failure sending request")
888		return
889	}
890
891	return
892}
893
894// UpdatePreparer prepares the Update request.
895func (client JobsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, jobName string, jobResourceUpdateParameter JobResourceUpdateParameter, ifMatch string) (*http.Request, error) {
896	pathParameters := map[string]interface{}{
897		"jobName":           autorest.Encode("path", jobName),
898		"resourceGroupName": autorest.Encode("path", resourceGroupName),
899		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
900	}
901
902	const APIVersion = "2020-04-01"
903	queryParameters := map[string]interface{}{
904		"api-version": APIVersion,
905	}
906
907	preparer := autorest.CreatePreparer(
908		autorest.AsContentType("application/json; charset=utf-8"),
909		autorest.AsPatch(),
910		autorest.WithBaseURL(client.BaseURI),
911		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataBox/jobs/{jobName}", pathParameters),
912		autorest.WithJSON(jobResourceUpdateParameter),
913		autorest.WithQueryParameters(queryParameters))
914	if len(ifMatch) > 0 {
915		preparer = autorest.DecoratePreparer(preparer,
916			autorest.WithHeader("If-Match", autorest.String(ifMatch)))
917	}
918	return preparer.Prepare((&http.Request{}).WithContext(ctx))
919}
920
921// UpdateSender sends the Update request. The method will close the
922// http.Response Body if it receives an error.
923func (client JobsClient) UpdateSender(req *http.Request) (future JobsUpdateFuture, err error) {
924	var resp *http.Response
925	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
926	if err != nil {
927		return
928	}
929	var azf azure.Future
930	azf, err = azure.NewFutureFromResponse(resp)
931	future.FutureAPI = &azf
932	future.Result = func(client JobsClient) (jr JobResource, err error) {
933		var done bool
934		done, err = future.DoneWithContext(context.Background(), client)
935		if err != nil {
936			err = autorest.NewErrorWithError(err, "databox.JobsUpdateFuture", "Result", future.Response(), "Polling failure")
937			return
938		}
939		if !done {
940			err = azure.NewAsyncOpIncompleteError("databox.JobsUpdateFuture")
941			return
942		}
943		sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
944		if jr.Response.Response, err = future.GetResult(sender); err == nil && jr.Response.Response.StatusCode != http.StatusNoContent {
945			jr, err = client.UpdateResponder(jr.Response.Response)
946			if err != nil {
947				err = autorest.NewErrorWithError(err, "databox.JobsUpdateFuture", "Result", jr.Response.Response, "Failure responding to request")
948			}
949		}
950		return
951	}
952	return
953}
954
955// UpdateResponder handles the response to the Update request. The method always
956// closes the http.Response Body.
957func (client JobsClient) UpdateResponder(resp *http.Response) (result JobResource, err error) {
958	err = autorest.Respond(
959		resp,
960		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
961		autorest.ByUnmarshallingJSON(&result),
962		autorest.ByClosing())
963	result.Response = autorest.Response{Response: resp}
964	return
965}
966