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// NamedValueClient is the apiManagement Client
19type NamedValueClient struct {
20	BaseClient
21}
22
23// NewNamedValueClient creates an instance of the NamedValueClient client.
24func NewNamedValueClient(subscriptionID string) NamedValueClient {
25	return NewNamedValueClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewNamedValueClientWithBaseURI creates an instance of the NamedValueClient 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 NewNamedValueClientWithBaseURI(baseURI string, subscriptionID string) NamedValueClient {
31	return NamedValueClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// CreateOrUpdate creates or updates named value.
35// Parameters:
36// resourceGroupName - the name of the resource group.
37// serviceName - the name of the API Management service.
38// namedValueID - identifier of the NamedValue.
39// parameters - create parameters.
40// ifMatch - eTag of the Entity. Not required when creating an entity, but required when updating an entity.
41func (client NamedValueClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, namedValueID string, parameters NamedValueCreateContract, ifMatch string) (result NamedValueCreateOrUpdateFuture, err error) {
42	if tracing.IsEnabled() {
43		ctx = tracing.StartSpan(ctx, fqdn+"/NamedValueClient.CreateOrUpdate")
44		defer func() {
45			sc := -1
46			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
47				sc = result.FutureAPI.Response().StatusCode
48			}
49			tracing.EndSpan(ctx, sc, err)
50		}()
51	}
52	if err := validation.Validate([]validation.Validation{
53		{TargetValue: serviceName,
54			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
55				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
56				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
57		{TargetValue: namedValueID,
58			Constraints: []validation.Constraint{{Target: "namedValueID", Name: validation.MaxLength, Rule: 256, Chain: nil},
59				{Target: "namedValueID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
60		{TargetValue: parameters,
61			Constraints: []validation.Constraint{{Target: "parameters.NamedValueCreateContractProperties", Name: validation.Null, Rule: false,
62				Chain: []validation.Constraint{{Target: "parameters.NamedValueCreateContractProperties.DisplayName", Name: validation.Null, Rule: true,
63					Chain: []validation.Constraint{{Target: "parameters.NamedValueCreateContractProperties.DisplayName", Name: validation.MaxLength, Rule: 256, Chain: nil},
64						{Target: "parameters.NamedValueCreateContractProperties.DisplayName", Name: validation.MinLength, Rule: 1, Chain: nil},
65						{Target: "parameters.NamedValueCreateContractProperties.DisplayName", Name: validation.Pattern, Rule: `^[A-Za-z0-9-._]+$`, Chain: nil},
66					}},
67					{Target: "parameters.NamedValueCreateContractProperties.Value", Name: validation.Null, Rule: false,
68						Chain: []validation.Constraint{{Target: "parameters.NamedValueCreateContractProperties.Value", Name: validation.MaxLength, Rule: 4096, Chain: nil}}},
69				}}}}}); err != nil {
70		return result, validation.NewError("apimanagement.NamedValueClient", "CreateOrUpdate", err.Error())
71	}
72
73	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, namedValueID, parameters, ifMatch)
74	if err != nil {
75		err = autorest.NewErrorWithError(err, "apimanagement.NamedValueClient", "CreateOrUpdate", nil, "Failure preparing request")
76		return
77	}
78
79	result, err = client.CreateOrUpdateSender(req)
80	if err != nil {
81		err = autorest.NewErrorWithError(err, "apimanagement.NamedValueClient", "CreateOrUpdate", nil, "Failure sending request")
82		return
83	}
84
85	return
86}
87
88// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
89func (client NamedValueClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, namedValueID string, parameters NamedValueCreateContract, ifMatch string) (*http.Request, error) {
90	pathParameters := map[string]interface{}{
91		"namedValueId":      autorest.Encode("path", namedValueID),
92		"resourceGroupName": autorest.Encode("path", resourceGroupName),
93		"serviceName":       autorest.Encode("path", serviceName),
94		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
95	}
96
97	const APIVersion = "2021-01-01-preview"
98	queryParameters := map[string]interface{}{
99		"api-version": APIVersion,
100	}
101
102	preparer := autorest.CreatePreparer(
103		autorest.AsContentType("application/json; charset=utf-8"),
104		autorest.AsPut(),
105		autorest.WithBaseURL(client.BaseURI),
106		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/namedValues/{namedValueId}", pathParameters),
107		autorest.WithJSON(parameters),
108		autorest.WithQueryParameters(queryParameters))
109	if len(ifMatch) > 0 {
110		preparer = autorest.DecoratePreparer(preparer,
111			autorest.WithHeader("If-Match", autorest.String(ifMatch)))
112	}
113	return preparer.Prepare((&http.Request{}).WithContext(ctx))
114}
115
116// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
117// http.Response Body if it receives an error.
118func (client NamedValueClient) CreateOrUpdateSender(req *http.Request) (future NamedValueCreateOrUpdateFuture, err error) {
119	var resp *http.Response
120	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
121	if err != nil {
122		return
123	}
124	var azf azure.Future
125	azf, err = azure.NewFutureFromResponse(resp)
126	future.FutureAPI = &azf
127	future.Result = future.result
128	return
129}
130
131// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
132// closes the http.Response Body.
133func (client NamedValueClient) CreateOrUpdateResponder(resp *http.Response) (result NamedValueContract, err error) {
134	err = autorest.Respond(
135		resp,
136		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusAccepted),
137		autorest.ByUnmarshallingJSON(&result),
138		autorest.ByClosing())
139	result.Response = autorest.Response{Response: resp}
140	return
141}
142
143// Delete deletes specific named value from the API Management service instance.
144// Parameters:
145// resourceGroupName - the name of the resource group.
146// serviceName - the name of the API Management service.
147// namedValueID - identifier of the NamedValue.
148// ifMatch - eTag of the Entity. ETag should match the current entity state from the header response of the GET
149// request or it should be * for unconditional update.
150func (client NamedValueClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, namedValueID string, ifMatch string) (result autorest.Response, err error) {
151	if tracing.IsEnabled() {
152		ctx = tracing.StartSpan(ctx, fqdn+"/NamedValueClient.Delete")
153		defer func() {
154			sc := -1
155			if result.Response != nil {
156				sc = result.Response.StatusCode
157			}
158			tracing.EndSpan(ctx, sc, err)
159		}()
160	}
161	if err := validation.Validate([]validation.Validation{
162		{TargetValue: serviceName,
163			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
164				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
165				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
166		{TargetValue: namedValueID,
167			Constraints: []validation.Constraint{{Target: "namedValueID", Name: validation.MaxLength, Rule: 256, Chain: nil},
168				{Target: "namedValueID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
169		return result, validation.NewError("apimanagement.NamedValueClient", "Delete", err.Error())
170	}
171
172	req, err := client.DeletePreparer(ctx, resourceGroupName, serviceName, namedValueID, ifMatch)
173	if err != nil {
174		err = autorest.NewErrorWithError(err, "apimanagement.NamedValueClient", "Delete", nil, "Failure preparing request")
175		return
176	}
177
178	resp, err := client.DeleteSender(req)
179	if err != nil {
180		result.Response = resp
181		err = autorest.NewErrorWithError(err, "apimanagement.NamedValueClient", "Delete", resp, "Failure sending request")
182		return
183	}
184
185	result, err = client.DeleteResponder(resp)
186	if err != nil {
187		err = autorest.NewErrorWithError(err, "apimanagement.NamedValueClient", "Delete", resp, "Failure responding to request")
188		return
189	}
190
191	return
192}
193
194// DeletePreparer prepares the Delete request.
195func (client NamedValueClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, namedValueID string, ifMatch string) (*http.Request, error) {
196	pathParameters := map[string]interface{}{
197		"namedValueId":      autorest.Encode("path", namedValueID),
198		"resourceGroupName": autorest.Encode("path", resourceGroupName),
199		"serviceName":       autorest.Encode("path", serviceName),
200		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
201	}
202
203	const APIVersion = "2021-01-01-preview"
204	queryParameters := map[string]interface{}{
205		"api-version": APIVersion,
206	}
207
208	preparer := autorest.CreatePreparer(
209		autorest.AsDelete(),
210		autorest.WithBaseURL(client.BaseURI),
211		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/namedValues/{namedValueId}", pathParameters),
212		autorest.WithQueryParameters(queryParameters),
213		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
214	return preparer.Prepare((&http.Request{}).WithContext(ctx))
215}
216
217// DeleteSender sends the Delete request. The method will close the
218// http.Response Body if it receives an error.
219func (client NamedValueClient) DeleteSender(req *http.Request) (*http.Response, error) {
220	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
221}
222
223// DeleteResponder handles the response to the Delete request. The method always
224// closes the http.Response Body.
225func (client NamedValueClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
226	err = autorest.Respond(
227		resp,
228		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
229		autorest.ByClosing())
230	result.Response = resp
231	return
232}
233
234// Get gets the details of the named value specified by its identifier.
235// Parameters:
236// resourceGroupName - the name of the resource group.
237// serviceName - the name of the API Management service.
238// namedValueID - identifier of the NamedValue.
239func (client NamedValueClient) Get(ctx context.Context, resourceGroupName string, serviceName string, namedValueID string) (result NamedValueContract, err error) {
240	if tracing.IsEnabled() {
241		ctx = tracing.StartSpan(ctx, fqdn+"/NamedValueClient.Get")
242		defer func() {
243			sc := -1
244			if result.Response.Response != nil {
245				sc = result.Response.Response.StatusCode
246			}
247			tracing.EndSpan(ctx, sc, err)
248		}()
249	}
250	if err := validation.Validate([]validation.Validation{
251		{TargetValue: serviceName,
252			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
253				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
254				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
255		{TargetValue: namedValueID,
256			Constraints: []validation.Constraint{{Target: "namedValueID", Name: validation.MaxLength, Rule: 256, Chain: nil},
257				{Target: "namedValueID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
258		return result, validation.NewError("apimanagement.NamedValueClient", "Get", err.Error())
259	}
260
261	req, err := client.GetPreparer(ctx, resourceGroupName, serviceName, namedValueID)
262	if err != nil {
263		err = autorest.NewErrorWithError(err, "apimanagement.NamedValueClient", "Get", nil, "Failure preparing request")
264		return
265	}
266
267	resp, err := client.GetSender(req)
268	if err != nil {
269		result.Response = autorest.Response{Response: resp}
270		err = autorest.NewErrorWithError(err, "apimanagement.NamedValueClient", "Get", resp, "Failure sending request")
271		return
272	}
273
274	result, err = client.GetResponder(resp)
275	if err != nil {
276		err = autorest.NewErrorWithError(err, "apimanagement.NamedValueClient", "Get", resp, "Failure responding to request")
277		return
278	}
279
280	return
281}
282
283// GetPreparer prepares the Get request.
284func (client NamedValueClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, namedValueID string) (*http.Request, error) {
285	pathParameters := map[string]interface{}{
286		"namedValueId":      autorest.Encode("path", namedValueID),
287		"resourceGroupName": autorest.Encode("path", resourceGroupName),
288		"serviceName":       autorest.Encode("path", serviceName),
289		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
290	}
291
292	const APIVersion = "2021-01-01-preview"
293	queryParameters := map[string]interface{}{
294		"api-version": APIVersion,
295	}
296
297	preparer := autorest.CreatePreparer(
298		autorest.AsGet(),
299		autorest.WithBaseURL(client.BaseURI),
300		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/namedValues/{namedValueId}", pathParameters),
301		autorest.WithQueryParameters(queryParameters))
302	return preparer.Prepare((&http.Request{}).WithContext(ctx))
303}
304
305// GetSender sends the Get request. The method will close the
306// http.Response Body if it receives an error.
307func (client NamedValueClient) GetSender(req *http.Request) (*http.Response, error) {
308	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
309}
310
311// GetResponder handles the response to the Get request. The method always
312// closes the http.Response Body.
313func (client NamedValueClient) GetResponder(resp *http.Response) (result NamedValueContract, err error) {
314	err = autorest.Respond(
315		resp,
316		azure.WithErrorUnlessStatusCode(http.StatusOK),
317		autorest.ByUnmarshallingJSON(&result),
318		autorest.ByClosing())
319	result.Response = autorest.Response{Response: resp}
320	return
321}
322
323// GetEntityTag gets the entity state (Etag) version of the named value specified by its identifier.
324// Parameters:
325// resourceGroupName - the name of the resource group.
326// serviceName - the name of the API Management service.
327// namedValueID - identifier of the NamedValue.
328func (client NamedValueClient) GetEntityTag(ctx context.Context, resourceGroupName string, serviceName string, namedValueID string) (result autorest.Response, err error) {
329	if tracing.IsEnabled() {
330		ctx = tracing.StartSpan(ctx, fqdn+"/NamedValueClient.GetEntityTag")
331		defer func() {
332			sc := -1
333			if result.Response != nil {
334				sc = result.Response.StatusCode
335			}
336			tracing.EndSpan(ctx, sc, err)
337		}()
338	}
339	if err := validation.Validate([]validation.Validation{
340		{TargetValue: serviceName,
341			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
342				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
343				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
344		{TargetValue: namedValueID,
345			Constraints: []validation.Constraint{{Target: "namedValueID", Name: validation.MaxLength, Rule: 256, Chain: nil},
346				{Target: "namedValueID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
347		return result, validation.NewError("apimanagement.NamedValueClient", "GetEntityTag", err.Error())
348	}
349
350	req, err := client.GetEntityTagPreparer(ctx, resourceGroupName, serviceName, namedValueID)
351	if err != nil {
352		err = autorest.NewErrorWithError(err, "apimanagement.NamedValueClient", "GetEntityTag", nil, "Failure preparing request")
353		return
354	}
355
356	resp, err := client.GetEntityTagSender(req)
357	if err != nil {
358		result.Response = resp
359		err = autorest.NewErrorWithError(err, "apimanagement.NamedValueClient", "GetEntityTag", resp, "Failure sending request")
360		return
361	}
362
363	result, err = client.GetEntityTagResponder(resp)
364	if err != nil {
365		err = autorest.NewErrorWithError(err, "apimanagement.NamedValueClient", "GetEntityTag", resp, "Failure responding to request")
366		return
367	}
368
369	return
370}
371
372// GetEntityTagPreparer prepares the GetEntityTag request.
373func (client NamedValueClient) GetEntityTagPreparer(ctx context.Context, resourceGroupName string, serviceName string, namedValueID string) (*http.Request, error) {
374	pathParameters := map[string]interface{}{
375		"namedValueId":      autorest.Encode("path", namedValueID),
376		"resourceGroupName": autorest.Encode("path", resourceGroupName),
377		"serviceName":       autorest.Encode("path", serviceName),
378		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
379	}
380
381	const APIVersion = "2021-01-01-preview"
382	queryParameters := map[string]interface{}{
383		"api-version": APIVersion,
384	}
385
386	preparer := autorest.CreatePreparer(
387		autorest.AsHead(),
388		autorest.WithBaseURL(client.BaseURI),
389		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/namedValues/{namedValueId}", pathParameters),
390		autorest.WithQueryParameters(queryParameters))
391	return preparer.Prepare((&http.Request{}).WithContext(ctx))
392}
393
394// GetEntityTagSender sends the GetEntityTag request. The method will close the
395// http.Response Body if it receives an error.
396func (client NamedValueClient) GetEntityTagSender(req *http.Request) (*http.Response, error) {
397	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
398}
399
400// GetEntityTagResponder handles the response to the GetEntityTag request. The method always
401// closes the http.Response Body.
402func (client NamedValueClient) GetEntityTagResponder(resp *http.Response) (result autorest.Response, err error) {
403	err = autorest.Respond(
404		resp,
405		azure.WithErrorUnlessStatusCode(http.StatusOK),
406		autorest.ByClosing())
407	result.Response = resp
408	return
409}
410
411// ListByService lists a collection of named values defined within a service instance.
412// Parameters:
413// resourceGroupName - the name of the resource group.
414// serviceName - the name of the API Management service.
415// filter - |     Field     |     Usage     |     Supported operators     |     Supported functions
416// |</br>|-------------|-------------|-------------|-------------|</br>| tags | filter | ge, le, eq, ne, gt, lt
417// | substringof, contains, startswith, endswith, any, all |</br>| displayName | filter | ge, le, eq, ne, gt,
418// lt | substringof, contains, startswith, endswith |</br>
419// top - number of records to return.
420// skip - number of records to skip.
421// isKeyVaultRefreshFailed - when set to true, the response contains only named value entities which failed
422// refresh.
423func (client NamedValueClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32, isKeyVaultRefreshFailed *bool) (result NamedValueCollectionPage, err error) {
424	if tracing.IsEnabled() {
425		ctx = tracing.StartSpan(ctx, fqdn+"/NamedValueClient.ListByService")
426		defer func() {
427			sc := -1
428			if result.nvc.Response.Response != nil {
429				sc = result.nvc.Response.Response.StatusCode
430			}
431			tracing.EndSpan(ctx, sc, err)
432		}()
433	}
434	if err := validation.Validate([]validation.Validation{
435		{TargetValue: serviceName,
436			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
437				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
438				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
439		{TargetValue: top,
440			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
441				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}}}}},
442		{TargetValue: skip,
443			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
444				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil {
445		return result, validation.NewError("apimanagement.NamedValueClient", "ListByService", err.Error())
446	}
447
448	result.fn = client.listByServiceNextResults
449	req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName, filter, top, skip, isKeyVaultRefreshFailed)
450	if err != nil {
451		err = autorest.NewErrorWithError(err, "apimanagement.NamedValueClient", "ListByService", nil, "Failure preparing request")
452		return
453	}
454
455	resp, err := client.ListByServiceSender(req)
456	if err != nil {
457		result.nvc.Response = autorest.Response{Response: resp}
458		err = autorest.NewErrorWithError(err, "apimanagement.NamedValueClient", "ListByService", resp, "Failure sending request")
459		return
460	}
461
462	result.nvc, err = client.ListByServiceResponder(resp)
463	if err != nil {
464		err = autorest.NewErrorWithError(err, "apimanagement.NamedValueClient", "ListByService", resp, "Failure responding to request")
465		return
466	}
467	if result.nvc.hasNextLink() && result.nvc.IsEmpty() {
468		err = result.NextWithContext(ctx)
469		return
470	}
471
472	return
473}
474
475// ListByServicePreparer prepares the ListByService request.
476func (client NamedValueClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32, isKeyVaultRefreshFailed *bool) (*http.Request, error) {
477	pathParameters := map[string]interface{}{
478		"resourceGroupName": autorest.Encode("path", resourceGroupName),
479		"serviceName":       autorest.Encode("path", serviceName),
480		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
481	}
482
483	const APIVersion = "2021-01-01-preview"
484	queryParameters := map[string]interface{}{
485		"api-version": APIVersion,
486	}
487	if len(filter) > 0 {
488		queryParameters["$filter"] = autorest.Encode("query", filter)
489	}
490	if top != nil {
491		queryParameters["$top"] = autorest.Encode("query", *top)
492	}
493	if skip != nil {
494		queryParameters["$skip"] = autorest.Encode("query", *skip)
495	}
496	if isKeyVaultRefreshFailed != nil {
497		queryParameters["isKeyVaultRefreshFailed"] = autorest.Encode("query", *isKeyVaultRefreshFailed)
498	}
499
500	preparer := autorest.CreatePreparer(
501		autorest.AsGet(),
502		autorest.WithBaseURL(client.BaseURI),
503		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/namedValues", pathParameters),
504		autorest.WithQueryParameters(queryParameters))
505	return preparer.Prepare((&http.Request{}).WithContext(ctx))
506}
507
508// ListByServiceSender sends the ListByService request. The method will close the
509// http.Response Body if it receives an error.
510func (client NamedValueClient) ListByServiceSender(req *http.Request) (*http.Response, error) {
511	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
512}
513
514// ListByServiceResponder handles the response to the ListByService request. The method always
515// closes the http.Response Body.
516func (client NamedValueClient) ListByServiceResponder(resp *http.Response) (result NamedValueCollection, err error) {
517	err = autorest.Respond(
518		resp,
519		azure.WithErrorUnlessStatusCode(http.StatusOK),
520		autorest.ByUnmarshallingJSON(&result),
521		autorest.ByClosing())
522	result.Response = autorest.Response{Response: resp}
523	return
524}
525
526// listByServiceNextResults retrieves the next set of results, if any.
527func (client NamedValueClient) listByServiceNextResults(ctx context.Context, lastResults NamedValueCollection) (result NamedValueCollection, err error) {
528	req, err := lastResults.namedValueCollectionPreparer(ctx)
529	if err != nil {
530		return result, autorest.NewErrorWithError(err, "apimanagement.NamedValueClient", "listByServiceNextResults", nil, "Failure preparing next results request")
531	}
532	if req == nil {
533		return
534	}
535	resp, err := client.ListByServiceSender(req)
536	if err != nil {
537		result.Response = autorest.Response{Response: resp}
538		return result, autorest.NewErrorWithError(err, "apimanagement.NamedValueClient", "listByServiceNextResults", resp, "Failure sending next results request")
539	}
540	result, err = client.ListByServiceResponder(resp)
541	if err != nil {
542		err = autorest.NewErrorWithError(err, "apimanagement.NamedValueClient", "listByServiceNextResults", resp, "Failure responding to next results request")
543	}
544	return
545}
546
547// ListByServiceComplete enumerates all values, automatically crossing page boundaries as required.
548func (client NamedValueClient) ListByServiceComplete(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32, isKeyVaultRefreshFailed *bool) (result NamedValueCollectionIterator, err error) {
549	if tracing.IsEnabled() {
550		ctx = tracing.StartSpan(ctx, fqdn+"/NamedValueClient.ListByService")
551		defer func() {
552			sc := -1
553			if result.Response().Response.Response != nil {
554				sc = result.page.Response().Response.Response.StatusCode
555			}
556			tracing.EndSpan(ctx, sc, err)
557		}()
558	}
559	result.page, err = client.ListByService(ctx, resourceGroupName, serviceName, filter, top, skip, isKeyVaultRefreshFailed)
560	return
561}
562
563// ListValue gets the secret of the named value specified by its identifier.
564// Parameters:
565// resourceGroupName - the name of the resource group.
566// serviceName - the name of the API Management service.
567// namedValueID - identifier of the NamedValue.
568func (client NamedValueClient) ListValue(ctx context.Context, resourceGroupName string, serviceName string, namedValueID string) (result NamedValueSecretContract, err error) {
569	if tracing.IsEnabled() {
570		ctx = tracing.StartSpan(ctx, fqdn+"/NamedValueClient.ListValue")
571		defer func() {
572			sc := -1
573			if result.Response.Response != nil {
574				sc = result.Response.Response.StatusCode
575			}
576			tracing.EndSpan(ctx, sc, err)
577		}()
578	}
579	if err := validation.Validate([]validation.Validation{
580		{TargetValue: serviceName,
581			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
582				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
583				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
584		{TargetValue: namedValueID,
585			Constraints: []validation.Constraint{{Target: "namedValueID", Name: validation.MaxLength, Rule: 256, Chain: nil},
586				{Target: "namedValueID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
587		return result, validation.NewError("apimanagement.NamedValueClient", "ListValue", err.Error())
588	}
589
590	req, err := client.ListValuePreparer(ctx, resourceGroupName, serviceName, namedValueID)
591	if err != nil {
592		err = autorest.NewErrorWithError(err, "apimanagement.NamedValueClient", "ListValue", nil, "Failure preparing request")
593		return
594	}
595
596	resp, err := client.ListValueSender(req)
597	if err != nil {
598		result.Response = autorest.Response{Response: resp}
599		err = autorest.NewErrorWithError(err, "apimanagement.NamedValueClient", "ListValue", resp, "Failure sending request")
600		return
601	}
602
603	result, err = client.ListValueResponder(resp)
604	if err != nil {
605		err = autorest.NewErrorWithError(err, "apimanagement.NamedValueClient", "ListValue", resp, "Failure responding to request")
606		return
607	}
608
609	return
610}
611
612// ListValuePreparer prepares the ListValue request.
613func (client NamedValueClient) ListValuePreparer(ctx context.Context, resourceGroupName string, serviceName string, namedValueID string) (*http.Request, error) {
614	pathParameters := map[string]interface{}{
615		"namedValueId":      autorest.Encode("path", namedValueID),
616		"resourceGroupName": autorest.Encode("path", resourceGroupName),
617		"serviceName":       autorest.Encode("path", serviceName),
618		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
619	}
620
621	const APIVersion = "2021-01-01-preview"
622	queryParameters := map[string]interface{}{
623		"api-version": APIVersion,
624	}
625
626	preparer := autorest.CreatePreparer(
627		autorest.AsPost(),
628		autorest.WithBaseURL(client.BaseURI),
629		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/namedValues/{namedValueId}/listValue", pathParameters),
630		autorest.WithQueryParameters(queryParameters))
631	return preparer.Prepare((&http.Request{}).WithContext(ctx))
632}
633
634// ListValueSender sends the ListValue request. The method will close the
635// http.Response Body if it receives an error.
636func (client NamedValueClient) ListValueSender(req *http.Request) (*http.Response, error) {
637	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
638}
639
640// ListValueResponder handles the response to the ListValue request. The method always
641// closes the http.Response Body.
642func (client NamedValueClient) ListValueResponder(resp *http.Response) (result NamedValueSecretContract, err error) {
643	err = autorest.Respond(
644		resp,
645		azure.WithErrorUnlessStatusCode(http.StatusOK),
646		autorest.ByUnmarshallingJSON(&result),
647		autorest.ByClosing())
648	result.Response = autorest.Response{Response: resp}
649	return
650}
651
652// RefreshSecret refresh the secret of the named value specified by its identifier.
653// Parameters:
654// resourceGroupName - the name of the resource group.
655// serviceName - the name of the API Management service.
656// namedValueID - identifier of the NamedValue.
657func (client NamedValueClient) RefreshSecret(ctx context.Context, resourceGroupName string, serviceName string, namedValueID string) (result NamedValueRefreshSecretFuture, err error) {
658	if tracing.IsEnabled() {
659		ctx = tracing.StartSpan(ctx, fqdn+"/NamedValueClient.RefreshSecret")
660		defer func() {
661			sc := -1
662			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
663				sc = result.FutureAPI.Response().StatusCode
664			}
665			tracing.EndSpan(ctx, sc, err)
666		}()
667	}
668	if err := validation.Validate([]validation.Validation{
669		{TargetValue: serviceName,
670			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
671				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
672				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
673		{TargetValue: namedValueID,
674			Constraints: []validation.Constraint{{Target: "namedValueID", Name: validation.MaxLength, Rule: 256, Chain: nil},
675				{Target: "namedValueID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
676		return result, validation.NewError("apimanagement.NamedValueClient", "RefreshSecret", err.Error())
677	}
678
679	req, err := client.RefreshSecretPreparer(ctx, resourceGroupName, serviceName, namedValueID)
680	if err != nil {
681		err = autorest.NewErrorWithError(err, "apimanagement.NamedValueClient", "RefreshSecret", nil, "Failure preparing request")
682		return
683	}
684
685	result, err = client.RefreshSecretSender(req)
686	if err != nil {
687		err = autorest.NewErrorWithError(err, "apimanagement.NamedValueClient", "RefreshSecret", nil, "Failure sending request")
688		return
689	}
690
691	return
692}
693
694// RefreshSecretPreparer prepares the RefreshSecret request.
695func (client NamedValueClient) RefreshSecretPreparer(ctx context.Context, resourceGroupName string, serviceName string, namedValueID string) (*http.Request, error) {
696	pathParameters := map[string]interface{}{
697		"namedValueId":      autorest.Encode("path", namedValueID),
698		"resourceGroupName": autorest.Encode("path", resourceGroupName),
699		"serviceName":       autorest.Encode("path", serviceName),
700		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
701	}
702
703	const APIVersion = "2021-01-01-preview"
704	queryParameters := map[string]interface{}{
705		"api-version": APIVersion,
706	}
707
708	preparer := autorest.CreatePreparer(
709		autorest.AsPost(),
710		autorest.WithBaseURL(client.BaseURI),
711		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/namedValues/{namedValueId}/refreshSecret", pathParameters),
712		autorest.WithQueryParameters(queryParameters))
713	return preparer.Prepare((&http.Request{}).WithContext(ctx))
714}
715
716// RefreshSecretSender sends the RefreshSecret request. The method will close the
717// http.Response Body if it receives an error.
718func (client NamedValueClient) RefreshSecretSender(req *http.Request) (future NamedValueRefreshSecretFuture, err error) {
719	var resp *http.Response
720	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
721	if err != nil {
722		return
723	}
724	var azf azure.Future
725	azf, err = azure.NewFutureFromResponse(resp)
726	future.FutureAPI = &azf
727	future.Result = future.result
728	return
729}
730
731// RefreshSecretResponder handles the response to the RefreshSecret request. The method always
732// closes the http.Response Body.
733func (client NamedValueClient) RefreshSecretResponder(resp *http.Response) (result NamedValueContract, err error) {
734	err = autorest.Respond(
735		resp,
736		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
737		autorest.ByUnmarshallingJSON(&result),
738		autorest.ByClosing())
739	result.Response = autorest.Response{Response: resp}
740	return
741}
742
743// Update updates the specific named value.
744// Parameters:
745// resourceGroupName - the name of the resource group.
746// serviceName - the name of the API Management service.
747// namedValueID - identifier of the NamedValue.
748// parameters - update parameters.
749// ifMatch - eTag of the Entity. ETag should match the current entity state from the header response of the GET
750// request or it should be * for unconditional update.
751func (client NamedValueClient) Update(ctx context.Context, resourceGroupName string, serviceName string, namedValueID string, parameters NamedValueUpdateParameters, ifMatch string) (result NamedValueUpdateFuture, err error) {
752	if tracing.IsEnabled() {
753		ctx = tracing.StartSpan(ctx, fqdn+"/NamedValueClient.Update")
754		defer func() {
755			sc := -1
756			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
757				sc = result.FutureAPI.Response().StatusCode
758			}
759			tracing.EndSpan(ctx, sc, err)
760		}()
761	}
762	if err := validation.Validate([]validation.Validation{
763		{TargetValue: serviceName,
764			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
765				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
766				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
767		{TargetValue: namedValueID,
768			Constraints: []validation.Constraint{{Target: "namedValueID", Name: validation.MaxLength, Rule: 256, Chain: nil},
769				{Target: "namedValueID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
770		return result, validation.NewError("apimanagement.NamedValueClient", "Update", err.Error())
771	}
772
773	req, err := client.UpdatePreparer(ctx, resourceGroupName, serviceName, namedValueID, parameters, ifMatch)
774	if err != nil {
775		err = autorest.NewErrorWithError(err, "apimanagement.NamedValueClient", "Update", nil, "Failure preparing request")
776		return
777	}
778
779	result, err = client.UpdateSender(req)
780	if err != nil {
781		err = autorest.NewErrorWithError(err, "apimanagement.NamedValueClient", "Update", nil, "Failure sending request")
782		return
783	}
784
785	return
786}
787
788// UpdatePreparer prepares the Update request.
789func (client NamedValueClient) UpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, namedValueID string, parameters NamedValueUpdateParameters, ifMatch string) (*http.Request, error) {
790	pathParameters := map[string]interface{}{
791		"namedValueId":      autorest.Encode("path", namedValueID),
792		"resourceGroupName": autorest.Encode("path", resourceGroupName),
793		"serviceName":       autorest.Encode("path", serviceName),
794		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
795	}
796
797	const APIVersion = "2021-01-01-preview"
798	queryParameters := map[string]interface{}{
799		"api-version": APIVersion,
800	}
801
802	preparer := autorest.CreatePreparer(
803		autorest.AsContentType("application/json; charset=utf-8"),
804		autorest.AsPatch(),
805		autorest.WithBaseURL(client.BaseURI),
806		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/namedValues/{namedValueId}", pathParameters),
807		autorest.WithJSON(parameters),
808		autorest.WithQueryParameters(queryParameters),
809		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
810	return preparer.Prepare((&http.Request{}).WithContext(ctx))
811}
812
813// UpdateSender sends the Update request. The method will close the
814// http.Response Body if it receives an error.
815func (client NamedValueClient) UpdateSender(req *http.Request) (future NamedValueUpdateFuture, err error) {
816	var resp *http.Response
817	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
818	if err != nil {
819		return
820	}
821	var azf azure.Future
822	azf, err = azure.NewFutureFromResponse(resp)
823	future.FutureAPI = &azf
824	future.Result = future.result
825	return
826}
827
828// UpdateResponder handles the response to the Update request. The method always
829// closes the http.Response Body.
830func (client NamedValueClient) UpdateResponder(resp *http.Response) (result NamedValueContract, err error) {
831	err = autorest.Respond(
832		resp,
833		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
834		autorest.ByUnmarshallingJSON(&result),
835		autorest.ByClosing())
836	result.Response = autorest.Response{Response: resp}
837	return
838}
839