1package dtl
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/tracing"
25	"net/http"
26)
27
28// ArtifactClient is the azure DevTest Labs REST API version 2015-05-21-preview.
29type ArtifactClient struct {
30	BaseClient
31}
32
33// NewArtifactClient creates an instance of the ArtifactClient client.
34func NewArtifactClient(subscriptionID string) ArtifactClient {
35	return NewArtifactClientWithBaseURI(DefaultBaseURI, subscriptionID)
36}
37
38// NewArtifactClientWithBaseURI creates an instance of the ArtifactClient client.
39func NewArtifactClientWithBaseURI(baseURI string, subscriptionID string) ArtifactClient {
40	return ArtifactClient{NewWithBaseURI(baseURI, subscriptionID)}
41}
42
43// GenerateArmTemplate generates an ARM template for the given artifact, uploads the required files to a storage
44// account, and validates the generated artifact.
45// Parameters:
46// resourceGroupName - the name of the resource group.
47// labName - the name of the lab.
48// artifactSourceName - the name of the artifact source.
49// name - the name of the artifact.
50func (client ArtifactClient) GenerateArmTemplate(ctx context.Context, resourceGroupName string, labName string, artifactSourceName string, name string, generateArmTemplateRequest GenerateArmTemplateRequest) (result ArmTemplateInfo, err error) {
51	if tracing.IsEnabled() {
52		ctx = tracing.StartSpan(ctx, fqdn+"/ArtifactClient.GenerateArmTemplate")
53		defer func() {
54			sc := -1
55			if result.Response.Response != nil {
56				sc = result.Response.Response.StatusCode
57			}
58			tracing.EndSpan(ctx, sc, err)
59		}()
60	}
61	req, err := client.GenerateArmTemplatePreparer(ctx, resourceGroupName, labName, artifactSourceName, name, generateArmTemplateRequest)
62	if err != nil {
63		err = autorest.NewErrorWithError(err, "dtl.ArtifactClient", "GenerateArmTemplate", nil, "Failure preparing request")
64		return
65	}
66
67	resp, err := client.GenerateArmTemplateSender(req)
68	if err != nil {
69		result.Response = autorest.Response{Response: resp}
70		err = autorest.NewErrorWithError(err, "dtl.ArtifactClient", "GenerateArmTemplate", resp, "Failure sending request")
71		return
72	}
73
74	result, err = client.GenerateArmTemplateResponder(resp)
75	if err != nil {
76		err = autorest.NewErrorWithError(err, "dtl.ArtifactClient", "GenerateArmTemplate", resp, "Failure responding to request")
77	}
78
79	return
80}
81
82// GenerateArmTemplatePreparer prepares the GenerateArmTemplate request.
83func (client ArtifactClient) GenerateArmTemplatePreparer(ctx context.Context, resourceGroupName string, labName string, artifactSourceName string, name string, generateArmTemplateRequest GenerateArmTemplateRequest) (*http.Request, error) {
84	pathParameters := map[string]interface{}{
85		"artifactSourceName": autorest.Encode("path", artifactSourceName),
86		"labName":            autorest.Encode("path", labName),
87		"name":               autorest.Encode("path", name),
88		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
89		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
90	}
91
92	const APIVersion = "2015-05-21-preview"
93	queryParameters := map[string]interface{}{
94		"api-version": APIVersion,
95	}
96
97	preparer := autorest.CreatePreparer(
98		autorest.AsContentType("application/json; charset=utf-8"),
99		autorest.AsPost(),
100		autorest.WithBaseURL(client.BaseURI),
101		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{artifactSourceName}/artifacts/{name}/generateArmTemplate", pathParameters),
102		autorest.WithJSON(generateArmTemplateRequest),
103		autorest.WithQueryParameters(queryParameters))
104	return preparer.Prepare((&http.Request{}).WithContext(ctx))
105}
106
107// GenerateArmTemplateSender sends the GenerateArmTemplate request. The method will close the
108// http.Response Body if it receives an error.
109func (client ArtifactClient) GenerateArmTemplateSender(req *http.Request) (*http.Response, error) {
110	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
111	return autorest.SendWithSender(client, req, sd...)
112}
113
114// GenerateArmTemplateResponder handles the response to the GenerateArmTemplate request. The method always
115// closes the http.Response Body.
116func (client ArtifactClient) GenerateArmTemplateResponder(resp *http.Response) (result ArmTemplateInfo, err error) {
117	err = autorest.Respond(
118		resp,
119		client.ByInspecting(),
120		azure.WithErrorUnlessStatusCode(http.StatusOK),
121		autorest.ByUnmarshallingJSON(&result),
122		autorest.ByClosing())
123	result.Response = autorest.Response{Response: resp}
124	return
125}
126
127// GetResource get artifact.
128// Parameters:
129// resourceGroupName - the name of the resource group.
130// labName - the name of the lab.
131// artifactSourceName - the name of the artifact source.
132// name - the name of the artifact.
133func (client ArtifactClient) GetResource(ctx context.Context, resourceGroupName string, labName string, artifactSourceName string, name string) (result Artifact, err error) {
134	if tracing.IsEnabled() {
135		ctx = tracing.StartSpan(ctx, fqdn+"/ArtifactClient.GetResource")
136		defer func() {
137			sc := -1
138			if result.Response.Response != nil {
139				sc = result.Response.Response.StatusCode
140			}
141			tracing.EndSpan(ctx, sc, err)
142		}()
143	}
144	req, err := client.GetResourcePreparer(ctx, resourceGroupName, labName, artifactSourceName, name)
145	if err != nil {
146		err = autorest.NewErrorWithError(err, "dtl.ArtifactClient", "GetResource", nil, "Failure preparing request")
147		return
148	}
149
150	resp, err := client.GetResourceSender(req)
151	if err != nil {
152		result.Response = autorest.Response{Response: resp}
153		err = autorest.NewErrorWithError(err, "dtl.ArtifactClient", "GetResource", resp, "Failure sending request")
154		return
155	}
156
157	result, err = client.GetResourceResponder(resp)
158	if err != nil {
159		err = autorest.NewErrorWithError(err, "dtl.ArtifactClient", "GetResource", resp, "Failure responding to request")
160	}
161
162	return
163}
164
165// GetResourcePreparer prepares the GetResource request.
166func (client ArtifactClient) GetResourcePreparer(ctx context.Context, resourceGroupName string, labName string, artifactSourceName string, name string) (*http.Request, error) {
167	pathParameters := map[string]interface{}{
168		"artifactSourceName": autorest.Encode("path", artifactSourceName),
169		"labName":            autorest.Encode("path", labName),
170		"name":               autorest.Encode("path", name),
171		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
172		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
173	}
174
175	const APIVersion = "2015-05-21-preview"
176	queryParameters := map[string]interface{}{
177		"api-version": APIVersion,
178	}
179
180	preparer := autorest.CreatePreparer(
181		autorest.AsGet(),
182		autorest.WithBaseURL(client.BaseURI),
183		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{artifactSourceName}/artifacts/{name}", pathParameters),
184		autorest.WithQueryParameters(queryParameters))
185	return preparer.Prepare((&http.Request{}).WithContext(ctx))
186}
187
188// GetResourceSender sends the GetResource request. The method will close the
189// http.Response Body if it receives an error.
190func (client ArtifactClient) GetResourceSender(req *http.Request) (*http.Response, error) {
191	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
192	return autorest.SendWithSender(client, req, sd...)
193}
194
195// GetResourceResponder handles the response to the GetResource request. The method always
196// closes the http.Response Body.
197func (client ArtifactClient) GetResourceResponder(resp *http.Response) (result Artifact, err error) {
198	err = autorest.Respond(
199		resp,
200		client.ByInspecting(),
201		azure.WithErrorUnlessStatusCode(http.StatusOK),
202		autorest.ByUnmarshallingJSON(&result),
203		autorest.ByClosing())
204	result.Response = autorest.Response{Response: resp}
205	return
206}
207
208// List list artifacts.
209// Parameters:
210// resourceGroupName - the name of the resource group.
211// labName - the name of the lab.
212// artifactSourceName - the name of the artifact source.
213// filter - the filter to apply on the operation.
214func (client ArtifactClient) List(ctx context.Context, resourceGroupName string, labName string, artifactSourceName string, filter string, top *int32, orderBy string) (result ResponseWithContinuationArtifactPage, err error) {
215	if tracing.IsEnabled() {
216		ctx = tracing.StartSpan(ctx, fqdn+"/ArtifactClient.List")
217		defer func() {
218			sc := -1
219			if result.rwca.Response.Response != nil {
220				sc = result.rwca.Response.Response.StatusCode
221			}
222			tracing.EndSpan(ctx, sc, err)
223		}()
224	}
225	result.fn = client.listNextResults
226	req, err := client.ListPreparer(ctx, resourceGroupName, labName, artifactSourceName, filter, top, orderBy)
227	if err != nil {
228		err = autorest.NewErrorWithError(err, "dtl.ArtifactClient", "List", nil, "Failure preparing request")
229		return
230	}
231
232	resp, err := client.ListSender(req)
233	if err != nil {
234		result.rwca.Response = autorest.Response{Response: resp}
235		err = autorest.NewErrorWithError(err, "dtl.ArtifactClient", "List", resp, "Failure sending request")
236		return
237	}
238
239	result.rwca, err = client.ListResponder(resp)
240	if err != nil {
241		err = autorest.NewErrorWithError(err, "dtl.ArtifactClient", "List", resp, "Failure responding to request")
242	}
243
244	return
245}
246
247// ListPreparer prepares the List request.
248func (client ArtifactClient) ListPreparer(ctx context.Context, resourceGroupName string, labName string, artifactSourceName string, filter string, top *int32, orderBy string) (*http.Request, error) {
249	pathParameters := map[string]interface{}{
250		"artifactSourceName": autorest.Encode("path", artifactSourceName),
251		"labName":            autorest.Encode("path", labName),
252		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
253		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
254	}
255
256	const APIVersion = "2015-05-21-preview"
257	queryParameters := map[string]interface{}{
258		"api-version": APIVersion,
259	}
260	if len(filter) > 0 {
261		queryParameters["$filter"] = autorest.Encode("query", filter)
262	}
263	if top != nil {
264		queryParameters["$top"] = autorest.Encode("query", *top)
265	}
266	if len(orderBy) > 0 {
267		queryParameters["$orderBy"] = autorest.Encode("query", orderBy)
268	}
269
270	preparer := autorest.CreatePreparer(
271		autorest.AsGet(),
272		autorest.WithBaseURL(client.BaseURI),
273		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{artifactSourceName}/artifacts", pathParameters),
274		autorest.WithQueryParameters(queryParameters))
275	return preparer.Prepare((&http.Request{}).WithContext(ctx))
276}
277
278// ListSender sends the List request. The method will close the
279// http.Response Body if it receives an error.
280func (client ArtifactClient) ListSender(req *http.Request) (*http.Response, error) {
281	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
282	return autorest.SendWithSender(client, req, sd...)
283}
284
285// ListResponder handles the response to the List request. The method always
286// closes the http.Response Body.
287func (client ArtifactClient) ListResponder(resp *http.Response) (result ResponseWithContinuationArtifact, err error) {
288	err = autorest.Respond(
289		resp,
290		client.ByInspecting(),
291		azure.WithErrorUnlessStatusCode(http.StatusOK),
292		autorest.ByUnmarshallingJSON(&result),
293		autorest.ByClosing())
294	result.Response = autorest.Response{Response: resp}
295	return
296}
297
298// listNextResults retrieves the next set of results, if any.
299func (client ArtifactClient) listNextResults(ctx context.Context, lastResults ResponseWithContinuationArtifact) (result ResponseWithContinuationArtifact, err error) {
300	req, err := lastResults.responseWithContinuationArtifactPreparer(ctx)
301	if err != nil {
302		return result, autorest.NewErrorWithError(err, "dtl.ArtifactClient", "listNextResults", nil, "Failure preparing next results request")
303	}
304	if req == nil {
305		return
306	}
307	resp, err := client.ListSender(req)
308	if err != nil {
309		result.Response = autorest.Response{Response: resp}
310		return result, autorest.NewErrorWithError(err, "dtl.ArtifactClient", "listNextResults", resp, "Failure sending next results request")
311	}
312	result, err = client.ListResponder(resp)
313	if err != nil {
314		err = autorest.NewErrorWithError(err, "dtl.ArtifactClient", "listNextResults", resp, "Failure responding to next results request")
315	}
316	return
317}
318
319// ListComplete enumerates all values, automatically crossing page boundaries as required.
320func (client ArtifactClient) ListComplete(ctx context.Context, resourceGroupName string, labName string, artifactSourceName string, filter string, top *int32, orderBy string) (result ResponseWithContinuationArtifactIterator, err error) {
321	if tracing.IsEnabled() {
322		ctx = tracing.StartSpan(ctx, fqdn+"/ArtifactClient.List")
323		defer func() {
324			sc := -1
325			if result.Response().Response.Response != nil {
326				sc = result.page.Response().Response.Response.StatusCode
327			}
328			tracing.EndSpan(ctx, sc, err)
329		}()
330	}
331	result.page, err = client.List(ctx, resourceGroupName, labName, artifactSourceName, filter, top, orderBy)
332	return
333}
334