1package sql
2
3// Copyright (c) Microsoft Corporation. All rights reserved.
4// Licensed under the MIT License. See License.txt in the project root for license information.
5//
6// Code generated by Microsoft (R) AutoRest Code Generator.
7// Changes may cause incorrect behavior and will be lost if the code is regenerated.
8
9import (
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// ServerTrustGroupsClient is the the Azure SQL Database management API provides a RESTful set of web services that
19// interact with Azure SQL Database services to manage your databases. The API enables you to create, retrieve, update,
20// and delete databases.
21type ServerTrustGroupsClient struct {
22	BaseClient
23}
24
25// NewServerTrustGroupsClient creates an instance of the ServerTrustGroupsClient client.
26func NewServerTrustGroupsClient(subscriptionID string) ServerTrustGroupsClient {
27	return NewServerTrustGroupsClientWithBaseURI(DefaultBaseURI, subscriptionID)
28}
29
30// NewServerTrustGroupsClientWithBaseURI creates an instance of the ServerTrustGroupsClient client using a custom
31// endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
32// stack).
33func NewServerTrustGroupsClientWithBaseURI(baseURI string, subscriptionID string) ServerTrustGroupsClient {
34	return ServerTrustGroupsClient{NewWithBaseURI(baseURI, subscriptionID)}
35}
36
37// CreateOrUpdate creates or updates a server trust group.
38// Parameters:
39// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
40// from the Azure Resource Manager API or the portal.
41// locationName - the name of the region where the resource is located.
42// serverTrustGroupName - the name of the server trust group.
43// parameters - the server trust group parameters.
44func (client ServerTrustGroupsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, locationName string, serverTrustGroupName string, parameters ServerTrustGroup) (result ServerTrustGroupsCreateOrUpdateFuture, err error) {
45	if tracing.IsEnabled() {
46		ctx = tracing.StartSpan(ctx, fqdn+"/ServerTrustGroupsClient.CreateOrUpdate")
47		defer func() {
48			sc := -1
49			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
50				sc = result.FutureAPI.Response().StatusCode
51			}
52			tracing.EndSpan(ctx, sc, err)
53		}()
54	}
55	if err := validation.Validate([]validation.Validation{
56		{TargetValue: parameters,
57			Constraints: []validation.Constraint{{Target: "parameters.ServerTrustGroupProperties", Name: validation.Null, Rule: false,
58				Chain: []validation.Constraint{{Target: "parameters.ServerTrustGroupProperties.GroupMembers", Name: validation.Null, Rule: true, Chain: nil},
59					{Target: "parameters.ServerTrustGroupProperties.TrustScopes", Name: validation.Null, Rule: true, Chain: nil},
60				}}}}}); err != nil {
61		return result, validation.NewError("sql.ServerTrustGroupsClient", "CreateOrUpdate", err.Error())
62	}
63
64	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, locationName, serverTrustGroupName, parameters)
65	if err != nil {
66		err = autorest.NewErrorWithError(err, "sql.ServerTrustGroupsClient", "CreateOrUpdate", nil, "Failure preparing request")
67		return
68	}
69
70	result, err = client.CreateOrUpdateSender(req)
71	if err != nil {
72		err = autorest.NewErrorWithError(err, "sql.ServerTrustGroupsClient", "CreateOrUpdate", nil, "Failure sending request")
73		return
74	}
75
76	return
77}
78
79// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
80func (client ServerTrustGroupsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, locationName string, serverTrustGroupName string, parameters ServerTrustGroup) (*http.Request, error) {
81	pathParameters := map[string]interface{}{
82		"locationName":         autorest.Encode("path", locationName),
83		"resourceGroupName":    autorest.Encode("path", resourceGroupName),
84		"serverTrustGroupName": autorest.Encode("path", serverTrustGroupName),
85		"subscriptionId":       autorest.Encode("path", client.SubscriptionID),
86	}
87
88	const APIVersion = "2020-02-02-preview"
89	queryParameters := map[string]interface{}{
90		"api-version": APIVersion,
91	}
92
93	preparer := autorest.CreatePreparer(
94		autorest.AsContentType("application/json; charset=utf-8"),
95		autorest.AsPut(),
96		autorest.WithBaseURL(client.BaseURI),
97		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/serverTrustGroups/{serverTrustGroupName}", pathParameters),
98		autorest.WithJSON(parameters),
99		autorest.WithQueryParameters(queryParameters))
100	return preparer.Prepare((&http.Request{}).WithContext(ctx))
101}
102
103// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
104// http.Response Body if it receives an error.
105func (client ServerTrustGroupsClient) CreateOrUpdateSender(req *http.Request) (future ServerTrustGroupsCreateOrUpdateFuture, err error) {
106	var resp *http.Response
107	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
108	if err != nil {
109		return
110	}
111	var azf azure.Future
112	azf, err = azure.NewFutureFromResponse(resp)
113	future.FutureAPI = &azf
114	future.Result = future.result
115	return
116}
117
118// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
119// closes the http.Response Body.
120func (client ServerTrustGroupsClient) CreateOrUpdateResponder(resp *http.Response) (result ServerTrustGroup, err error) {
121	err = autorest.Respond(
122		resp,
123		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusAccepted),
124		autorest.ByUnmarshallingJSON(&result),
125		autorest.ByClosing())
126	result.Response = autorest.Response{Response: resp}
127	return
128}
129
130// Delete deletes a server trust group.
131// Parameters:
132// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
133// from the Azure Resource Manager API or the portal.
134// locationName - the name of the region where the resource is located.
135// serverTrustGroupName - the name of the server trust group.
136func (client ServerTrustGroupsClient) Delete(ctx context.Context, resourceGroupName string, locationName string, serverTrustGroupName string) (result ServerTrustGroupsDeleteFuture, err error) {
137	if tracing.IsEnabled() {
138		ctx = tracing.StartSpan(ctx, fqdn+"/ServerTrustGroupsClient.Delete")
139		defer func() {
140			sc := -1
141			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
142				sc = result.FutureAPI.Response().StatusCode
143			}
144			tracing.EndSpan(ctx, sc, err)
145		}()
146	}
147	req, err := client.DeletePreparer(ctx, resourceGroupName, locationName, serverTrustGroupName)
148	if err != nil {
149		err = autorest.NewErrorWithError(err, "sql.ServerTrustGroupsClient", "Delete", nil, "Failure preparing request")
150		return
151	}
152
153	result, err = client.DeleteSender(req)
154	if err != nil {
155		err = autorest.NewErrorWithError(err, "sql.ServerTrustGroupsClient", "Delete", nil, "Failure sending request")
156		return
157	}
158
159	return
160}
161
162// DeletePreparer prepares the Delete request.
163func (client ServerTrustGroupsClient) DeletePreparer(ctx context.Context, resourceGroupName string, locationName string, serverTrustGroupName string) (*http.Request, error) {
164	pathParameters := map[string]interface{}{
165		"locationName":         autorest.Encode("path", locationName),
166		"resourceGroupName":    autorest.Encode("path", resourceGroupName),
167		"serverTrustGroupName": autorest.Encode("path", serverTrustGroupName),
168		"subscriptionId":       autorest.Encode("path", client.SubscriptionID),
169	}
170
171	const APIVersion = "2020-02-02-preview"
172	queryParameters := map[string]interface{}{
173		"api-version": APIVersion,
174	}
175
176	preparer := autorest.CreatePreparer(
177		autorest.AsDelete(),
178		autorest.WithBaseURL(client.BaseURI),
179		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/serverTrustGroups/{serverTrustGroupName}", pathParameters),
180		autorest.WithQueryParameters(queryParameters))
181	return preparer.Prepare((&http.Request{}).WithContext(ctx))
182}
183
184// DeleteSender sends the Delete request. The method will close the
185// http.Response Body if it receives an error.
186func (client ServerTrustGroupsClient) DeleteSender(req *http.Request) (future ServerTrustGroupsDeleteFuture, err error) {
187	var resp *http.Response
188	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
189	if err != nil {
190		return
191	}
192	var azf azure.Future
193	azf, err = azure.NewFutureFromResponse(resp)
194	future.FutureAPI = &azf
195	future.Result = future.result
196	return
197}
198
199// DeleteResponder handles the response to the Delete request. The method always
200// closes the http.Response Body.
201func (client ServerTrustGroupsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
202	err = autorest.Respond(
203		resp,
204		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
205		autorest.ByClosing())
206	result.Response = resp
207	return
208}
209
210// Get gets a server trust group.
211// Parameters:
212// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
213// from the Azure Resource Manager API or the portal.
214// locationName - the name of the region where the resource is located.
215// serverTrustGroupName - the name of the server trust group.
216func (client ServerTrustGroupsClient) Get(ctx context.Context, resourceGroupName string, locationName string, serverTrustGroupName string) (result ServerTrustGroup, err error) {
217	if tracing.IsEnabled() {
218		ctx = tracing.StartSpan(ctx, fqdn+"/ServerTrustGroupsClient.Get")
219		defer func() {
220			sc := -1
221			if result.Response.Response != nil {
222				sc = result.Response.Response.StatusCode
223			}
224			tracing.EndSpan(ctx, sc, err)
225		}()
226	}
227	req, err := client.GetPreparer(ctx, resourceGroupName, locationName, serverTrustGroupName)
228	if err != nil {
229		err = autorest.NewErrorWithError(err, "sql.ServerTrustGroupsClient", "Get", nil, "Failure preparing request")
230		return
231	}
232
233	resp, err := client.GetSender(req)
234	if err != nil {
235		result.Response = autorest.Response{Response: resp}
236		err = autorest.NewErrorWithError(err, "sql.ServerTrustGroupsClient", "Get", resp, "Failure sending request")
237		return
238	}
239
240	result, err = client.GetResponder(resp)
241	if err != nil {
242		err = autorest.NewErrorWithError(err, "sql.ServerTrustGroupsClient", "Get", resp, "Failure responding to request")
243		return
244	}
245
246	return
247}
248
249// GetPreparer prepares the Get request.
250func (client ServerTrustGroupsClient) GetPreparer(ctx context.Context, resourceGroupName string, locationName string, serverTrustGroupName string) (*http.Request, error) {
251	pathParameters := map[string]interface{}{
252		"locationName":         autorest.Encode("path", locationName),
253		"resourceGroupName":    autorest.Encode("path", resourceGroupName),
254		"serverTrustGroupName": autorest.Encode("path", serverTrustGroupName),
255		"subscriptionId":       autorest.Encode("path", client.SubscriptionID),
256	}
257
258	const APIVersion = "2020-02-02-preview"
259	queryParameters := map[string]interface{}{
260		"api-version": APIVersion,
261	}
262
263	preparer := autorest.CreatePreparer(
264		autorest.AsGet(),
265		autorest.WithBaseURL(client.BaseURI),
266		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/serverTrustGroups/{serverTrustGroupName}", pathParameters),
267		autorest.WithQueryParameters(queryParameters))
268	return preparer.Prepare((&http.Request{}).WithContext(ctx))
269}
270
271// GetSender sends the Get request. The method will close the
272// http.Response Body if it receives an error.
273func (client ServerTrustGroupsClient) GetSender(req *http.Request) (*http.Response, error) {
274	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
275}
276
277// GetResponder handles the response to the Get request. The method always
278// closes the http.Response Body.
279func (client ServerTrustGroupsClient) GetResponder(resp *http.Response) (result ServerTrustGroup, err error) {
280	err = autorest.Respond(
281		resp,
282		azure.WithErrorUnlessStatusCode(http.StatusOK),
283		autorest.ByUnmarshallingJSON(&result),
284		autorest.ByClosing())
285	result.Response = autorest.Response{Response: resp}
286	return
287}
288
289// ListByInstance gets a server trust groups by instance name.
290// Parameters:
291// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
292// from the Azure Resource Manager API or the portal.
293// managedInstanceName - the name of the managed instance.
294func (client ServerTrustGroupsClient) ListByInstance(ctx context.Context, resourceGroupName string, managedInstanceName string) (result ServerTrustGroupListResultPage, err error) {
295	if tracing.IsEnabled() {
296		ctx = tracing.StartSpan(ctx, fqdn+"/ServerTrustGroupsClient.ListByInstance")
297		defer func() {
298			sc := -1
299			if result.stglr.Response.Response != nil {
300				sc = result.stglr.Response.Response.StatusCode
301			}
302			tracing.EndSpan(ctx, sc, err)
303		}()
304	}
305	result.fn = client.listByInstanceNextResults
306	req, err := client.ListByInstancePreparer(ctx, resourceGroupName, managedInstanceName)
307	if err != nil {
308		err = autorest.NewErrorWithError(err, "sql.ServerTrustGroupsClient", "ListByInstance", nil, "Failure preparing request")
309		return
310	}
311
312	resp, err := client.ListByInstanceSender(req)
313	if err != nil {
314		result.stglr.Response = autorest.Response{Response: resp}
315		err = autorest.NewErrorWithError(err, "sql.ServerTrustGroupsClient", "ListByInstance", resp, "Failure sending request")
316		return
317	}
318
319	result.stglr, err = client.ListByInstanceResponder(resp)
320	if err != nil {
321		err = autorest.NewErrorWithError(err, "sql.ServerTrustGroupsClient", "ListByInstance", resp, "Failure responding to request")
322		return
323	}
324	if result.stglr.hasNextLink() && result.stglr.IsEmpty() {
325		err = result.NextWithContext(ctx)
326		return
327	}
328
329	return
330}
331
332// ListByInstancePreparer prepares the ListByInstance request.
333func (client ServerTrustGroupsClient) ListByInstancePreparer(ctx context.Context, resourceGroupName string, managedInstanceName string) (*http.Request, error) {
334	pathParameters := map[string]interface{}{
335		"managedInstanceName": autorest.Encode("path", managedInstanceName),
336		"resourceGroupName":   autorest.Encode("path", resourceGroupName),
337		"subscriptionId":      autorest.Encode("path", client.SubscriptionID),
338	}
339
340	const APIVersion = "2020-02-02-preview"
341	queryParameters := map[string]interface{}{
342		"api-version": APIVersion,
343	}
344
345	preparer := autorest.CreatePreparer(
346		autorest.AsGet(),
347		autorest.WithBaseURL(client.BaseURI),
348		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/serverTrustGroups", pathParameters),
349		autorest.WithQueryParameters(queryParameters))
350	return preparer.Prepare((&http.Request{}).WithContext(ctx))
351}
352
353// ListByInstanceSender sends the ListByInstance request. The method will close the
354// http.Response Body if it receives an error.
355func (client ServerTrustGroupsClient) ListByInstanceSender(req *http.Request) (*http.Response, error) {
356	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
357}
358
359// ListByInstanceResponder handles the response to the ListByInstance request. The method always
360// closes the http.Response Body.
361func (client ServerTrustGroupsClient) ListByInstanceResponder(resp *http.Response) (result ServerTrustGroupListResult, err error) {
362	err = autorest.Respond(
363		resp,
364		azure.WithErrorUnlessStatusCode(http.StatusOK),
365		autorest.ByUnmarshallingJSON(&result),
366		autorest.ByClosing())
367	result.Response = autorest.Response{Response: resp}
368	return
369}
370
371// listByInstanceNextResults retrieves the next set of results, if any.
372func (client ServerTrustGroupsClient) listByInstanceNextResults(ctx context.Context, lastResults ServerTrustGroupListResult) (result ServerTrustGroupListResult, err error) {
373	req, err := lastResults.serverTrustGroupListResultPreparer(ctx)
374	if err != nil {
375		return result, autorest.NewErrorWithError(err, "sql.ServerTrustGroupsClient", "listByInstanceNextResults", nil, "Failure preparing next results request")
376	}
377	if req == nil {
378		return
379	}
380	resp, err := client.ListByInstanceSender(req)
381	if err != nil {
382		result.Response = autorest.Response{Response: resp}
383		return result, autorest.NewErrorWithError(err, "sql.ServerTrustGroupsClient", "listByInstanceNextResults", resp, "Failure sending next results request")
384	}
385	result, err = client.ListByInstanceResponder(resp)
386	if err != nil {
387		err = autorest.NewErrorWithError(err, "sql.ServerTrustGroupsClient", "listByInstanceNextResults", resp, "Failure responding to next results request")
388	}
389	return
390}
391
392// ListByInstanceComplete enumerates all values, automatically crossing page boundaries as required.
393func (client ServerTrustGroupsClient) ListByInstanceComplete(ctx context.Context, resourceGroupName string, managedInstanceName string) (result ServerTrustGroupListResultIterator, err error) {
394	if tracing.IsEnabled() {
395		ctx = tracing.StartSpan(ctx, fqdn+"/ServerTrustGroupsClient.ListByInstance")
396		defer func() {
397			sc := -1
398			if result.Response().Response.Response != nil {
399				sc = result.page.Response().Response.Response.StatusCode
400			}
401			tracing.EndSpan(ctx, sc, err)
402		}()
403	}
404	result.page, err = client.ListByInstance(ctx, resourceGroupName, managedInstanceName)
405	return
406}
407
408// ListByLocation lists a server trust group.
409// Parameters:
410// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
411// from the Azure Resource Manager API or the portal.
412// locationName - the name of the region where the resource is located.
413func (client ServerTrustGroupsClient) ListByLocation(ctx context.Context, resourceGroupName string, locationName string) (result ServerTrustGroupListResultPage, err error) {
414	if tracing.IsEnabled() {
415		ctx = tracing.StartSpan(ctx, fqdn+"/ServerTrustGroupsClient.ListByLocation")
416		defer func() {
417			sc := -1
418			if result.stglr.Response.Response != nil {
419				sc = result.stglr.Response.Response.StatusCode
420			}
421			tracing.EndSpan(ctx, sc, err)
422		}()
423	}
424	result.fn = client.listByLocationNextResults
425	req, err := client.ListByLocationPreparer(ctx, resourceGroupName, locationName)
426	if err != nil {
427		err = autorest.NewErrorWithError(err, "sql.ServerTrustGroupsClient", "ListByLocation", nil, "Failure preparing request")
428		return
429	}
430
431	resp, err := client.ListByLocationSender(req)
432	if err != nil {
433		result.stglr.Response = autorest.Response{Response: resp}
434		err = autorest.NewErrorWithError(err, "sql.ServerTrustGroupsClient", "ListByLocation", resp, "Failure sending request")
435		return
436	}
437
438	result.stglr, err = client.ListByLocationResponder(resp)
439	if err != nil {
440		err = autorest.NewErrorWithError(err, "sql.ServerTrustGroupsClient", "ListByLocation", resp, "Failure responding to request")
441		return
442	}
443	if result.stglr.hasNextLink() && result.stglr.IsEmpty() {
444		err = result.NextWithContext(ctx)
445		return
446	}
447
448	return
449}
450
451// ListByLocationPreparer prepares the ListByLocation request.
452func (client ServerTrustGroupsClient) ListByLocationPreparer(ctx context.Context, resourceGroupName string, locationName string) (*http.Request, error) {
453	pathParameters := map[string]interface{}{
454		"locationName":      autorest.Encode("path", locationName),
455		"resourceGroupName": autorest.Encode("path", resourceGroupName),
456		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
457	}
458
459	const APIVersion = "2020-02-02-preview"
460	queryParameters := map[string]interface{}{
461		"api-version": APIVersion,
462	}
463
464	preparer := autorest.CreatePreparer(
465		autorest.AsGet(),
466		autorest.WithBaseURL(client.BaseURI),
467		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/serverTrustGroups", pathParameters),
468		autorest.WithQueryParameters(queryParameters))
469	return preparer.Prepare((&http.Request{}).WithContext(ctx))
470}
471
472// ListByLocationSender sends the ListByLocation request. The method will close the
473// http.Response Body if it receives an error.
474func (client ServerTrustGroupsClient) ListByLocationSender(req *http.Request) (*http.Response, error) {
475	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
476}
477
478// ListByLocationResponder handles the response to the ListByLocation request. The method always
479// closes the http.Response Body.
480func (client ServerTrustGroupsClient) ListByLocationResponder(resp *http.Response) (result ServerTrustGroupListResult, err error) {
481	err = autorest.Respond(
482		resp,
483		azure.WithErrorUnlessStatusCode(http.StatusOK),
484		autorest.ByUnmarshallingJSON(&result),
485		autorest.ByClosing())
486	result.Response = autorest.Response{Response: resp}
487	return
488}
489
490// listByLocationNextResults retrieves the next set of results, if any.
491func (client ServerTrustGroupsClient) listByLocationNextResults(ctx context.Context, lastResults ServerTrustGroupListResult) (result ServerTrustGroupListResult, err error) {
492	req, err := lastResults.serverTrustGroupListResultPreparer(ctx)
493	if err != nil {
494		return result, autorest.NewErrorWithError(err, "sql.ServerTrustGroupsClient", "listByLocationNextResults", nil, "Failure preparing next results request")
495	}
496	if req == nil {
497		return
498	}
499	resp, err := client.ListByLocationSender(req)
500	if err != nil {
501		result.Response = autorest.Response{Response: resp}
502		return result, autorest.NewErrorWithError(err, "sql.ServerTrustGroupsClient", "listByLocationNextResults", resp, "Failure sending next results request")
503	}
504	result, err = client.ListByLocationResponder(resp)
505	if err != nil {
506		err = autorest.NewErrorWithError(err, "sql.ServerTrustGroupsClient", "listByLocationNextResults", resp, "Failure responding to next results request")
507	}
508	return
509}
510
511// ListByLocationComplete enumerates all values, automatically crossing page boundaries as required.
512func (client ServerTrustGroupsClient) ListByLocationComplete(ctx context.Context, resourceGroupName string, locationName string) (result ServerTrustGroupListResultIterator, err error) {
513	if tracing.IsEnabled() {
514		ctx = tracing.StartSpan(ctx, fqdn+"/ServerTrustGroupsClient.ListByLocation")
515		defer func() {
516			sc := -1
517			if result.Response().Response.Response != nil {
518				sc = result.page.Response().Response.Response.StatusCode
519			}
520			tracing.EndSpan(ctx, sc, err)
521		}()
522	}
523	result.page, err = client.ListByLocation(ctx, resourceGroupName, locationName)
524	return
525}
526