1package synapse
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// IntegrationRuntimeAuthKeysClient is the azure Synapse Analytics Management Client
19type IntegrationRuntimeAuthKeysClient struct {
20	BaseClient
21}
22
23// NewIntegrationRuntimeAuthKeysClient creates an instance of the IntegrationRuntimeAuthKeysClient client.
24func NewIntegrationRuntimeAuthKeysClient(subscriptionID string) IntegrationRuntimeAuthKeysClient {
25	return NewIntegrationRuntimeAuthKeysClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewIntegrationRuntimeAuthKeysClientWithBaseURI creates an instance of the IntegrationRuntimeAuthKeysClient client
29// using a custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign
30// clouds, Azure stack).
31func NewIntegrationRuntimeAuthKeysClientWithBaseURI(baseURI string, subscriptionID string) IntegrationRuntimeAuthKeysClient {
32	return IntegrationRuntimeAuthKeysClient{NewWithBaseURI(baseURI, subscriptionID)}
33}
34
35// List list authentication keys in an integration runtime
36// Parameters:
37// resourceGroupName - the name of the resource group. The name is case insensitive.
38// workspaceName - the name of the workspace.
39// integrationRuntimeName - integration runtime name
40func (client IntegrationRuntimeAuthKeysClient) List(ctx context.Context, resourceGroupName string, workspaceName string, integrationRuntimeName string) (result IntegrationRuntimeAuthKeys, err error) {
41	if tracing.IsEnabled() {
42		ctx = tracing.StartSpan(ctx, fqdn+"/IntegrationRuntimeAuthKeysClient.List")
43		defer func() {
44			sc := -1
45			if result.Response.Response != nil {
46				sc = result.Response.Response.StatusCode
47			}
48			tracing.EndSpan(ctx, sc, err)
49		}()
50	}
51	if err := validation.Validate([]validation.Validation{
52		{TargetValue: client.SubscriptionID,
53			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
54		{TargetValue: resourceGroupName,
55			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
56				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
57		return result, validation.NewError("synapse.IntegrationRuntimeAuthKeysClient", "List", err.Error())
58	}
59
60	req, err := client.ListPreparer(ctx, resourceGroupName, workspaceName, integrationRuntimeName)
61	if err != nil {
62		err = autorest.NewErrorWithError(err, "synapse.IntegrationRuntimeAuthKeysClient", "List", nil, "Failure preparing request")
63		return
64	}
65
66	resp, err := client.ListSender(req)
67	if err != nil {
68		result.Response = autorest.Response{Response: resp}
69		err = autorest.NewErrorWithError(err, "synapse.IntegrationRuntimeAuthKeysClient", "List", resp, "Failure sending request")
70		return
71	}
72
73	result, err = client.ListResponder(resp)
74	if err != nil {
75		err = autorest.NewErrorWithError(err, "synapse.IntegrationRuntimeAuthKeysClient", "List", resp, "Failure responding to request")
76		return
77	}
78
79	return
80}
81
82// ListPreparer prepares the List request.
83func (client IntegrationRuntimeAuthKeysClient) ListPreparer(ctx context.Context, resourceGroupName string, workspaceName string, integrationRuntimeName string) (*http.Request, error) {
84	pathParameters := map[string]interface{}{
85		"integrationRuntimeName": autorest.Encode("path", integrationRuntimeName),
86		"resourceGroupName":      autorest.Encode("path", resourceGroupName),
87		"subscriptionId":         autorest.Encode("path", client.SubscriptionID),
88		"workspaceName":          autorest.Encode("path", workspaceName),
89	}
90
91	const APIVersion = "2021-06-01-preview"
92	queryParameters := map[string]interface{}{
93		"api-version": APIVersion,
94	}
95
96	preparer := autorest.CreatePreparer(
97		autorest.AsPost(),
98		autorest.WithBaseURL(client.BaseURI),
99		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Synapse/workspaces/{workspaceName}/integrationRuntimes/{integrationRuntimeName}/listAuthKeys", pathParameters),
100		autorest.WithQueryParameters(queryParameters))
101	return preparer.Prepare((&http.Request{}).WithContext(ctx))
102}
103
104// ListSender sends the List request. The method will close the
105// http.Response Body if it receives an error.
106func (client IntegrationRuntimeAuthKeysClient) ListSender(req *http.Request) (*http.Response, error) {
107	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
108}
109
110// ListResponder handles the response to the List request. The method always
111// closes the http.Response Body.
112func (client IntegrationRuntimeAuthKeysClient) ListResponder(resp *http.Response) (result IntegrationRuntimeAuthKeys, err error) {
113	err = autorest.Respond(
114		resp,
115		azure.WithErrorUnlessStatusCode(http.StatusOK),
116		autorest.ByUnmarshallingJSON(&result),
117		autorest.ByClosing())
118	result.Response = autorest.Response{Response: resp}
119	return
120}
121
122// Regenerate regenerate the authentication key for an integration runtime
123// Parameters:
124// resourceGroupName - the name of the resource group. The name is case insensitive.
125// workspaceName - the name of the workspace.
126// integrationRuntimeName - integration runtime name
127// regenerateKeyParameters - the parameters for regenerating integration runtime authentication key.
128func (client IntegrationRuntimeAuthKeysClient) Regenerate(ctx context.Context, resourceGroupName string, workspaceName string, integrationRuntimeName string, regenerateKeyParameters IntegrationRuntimeRegenerateKeyParameters) (result IntegrationRuntimeAuthKeys, err error) {
129	if tracing.IsEnabled() {
130		ctx = tracing.StartSpan(ctx, fqdn+"/IntegrationRuntimeAuthKeysClient.Regenerate")
131		defer func() {
132			sc := -1
133			if result.Response.Response != nil {
134				sc = result.Response.Response.StatusCode
135			}
136			tracing.EndSpan(ctx, sc, err)
137		}()
138	}
139	if err := validation.Validate([]validation.Validation{
140		{TargetValue: client.SubscriptionID,
141			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
142		{TargetValue: resourceGroupName,
143			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
144				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
145		return result, validation.NewError("synapse.IntegrationRuntimeAuthKeysClient", "Regenerate", err.Error())
146	}
147
148	req, err := client.RegeneratePreparer(ctx, resourceGroupName, workspaceName, integrationRuntimeName, regenerateKeyParameters)
149	if err != nil {
150		err = autorest.NewErrorWithError(err, "synapse.IntegrationRuntimeAuthKeysClient", "Regenerate", nil, "Failure preparing request")
151		return
152	}
153
154	resp, err := client.RegenerateSender(req)
155	if err != nil {
156		result.Response = autorest.Response{Response: resp}
157		err = autorest.NewErrorWithError(err, "synapse.IntegrationRuntimeAuthKeysClient", "Regenerate", resp, "Failure sending request")
158		return
159	}
160
161	result, err = client.RegenerateResponder(resp)
162	if err != nil {
163		err = autorest.NewErrorWithError(err, "synapse.IntegrationRuntimeAuthKeysClient", "Regenerate", resp, "Failure responding to request")
164		return
165	}
166
167	return
168}
169
170// RegeneratePreparer prepares the Regenerate request.
171func (client IntegrationRuntimeAuthKeysClient) RegeneratePreparer(ctx context.Context, resourceGroupName string, workspaceName string, integrationRuntimeName string, regenerateKeyParameters IntegrationRuntimeRegenerateKeyParameters) (*http.Request, error) {
172	pathParameters := map[string]interface{}{
173		"integrationRuntimeName": autorest.Encode("path", integrationRuntimeName),
174		"resourceGroupName":      autorest.Encode("path", resourceGroupName),
175		"subscriptionId":         autorest.Encode("path", client.SubscriptionID),
176		"workspaceName":          autorest.Encode("path", workspaceName),
177	}
178
179	const APIVersion = "2021-06-01-preview"
180	queryParameters := map[string]interface{}{
181		"api-version": APIVersion,
182	}
183
184	preparer := autorest.CreatePreparer(
185		autorest.AsContentType("application/json; charset=utf-8"),
186		autorest.AsPost(),
187		autorest.WithBaseURL(client.BaseURI),
188		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Synapse/workspaces/{workspaceName}/integrationRuntimes/{integrationRuntimeName}/regenerateAuthKey", pathParameters),
189		autorest.WithJSON(regenerateKeyParameters),
190		autorest.WithQueryParameters(queryParameters))
191	return preparer.Prepare((&http.Request{}).WithContext(ctx))
192}
193
194// RegenerateSender sends the Regenerate request. The method will close the
195// http.Response Body if it receives an error.
196func (client IntegrationRuntimeAuthKeysClient) RegenerateSender(req *http.Request) (*http.Response, error) {
197	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
198}
199
200// RegenerateResponder handles the response to the Regenerate request. The method always
201// closes the http.Response Body.
202func (client IntegrationRuntimeAuthKeysClient) RegenerateResponder(resp *http.Response) (result IntegrationRuntimeAuthKeys, err error) {
203	err = autorest.Respond(
204		resp,
205		azure.WithErrorUnlessStatusCode(http.StatusOK),
206		autorest.ByUnmarshallingJSON(&result),
207		autorest.ByClosing())
208	result.Response = autorest.Response{Response: resp}
209	return
210}
211