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// IssueClient is the apiManagement Client
30type IssueClient struct {
31	BaseClient
32}
33
34// NewIssueClient creates an instance of the IssueClient client.
35func NewIssueClient(subscriptionID string) IssueClient {
36	return NewIssueClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewIssueClientWithBaseURI creates an instance of the IssueClient client.
40func NewIssueClientWithBaseURI(baseURI string, subscriptionID string) IssueClient {
41	return IssueClient{NewWithBaseURI(baseURI, subscriptionID)}
42}
43
44// Get gets API Management issue details
45// Parameters:
46// resourceGroupName - the name of the resource group.
47// serviceName - the name of the API Management service.
48// issueID - issue identifier. Must be unique in the current API Management service instance.
49func (client IssueClient) Get(ctx context.Context, resourceGroupName string, serviceName string, issueID string) (result IssueContract, err error) {
50	if tracing.IsEnabled() {
51		ctx = tracing.StartSpan(ctx, fqdn+"/IssueClient.Get")
52		defer func() {
53			sc := -1
54			if result.Response.Response != nil {
55				sc = result.Response.Response.StatusCode
56			}
57			tracing.EndSpan(ctx, sc, err)
58		}()
59	}
60	if err := validation.Validate([]validation.Validation{
61		{TargetValue: serviceName,
62			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
63				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
64				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
65		{TargetValue: issueID,
66			Constraints: []validation.Constraint{{Target: "issueID", Name: validation.MaxLength, Rule: 256, Chain: nil},
67				{Target: "issueID", Name: validation.MinLength, Rule: 1, Chain: nil},
68				{Target: "issueID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
69		return result, validation.NewError("apimanagement.IssueClient", "Get", err.Error())
70	}
71
72	req, err := client.GetPreparer(ctx, resourceGroupName, serviceName, issueID)
73	if err != nil {
74		err = autorest.NewErrorWithError(err, "apimanagement.IssueClient", "Get", nil, "Failure preparing request")
75		return
76	}
77
78	resp, err := client.GetSender(req)
79	if err != nil {
80		result.Response = autorest.Response{Response: resp}
81		err = autorest.NewErrorWithError(err, "apimanagement.IssueClient", "Get", resp, "Failure sending request")
82		return
83	}
84
85	result, err = client.GetResponder(resp)
86	if err != nil {
87		err = autorest.NewErrorWithError(err, "apimanagement.IssueClient", "Get", resp, "Failure responding to request")
88	}
89
90	return
91}
92
93// GetPreparer prepares the Get request.
94func (client IssueClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, issueID string) (*http.Request, error) {
95	pathParameters := map[string]interface{}{
96		"issueId":           autorest.Encode("path", issueID),
97		"resourceGroupName": autorest.Encode("path", resourceGroupName),
98		"serviceName":       autorest.Encode("path", serviceName),
99		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
100	}
101
102	const APIVersion = "2019-01-01"
103	queryParameters := map[string]interface{}{
104		"api-version": APIVersion,
105	}
106
107	preparer := autorest.CreatePreparer(
108		autorest.AsGet(),
109		autorest.WithBaseURL(client.BaseURI),
110		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/issues/{issueId}", pathParameters),
111		autorest.WithQueryParameters(queryParameters))
112	return preparer.Prepare((&http.Request{}).WithContext(ctx))
113}
114
115// GetSender sends the Get request. The method will close the
116// http.Response Body if it receives an error.
117func (client IssueClient) GetSender(req *http.Request) (*http.Response, error) {
118	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
119	return autorest.SendWithSender(client, req, sd...)
120}
121
122// GetResponder handles the response to the Get request. The method always
123// closes the http.Response Body.
124func (client IssueClient) GetResponder(resp *http.Response) (result IssueContract, err error) {
125	err = autorest.Respond(
126		resp,
127		client.ByInspecting(),
128		azure.WithErrorUnlessStatusCode(http.StatusOK),
129		autorest.ByUnmarshallingJSON(&result),
130		autorest.ByClosing())
131	result.Response = autorest.Response{Response: resp}
132	return
133}
134
135// ListByService lists a collection of issues in the specified service instance.
136// Parameters:
137// resourceGroupName - the name of the resource group.
138// serviceName - the name of the API Management service.
139// filter - |   Field     |     Usage     |     Supported operators     |     Supported functions
140// |</br>|-------------|-------------|-------------|-------------|</br>| name | filter | ge, le, eq, ne, gt, lt
141// | substringof, contains, startswith, endswith | </br>| apiId | filter | ge, le, eq, ne, gt, lt |
142// substringof, contains, startswith, endswith | </br>| title | filter | ge, le, eq, ne, gt, lt | substringof,
143// contains, startswith, endswith | </br>| description | filter | ge, le, eq, ne, gt, lt | substringof,
144// contains, startswith, endswith | </br>| authorName | filter | ge, le, eq, ne, gt, lt | substringof,
145// contains, startswith, endswith | </br>| state | filter | eq |     | </br>
146// top - number of records to return.
147// skip - number of records to skip.
148func (client IssueClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result IssueCollectionPage, err error) {
149	if tracing.IsEnabled() {
150		ctx = tracing.StartSpan(ctx, fqdn+"/IssueClient.ListByService")
151		defer func() {
152			sc := -1
153			if result.ic.Response.Response != nil {
154				sc = result.ic.Response.Response.StatusCode
155			}
156			tracing.EndSpan(ctx, sc, err)
157		}()
158	}
159	if err := validation.Validate([]validation.Validation{
160		{TargetValue: serviceName,
161			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
162				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
163				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
164		{TargetValue: top,
165			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
166				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}}}}},
167		{TargetValue: skip,
168			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
169				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: 0, Chain: nil}}}}}}); err != nil {
170		return result, validation.NewError("apimanagement.IssueClient", "ListByService", err.Error())
171	}
172
173	result.fn = client.listByServiceNextResults
174	req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName, filter, top, skip)
175	if err != nil {
176		err = autorest.NewErrorWithError(err, "apimanagement.IssueClient", "ListByService", nil, "Failure preparing request")
177		return
178	}
179
180	resp, err := client.ListByServiceSender(req)
181	if err != nil {
182		result.ic.Response = autorest.Response{Response: resp}
183		err = autorest.NewErrorWithError(err, "apimanagement.IssueClient", "ListByService", resp, "Failure sending request")
184		return
185	}
186
187	result.ic, err = client.ListByServiceResponder(resp)
188	if err != nil {
189		err = autorest.NewErrorWithError(err, "apimanagement.IssueClient", "ListByService", resp, "Failure responding to request")
190	}
191
192	return
193}
194
195// ListByServicePreparer prepares the ListByService request.
196func (client IssueClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (*http.Request, error) {
197	pathParameters := map[string]interface{}{
198		"resourceGroupName": autorest.Encode("path", resourceGroupName),
199		"serviceName":       autorest.Encode("path", serviceName),
200		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
201	}
202
203	const APIVersion = "2019-01-01"
204	queryParameters := map[string]interface{}{
205		"api-version": APIVersion,
206	}
207	if len(filter) > 0 {
208		queryParameters["$filter"] = autorest.Encode("query", filter)
209	}
210	if top != nil {
211		queryParameters["$top"] = autorest.Encode("query", *top)
212	}
213	if skip != nil {
214		queryParameters["$skip"] = autorest.Encode("query", *skip)
215	}
216
217	preparer := autorest.CreatePreparer(
218		autorest.AsGet(),
219		autorest.WithBaseURL(client.BaseURI),
220		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/issues", pathParameters),
221		autorest.WithQueryParameters(queryParameters))
222	return preparer.Prepare((&http.Request{}).WithContext(ctx))
223}
224
225// ListByServiceSender sends the ListByService request. The method will close the
226// http.Response Body if it receives an error.
227func (client IssueClient) ListByServiceSender(req *http.Request) (*http.Response, error) {
228	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
229	return autorest.SendWithSender(client, req, sd...)
230}
231
232// ListByServiceResponder handles the response to the ListByService request. The method always
233// closes the http.Response Body.
234func (client IssueClient) ListByServiceResponder(resp *http.Response) (result IssueCollection, err error) {
235	err = autorest.Respond(
236		resp,
237		client.ByInspecting(),
238		azure.WithErrorUnlessStatusCode(http.StatusOK),
239		autorest.ByUnmarshallingJSON(&result),
240		autorest.ByClosing())
241	result.Response = autorest.Response{Response: resp}
242	return
243}
244
245// listByServiceNextResults retrieves the next set of results, if any.
246func (client IssueClient) listByServiceNextResults(ctx context.Context, lastResults IssueCollection) (result IssueCollection, err error) {
247	req, err := lastResults.issueCollectionPreparer(ctx)
248	if err != nil {
249		return result, autorest.NewErrorWithError(err, "apimanagement.IssueClient", "listByServiceNextResults", nil, "Failure preparing next results request")
250	}
251	if req == nil {
252		return
253	}
254	resp, err := client.ListByServiceSender(req)
255	if err != nil {
256		result.Response = autorest.Response{Response: resp}
257		return result, autorest.NewErrorWithError(err, "apimanagement.IssueClient", "listByServiceNextResults", resp, "Failure sending next results request")
258	}
259	result, err = client.ListByServiceResponder(resp)
260	if err != nil {
261		err = autorest.NewErrorWithError(err, "apimanagement.IssueClient", "listByServiceNextResults", resp, "Failure responding to next results request")
262	}
263	return
264}
265
266// ListByServiceComplete enumerates all values, automatically crossing page boundaries as required.
267func (client IssueClient) ListByServiceComplete(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result IssueCollectionIterator, err error) {
268	if tracing.IsEnabled() {
269		ctx = tracing.StartSpan(ctx, fqdn+"/IssueClient.ListByService")
270		defer func() {
271			sc := -1
272			if result.Response().Response.Response != nil {
273				sc = result.page.Response().Response.Response.StatusCode
274			}
275			tracing.EndSpan(ctx, sc, err)
276		}()
277	}
278	result.page, err = client.ListByService(ctx, resourceGroupName, serviceName, filter, top, skip)
279	return
280}
281