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// TenantConfigurationSyncStateClient is the apiManagement Client
30type TenantConfigurationSyncStateClient struct {
31	BaseClient
32}
33
34// NewTenantConfigurationSyncStateClient creates an instance of the TenantConfigurationSyncStateClient client.
35func NewTenantConfigurationSyncStateClient(subscriptionID string) TenantConfigurationSyncStateClient {
36	return NewTenantConfigurationSyncStateClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewTenantConfigurationSyncStateClientWithBaseURI creates an instance of the TenantConfigurationSyncStateClient
40// client.
41func NewTenantConfigurationSyncStateClientWithBaseURI(baseURI string, subscriptionID string) TenantConfigurationSyncStateClient {
42	return TenantConfigurationSyncStateClient{NewWithBaseURI(baseURI, subscriptionID)}
43}
44
45// Get gets the status of the most recent synchronization between the configuration database and the Git repository.
46// Parameters:
47// resourceGroupName - the name of the resource group.
48// serviceName - the name of the API Management service.
49func (client TenantConfigurationSyncStateClient) Get(ctx context.Context, resourceGroupName string, serviceName string) (result TenantConfigurationSyncStateContract, err error) {
50	if tracing.IsEnabled() {
51		ctx = tracing.StartSpan(ctx, fqdn+"/TenantConfigurationSyncStateClient.Get")
52		defer func() {
53			sc := -1
54			if result.Response.Response != nil {
55				sc = result.Response.Response.StatusCode
56			}
57			tracing.EndSpan(ctx, sc, err)
58		}()
59	}
60	if err := validation.Validate([]validation.Validation{
61		{TargetValue: serviceName,
62			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
63				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
64				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}}); err != nil {
65		return result, validation.NewError("apimanagement.TenantConfigurationSyncStateClient", "Get", err.Error())
66	}
67
68	req, err := client.GetPreparer(ctx, resourceGroupName, serviceName)
69	if err != nil {
70		err = autorest.NewErrorWithError(err, "apimanagement.TenantConfigurationSyncStateClient", "Get", nil, "Failure preparing request")
71		return
72	}
73
74	resp, err := client.GetSender(req)
75	if err != nil {
76		result.Response = autorest.Response{Response: resp}
77		err = autorest.NewErrorWithError(err, "apimanagement.TenantConfigurationSyncStateClient", "Get", resp, "Failure sending request")
78		return
79	}
80
81	result, err = client.GetResponder(resp)
82	if err != nil {
83		err = autorest.NewErrorWithError(err, "apimanagement.TenantConfigurationSyncStateClient", "Get", resp, "Failure responding to request")
84	}
85
86	return
87}
88
89// GetPreparer prepares the Get request.
90func (client TenantConfigurationSyncStateClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string) (*http.Request, error) {
91	pathParameters := map[string]interface{}{
92		"resourceGroupName": autorest.Encode("path", resourceGroupName),
93		"serviceName":       autorest.Encode("path", serviceName),
94		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
95	}
96
97	const APIVersion = "2016-10-10"
98	queryParameters := map[string]interface{}{
99		"api-version": APIVersion,
100	}
101
102	preparer := autorest.CreatePreparer(
103		autorest.AsGet(),
104		autorest.WithBaseURL(client.BaseURI),
105		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/tenant/configuration/syncState", pathParameters),
106		autorest.WithQueryParameters(queryParameters))
107	return preparer.Prepare((&http.Request{}).WithContext(ctx))
108}
109
110// GetSender sends the Get request. The method will close the
111// http.Response Body if it receives an error.
112func (client TenantConfigurationSyncStateClient) GetSender(req *http.Request) (*http.Response, error) {
113	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
114	return autorest.SendWithSender(client, req, sd...)
115}
116
117// GetResponder handles the response to the Get request. The method always
118// closes the http.Response Body.
119func (client TenantConfigurationSyncStateClient) GetResponder(resp *http.Response) (result TenantConfigurationSyncStateContract, err error) {
120	err = autorest.Respond(
121		resp,
122		client.ByInspecting(),
123		azure.WithErrorUnlessStatusCode(http.StatusOK),
124		autorest.ByUnmarshallingJSON(&result),
125		autorest.ByClosing())
126	result.Response = autorest.Response{Response: resp}
127	return
128}
129