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