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// APIIssueClient is the apiManagement Client
30type APIIssueClient struct {
31	BaseClient
32}
33
34// NewAPIIssueClient creates an instance of the APIIssueClient client.
35func NewAPIIssueClient(subscriptionID string) APIIssueClient {
36	return NewAPIIssueClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewAPIIssueClientWithBaseURI creates an instance of the APIIssueClient 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 NewAPIIssueClientWithBaseURI(baseURI string, subscriptionID string) APIIssueClient {
42	return APIIssueClient{NewWithBaseURI(baseURI, subscriptionID)}
43}
44
45// CreateOrUpdate creates a new Issue for an API or updates an existing one.
46// Parameters:
47// resourceGroupName - the name of the resource group.
48// serviceName - the name of the API Management service.
49// apiid - API identifier. Must be unique in the current API Management service instance.
50// issueID - issue identifier. Must be unique in the current API Management service instance.
51// parameters - create parameters.
52// ifMatch - eTag of the Issue Entity. ETag should match the current entity state from the header response of
53// the GET request or it should be * for unconditional update.
54func (client APIIssueClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string, parameters IssueContract, ifMatch string) (result IssueContract, err error) {
55	if tracing.IsEnabled() {
56		ctx = tracing.StartSpan(ctx, fqdn+"/APIIssueClient.CreateOrUpdate")
57		defer func() {
58			sc := -1
59			if result.Response.Response != nil {
60				sc = result.Response.Response.StatusCode
61			}
62			tracing.EndSpan(ctx, sc, err)
63		}()
64	}
65	if err := validation.Validate([]validation.Validation{
66		{TargetValue: serviceName,
67			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
68				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
69				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
70		{TargetValue: apiid,
71			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil},
72				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil},
73				{Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
74		{TargetValue: issueID,
75			Constraints: []validation.Constraint{{Target: "issueID", Name: validation.MaxLength, Rule: 256, Chain: nil},
76				{Target: "issueID", Name: validation.MinLength, Rule: 1, Chain: nil},
77				{Target: "issueID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
78		{TargetValue: parameters,
79			Constraints: []validation.Constraint{{Target: "parameters.IssueContractProperties", Name: validation.Null, Rule: false,
80				Chain: []validation.Constraint{{Target: "parameters.IssueContractProperties.Title", Name: validation.Null, Rule: true, Chain: nil},
81					{Target: "parameters.IssueContractProperties.Description", Name: validation.Null, Rule: true, Chain: nil},
82					{Target: "parameters.IssueContractProperties.UserID", Name: validation.Null, Rule: true, Chain: nil},
83				}}}}}); err != nil {
84		return result, validation.NewError("apimanagement.APIIssueClient", "CreateOrUpdate", err.Error())
85	}
86
87	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, apiid, issueID, parameters, ifMatch)
88	if err != nil {
89		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueClient", "CreateOrUpdate", nil, "Failure preparing request")
90		return
91	}
92
93	resp, err := client.CreateOrUpdateSender(req)
94	if err != nil {
95		result.Response = autorest.Response{Response: resp}
96		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueClient", "CreateOrUpdate", resp, "Failure sending request")
97		return
98	}
99
100	result, err = client.CreateOrUpdateResponder(resp)
101	if err != nil {
102		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueClient", "CreateOrUpdate", resp, "Failure responding to request")
103		return
104	}
105
106	return
107}
108
109// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
110func (client APIIssueClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string, parameters IssueContract, ifMatch string) (*http.Request, error) {
111	pathParameters := map[string]interface{}{
112		"apiId":             autorest.Encode("path", apiid),
113		"issueId":           autorest.Encode("path", issueID),
114		"resourceGroupName": autorest.Encode("path", resourceGroupName),
115		"serviceName":       autorest.Encode("path", serviceName),
116		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
117	}
118
119	const APIVersion = "2017-03-01"
120	queryParameters := map[string]interface{}{
121		"api-version": APIVersion,
122	}
123
124	preparer := autorest.CreatePreparer(
125		autorest.AsContentType("application/json; charset=utf-8"),
126		autorest.AsPut(),
127		autorest.WithBaseURL(client.BaseURI),
128		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/issues/{issueId}", pathParameters),
129		autorest.WithJSON(parameters),
130		autorest.WithQueryParameters(queryParameters))
131	if len(ifMatch) > 0 {
132		preparer = autorest.DecoratePreparer(preparer,
133			autorest.WithHeader("If-Match", autorest.String(ifMatch)))
134	}
135	return preparer.Prepare((&http.Request{}).WithContext(ctx))
136}
137
138// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
139// http.Response Body if it receives an error.
140func (client APIIssueClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
141	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
142}
143
144// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
145// closes the http.Response Body.
146func (client APIIssueClient) CreateOrUpdateResponder(resp *http.Response) (result IssueContract, err error) {
147	err = autorest.Respond(
148		resp,
149		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
150		autorest.ByUnmarshallingJSON(&result),
151		autorest.ByClosing())
152	result.Response = autorest.Response{Response: resp}
153	return
154}
155
156// Delete deletes the specified Issue from an API.
157// Parameters:
158// resourceGroupName - the name of the resource group.
159// serviceName - the name of the API Management service.
160// apiid - API identifier. Must be unique in the current API Management service instance.
161// issueID - issue identifier. Must be unique in the current API Management service instance.
162// ifMatch - eTag of the Issue Entity. ETag should match the current entity state from the header response of
163// the GET request or it should be * for unconditional update.
164func (client APIIssueClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string, ifMatch string) (result autorest.Response, err error) {
165	if tracing.IsEnabled() {
166		ctx = tracing.StartSpan(ctx, fqdn+"/APIIssueClient.Delete")
167		defer func() {
168			sc := -1
169			if result.Response != nil {
170				sc = result.Response.StatusCode
171			}
172			tracing.EndSpan(ctx, sc, err)
173		}()
174	}
175	if err := validation.Validate([]validation.Validation{
176		{TargetValue: serviceName,
177			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
178				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
179				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
180		{TargetValue: apiid,
181			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil},
182				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil},
183				{Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
184		{TargetValue: issueID,
185			Constraints: []validation.Constraint{{Target: "issueID", Name: validation.MaxLength, Rule: 256, Chain: nil},
186				{Target: "issueID", Name: validation.MinLength, Rule: 1, Chain: nil},
187				{Target: "issueID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
188		return result, validation.NewError("apimanagement.APIIssueClient", "Delete", err.Error())
189	}
190
191	req, err := client.DeletePreparer(ctx, resourceGroupName, serviceName, apiid, issueID, ifMatch)
192	if err != nil {
193		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueClient", "Delete", nil, "Failure preparing request")
194		return
195	}
196
197	resp, err := client.DeleteSender(req)
198	if err != nil {
199		result.Response = resp
200		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueClient", "Delete", resp, "Failure sending request")
201		return
202	}
203
204	result, err = client.DeleteResponder(resp)
205	if err != nil {
206		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueClient", "Delete", resp, "Failure responding to request")
207		return
208	}
209
210	return
211}
212
213// DeletePreparer prepares the Delete request.
214func (client APIIssueClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string, ifMatch string) (*http.Request, error) {
215	pathParameters := map[string]interface{}{
216		"apiId":             autorest.Encode("path", apiid),
217		"issueId":           autorest.Encode("path", issueID),
218		"resourceGroupName": autorest.Encode("path", resourceGroupName),
219		"serviceName":       autorest.Encode("path", serviceName),
220		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
221	}
222
223	const APIVersion = "2017-03-01"
224	queryParameters := map[string]interface{}{
225		"api-version": APIVersion,
226	}
227
228	preparer := autorest.CreatePreparer(
229		autorest.AsDelete(),
230		autorest.WithBaseURL(client.BaseURI),
231		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/issues/{issueId}", pathParameters),
232		autorest.WithQueryParameters(queryParameters),
233		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
234	return preparer.Prepare((&http.Request{}).WithContext(ctx))
235}
236
237// DeleteSender sends the Delete request. The method will close the
238// http.Response Body if it receives an error.
239func (client APIIssueClient) DeleteSender(req *http.Request) (*http.Response, error) {
240	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
241}
242
243// DeleteResponder handles the response to the Delete request. The method always
244// closes the http.Response Body.
245func (client APIIssueClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
246	err = autorest.Respond(
247		resp,
248		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
249		autorest.ByClosing())
250	result.Response = resp
251	return
252}
253
254// Get gets the details of the Issue for an API specified by its identifier.
255// Parameters:
256// resourceGroupName - the name of the resource group.
257// serviceName - the name of the API Management service.
258// apiid - API identifier. Must be unique in the current API Management service instance.
259// issueID - issue identifier. Must be unique in the current API Management service instance.
260func (client APIIssueClient) Get(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string) (result IssueContract, err error) {
261	if tracing.IsEnabled() {
262		ctx = tracing.StartSpan(ctx, fqdn+"/APIIssueClient.Get")
263		defer func() {
264			sc := -1
265			if result.Response.Response != nil {
266				sc = result.Response.Response.StatusCode
267			}
268			tracing.EndSpan(ctx, sc, err)
269		}()
270	}
271	if err := validation.Validate([]validation.Validation{
272		{TargetValue: serviceName,
273			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
274				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
275				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
276		{TargetValue: apiid,
277			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil},
278				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil},
279				{Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
280		{TargetValue: issueID,
281			Constraints: []validation.Constraint{{Target: "issueID", Name: validation.MaxLength, Rule: 256, Chain: nil},
282				{Target: "issueID", Name: validation.MinLength, Rule: 1, Chain: nil},
283				{Target: "issueID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
284		return result, validation.NewError("apimanagement.APIIssueClient", "Get", err.Error())
285	}
286
287	req, err := client.GetPreparer(ctx, resourceGroupName, serviceName, apiid, issueID)
288	if err != nil {
289		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueClient", "Get", nil, "Failure preparing request")
290		return
291	}
292
293	resp, err := client.GetSender(req)
294	if err != nil {
295		result.Response = autorest.Response{Response: resp}
296		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueClient", "Get", resp, "Failure sending request")
297		return
298	}
299
300	result, err = client.GetResponder(resp)
301	if err != nil {
302		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueClient", "Get", resp, "Failure responding to request")
303		return
304	}
305
306	return
307}
308
309// GetPreparer prepares the Get request.
310func (client APIIssueClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string) (*http.Request, error) {
311	pathParameters := map[string]interface{}{
312		"apiId":             autorest.Encode("path", apiid),
313		"issueId":           autorest.Encode("path", issueID),
314		"resourceGroupName": autorest.Encode("path", resourceGroupName),
315		"serviceName":       autorest.Encode("path", serviceName),
316		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
317	}
318
319	const APIVersion = "2017-03-01"
320	queryParameters := map[string]interface{}{
321		"api-version": APIVersion,
322	}
323
324	preparer := autorest.CreatePreparer(
325		autorest.AsGet(),
326		autorest.WithBaseURL(client.BaseURI),
327		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/issues/{issueId}", pathParameters),
328		autorest.WithQueryParameters(queryParameters))
329	return preparer.Prepare((&http.Request{}).WithContext(ctx))
330}
331
332// GetSender sends the Get request. The method will close the
333// http.Response Body if it receives an error.
334func (client APIIssueClient) GetSender(req *http.Request) (*http.Response, error) {
335	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
336}
337
338// GetResponder handles the response to the Get request. The method always
339// closes the http.Response Body.
340func (client APIIssueClient) GetResponder(resp *http.Response) (result IssueContract, err error) {
341	err = autorest.Respond(
342		resp,
343		azure.WithErrorUnlessStatusCode(http.StatusOK),
344		autorest.ByUnmarshallingJSON(&result),
345		autorest.ByClosing())
346	result.Response = autorest.Response{Response: resp}
347	return
348}
349
350// Head gets the entity state (Etag) version of the Issue for an API specified by its identifier.
351// Parameters:
352// resourceGroupName - the name of the resource group.
353// serviceName - the name of the API Management service.
354// apiid - API identifier. Must be unique in the current API Management service instance.
355// issueID - issue identifier. Must be unique in the current API Management service instance.
356func (client APIIssueClient) Head(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string) (result autorest.Response, err error) {
357	if tracing.IsEnabled() {
358		ctx = tracing.StartSpan(ctx, fqdn+"/APIIssueClient.Head")
359		defer func() {
360			sc := -1
361			if result.Response != nil {
362				sc = result.Response.StatusCode
363			}
364			tracing.EndSpan(ctx, sc, err)
365		}()
366	}
367	if err := validation.Validate([]validation.Validation{
368		{TargetValue: serviceName,
369			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
370				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
371				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
372		{TargetValue: apiid,
373			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil},
374				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil},
375				{Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
376		{TargetValue: issueID,
377			Constraints: []validation.Constraint{{Target: "issueID", Name: validation.MaxLength, Rule: 256, Chain: nil},
378				{Target: "issueID", Name: validation.MinLength, Rule: 1, Chain: nil},
379				{Target: "issueID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
380		return result, validation.NewError("apimanagement.APIIssueClient", "Head", err.Error())
381	}
382
383	req, err := client.HeadPreparer(ctx, resourceGroupName, serviceName, apiid, issueID)
384	if err != nil {
385		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueClient", "Head", nil, "Failure preparing request")
386		return
387	}
388
389	resp, err := client.HeadSender(req)
390	if err != nil {
391		result.Response = resp
392		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueClient", "Head", resp, "Failure sending request")
393		return
394	}
395
396	result, err = client.HeadResponder(resp)
397	if err != nil {
398		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueClient", "Head", resp, "Failure responding to request")
399		return
400	}
401
402	return
403}
404
405// HeadPreparer prepares the Head request.
406func (client APIIssueClient) HeadPreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string) (*http.Request, error) {
407	pathParameters := map[string]interface{}{
408		"apiId":             autorest.Encode("path", apiid),
409		"issueId":           autorest.Encode("path", issueID),
410		"resourceGroupName": autorest.Encode("path", resourceGroupName),
411		"serviceName":       autorest.Encode("path", serviceName),
412		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
413	}
414
415	const APIVersion = "2017-03-01"
416	queryParameters := map[string]interface{}{
417		"api-version": APIVersion,
418	}
419
420	preparer := autorest.CreatePreparer(
421		autorest.AsHead(),
422		autorest.WithBaseURL(client.BaseURI),
423		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/issues/{issueId}", pathParameters),
424		autorest.WithQueryParameters(queryParameters))
425	return preparer.Prepare((&http.Request{}).WithContext(ctx))
426}
427
428// HeadSender sends the Head request. The method will close the
429// http.Response Body if it receives an error.
430func (client APIIssueClient) HeadSender(req *http.Request) (*http.Response, error) {
431	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
432}
433
434// HeadResponder handles the response to the Head request. The method always
435// closes the http.Response Body.
436func (client APIIssueClient) HeadResponder(resp *http.Response) (result autorest.Response, err error) {
437	err = autorest.Respond(
438		resp,
439		azure.WithErrorUnlessStatusCode(http.StatusOK),
440		autorest.ByClosing())
441	result.Response = resp
442	return
443}
444