1 package authoring
2
3
4
5
6
7
8
9 import (
10 "context"
11 "github.com/Azure/go-autorest/autorest"
12 "github.com/Azure/go-autorest/autorest/azure"
13 "github.com/Azure/go-autorest/autorest/validation"
14 "github.com/Azure/go-autorest/tracing"
15 "github.com/gofrs/uuid"
16 "net/http"
17 )
18
19
20 type AzureAccountsClient struct {
21 BaseClient
22 }
23
24
25 func NewAzureAccountsClient(endpoint string) AzureAccountsClient {
26 return AzureAccountsClient{New(endpoint)}
27 }
28
29
30
31
32
33 func (client AzureAccountsClient) AssignToApp(ctx context.Context, appID uuid.UUID, azureAccountInfoObject *AzureAccountInfoObject) (result OperationStatus, err error) {
34 if tracing.IsEnabled() {
35 ctx = tracing.StartSpan(ctx, fqdn+"/AzureAccountsClient.AssignToApp")
36 defer func() {
37 sc := -1
38 if result.Response.Response != nil {
39 sc = result.Response.Response.StatusCode
40 }
41 tracing.EndSpan(ctx, sc, err)
42 }()
43 }
44 if err := validation.Validate([]validation.Validation{
45 {TargetValue: azureAccountInfoObject,
46 Constraints: []validation.Constraint{{Target: "azureAccountInfoObject", Name: validation.Null, Rule: false,
47 Chain: []validation.Constraint{{Target: "azureAccountInfoObject.AzureSubscriptionID", Name: validation.Null, Rule: true, Chain: nil},
48 {Target: "azureAccountInfoObject.ResourceGroup", Name: validation.Null, Rule: true, Chain: nil},
49 {Target: "azureAccountInfoObject.AccountName", Name: validation.Null, Rule: true, Chain: nil},
50 }}}}}); err != nil {
51 return result, validation.NewError("authoring.AzureAccountsClient", "AssignToApp", err.Error())
52 }
53
54 req, err := client.AssignToAppPreparer(ctx, appID, azureAccountInfoObject)
55 if err != nil {
56 err = autorest.NewErrorWithError(err, "authoring.AzureAccountsClient", "AssignToApp", nil, "Failure preparing request")
57 return
58 }
59
60 resp, err := client.AssignToAppSender(req)
61 if err != nil {
62 result.Response = autorest.Response{Response: resp}
63 err = autorest.NewErrorWithError(err, "authoring.AzureAccountsClient", "AssignToApp", resp, "Failure sending request")
64 return
65 }
66
67 result, err = client.AssignToAppResponder(resp)
68 if err != nil {
69 err = autorest.NewErrorWithError(err, "authoring.AzureAccountsClient", "AssignToApp", resp, "Failure responding to request")
70 return
71 }
72
73 return
74 }
75
76
77 func (client AzureAccountsClient) AssignToAppPreparer(ctx context.Context, appID uuid.UUID, azureAccountInfoObject *AzureAccountInfoObject) (*http.Request, error) {
78 urlParameters := map[string]interface{}{
79 "Endpoint": client.Endpoint,
80 }
81
82 pathParameters := map[string]interface{}{
83 "appId": autorest.Encode("path", appID),
84 }
85
86 preparer := autorest.CreatePreparer(
87 autorest.AsContentType("application/json; charset=utf-8"),
88 autorest.AsPost(),
89 autorest.WithCustomBaseURL("{Endpoint}/luis/api/v2.0", urlParameters),
90 autorest.WithPathParameters("/apps/{appId}/azureaccounts", pathParameters))
91 if azureAccountInfoObject != nil {
92 preparer = autorest.DecoratePreparer(preparer,
93 autorest.WithJSON(azureAccountInfoObject))
94 }
95 return preparer.Prepare((&http.Request{}).WithContext(ctx))
96 }
97
98
99
100 func (client AzureAccountsClient) AssignToAppSender(req *http.Request) (*http.Response, error) {
101 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
102 }
103
104
105
106 func (client AzureAccountsClient) AssignToAppResponder(resp *http.Response) (result OperationStatus, err error) {
107 err = autorest.Respond(
108 resp,
109 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
110 autorest.ByUnmarshallingJSON(&result),
111 autorest.ByClosing())
112 result.Response = autorest.Response{Response: resp}
113 return
114 }
115
116
117
118
119 func (client AzureAccountsClient) GetAssigned(ctx context.Context, appID uuid.UUID) (result ListAzureAccountInfoObject, err error) {
120 if tracing.IsEnabled() {
121 ctx = tracing.StartSpan(ctx, fqdn+"/AzureAccountsClient.GetAssigned")
122 defer func() {
123 sc := -1
124 if result.Response.Response != nil {
125 sc = result.Response.Response.StatusCode
126 }
127 tracing.EndSpan(ctx, sc, err)
128 }()
129 }
130 req, err := client.GetAssignedPreparer(ctx, appID)
131 if err != nil {
132 err = autorest.NewErrorWithError(err, "authoring.AzureAccountsClient", "GetAssigned", nil, "Failure preparing request")
133 return
134 }
135
136 resp, err := client.GetAssignedSender(req)
137 if err != nil {
138 result.Response = autorest.Response{Response: resp}
139 err = autorest.NewErrorWithError(err, "authoring.AzureAccountsClient", "GetAssigned", resp, "Failure sending request")
140 return
141 }
142
143 result, err = client.GetAssignedResponder(resp)
144 if err != nil {
145 err = autorest.NewErrorWithError(err, "authoring.AzureAccountsClient", "GetAssigned", resp, "Failure responding to request")
146 return
147 }
148
149 return
150 }
151
152
153 func (client AzureAccountsClient) GetAssignedPreparer(ctx context.Context, appID uuid.UUID) (*http.Request, error) {
154 urlParameters := map[string]interface{}{
155 "Endpoint": client.Endpoint,
156 }
157
158 pathParameters := map[string]interface{}{
159 "appId": autorest.Encode("path", appID),
160 }
161
162 preparer := autorest.CreatePreparer(
163 autorest.AsGet(),
164 autorest.WithCustomBaseURL("{Endpoint}/luis/api/v2.0", urlParameters),
165 autorest.WithPathParameters("/apps/{appId}/azureaccounts", pathParameters))
166 return preparer.Prepare((&http.Request{}).WithContext(ctx))
167 }
168
169
170
171 func (client AzureAccountsClient) GetAssignedSender(req *http.Request) (*http.Response, error) {
172 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
173 }
174
175
176
177 func (client AzureAccountsClient) GetAssignedResponder(resp *http.Response) (result ListAzureAccountInfoObject, err error) {
178 err = autorest.Respond(
179 resp,
180 azure.WithErrorUnlessStatusCode(http.StatusOK),
181 autorest.ByUnmarshallingJSON(&result.Value),
182 autorest.ByClosing())
183 result.Response = autorest.Response{Response: resp}
184 return
185 }
186
187
188 func (client AzureAccountsClient) ListUserLUISAccounts(ctx context.Context) (result ListAzureAccountInfoObject, err error) {
189 if tracing.IsEnabled() {
190 ctx = tracing.StartSpan(ctx, fqdn+"/AzureAccountsClient.ListUserLUISAccounts")
191 defer func() {
192 sc := -1
193 if result.Response.Response != nil {
194 sc = result.Response.Response.StatusCode
195 }
196 tracing.EndSpan(ctx, sc, err)
197 }()
198 }
199 req, err := client.ListUserLUISAccountsPreparer(ctx)
200 if err != nil {
201 err = autorest.NewErrorWithError(err, "authoring.AzureAccountsClient", "ListUserLUISAccounts", nil, "Failure preparing request")
202 return
203 }
204
205 resp, err := client.ListUserLUISAccountsSender(req)
206 if err != nil {
207 result.Response = autorest.Response{Response: resp}
208 err = autorest.NewErrorWithError(err, "authoring.AzureAccountsClient", "ListUserLUISAccounts", resp, "Failure sending request")
209 return
210 }
211
212 result, err = client.ListUserLUISAccountsResponder(resp)
213 if err != nil {
214 err = autorest.NewErrorWithError(err, "authoring.AzureAccountsClient", "ListUserLUISAccounts", resp, "Failure responding to request")
215 return
216 }
217
218 return
219 }
220
221
222 func (client AzureAccountsClient) ListUserLUISAccountsPreparer(ctx context.Context) (*http.Request, error) {
223 urlParameters := map[string]interface{}{
224 "Endpoint": client.Endpoint,
225 }
226
227 preparer := autorest.CreatePreparer(
228 autorest.AsGet(),
229 autorest.WithCustomBaseURL("{Endpoint}/luis/api/v2.0", urlParameters),
230 autorest.WithPath("/azureaccounts"))
231 return preparer.Prepare((&http.Request{}).WithContext(ctx))
232 }
233
234
235
236 func (client AzureAccountsClient) ListUserLUISAccountsSender(req *http.Request) (*http.Response, error) {
237 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
238 }
239
240
241
242 func (client AzureAccountsClient) ListUserLUISAccountsResponder(resp *http.Response) (result ListAzureAccountInfoObject, err error) {
243 err = autorest.Respond(
244 resp,
245 azure.WithErrorUnlessStatusCode(http.StatusOK),
246 autorest.ByUnmarshallingJSON(&result.Value),
247 autorest.ByClosing())
248 result.Response = autorest.Response{Response: resp}
249 return
250 }
251
252
253
254
255
256 func (client AzureAccountsClient) RemoveFromApp(ctx context.Context, appID uuid.UUID, azureAccountInfoObject *AzureAccountInfoObject) (result OperationStatus, err error) {
257 if tracing.IsEnabled() {
258 ctx = tracing.StartSpan(ctx, fqdn+"/AzureAccountsClient.RemoveFromApp")
259 defer func() {
260 sc := -1
261 if result.Response.Response != nil {
262 sc = result.Response.Response.StatusCode
263 }
264 tracing.EndSpan(ctx, sc, err)
265 }()
266 }
267 if err := validation.Validate([]validation.Validation{
268 {TargetValue: azureAccountInfoObject,
269 Constraints: []validation.Constraint{{Target: "azureAccountInfoObject", Name: validation.Null, Rule: false,
270 Chain: []validation.Constraint{{Target: "azureAccountInfoObject.AzureSubscriptionID", Name: validation.Null, Rule: true, Chain: nil},
271 {Target: "azureAccountInfoObject.ResourceGroup", Name: validation.Null, Rule: true, Chain: nil},
272 {Target: "azureAccountInfoObject.AccountName", Name: validation.Null, Rule: true, Chain: nil},
273 }}}}}); err != nil {
274 return result, validation.NewError("authoring.AzureAccountsClient", "RemoveFromApp", err.Error())
275 }
276
277 req, err := client.RemoveFromAppPreparer(ctx, appID, azureAccountInfoObject)
278 if err != nil {
279 err = autorest.NewErrorWithError(err, "authoring.AzureAccountsClient", "RemoveFromApp", nil, "Failure preparing request")
280 return
281 }
282
283 resp, err := client.RemoveFromAppSender(req)
284 if err != nil {
285 result.Response = autorest.Response{Response: resp}
286 err = autorest.NewErrorWithError(err, "authoring.AzureAccountsClient", "RemoveFromApp", resp, "Failure sending request")
287 return
288 }
289
290 result, err = client.RemoveFromAppResponder(resp)
291 if err != nil {
292 err = autorest.NewErrorWithError(err, "authoring.AzureAccountsClient", "RemoveFromApp", resp, "Failure responding to request")
293 return
294 }
295
296 return
297 }
298
299
300 func (client AzureAccountsClient) RemoveFromAppPreparer(ctx context.Context, appID uuid.UUID, azureAccountInfoObject *AzureAccountInfoObject) (*http.Request, error) {
301 urlParameters := map[string]interface{}{
302 "Endpoint": client.Endpoint,
303 }
304
305 pathParameters := map[string]interface{}{
306 "appId": autorest.Encode("path", appID),
307 }
308
309 preparer := autorest.CreatePreparer(
310 autorest.AsContentType("application/json; charset=utf-8"),
311 autorest.AsDelete(),
312 autorest.WithCustomBaseURL("{Endpoint}/luis/api/v2.0", urlParameters),
313 autorest.WithPathParameters("/apps/{appId}/azureaccounts", pathParameters))
314 if azureAccountInfoObject != nil {
315 preparer = autorest.DecoratePreparer(preparer,
316 autorest.WithJSON(azureAccountInfoObject))
317 }
318 return preparer.Prepare((&http.Request{}).WithContext(ctx))
319 }
320
321
322
323 func (client AzureAccountsClient) RemoveFromAppSender(req *http.Request) (*http.Response, error) {
324 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
325 }
326
327
328
329 func (client AzureAccountsClient) RemoveFromAppResponder(resp *http.Response) (result OperationStatus, err error) {
330 err = autorest.Respond(
331 resp,
332 azure.WithErrorUnlessStatusCode(http.StatusOK),
333 autorest.ByUnmarshallingJSON(&result),
334 autorest.ByClosing())
335 result.Response = autorest.Response{Response: resp}
336 return
337 }
338
View as plain text