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