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// SignInSettingsClient is the apiManagement Client
19type SignInSettingsClient struct {
20	BaseClient
21}
22
23// NewSignInSettingsClient creates an instance of the SignInSettingsClient client.
24func NewSignInSettingsClient(subscriptionID string) SignInSettingsClient {
25	return NewSignInSettingsClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewSignInSettingsClientWithBaseURI creates an instance of the SignInSettingsClient client using a custom endpoint.
29// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
30func NewSignInSettingsClientWithBaseURI(baseURI string, subscriptionID string) SignInSettingsClient {
31	return SignInSettingsClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// CreateOrUpdate create or Update Sign-In settings.
35// Parameters:
36// resourceGroupName - the name of the resource group.
37// serviceName - the name of the API Management service.
38// parameters - create or update parameters.
39// ifMatch - eTag of the Entity. Not required when creating an entity, but required when updating an entity.
40func (client SignInSettingsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, parameters PortalSigninSettings, ifMatch string) (result PortalSigninSettings, err error) {
41	if tracing.IsEnabled() {
42		ctx = tracing.StartSpan(ctx, fqdn+"/SignInSettingsClient.CreateOrUpdate")
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: serviceName,
53			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
54				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
55				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}}); err != nil {
56		return result, validation.NewError("apimanagement.SignInSettingsClient", "CreateOrUpdate", err.Error())
57	}
58
59	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, parameters, ifMatch)
60	if err != nil {
61		err = autorest.NewErrorWithError(err, "apimanagement.SignInSettingsClient", "CreateOrUpdate", nil, "Failure preparing request")
62		return
63	}
64
65	resp, err := client.CreateOrUpdateSender(req)
66	if err != nil {
67		result.Response = autorest.Response{Response: resp}
68		err = autorest.NewErrorWithError(err, "apimanagement.SignInSettingsClient", "CreateOrUpdate", resp, "Failure sending request")
69		return
70	}
71
72	result, err = client.CreateOrUpdateResponder(resp)
73	if err != nil {
74		err = autorest.NewErrorWithError(err, "apimanagement.SignInSettingsClient", "CreateOrUpdate", resp, "Failure responding to request")
75		return
76	}
77
78	return
79}
80
81// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
82func (client SignInSettingsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, parameters PortalSigninSettings, ifMatch string) (*http.Request, error) {
83	pathParameters := map[string]interface{}{
84		"resourceGroupName": autorest.Encode("path", resourceGroupName),
85		"serviceName":       autorest.Encode("path", serviceName),
86		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
87	}
88
89	const APIVersion = "2018-06-01-preview"
90	queryParameters := map[string]interface{}{
91		"api-version": APIVersion,
92	}
93
94	preparer := autorest.CreatePreparer(
95		autorest.AsContentType("application/json; charset=utf-8"),
96		autorest.AsPut(),
97		autorest.WithBaseURL(client.BaseURI),
98		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/portalsettings/signin", pathParameters),
99		autorest.WithJSON(parameters),
100		autorest.WithQueryParameters(queryParameters))
101	if len(ifMatch) > 0 {
102		preparer = autorest.DecoratePreparer(preparer,
103			autorest.WithHeader("If-Match", autorest.String(ifMatch)))
104	}
105	return preparer.Prepare((&http.Request{}).WithContext(ctx))
106}
107
108// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
109// http.Response Body if it receives an error.
110func (client SignInSettingsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
111	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
112}
113
114// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
115// closes the http.Response Body.
116func (client SignInSettingsClient) CreateOrUpdateResponder(resp *http.Response) (result PortalSigninSettings, err error) {
117	err = autorest.Respond(
118		resp,
119		azure.WithErrorUnlessStatusCode(http.StatusOK),
120		autorest.ByUnmarshallingJSON(&result),
121		autorest.ByClosing())
122	result.Response = autorest.Response{Response: resp}
123	return
124}
125
126// Get get Sign In Settings for the Portal
127// Parameters:
128// resourceGroupName - the name of the resource group.
129// serviceName - the name of the API Management service.
130func (client SignInSettingsClient) Get(ctx context.Context, resourceGroupName string, serviceName string) (result PortalSigninSettings, err error) {
131	if tracing.IsEnabled() {
132		ctx = tracing.StartSpan(ctx, fqdn+"/SignInSettingsClient.Get")
133		defer func() {
134			sc := -1
135			if result.Response.Response != nil {
136				sc = result.Response.Response.StatusCode
137			}
138			tracing.EndSpan(ctx, sc, err)
139		}()
140	}
141	if err := validation.Validate([]validation.Validation{
142		{TargetValue: serviceName,
143			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
144				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
145				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}}); err != nil {
146		return result, validation.NewError("apimanagement.SignInSettingsClient", "Get", err.Error())
147	}
148
149	req, err := client.GetPreparer(ctx, resourceGroupName, serviceName)
150	if err != nil {
151		err = autorest.NewErrorWithError(err, "apimanagement.SignInSettingsClient", "Get", nil, "Failure preparing request")
152		return
153	}
154
155	resp, err := client.GetSender(req)
156	if err != nil {
157		result.Response = autorest.Response{Response: resp}
158		err = autorest.NewErrorWithError(err, "apimanagement.SignInSettingsClient", "Get", resp, "Failure sending request")
159		return
160	}
161
162	result, err = client.GetResponder(resp)
163	if err != nil {
164		err = autorest.NewErrorWithError(err, "apimanagement.SignInSettingsClient", "Get", resp, "Failure responding to request")
165		return
166	}
167
168	return
169}
170
171// GetPreparer prepares the Get request.
172func (client SignInSettingsClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string) (*http.Request, error) {
173	pathParameters := map[string]interface{}{
174		"resourceGroupName": autorest.Encode("path", resourceGroupName),
175		"serviceName":       autorest.Encode("path", serviceName),
176		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
177	}
178
179	const APIVersion = "2018-06-01-preview"
180	queryParameters := map[string]interface{}{
181		"api-version": APIVersion,
182	}
183
184	preparer := autorest.CreatePreparer(
185		autorest.AsGet(),
186		autorest.WithBaseURL(client.BaseURI),
187		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/portalsettings/signin", pathParameters),
188		autorest.WithQueryParameters(queryParameters))
189	return preparer.Prepare((&http.Request{}).WithContext(ctx))
190}
191
192// GetSender sends the Get request. The method will close the
193// http.Response Body if it receives an error.
194func (client SignInSettingsClient) GetSender(req *http.Request) (*http.Response, error) {
195	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
196}
197
198// GetResponder handles the response to the Get request. The method always
199// closes the http.Response Body.
200func (client SignInSettingsClient) GetResponder(resp *http.Response) (result PortalSigninSettings, err error) {
201	err = autorest.Respond(
202		resp,
203		azure.WithErrorUnlessStatusCode(http.StatusOK),
204		autorest.ByUnmarshallingJSON(&result),
205		autorest.ByClosing())
206	result.Response = autorest.Response{Response: resp}
207	return
208}
209
210// GetEntityTag gets the entity state (Etag) version of the SignInSettings.
211// Parameters:
212// resourceGroupName - the name of the resource group.
213// serviceName - the name of the API Management service.
214func (client SignInSettingsClient) GetEntityTag(ctx context.Context, resourceGroupName string, serviceName string) (result autorest.Response, err error) {
215	if tracing.IsEnabled() {
216		ctx = tracing.StartSpan(ctx, fqdn+"/SignInSettingsClient.GetEntityTag")
217		defer func() {
218			sc := -1
219			if result.Response != nil {
220				sc = result.Response.StatusCode
221			}
222			tracing.EndSpan(ctx, sc, err)
223		}()
224	}
225	if err := validation.Validate([]validation.Validation{
226		{TargetValue: serviceName,
227			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
228				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
229				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}}); err != nil {
230		return result, validation.NewError("apimanagement.SignInSettingsClient", "GetEntityTag", err.Error())
231	}
232
233	req, err := client.GetEntityTagPreparer(ctx, resourceGroupName, serviceName)
234	if err != nil {
235		err = autorest.NewErrorWithError(err, "apimanagement.SignInSettingsClient", "GetEntityTag", nil, "Failure preparing request")
236		return
237	}
238
239	resp, err := client.GetEntityTagSender(req)
240	if err != nil {
241		result.Response = resp
242		err = autorest.NewErrorWithError(err, "apimanagement.SignInSettingsClient", "GetEntityTag", resp, "Failure sending request")
243		return
244	}
245
246	result, err = client.GetEntityTagResponder(resp)
247	if err != nil {
248		err = autorest.NewErrorWithError(err, "apimanagement.SignInSettingsClient", "GetEntityTag", resp, "Failure responding to request")
249		return
250	}
251
252	return
253}
254
255// GetEntityTagPreparer prepares the GetEntityTag request.
256func (client SignInSettingsClient) GetEntityTagPreparer(ctx context.Context, resourceGroupName string, serviceName string) (*http.Request, error) {
257	pathParameters := map[string]interface{}{
258		"resourceGroupName": autorest.Encode("path", resourceGroupName),
259		"serviceName":       autorest.Encode("path", serviceName),
260		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
261	}
262
263	const APIVersion = "2018-06-01-preview"
264	queryParameters := map[string]interface{}{
265		"api-version": APIVersion,
266	}
267
268	preparer := autorest.CreatePreparer(
269		autorest.AsHead(),
270		autorest.WithBaseURL(client.BaseURI),
271		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/portalsettings/signin", pathParameters),
272		autorest.WithQueryParameters(queryParameters))
273	return preparer.Prepare((&http.Request{}).WithContext(ctx))
274}
275
276// GetEntityTagSender sends the GetEntityTag request. The method will close the
277// http.Response Body if it receives an error.
278func (client SignInSettingsClient) GetEntityTagSender(req *http.Request) (*http.Response, error) {
279	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
280}
281
282// GetEntityTagResponder handles the response to the GetEntityTag request. The method always
283// closes the http.Response Body.
284func (client SignInSettingsClient) GetEntityTagResponder(resp *http.Response) (result autorest.Response, err error) {
285	err = autorest.Respond(
286		resp,
287		azure.WithErrorUnlessStatusCode(http.StatusOK),
288		autorest.ByClosing())
289	result.Response = resp
290	return
291}
292
293// Update update Sign-In settings.
294// Parameters:
295// resourceGroupName - the name of the resource group.
296// serviceName - the name of the API Management service.
297// parameters - update Sign-In settings.
298// ifMatch - eTag of the Entity. ETag should match the current entity state from the header response of the GET
299// request or it should be * for unconditional update.
300func (client SignInSettingsClient) Update(ctx context.Context, resourceGroupName string, serviceName string, parameters PortalSigninSettings, ifMatch string) (result autorest.Response, err error) {
301	if tracing.IsEnabled() {
302		ctx = tracing.StartSpan(ctx, fqdn+"/SignInSettingsClient.Update")
303		defer func() {
304			sc := -1
305			if result.Response != nil {
306				sc = result.Response.StatusCode
307			}
308			tracing.EndSpan(ctx, sc, err)
309		}()
310	}
311	if err := validation.Validate([]validation.Validation{
312		{TargetValue: serviceName,
313			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
314				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
315				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}}); err != nil {
316		return result, validation.NewError("apimanagement.SignInSettingsClient", "Update", err.Error())
317	}
318
319	req, err := client.UpdatePreparer(ctx, resourceGroupName, serviceName, parameters, ifMatch)
320	if err != nil {
321		err = autorest.NewErrorWithError(err, "apimanagement.SignInSettingsClient", "Update", nil, "Failure preparing request")
322		return
323	}
324
325	resp, err := client.UpdateSender(req)
326	if err != nil {
327		result.Response = resp
328		err = autorest.NewErrorWithError(err, "apimanagement.SignInSettingsClient", "Update", resp, "Failure sending request")
329		return
330	}
331
332	result, err = client.UpdateResponder(resp)
333	if err != nil {
334		err = autorest.NewErrorWithError(err, "apimanagement.SignInSettingsClient", "Update", resp, "Failure responding to request")
335		return
336	}
337
338	return
339}
340
341// UpdatePreparer prepares the Update request.
342func (client SignInSettingsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, parameters PortalSigninSettings, ifMatch string) (*http.Request, error) {
343	pathParameters := map[string]interface{}{
344		"resourceGroupName": autorest.Encode("path", resourceGroupName),
345		"serviceName":       autorest.Encode("path", serviceName),
346		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
347	}
348
349	const APIVersion = "2018-06-01-preview"
350	queryParameters := map[string]interface{}{
351		"api-version": APIVersion,
352	}
353
354	preparer := autorest.CreatePreparer(
355		autorest.AsContentType("application/json; charset=utf-8"),
356		autorest.AsPatch(),
357		autorest.WithBaseURL(client.BaseURI),
358		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/portalsettings/signin", pathParameters),
359		autorest.WithJSON(parameters),
360		autorest.WithQueryParameters(queryParameters),
361		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
362	return preparer.Prepare((&http.Request{}).WithContext(ctx))
363}
364
365// UpdateSender sends the Update request. The method will close the
366// http.Response Body if it receives an error.
367func (client SignInSettingsClient) UpdateSender(req *http.Request) (*http.Response, error) {
368	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
369}
370
371// UpdateResponder handles the response to the Update request. The method always
372// closes the http.Response Body.
373func (client SignInSettingsClient) UpdateResponder(resp *http.Response) (result autorest.Response, err error) {
374	err = autorest.Respond(
375		resp,
376		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
377		autorest.ByClosing())
378	result.Response = resp
379	return
380}
381