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	}
104
105	return
106}
107
108// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
109func (client APIIssueClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string, parameters IssueContract, ifMatch string) (*http.Request, error) {
110	pathParameters := map[string]interface{}{
111		"apiId":             autorest.Encode("path", apiid),
112		"issueId":           autorest.Encode("path", issueID),
113		"resourceGroupName": autorest.Encode("path", resourceGroupName),
114		"serviceName":       autorest.Encode("path", serviceName),
115		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
116	}
117
118	const APIVersion = "2017-03-01"
119	queryParameters := map[string]interface{}{
120		"api-version": APIVersion,
121	}
122
123	preparer := autorest.CreatePreparer(
124		autorest.AsContentType("application/json; charset=utf-8"),
125		autorest.AsPut(),
126		autorest.WithBaseURL(client.BaseURI),
127		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/issues/{issueId}", pathParameters),
128		autorest.WithJSON(parameters),
129		autorest.WithQueryParameters(queryParameters))
130	if len(ifMatch) > 0 {
131		preparer = autorest.DecoratePreparer(preparer,
132			autorest.WithHeader("If-Match", autorest.String(ifMatch)))
133	}
134	return preparer.Prepare((&http.Request{}).WithContext(ctx))
135}
136
137// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
138// http.Response Body if it receives an error.
139func (client APIIssueClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
140	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
141}
142
143// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
144// closes the http.Response Body.
145func (client APIIssueClient) CreateOrUpdateResponder(resp *http.Response) (result IssueContract, err error) {
146	err = autorest.Respond(
147		resp,
148		client.ByInspecting(),
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	}
208
209	return
210}
211
212// DeletePreparer prepares the Delete request.
213func (client APIIssueClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string, ifMatch string) (*http.Request, error) {
214	pathParameters := map[string]interface{}{
215		"apiId":             autorest.Encode("path", apiid),
216		"issueId":           autorest.Encode("path", issueID),
217		"resourceGroupName": autorest.Encode("path", resourceGroupName),
218		"serviceName":       autorest.Encode("path", serviceName),
219		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
220	}
221
222	const APIVersion = "2017-03-01"
223	queryParameters := map[string]interface{}{
224		"api-version": APIVersion,
225	}
226
227	preparer := autorest.CreatePreparer(
228		autorest.AsDelete(),
229		autorest.WithBaseURL(client.BaseURI),
230		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/issues/{issueId}", pathParameters),
231		autorest.WithQueryParameters(queryParameters),
232		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
233	return preparer.Prepare((&http.Request{}).WithContext(ctx))
234}
235
236// DeleteSender sends the Delete request. The method will close the
237// http.Response Body if it receives an error.
238func (client APIIssueClient) DeleteSender(req *http.Request) (*http.Response, error) {
239	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
240}
241
242// DeleteResponder handles the response to the Delete request. The method always
243// closes the http.Response Body.
244func (client APIIssueClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
245	err = autorest.Respond(
246		resp,
247		client.ByInspecting(),
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	}
304
305	return
306}
307
308// GetPreparer prepares the Get request.
309func (client APIIssueClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string) (*http.Request, error) {
310	pathParameters := map[string]interface{}{
311		"apiId":             autorest.Encode("path", apiid),
312		"issueId":           autorest.Encode("path", issueID),
313		"resourceGroupName": autorest.Encode("path", resourceGroupName),
314		"serviceName":       autorest.Encode("path", serviceName),
315		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
316	}
317
318	const APIVersion = "2017-03-01"
319	queryParameters := map[string]interface{}{
320		"api-version": APIVersion,
321	}
322
323	preparer := autorest.CreatePreparer(
324		autorest.AsGet(),
325		autorest.WithBaseURL(client.BaseURI),
326		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/issues/{issueId}", pathParameters),
327		autorest.WithQueryParameters(queryParameters))
328	return preparer.Prepare((&http.Request{}).WithContext(ctx))
329}
330
331// GetSender sends the Get request. The method will close the
332// http.Response Body if it receives an error.
333func (client APIIssueClient) GetSender(req *http.Request) (*http.Response, error) {
334	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
335}
336
337// GetResponder handles the response to the Get request. The method always
338// closes the http.Response Body.
339func (client APIIssueClient) GetResponder(resp *http.Response) (result IssueContract, err error) {
340	err = autorest.Respond(
341		resp,
342		client.ByInspecting(),
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	}
400
401	return
402}
403
404// HeadPreparer prepares the Head request.
405func (client APIIssueClient) HeadPreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string) (*http.Request, error) {
406	pathParameters := map[string]interface{}{
407		"apiId":             autorest.Encode("path", apiid),
408		"issueId":           autorest.Encode("path", issueID),
409		"resourceGroupName": autorest.Encode("path", resourceGroupName),
410		"serviceName":       autorest.Encode("path", serviceName),
411		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
412	}
413
414	const APIVersion = "2017-03-01"
415	queryParameters := map[string]interface{}{
416		"api-version": APIVersion,
417	}
418
419	preparer := autorest.CreatePreparer(
420		autorest.AsHead(),
421		autorest.WithBaseURL(client.BaseURI),
422		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/issues/{issueId}", pathParameters),
423		autorest.WithQueryParameters(queryParameters))
424	return preparer.Prepare((&http.Request{}).WithContext(ctx))
425}
426
427// HeadSender sends the Head request. The method will close the
428// http.Response Body if it receives an error.
429func (client APIIssueClient) HeadSender(req *http.Request) (*http.Response, error) {
430	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
431}
432
433// HeadResponder handles the response to the Head request. The method always
434// closes the http.Response Body.
435func (client APIIssueClient) HeadResponder(resp *http.Response) (result autorest.Response, err error) {
436	err = autorest.Respond(
437		resp,
438		client.ByInspecting(),
439		azure.WithErrorUnlessStatusCode(http.StatusOK),
440		autorest.ByClosing())
441	result.Response = resp
442	return
443}
444