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// APIExportClient is the apiManagement Client
19type APIExportClient struct {
20	BaseClient
21}
22
23// NewAPIExportClient creates an instance of the APIExportClient client.
24func NewAPIExportClient(subscriptionID string) APIExportClient {
25	return NewAPIExportClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewAPIExportClientWithBaseURI creates an instance of the APIExportClient client using a custom endpoint.  Use this
29// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
30func NewAPIExportClientWithBaseURI(baseURI string, subscriptionID string) APIExportClient {
31	return APIExportClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// Get gets the details of the API specified by its identifier in the format specified to the Storage Blob with SAS Key
35// valid for 5 minutes.
36// Parameters:
37// resourceGroupName - the name of the resource group.
38// serviceName - the name of the API Management service.
39// apiid - API revision identifier. Must be unique in the current API Management service instance. Non-current
40// revision has ;rev=n as a suffix where n is the revision number.
41// formatParameter - format in which to export the Api Details to the Storage Blob with Sas Key valid for 5
42// minutes.
43func (client APIExportClient) Get(ctx context.Context, resourceGroupName string, serviceName string, apiid string, formatParameter ExportFormat) (result APIExportResult, err error) {
44	if tracing.IsEnabled() {
45		ctx = tracing.StartSpan(ctx, fqdn+"/APIExportClient.Get")
46		defer func() {
47			sc := -1
48			if result.Response.Response != nil {
49				sc = result.Response.Response.StatusCode
50			}
51			tracing.EndSpan(ctx, sc, err)
52		}()
53	}
54	if err := validation.Validate([]validation.Validation{
55		{TargetValue: serviceName,
56			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
57				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
58				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
59		{TargetValue: apiid,
60			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil},
61				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil},
62				{Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
63		return result, validation.NewError("apimanagement.APIExportClient", "Get", err.Error())
64	}
65
66	req, err := client.GetPreparer(ctx, resourceGroupName, serviceName, apiid, formatParameter)
67	if err != nil {
68		err = autorest.NewErrorWithError(err, "apimanagement.APIExportClient", "Get", nil, "Failure preparing request")
69		return
70	}
71
72	resp, err := client.GetSender(req)
73	if err != nil {
74		result.Response = autorest.Response{Response: resp}
75		err = autorest.NewErrorWithError(err, "apimanagement.APIExportClient", "Get", resp, "Failure sending request")
76		return
77	}
78
79	result, err = client.GetResponder(resp)
80	if err != nil {
81		err = autorest.NewErrorWithError(err, "apimanagement.APIExportClient", "Get", resp, "Failure responding to request")
82		return
83	}
84
85	return
86}
87
88// GetPreparer prepares the Get request.
89func (client APIExportClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, formatParameter ExportFormat) (*http.Request, error) {
90	pathParameters := map[string]interface{}{
91		"apiId":             autorest.Encode("path", apiid),
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-06-01-preview"
98	queryParameters := map[string]interface{}{
99		"api-version": APIVersion,
100		"export":      autorest.Encode("query", "true"),
101		"format":      autorest.Encode("query", formatParameter),
102	}
103
104	preparer := autorest.CreatePreparer(
105		autorest.AsGet(),
106		autorest.WithBaseURL(client.BaseURI),
107		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}", pathParameters),
108		autorest.WithQueryParameters(queryParameters))
109	return preparer.Prepare((&http.Request{}).WithContext(ctx))
110}
111
112// GetSender sends the Get request. The method will close the
113// http.Response Body if it receives an error.
114func (client APIExportClient) GetSender(req *http.Request) (*http.Response, error) {
115	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
116}
117
118// GetResponder handles the response to the Get request. The method always
119// closes the http.Response Body.
120func (client APIExportClient) GetResponder(resp *http.Response) (result APIExportResult, err error) {
121	err = autorest.Respond(
122		resp,
123		azure.WithErrorUnlessStatusCode(http.StatusOK),
124		autorest.ByUnmarshallingJSON(&result),
125		autorest.ByClosing())
126	result.Response = autorest.Response{Response: resp}
127	return
128}
129