1package apimanagement
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// TenantConfigurationClient is the apiManagement Client
30type TenantConfigurationClient struct {
31	BaseClient
32}
33
34// NewTenantConfigurationClient creates an instance of the TenantConfigurationClient client.
35func NewTenantConfigurationClient(subscriptionID string) TenantConfigurationClient {
36	return NewTenantConfigurationClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewTenantConfigurationClientWithBaseURI creates an instance of the TenantConfigurationClient client using a custom
40// endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
41// stack).
42func NewTenantConfigurationClientWithBaseURI(baseURI string, subscriptionID string) TenantConfigurationClient {
43	return TenantConfigurationClient{NewWithBaseURI(baseURI, subscriptionID)}
44}
45
46// Deploy this operation applies changes from the specified Git branch to the configuration database. This is a long
47// running operation and could take several minutes to complete.
48// Parameters:
49// resourceGroupName - the name of the resource group.
50// serviceName - the name of the API Management service.
51// parameters - deploy Configuration parameters.
52func (client TenantConfigurationClient) Deploy(ctx context.Context, resourceGroupName string, serviceName string, parameters DeployConfigurationParameters) (result TenantConfigurationDeployFuture, err error) {
53	if tracing.IsEnabled() {
54		ctx = tracing.StartSpan(ctx, fqdn+"/TenantConfigurationClient.Deploy")
55		defer func() {
56			sc := -1
57			if result.Response() != nil {
58				sc = result.Response().StatusCode
59			}
60			tracing.EndSpan(ctx, sc, err)
61		}()
62	}
63	if err := validation.Validate([]validation.Validation{
64		{TargetValue: serviceName,
65			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
66				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
67				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
68		{TargetValue: parameters,
69			Constraints: []validation.Constraint{{Target: "parameters.Branch", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
70		return result, validation.NewError("apimanagement.TenantConfigurationClient", "Deploy", err.Error())
71	}
72
73	req, err := client.DeployPreparer(ctx, resourceGroupName, serviceName, parameters)
74	if err != nil {
75		err = autorest.NewErrorWithError(err, "apimanagement.TenantConfigurationClient", "Deploy", nil, "Failure preparing request")
76		return
77	}
78
79	result, err = client.DeploySender(req)
80	if err != nil {
81		err = autorest.NewErrorWithError(err, "apimanagement.TenantConfigurationClient", "Deploy", result.Response(), "Failure sending request")
82		return
83	}
84
85	return
86}
87
88// DeployPreparer prepares the Deploy request.
89func (client TenantConfigurationClient) DeployPreparer(ctx context.Context, resourceGroupName string, serviceName string, parameters DeployConfigurationParameters) (*http.Request, error) {
90	pathParameters := map[string]interface{}{
91		"configurationName": autorest.Encode("path", "configuration"),
92		"resourceGroupName": autorest.Encode("path", resourceGroupName),
93		"serviceName":       autorest.Encode("path", serviceName),
94		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
95	}
96
97	const APIVersion = "2018-01-01"
98	queryParameters := map[string]interface{}{
99		"api-version": APIVersion,
100	}
101
102	preparer := autorest.CreatePreparer(
103		autorest.AsContentType("application/json; charset=utf-8"),
104		autorest.AsPost(),
105		autorest.WithBaseURL(client.BaseURI),
106		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/tenant/{configurationName}/deploy", pathParameters),
107		autorest.WithJSON(parameters),
108		autorest.WithQueryParameters(queryParameters))
109	return preparer.Prepare((&http.Request{}).WithContext(ctx))
110}
111
112// DeploySender sends the Deploy request. The method will close the
113// http.Response Body if it receives an error.
114func (client TenantConfigurationClient) DeploySender(req *http.Request) (future TenantConfigurationDeployFuture, err error) {
115	var resp *http.Response
116	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
117	if err != nil {
118		return
119	}
120	future.Future, err = azure.NewFutureFromResponse(resp)
121	return
122}
123
124// DeployResponder handles the response to the Deploy request. The method always
125// closes the http.Response Body.
126func (client TenantConfigurationClient) DeployResponder(resp *http.Response) (result OperationResultContract, err error) {
127	err = autorest.Respond(
128		resp,
129		client.ByInspecting(),
130		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
131		autorest.ByUnmarshallingJSON(&result),
132		autorest.ByClosing())
133	result.Response = autorest.Response{Response: resp}
134	return
135}
136
137// GetSyncState gets the status of the most recent synchronization between the configuration database and the Git
138// repository.
139// Parameters:
140// resourceGroupName - the name of the resource group.
141// serviceName - the name of the API Management service.
142func (client TenantConfigurationClient) GetSyncState(ctx context.Context, resourceGroupName string, serviceName string) (result TenantConfigurationSyncStateContract, err error) {
143	if tracing.IsEnabled() {
144		ctx = tracing.StartSpan(ctx, fqdn+"/TenantConfigurationClient.GetSyncState")
145		defer func() {
146			sc := -1
147			if result.Response.Response != nil {
148				sc = result.Response.Response.StatusCode
149			}
150			tracing.EndSpan(ctx, sc, err)
151		}()
152	}
153	if err := validation.Validate([]validation.Validation{
154		{TargetValue: serviceName,
155			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
156				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
157				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}}); err != nil {
158		return result, validation.NewError("apimanagement.TenantConfigurationClient", "GetSyncState", err.Error())
159	}
160
161	req, err := client.GetSyncStatePreparer(ctx, resourceGroupName, serviceName)
162	if err != nil {
163		err = autorest.NewErrorWithError(err, "apimanagement.TenantConfigurationClient", "GetSyncState", nil, "Failure preparing request")
164		return
165	}
166
167	resp, err := client.GetSyncStateSender(req)
168	if err != nil {
169		result.Response = autorest.Response{Response: resp}
170		err = autorest.NewErrorWithError(err, "apimanagement.TenantConfigurationClient", "GetSyncState", resp, "Failure sending request")
171		return
172	}
173
174	result, err = client.GetSyncStateResponder(resp)
175	if err != nil {
176		err = autorest.NewErrorWithError(err, "apimanagement.TenantConfigurationClient", "GetSyncState", resp, "Failure responding to request")
177	}
178
179	return
180}
181
182// GetSyncStatePreparer prepares the GetSyncState request.
183func (client TenantConfigurationClient) GetSyncStatePreparer(ctx context.Context, resourceGroupName string, serviceName string) (*http.Request, error) {
184	pathParameters := map[string]interface{}{
185		"configurationName": autorest.Encode("path", "configuration"),
186		"resourceGroupName": autorest.Encode("path", resourceGroupName),
187		"serviceName":       autorest.Encode("path", serviceName),
188		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
189	}
190
191	const APIVersion = "2018-01-01"
192	queryParameters := map[string]interface{}{
193		"api-version": APIVersion,
194	}
195
196	preparer := autorest.CreatePreparer(
197		autorest.AsGet(),
198		autorest.WithBaseURL(client.BaseURI),
199		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/tenant/{configurationName}/syncState", pathParameters),
200		autorest.WithQueryParameters(queryParameters))
201	return preparer.Prepare((&http.Request{}).WithContext(ctx))
202}
203
204// GetSyncStateSender sends the GetSyncState request. The method will close the
205// http.Response Body if it receives an error.
206func (client TenantConfigurationClient) GetSyncStateSender(req *http.Request) (*http.Response, error) {
207	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
208}
209
210// GetSyncStateResponder handles the response to the GetSyncState request. The method always
211// closes the http.Response Body.
212func (client TenantConfigurationClient) GetSyncStateResponder(resp *http.Response) (result TenantConfigurationSyncStateContract, err error) {
213	err = autorest.Respond(
214		resp,
215		client.ByInspecting(),
216		azure.WithErrorUnlessStatusCode(http.StatusOK),
217		autorest.ByUnmarshallingJSON(&result),
218		autorest.ByClosing())
219	result.Response = autorest.Response{Response: resp}
220	return
221}
222
223// Save this operation creates a commit with the current configuration snapshot to the specified branch in the
224// repository. This is a long running operation and could take several minutes to complete.
225// Parameters:
226// resourceGroupName - the name of the resource group.
227// serviceName - the name of the API Management service.
228// parameters - save Configuration parameters.
229func (client TenantConfigurationClient) Save(ctx context.Context, resourceGroupName string, serviceName string, parameters SaveConfigurationParameter) (result TenantConfigurationSaveFuture, err error) {
230	if tracing.IsEnabled() {
231		ctx = tracing.StartSpan(ctx, fqdn+"/TenantConfigurationClient.Save")
232		defer func() {
233			sc := -1
234			if result.Response() != nil {
235				sc = result.Response().StatusCode
236			}
237			tracing.EndSpan(ctx, sc, err)
238		}()
239	}
240	if err := validation.Validate([]validation.Validation{
241		{TargetValue: serviceName,
242			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
243				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
244				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
245		{TargetValue: parameters,
246			Constraints: []validation.Constraint{{Target: "parameters.Branch", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
247		return result, validation.NewError("apimanagement.TenantConfigurationClient", "Save", err.Error())
248	}
249
250	req, err := client.SavePreparer(ctx, resourceGroupName, serviceName, parameters)
251	if err != nil {
252		err = autorest.NewErrorWithError(err, "apimanagement.TenantConfigurationClient", "Save", nil, "Failure preparing request")
253		return
254	}
255
256	result, err = client.SaveSender(req)
257	if err != nil {
258		err = autorest.NewErrorWithError(err, "apimanagement.TenantConfigurationClient", "Save", result.Response(), "Failure sending request")
259		return
260	}
261
262	return
263}
264
265// SavePreparer prepares the Save request.
266func (client TenantConfigurationClient) SavePreparer(ctx context.Context, resourceGroupName string, serviceName string, parameters SaveConfigurationParameter) (*http.Request, error) {
267	pathParameters := map[string]interface{}{
268		"configurationName": autorest.Encode("path", "configuration"),
269		"resourceGroupName": autorest.Encode("path", resourceGroupName),
270		"serviceName":       autorest.Encode("path", serviceName),
271		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
272	}
273
274	const APIVersion = "2018-01-01"
275	queryParameters := map[string]interface{}{
276		"api-version": APIVersion,
277	}
278
279	preparer := autorest.CreatePreparer(
280		autorest.AsContentType("application/json; charset=utf-8"),
281		autorest.AsPost(),
282		autorest.WithBaseURL(client.BaseURI),
283		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/tenant/{configurationName}/save", pathParameters),
284		autorest.WithJSON(parameters),
285		autorest.WithQueryParameters(queryParameters))
286	return preparer.Prepare((&http.Request{}).WithContext(ctx))
287}
288
289// SaveSender sends the Save request. The method will close the
290// http.Response Body if it receives an error.
291func (client TenantConfigurationClient) SaveSender(req *http.Request) (future TenantConfigurationSaveFuture, err error) {
292	var resp *http.Response
293	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
294	if err != nil {
295		return
296	}
297	future.Future, err = azure.NewFutureFromResponse(resp)
298	return
299}
300
301// SaveResponder handles the response to the Save request. The method always
302// closes the http.Response Body.
303func (client TenantConfigurationClient) SaveResponder(resp *http.Response) (result OperationResultContract, err error) {
304	err = autorest.Respond(
305		resp,
306		client.ByInspecting(),
307		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
308		autorest.ByUnmarshallingJSON(&result),
309		autorest.ByClosing())
310	result.Response = autorest.Response{Response: resp}
311	return
312}
313
314// Validate this operation validates the changes in the specified Git branch. This is a long running operation and
315// could take several minutes to complete.
316// Parameters:
317// resourceGroupName - the name of the resource group.
318// serviceName - the name of the API Management service.
319// parameters - validate Configuration parameters.
320func (client TenantConfigurationClient) Validate(ctx context.Context, resourceGroupName string, serviceName string, parameters DeployConfigurationParameters) (result TenantConfigurationValidateFuture, err error) {
321	if tracing.IsEnabled() {
322		ctx = tracing.StartSpan(ctx, fqdn+"/TenantConfigurationClient.Validate")
323		defer func() {
324			sc := -1
325			if result.Response() != nil {
326				sc = result.Response().StatusCode
327			}
328			tracing.EndSpan(ctx, sc, err)
329		}()
330	}
331	if err := validation.Validate([]validation.Validation{
332		{TargetValue: serviceName,
333			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
334				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
335				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
336		{TargetValue: parameters,
337			Constraints: []validation.Constraint{{Target: "parameters.Branch", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
338		return result, validation.NewError("apimanagement.TenantConfigurationClient", "Validate", err.Error())
339	}
340
341	req, err := client.ValidatePreparer(ctx, resourceGroupName, serviceName, parameters)
342	if err != nil {
343		err = autorest.NewErrorWithError(err, "apimanagement.TenantConfigurationClient", "Validate", nil, "Failure preparing request")
344		return
345	}
346
347	result, err = client.ValidateSender(req)
348	if err != nil {
349		err = autorest.NewErrorWithError(err, "apimanagement.TenantConfigurationClient", "Validate", result.Response(), "Failure sending request")
350		return
351	}
352
353	return
354}
355
356// ValidatePreparer prepares the Validate request.
357func (client TenantConfigurationClient) ValidatePreparer(ctx context.Context, resourceGroupName string, serviceName string, parameters DeployConfigurationParameters) (*http.Request, error) {
358	pathParameters := map[string]interface{}{
359		"configurationName": autorest.Encode("path", "configuration"),
360		"resourceGroupName": autorest.Encode("path", resourceGroupName),
361		"serviceName":       autorest.Encode("path", serviceName),
362		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
363	}
364
365	const APIVersion = "2018-01-01"
366	queryParameters := map[string]interface{}{
367		"api-version": APIVersion,
368	}
369
370	preparer := autorest.CreatePreparer(
371		autorest.AsContentType("application/json; charset=utf-8"),
372		autorest.AsPost(),
373		autorest.WithBaseURL(client.BaseURI),
374		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/tenant/{configurationName}/validate", pathParameters),
375		autorest.WithJSON(parameters),
376		autorest.WithQueryParameters(queryParameters))
377	return preparer.Prepare((&http.Request{}).WithContext(ctx))
378}
379
380// ValidateSender sends the Validate request. The method will close the
381// http.Response Body if it receives an error.
382func (client TenantConfigurationClient) ValidateSender(req *http.Request) (future TenantConfigurationValidateFuture, err error) {
383	var resp *http.Response
384	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
385	if err != nil {
386		return
387	}
388	future.Future, err = azure.NewFutureFromResponse(resp)
389	return
390}
391
392// ValidateResponder handles the response to the Validate request. The method always
393// closes the http.Response Body.
394func (client TenantConfigurationClient) ValidateResponder(resp *http.Response) (result OperationResultContract, err error) {
395	err = autorest.Respond(
396		resp,
397		client.ByInspecting(),
398		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
399		autorest.ByUnmarshallingJSON(&result),
400		autorest.ByClosing())
401	result.Response = autorest.Response{Response: resp}
402	return
403}
404