1package blueprint
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/tracing"
14	"net/http"
15)
16
17// PublishedArtifactsClient is the blueprint Client
18type PublishedArtifactsClient struct {
19	BaseClient
20}
21
22// NewPublishedArtifactsClient creates an instance of the PublishedArtifactsClient client.
23func NewPublishedArtifactsClient() PublishedArtifactsClient {
24	return NewPublishedArtifactsClientWithBaseURI(DefaultBaseURI)
25}
26
27// NewPublishedArtifactsClientWithBaseURI creates an instance of the PublishedArtifactsClient client using a custom
28// endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
29// stack).
30func NewPublishedArtifactsClientWithBaseURI(baseURI string) PublishedArtifactsClient {
31	return PublishedArtifactsClient{NewWithBaseURI(baseURI)}
32}
33
34// Get get an artifact for a published blueprint definition.
35// Parameters:
36// resourceScope - the scope of the resource. Valid scopes are: management group (format:
37// '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
38// '/subscriptions/{subscriptionId}').
39// blueprintName - name of the blueprint definition.
40// versionID - version of the published blueprint definition.
41// artifactName - name of the blueprint artifact.
42func (client PublishedArtifactsClient) Get(ctx context.Context, resourceScope string, blueprintName string, versionID string, artifactName string) (result ArtifactModel, err error) {
43	if tracing.IsEnabled() {
44		ctx = tracing.StartSpan(ctx, fqdn+"/PublishedArtifactsClient.Get")
45		defer func() {
46			sc := -1
47			if result.Response.Response != nil {
48				sc = result.Response.Response.StatusCode
49			}
50			tracing.EndSpan(ctx, sc, err)
51		}()
52	}
53	req, err := client.GetPreparer(ctx, resourceScope, blueprintName, versionID, artifactName)
54	if err != nil {
55		err = autorest.NewErrorWithError(err, "blueprint.PublishedArtifactsClient", "Get", nil, "Failure preparing request")
56		return
57	}
58
59	resp, err := client.GetSender(req)
60	if err != nil {
61		result.Response = autorest.Response{Response: resp}
62		err = autorest.NewErrorWithError(err, "blueprint.PublishedArtifactsClient", "Get", resp, "Failure sending request")
63		return
64	}
65
66	result, err = client.GetResponder(resp)
67	if err != nil {
68		err = autorest.NewErrorWithError(err, "blueprint.PublishedArtifactsClient", "Get", resp, "Failure responding to request")
69		return
70	}
71
72	return
73}
74
75// GetPreparer prepares the Get request.
76func (client PublishedArtifactsClient) GetPreparer(ctx context.Context, resourceScope string, blueprintName string, versionID string, artifactName string) (*http.Request, error) {
77	pathParameters := map[string]interface{}{
78		"artifactName":  autorest.Encode("path", artifactName),
79		"blueprintName": autorest.Encode("path", blueprintName),
80		"resourceScope": resourceScope,
81		"versionId":     autorest.Encode("path", versionID),
82	}
83
84	const APIVersion = "2018-11-01-preview"
85	queryParameters := map[string]interface{}{
86		"api-version": APIVersion,
87	}
88
89	preparer := autorest.CreatePreparer(
90		autorest.AsGet(),
91		autorest.WithBaseURL(client.BaseURI),
92		autorest.WithPathParameters("/{resourceScope}/providers/Microsoft.Blueprint/blueprints/{blueprintName}/versions/{versionId}/artifacts/{artifactName}", pathParameters),
93		autorest.WithQueryParameters(queryParameters))
94	return preparer.Prepare((&http.Request{}).WithContext(ctx))
95}
96
97// GetSender sends the Get request. The method will close the
98// http.Response Body if it receives an error.
99func (client PublishedArtifactsClient) GetSender(req *http.Request) (*http.Response, error) {
100	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
101}
102
103// GetResponder handles the response to the Get request. The method always
104// closes the http.Response Body.
105func (client PublishedArtifactsClient) GetResponder(resp *http.Response) (result ArtifactModel, err error) {
106	err = autorest.Respond(
107		resp,
108		azure.WithErrorUnlessStatusCode(http.StatusOK),
109		autorest.ByUnmarshallingJSON(&result),
110		autorest.ByClosing())
111	result.Response = autorest.Response{Response: resp}
112	return
113}
114
115// List list artifacts for a version of a published blueprint definition.
116// Parameters:
117// resourceScope - the scope of the resource. Valid scopes are: management group (format:
118// '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
119// '/subscriptions/{subscriptionId}').
120// blueprintName - name of the blueprint definition.
121// versionID - version of the published blueprint definition.
122func (client PublishedArtifactsClient) List(ctx context.Context, resourceScope string, blueprintName string, versionID string) (result ArtifactListPage, err error) {
123	if tracing.IsEnabled() {
124		ctx = tracing.StartSpan(ctx, fqdn+"/PublishedArtifactsClient.List")
125		defer func() {
126			sc := -1
127			if result.al.Response.Response != nil {
128				sc = result.al.Response.Response.StatusCode
129			}
130			tracing.EndSpan(ctx, sc, err)
131		}()
132	}
133	result.fn = client.listNextResults
134	req, err := client.ListPreparer(ctx, resourceScope, blueprintName, versionID)
135	if err != nil {
136		err = autorest.NewErrorWithError(err, "blueprint.PublishedArtifactsClient", "List", nil, "Failure preparing request")
137		return
138	}
139
140	resp, err := client.ListSender(req)
141	if err != nil {
142		result.al.Response = autorest.Response{Response: resp}
143		err = autorest.NewErrorWithError(err, "blueprint.PublishedArtifactsClient", "List", resp, "Failure sending request")
144		return
145	}
146
147	result.al, err = client.ListResponder(resp)
148	if err != nil {
149		err = autorest.NewErrorWithError(err, "blueprint.PublishedArtifactsClient", "List", resp, "Failure responding to request")
150		return
151	}
152	if result.al.hasNextLink() && result.al.IsEmpty() {
153		err = result.NextWithContext(ctx)
154		return
155	}
156
157	return
158}
159
160// ListPreparer prepares the List request.
161func (client PublishedArtifactsClient) ListPreparer(ctx context.Context, resourceScope string, blueprintName string, versionID string) (*http.Request, error) {
162	pathParameters := map[string]interface{}{
163		"blueprintName": autorest.Encode("path", blueprintName),
164		"resourceScope": resourceScope,
165		"versionId":     autorest.Encode("path", versionID),
166	}
167
168	const APIVersion = "2018-11-01-preview"
169	queryParameters := map[string]interface{}{
170		"api-version": APIVersion,
171	}
172
173	preparer := autorest.CreatePreparer(
174		autorest.AsGet(),
175		autorest.WithBaseURL(client.BaseURI),
176		autorest.WithPathParameters("/{resourceScope}/providers/Microsoft.Blueprint/blueprints/{blueprintName}/versions/{versionId}/artifacts", pathParameters),
177		autorest.WithQueryParameters(queryParameters))
178	return preparer.Prepare((&http.Request{}).WithContext(ctx))
179}
180
181// ListSender sends the List request. The method will close the
182// http.Response Body if it receives an error.
183func (client PublishedArtifactsClient) ListSender(req *http.Request) (*http.Response, error) {
184	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
185}
186
187// ListResponder handles the response to the List request. The method always
188// closes the http.Response Body.
189func (client PublishedArtifactsClient) ListResponder(resp *http.Response) (result ArtifactList, err error) {
190	err = autorest.Respond(
191		resp,
192		azure.WithErrorUnlessStatusCode(http.StatusOK),
193		autorest.ByUnmarshallingJSON(&result),
194		autorest.ByClosing())
195	result.Response = autorest.Response{Response: resp}
196	return
197}
198
199// listNextResults retrieves the next set of results, if any.
200func (client PublishedArtifactsClient) listNextResults(ctx context.Context, lastResults ArtifactList) (result ArtifactList, err error) {
201	req, err := lastResults.artifactListPreparer(ctx)
202	if err != nil {
203		return result, autorest.NewErrorWithError(err, "blueprint.PublishedArtifactsClient", "listNextResults", nil, "Failure preparing next results request")
204	}
205	if req == nil {
206		return
207	}
208	resp, err := client.ListSender(req)
209	if err != nil {
210		result.Response = autorest.Response{Response: resp}
211		return result, autorest.NewErrorWithError(err, "blueprint.PublishedArtifactsClient", "listNextResults", resp, "Failure sending next results request")
212	}
213	result, err = client.ListResponder(resp)
214	if err != nil {
215		err = autorest.NewErrorWithError(err, "blueprint.PublishedArtifactsClient", "listNextResults", resp, "Failure responding to next results request")
216	}
217	return
218}
219
220// ListComplete enumerates all values, automatically crossing page boundaries as required.
221func (client PublishedArtifactsClient) ListComplete(ctx context.Context, resourceScope string, blueprintName string, versionID string) (result ArtifactListIterator, err error) {
222	if tracing.IsEnabled() {
223		ctx = tracing.StartSpan(ctx, fqdn+"/PublishedArtifactsClient.List")
224		defer func() {
225			sc := -1
226			if result.Response().Response.Response != nil {
227				sc = result.page.Response().Response.Response.StatusCode
228			}
229			tracing.EndSpan(ctx, sc, err)
230		}()
231	}
232	result.page, err = client.List(ctx, resourceScope, blueprintName, versionID)
233	return
234}
235