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