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