1 package artifacts
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 "net/http"
16 )
17
18
19 type SQLScriptClient struct {
20 BaseClient
21 }
22
23
24 func NewSQLScriptClient(endpoint string) SQLScriptClient {
25 return SQLScriptClient{New(endpoint)}
26 }
27
28
29
30
31
32
33
34 func (client SQLScriptClient) CreateOrUpdateSQLScript(ctx context.Context, SQLScriptName string, SQLScript SQLScriptResource, ifMatch string) (result SQLScriptResource, err error) {
35 if tracing.IsEnabled() {
36 ctx = tracing.StartSpan(ctx, fqdn+"/SQLScriptClient.CreateOrUpdateSQLScript")
37 defer func() {
38 sc := -1
39 if result.Response.Response != nil {
40 sc = result.Response.Response.StatusCode
41 }
42 tracing.EndSpan(ctx, sc, err)
43 }()
44 }
45 if err := validation.Validate([]validation.Validation{
46 {TargetValue: SQLScript,
47 Constraints: []validation.Constraint{{Target: "SQLScript.Name", Name: validation.Null, Rule: true, Chain: nil},
48 {Target: "SQLScript.Properties", Name: validation.Null, Rule: true,
49 Chain: []validation.Constraint{{Target: "SQLScript.Properties.Content", Name: validation.Null, Rule: true,
50 Chain: []validation.Constraint{{Target: "SQLScript.Properties.Content.Query", Name: validation.Null, Rule: true, Chain: nil},
51 {Target: "SQLScript.Properties.Content.CurrentConnection", Name: validation.Null, Rule: true,
52 Chain: []validation.Constraint{{Target: "SQLScript.Properties.Content.CurrentConnection.Name", Name: validation.Null, Rule: true, Chain: nil}}},
53 }},
54 }}}}}); err != nil {
55 return result, validation.NewError("artifacts.SQLScriptClient", "CreateOrUpdateSQLScript", err.Error())
56 }
57
58 req, err := client.CreateOrUpdateSQLScriptPreparer(ctx, SQLScriptName, SQLScript, ifMatch)
59 if err != nil {
60 err = autorest.NewErrorWithError(err, "artifacts.SQLScriptClient", "CreateOrUpdateSQLScript", nil, "Failure preparing request")
61 return
62 }
63
64 resp, err := client.CreateOrUpdateSQLScriptSender(req)
65 if err != nil {
66 result.Response = autorest.Response{Response: resp}
67 err = autorest.NewErrorWithError(err, "artifacts.SQLScriptClient", "CreateOrUpdateSQLScript", resp, "Failure sending request")
68 return
69 }
70
71 result, err = client.CreateOrUpdateSQLScriptResponder(resp)
72 if err != nil {
73 err = autorest.NewErrorWithError(err, "artifacts.SQLScriptClient", "CreateOrUpdateSQLScript", resp, "Failure responding to request")
74 return
75 }
76
77 return
78 }
79
80
81 func (client SQLScriptClient) CreateOrUpdateSQLScriptPreparer(ctx context.Context, SQLScriptName string, SQLScript SQLScriptResource, ifMatch string) (*http.Request, error) {
82 urlParameters := map[string]interface{}{
83 "endpoint": client.Endpoint,
84 }
85
86 pathParameters := map[string]interface{}{
87 "sqlScriptName": autorest.Encode("path", SQLScriptName),
88 }
89
90 const APIVersion = "2019-06-01-preview"
91 queryParameters := map[string]interface{}{
92 "api-version": APIVersion,
93 }
94
95 SQLScript.ID = nil
96 SQLScript.Type = nil
97 SQLScript.Etag = nil
98 preparer := autorest.CreatePreparer(
99 autorest.AsContentType("application/json; charset=utf-8"),
100 autorest.AsPut(),
101 autorest.WithCustomBaseURL("{endpoint}", urlParameters),
102 autorest.WithPathParameters("/sqlScripts/{sqlScriptName}", pathParameters),
103 autorest.WithJSON(SQLScript),
104 autorest.WithQueryParameters(queryParameters))
105 if len(ifMatch) > 0 {
106 preparer = autorest.DecoratePreparer(preparer,
107 autorest.WithHeader("If-Match", autorest.String(ifMatch)))
108 }
109 return preparer.Prepare((&http.Request{}).WithContext(ctx))
110 }
111
112
113
114 func (client SQLScriptClient) CreateOrUpdateSQLScriptSender(req *http.Request) (*http.Response, error) {
115 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
116 }
117
118
119
120 func (client SQLScriptClient) CreateOrUpdateSQLScriptResponder(resp *http.Response) (result SQLScriptResource, err error) {
121 err = autorest.Respond(
122 resp,
123 azure.WithErrorUnlessStatusCode(http.StatusOK),
124 autorest.ByUnmarshallingJSON(&result),
125 autorest.ByClosing())
126 result.Response = autorest.Response{Response: resp}
127 return
128 }
129
130
131
132
133 func (client SQLScriptClient) DeleteSQLScript(ctx context.Context, SQLScriptName string) (result autorest.Response, err error) {
134 if tracing.IsEnabled() {
135 ctx = tracing.StartSpan(ctx, fqdn+"/SQLScriptClient.DeleteSQLScript")
136 defer func() {
137 sc := -1
138 if result.Response != nil {
139 sc = result.Response.StatusCode
140 }
141 tracing.EndSpan(ctx, sc, err)
142 }()
143 }
144 req, err := client.DeleteSQLScriptPreparer(ctx, SQLScriptName)
145 if err != nil {
146 err = autorest.NewErrorWithError(err, "artifacts.SQLScriptClient", "DeleteSQLScript", nil, "Failure preparing request")
147 return
148 }
149
150 resp, err := client.DeleteSQLScriptSender(req)
151 if err != nil {
152 result.Response = resp
153 err = autorest.NewErrorWithError(err, "artifacts.SQLScriptClient", "DeleteSQLScript", resp, "Failure sending request")
154 return
155 }
156
157 result, err = client.DeleteSQLScriptResponder(resp)
158 if err != nil {
159 err = autorest.NewErrorWithError(err, "artifacts.SQLScriptClient", "DeleteSQLScript", resp, "Failure responding to request")
160 return
161 }
162
163 return
164 }
165
166
167 func (client SQLScriptClient) DeleteSQLScriptPreparer(ctx context.Context, SQLScriptName string) (*http.Request, error) {
168 urlParameters := map[string]interface{}{
169 "endpoint": client.Endpoint,
170 }
171
172 pathParameters := map[string]interface{}{
173 "sqlScriptName": autorest.Encode("path", SQLScriptName),
174 }
175
176 const APIVersion = "2019-06-01-preview"
177 queryParameters := map[string]interface{}{
178 "api-version": APIVersion,
179 }
180
181 preparer := autorest.CreatePreparer(
182 autorest.AsDelete(),
183 autorest.WithCustomBaseURL("{endpoint}", urlParameters),
184 autorest.WithPathParameters("/sqlScripts/{sqlScriptName}", pathParameters),
185 autorest.WithQueryParameters(queryParameters))
186 return preparer.Prepare((&http.Request{}).WithContext(ctx))
187 }
188
189
190
191 func (client SQLScriptClient) DeleteSQLScriptSender(req *http.Request) (*http.Response, error) {
192 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
193 }
194
195
196
197 func (client SQLScriptClient) DeleteSQLScriptResponder(resp *http.Response) (result autorest.Response, err error) {
198 err = autorest.Respond(
199 resp,
200 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
201 autorest.ByClosing())
202 result.Response = resp
203 return
204 }
205
206
207
208
209
210
211 func (client SQLScriptClient) GetSQLScript(ctx context.Context, SQLScriptName string, ifNoneMatch string) (result SQLScriptResource, err error) {
212 if tracing.IsEnabled() {
213 ctx = tracing.StartSpan(ctx, fqdn+"/SQLScriptClient.GetSQLScript")
214 defer func() {
215 sc := -1
216 if result.Response.Response != nil {
217 sc = result.Response.Response.StatusCode
218 }
219 tracing.EndSpan(ctx, sc, err)
220 }()
221 }
222 req, err := client.GetSQLScriptPreparer(ctx, SQLScriptName, ifNoneMatch)
223 if err != nil {
224 err = autorest.NewErrorWithError(err, "artifacts.SQLScriptClient", "GetSQLScript", nil, "Failure preparing request")
225 return
226 }
227
228 resp, err := client.GetSQLScriptSender(req)
229 if err != nil {
230 result.Response = autorest.Response{Response: resp}
231 err = autorest.NewErrorWithError(err, "artifacts.SQLScriptClient", "GetSQLScript", resp, "Failure sending request")
232 return
233 }
234
235 result, err = client.GetSQLScriptResponder(resp)
236 if err != nil {
237 err = autorest.NewErrorWithError(err, "artifacts.SQLScriptClient", "GetSQLScript", resp, "Failure responding to request")
238 return
239 }
240
241 return
242 }
243
244
245 func (client SQLScriptClient) GetSQLScriptPreparer(ctx context.Context, SQLScriptName string, ifNoneMatch string) (*http.Request, error) {
246 urlParameters := map[string]interface{}{
247 "endpoint": client.Endpoint,
248 }
249
250 pathParameters := map[string]interface{}{
251 "sqlScriptName": autorest.Encode("path", SQLScriptName),
252 }
253
254 const APIVersion = "2019-06-01-preview"
255 queryParameters := map[string]interface{}{
256 "api-version": APIVersion,
257 }
258
259 preparer := autorest.CreatePreparer(
260 autorest.AsGet(),
261 autorest.WithCustomBaseURL("{endpoint}", urlParameters),
262 autorest.WithPathParameters("/sqlScripts/{sqlScriptName}", pathParameters),
263 autorest.WithQueryParameters(queryParameters))
264 if len(ifNoneMatch) > 0 {
265 preparer = autorest.DecoratePreparer(preparer,
266 autorest.WithHeader("If-None-Match", autorest.String(ifNoneMatch)))
267 }
268 return preparer.Prepare((&http.Request{}).WithContext(ctx))
269 }
270
271
272
273 func (client SQLScriptClient) GetSQLScriptSender(req *http.Request) (*http.Response, error) {
274 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
275 }
276
277
278
279 func (client SQLScriptClient) GetSQLScriptResponder(resp *http.Response) (result SQLScriptResource, err error) {
280 err = autorest.Respond(
281 resp,
282 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNotModified),
283 autorest.ByUnmarshallingJSON(&result),
284 autorest.ByClosing())
285 result.Response = autorest.Response{Response: resp}
286 return
287 }
288
289
290 func (client SQLScriptClient) GetSQLScriptsByWorkspace(ctx context.Context) (result SQLScriptsListResponsePage, err error) {
291 if tracing.IsEnabled() {
292 ctx = tracing.StartSpan(ctx, fqdn+"/SQLScriptClient.GetSQLScriptsByWorkspace")
293 defer func() {
294 sc := -1
295 if result.sslr.Response.Response != nil {
296 sc = result.sslr.Response.Response.StatusCode
297 }
298 tracing.EndSpan(ctx, sc, err)
299 }()
300 }
301 result.fn = client.getSQLScriptsByWorkspaceNextResults
302 req, err := client.GetSQLScriptsByWorkspacePreparer(ctx)
303 if err != nil {
304 err = autorest.NewErrorWithError(err, "artifacts.SQLScriptClient", "GetSQLScriptsByWorkspace", nil, "Failure preparing request")
305 return
306 }
307
308 resp, err := client.GetSQLScriptsByWorkspaceSender(req)
309 if err != nil {
310 result.sslr.Response = autorest.Response{Response: resp}
311 err = autorest.NewErrorWithError(err, "artifacts.SQLScriptClient", "GetSQLScriptsByWorkspace", resp, "Failure sending request")
312 return
313 }
314
315 result.sslr, err = client.GetSQLScriptsByWorkspaceResponder(resp)
316 if err != nil {
317 err = autorest.NewErrorWithError(err, "artifacts.SQLScriptClient", "GetSQLScriptsByWorkspace", resp, "Failure responding to request")
318 return
319 }
320 if result.sslr.hasNextLink() && result.sslr.IsEmpty() {
321 err = result.NextWithContext(ctx)
322 return
323 }
324
325 return
326 }
327
328
329 func (client SQLScriptClient) GetSQLScriptsByWorkspacePreparer(ctx context.Context) (*http.Request, error) {
330 urlParameters := map[string]interface{}{
331 "endpoint": client.Endpoint,
332 }
333
334 const APIVersion = "2019-06-01-preview"
335 queryParameters := map[string]interface{}{
336 "api-version": APIVersion,
337 }
338
339 preparer := autorest.CreatePreparer(
340 autorest.AsGet(),
341 autorest.WithCustomBaseURL("{endpoint}", urlParameters),
342 autorest.WithPath("/sqlScripts"),
343 autorest.WithQueryParameters(queryParameters))
344 return preparer.Prepare((&http.Request{}).WithContext(ctx))
345 }
346
347
348
349 func (client SQLScriptClient) GetSQLScriptsByWorkspaceSender(req *http.Request) (*http.Response, error) {
350 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
351 }
352
353
354
355 func (client SQLScriptClient) GetSQLScriptsByWorkspaceResponder(resp *http.Response) (result SQLScriptsListResponse, err error) {
356 err = autorest.Respond(
357 resp,
358 azure.WithErrorUnlessStatusCode(http.StatusOK),
359 autorest.ByUnmarshallingJSON(&result),
360 autorest.ByClosing())
361 result.Response = autorest.Response{Response: resp}
362 return
363 }
364
365
366 func (client SQLScriptClient) getSQLScriptsByWorkspaceNextResults(ctx context.Context, lastResults SQLScriptsListResponse) (result SQLScriptsListResponse, err error) {
367 req, err := lastResults.sQLScriptsListResponsePreparer(ctx)
368 if err != nil {
369 return result, autorest.NewErrorWithError(err, "artifacts.SQLScriptClient", "getSQLScriptsByWorkspaceNextResults", nil, "Failure preparing next results request")
370 }
371 if req == nil {
372 return
373 }
374 resp, err := client.GetSQLScriptsByWorkspaceSender(req)
375 if err != nil {
376 result.Response = autorest.Response{Response: resp}
377 return result, autorest.NewErrorWithError(err, "artifacts.SQLScriptClient", "getSQLScriptsByWorkspaceNextResults", resp, "Failure sending next results request")
378 }
379 result, err = client.GetSQLScriptsByWorkspaceResponder(resp)
380 if err != nil {
381 err = autorest.NewErrorWithError(err, "artifacts.SQLScriptClient", "getSQLScriptsByWorkspaceNextResults", resp, "Failure responding to next results request")
382 }
383 return
384 }
385
386
387 func (client SQLScriptClient) GetSQLScriptsByWorkspaceComplete(ctx context.Context) (result SQLScriptsListResponseIterator, err error) {
388 if tracing.IsEnabled() {
389 ctx = tracing.StartSpan(ctx, fqdn+"/SQLScriptClient.GetSQLScriptsByWorkspace")
390 defer func() {
391 sc := -1
392 if result.Response().Response.Response != nil {
393 sc = result.page.Response().Response.Response.StatusCode
394 }
395 tracing.EndSpan(ctx, sc, err)
396 }()
397 }
398 result.page, err = client.GetSQLScriptsByWorkspace(ctx)
399 return
400 }
401
402
403
404
405
406 func (client SQLScriptClient) RenameSQLScript(ctx context.Context, SQLScriptName string, request RenameRequest) (result SQLScriptRenameSQLScriptFuture, err error) {
407 if tracing.IsEnabled() {
408 ctx = tracing.StartSpan(ctx, fqdn+"/SQLScriptClient.RenameSQLScript")
409 defer func() {
410 sc := -1
411 if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
412 sc = result.FutureAPI.Response().StatusCode
413 }
414 tracing.EndSpan(ctx, sc, err)
415 }()
416 }
417 if err := validation.Validate([]validation.Validation{
418 {TargetValue: request,
419 Constraints: []validation.Constraint{{Target: "request.NewName", Name: validation.Null, Rule: false,
420 Chain: []validation.Constraint{{Target: "request.NewName", Name: validation.MaxLength, Rule: 260, Chain: nil},
421 {Target: "request.NewName", Name: validation.MinLength, Rule: 1, Chain: nil},
422 {Target: "request.NewName", Name: validation.Pattern, Rule: `^[A-Za-z0-9_][^<>*#.%&:\\+?/]*$`, Chain: nil},
423 }}}}}); err != nil {
424 return result, validation.NewError("artifacts.SQLScriptClient", "RenameSQLScript", err.Error())
425 }
426
427 req, err := client.RenameSQLScriptPreparer(ctx, SQLScriptName, request)
428 if err != nil {
429 err = autorest.NewErrorWithError(err, "artifacts.SQLScriptClient", "RenameSQLScript", nil, "Failure preparing request")
430 return
431 }
432
433 result, err = client.RenameSQLScriptSender(req)
434 if err != nil {
435 err = autorest.NewErrorWithError(err, "artifacts.SQLScriptClient", "RenameSQLScript", nil, "Failure sending request")
436 return
437 }
438
439 return
440 }
441
442
443 func (client SQLScriptClient) RenameSQLScriptPreparer(ctx context.Context, SQLScriptName string, request RenameRequest) (*http.Request, error) {
444 urlParameters := map[string]interface{}{
445 "endpoint": client.Endpoint,
446 }
447
448 pathParameters := map[string]interface{}{
449 "sqlScriptName": autorest.Encode("path", SQLScriptName),
450 }
451
452 const APIVersion = "2019-06-01-preview"
453 queryParameters := map[string]interface{}{
454 "api-version": APIVersion,
455 }
456
457 preparer := autorest.CreatePreparer(
458 autorest.AsContentType("application/json; charset=utf-8"),
459 autorest.AsPost(),
460 autorest.WithCustomBaseURL("{endpoint}", urlParameters),
461 autorest.WithPathParameters("/sqlScripts/{sqlScriptName}/rename", pathParameters),
462 autorest.WithJSON(request),
463 autorest.WithQueryParameters(queryParameters))
464 return preparer.Prepare((&http.Request{}).WithContext(ctx))
465 }
466
467
468
469 func (client SQLScriptClient) RenameSQLScriptSender(req *http.Request) (future SQLScriptRenameSQLScriptFuture, err error) {
470 var resp *http.Response
471 resp, err = client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
472 if err != nil {
473 return
474 }
475 var azf azure.Future
476 azf, err = azure.NewFutureFromResponse(resp)
477 future.FutureAPI = &azf
478 future.Result = future.result
479 return
480 }
481
482
483
484 func (client SQLScriptClient) RenameSQLScriptResponder(resp *http.Response) (result autorest.Response, err error) {
485 err = autorest.Respond(
486 resp,
487 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
488 autorest.ByClosing())
489 result.Response = resp
490 return
491 }
492
View as plain text