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// ServerCommunicationLinksClient is the the Azure SQL Database management API provides a RESTful set of web services
19// that interact with Azure SQL Database services to manage your databases. The API enables you to create, retrieve,
20// update, and delete databases.
21type ServerCommunicationLinksClient struct {
22	BaseClient
23}
24
25// NewServerCommunicationLinksClient creates an instance of the ServerCommunicationLinksClient client.
26func NewServerCommunicationLinksClient(subscriptionID string) ServerCommunicationLinksClient {
27	return NewServerCommunicationLinksClientWithBaseURI(DefaultBaseURI, subscriptionID)
28}
29
30// NewServerCommunicationLinksClientWithBaseURI creates an instance of the ServerCommunicationLinksClient client using
31// a custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign
32// clouds, Azure stack).
33func NewServerCommunicationLinksClientWithBaseURI(baseURI string, subscriptionID string) ServerCommunicationLinksClient {
34	return ServerCommunicationLinksClient{NewWithBaseURI(baseURI, subscriptionID)}
35}
36
37// CreateOrUpdate creates a server communication link.
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// serverName - the name of the server.
42// communicationLinkName - the name of the server communication link.
43// parameters - the required parameters for creating a server communication link.
44func (client ServerCommunicationLinksClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serverName string, communicationLinkName string, parameters ServerCommunicationLink) (result ServerCommunicationLinksCreateOrUpdateFuture, err error) {
45	if tracing.IsEnabled() {
46		ctx = tracing.StartSpan(ctx, fqdn+"/ServerCommunicationLinksClient.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.ServerCommunicationLinkProperties", Name: validation.Null, Rule: false,
58				Chain: []validation.Constraint{{Target: "parameters.ServerCommunicationLinkProperties.PartnerServer", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil {
59		return result, validation.NewError("sql.ServerCommunicationLinksClient", "CreateOrUpdate", err.Error())
60	}
61
62	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serverName, communicationLinkName, parameters)
63	if err != nil {
64		err = autorest.NewErrorWithError(err, "sql.ServerCommunicationLinksClient", "CreateOrUpdate", nil, "Failure preparing request")
65		return
66	}
67
68	result, err = client.CreateOrUpdateSender(req)
69	if err != nil {
70		err = autorest.NewErrorWithError(err, "sql.ServerCommunicationLinksClient", "CreateOrUpdate", nil, "Failure sending request")
71		return
72	}
73
74	return
75}
76
77// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
78func (client ServerCommunicationLinksClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serverName string, communicationLinkName string, parameters ServerCommunicationLink) (*http.Request, error) {
79	pathParameters := map[string]interface{}{
80		"communicationLinkName": autorest.Encode("path", communicationLinkName),
81		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
82		"serverName":            autorest.Encode("path", serverName),
83		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
84	}
85
86	const APIVersion = "2014-04-01"
87	queryParameters := map[string]interface{}{
88		"api-version": APIVersion,
89	}
90
91	parameters.Location = nil
92	parameters.Kind = nil
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/servers/{serverName}/communicationLinks/{communicationLinkName}", 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 ServerCommunicationLinksClient) CreateOrUpdateSender(req *http.Request) (future ServerCommunicationLinksCreateOrUpdateFuture, 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 ServerCommunicationLinksClient) CreateOrUpdateResponder(resp *http.Response) (result ServerCommunicationLink, 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 communication link.
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// serverName - the name of the server.
135// communicationLinkName - the name of the server communication link.
136func (client ServerCommunicationLinksClient) Delete(ctx context.Context, resourceGroupName string, serverName string, communicationLinkName string) (result autorest.Response, err error) {
137	if tracing.IsEnabled() {
138		ctx = tracing.StartSpan(ctx, fqdn+"/ServerCommunicationLinksClient.Delete")
139		defer func() {
140			sc := -1
141			if result.Response != nil {
142				sc = result.Response.StatusCode
143			}
144			tracing.EndSpan(ctx, sc, err)
145		}()
146	}
147	req, err := client.DeletePreparer(ctx, resourceGroupName, serverName, communicationLinkName)
148	if err != nil {
149		err = autorest.NewErrorWithError(err, "sql.ServerCommunicationLinksClient", "Delete", nil, "Failure preparing request")
150		return
151	}
152
153	resp, err := client.DeleteSender(req)
154	if err != nil {
155		result.Response = resp
156		err = autorest.NewErrorWithError(err, "sql.ServerCommunicationLinksClient", "Delete", resp, "Failure sending request")
157		return
158	}
159
160	result, err = client.DeleteResponder(resp)
161	if err != nil {
162		err = autorest.NewErrorWithError(err, "sql.ServerCommunicationLinksClient", "Delete", resp, "Failure responding to request")
163		return
164	}
165
166	return
167}
168
169// DeletePreparer prepares the Delete request.
170func (client ServerCommunicationLinksClient) DeletePreparer(ctx context.Context, resourceGroupName string, serverName string, communicationLinkName string) (*http.Request, error) {
171	pathParameters := map[string]interface{}{
172		"communicationLinkName": autorest.Encode("path", communicationLinkName),
173		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
174		"serverName":            autorest.Encode("path", serverName),
175		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
176	}
177
178	const APIVersion = "2014-04-01"
179	queryParameters := map[string]interface{}{
180		"api-version": APIVersion,
181	}
182
183	preparer := autorest.CreatePreparer(
184		autorest.AsDelete(),
185		autorest.WithBaseURL(client.BaseURI),
186		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/communicationLinks/{communicationLinkName}", pathParameters),
187		autorest.WithQueryParameters(queryParameters))
188	return preparer.Prepare((&http.Request{}).WithContext(ctx))
189}
190
191// DeleteSender sends the Delete request. The method will close the
192// http.Response Body if it receives an error.
193func (client ServerCommunicationLinksClient) DeleteSender(req *http.Request) (*http.Response, error) {
194	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
195}
196
197// DeleteResponder handles the response to the Delete request. The method always
198// closes the http.Response Body.
199func (client ServerCommunicationLinksClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
200	err = autorest.Respond(
201		resp,
202		azure.WithErrorUnlessStatusCode(http.StatusOK),
203		autorest.ByClosing())
204	result.Response = resp
205	return
206}
207
208// Get returns a server communication link.
209// Parameters:
210// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
211// from the Azure Resource Manager API or the portal.
212// serverName - the name of the server.
213// communicationLinkName - the name of the server communication link.
214func (client ServerCommunicationLinksClient) Get(ctx context.Context, resourceGroupName string, serverName string, communicationLinkName string) (result ServerCommunicationLink, err error) {
215	if tracing.IsEnabled() {
216		ctx = tracing.StartSpan(ctx, fqdn+"/ServerCommunicationLinksClient.Get")
217		defer func() {
218			sc := -1
219			if result.Response.Response != nil {
220				sc = result.Response.Response.StatusCode
221			}
222			tracing.EndSpan(ctx, sc, err)
223		}()
224	}
225	req, err := client.GetPreparer(ctx, resourceGroupName, serverName, communicationLinkName)
226	if err != nil {
227		err = autorest.NewErrorWithError(err, "sql.ServerCommunicationLinksClient", "Get", nil, "Failure preparing request")
228		return
229	}
230
231	resp, err := client.GetSender(req)
232	if err != nil {
233		result.Response = autorest.Response{Response: resp}
234		err = autorest.NewErrorWithError(err, "sql.ServerCommunicationLinksClient", "Get", resp, "Failure sending request")
235		return
236	}
237
238	result, err = client.GetResponder(resp)
239	if err != nil {
240		err = autorest.NewErrorWithError(err, "sql.ServerCommunicationLinksClient", "Get", resp, "Failure responding to request")
241		return
242	}
243
244	return
245}
246
247// GetPreparer prepares the Get request.
248func (client ServerCommunicationLinksClient) GetPreparer(ctx context.Context, resourceGroupName string, serverName string, communicationLinkName string) (*http.Request, error) {
249	pathParameters := map[string]interface{}{
250		"communicationLinkName": autorest.Encode("path", communicationLinkName),
251		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
252		"serverName":            autorest.Encode("path", serverName),
253		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
254	}
255
256	const APIVersion = "2014-04-01"
257	queryParameters := map[string]interface{}{
258		"api-version": APIVersion,
259	}
260
261	preparer := autorest.CreatePreparer(
262		autorest.AsGet(),
263		autorest.WithBaseURL(client.BaseURI),
264		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/communicationLinks/{communicationLinkName}", pathParameters),
265		autorest.WithQueryParameters(queryParameters))
266	return preparer.Prepare((&http.Request{}).WithContext(ctx))
267}
268
269// GetSender sends the Get request. The method will close the
270// http.Response Body if it receives an error.
271func (client ServerCommunicationLinksClient) GetSender(req *http.Request) (*http.Response, error) {
272	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
273}
274
275// GetResponder handles the response to the Get request. The method always
276// closes the http.Response Body.
277func (client ServerCommunicationLinksClient) GetResponder(resp *http.Response) (result ServerCommunicationLink, err error) {
278	err = autorest.Respond(
279		resp,
280		azure.WithErrorUnlessStatusCode(http.StatusOK),
281		autorest.ByUnmarshallingJSON(&result),
282		autorest.ByClosing())
283	result.Response = autorest.Response{Response: resp}
284	return
285}
286
287// ListByServer gets a list of server communication links.
288// Parameters:
289// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
290// from the Azure Resource Manager API or the portal.
291// serverName - the name of the server.
292func (client ServerCommunicationLinksClient) ListByServer(ctx context.Context, resourceGroupName string, serverName string) (result ServerCommunicationLinkListResult, err error) {
293	if tracing.IsEnabled() {
294		ctx = tracing.StartSpan(ctx, fqdn+"/ServerCommunicationLinksClient.ListByServer")
295		defer func() {
296			sc := -1
297			if result.Response.Response != nil {
298				sc = result.Response.Response.StatusCode
299			}
300			tracing.EndSpan(ctx, sc, err)
301		}()
302	}
303	req, err := client.ListByServerPreparer(ctx, resourceGroupName, serverName)
304	if err != nil {
305		err = autorest.NewErrorWithError(err, "sql.ServerCommunicationLinksClient", "ListByServer", nil, "Failure preparing request")
306		return
307	}
308
309	resp, err := client.ListByServerSender(req)
310	if err != nil {
311		result.Response = autorest.Response{Response: resp}
312		err = autorest.NewErrorWithError(err, "sql.ServerCommunicationLinksClient", "ListByServer", resp, "Failure sending request")
313		return
314	}
315
316	result, err = client.ListByServerResponder(resp)
317	if err != nil {
318		err = autorest.NewErrorWithError(err, "sql.ServerCommunicationLinksClient", "ListByServer", resp, "Failure responding to request")
319		return
320	}
321
322	return
323}
324
325// ListByServerPreparer prepares the ListByServer request.
326func (client ServerCommunicationLinksClient) ListByServerPreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) {
327	pathParameters := map[string]interface{}{
328		"resourceGroupName": autorest.Encode("path", resourceGroupName),
329		"serverName":        autorest.Encode("path", serverName),
330		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
331	}
332
333	const APIVersion = "2014-04-01"
334	queryParameters := map[string]interface{}{
335		"api-version": APIVersion,
336	}
337
338	preparer := autorest.CreatePreparer(
339		autorest.AsGet(),
340		autorest.WithBaseURL(client.BaseURI),
341		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/communicationLinks", pathParameters),
342		autorest.WithQueryParameters(queryParameters))
343	return preparer.Prepare((&http.Request{}).WithContext(ctx))
344}
345
346// ListByServerSender sends the ListByServer request. The method will close the
347// http.Response Body if it receives an error.
348func (client ServerCommunicationLinksClient) ListByServerSender(req *http.Request) (*http.Response, error) {
349	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
350}
351
352// ListByServerResponder handles the response to the ListByServer request. The method always
353// closes the http.Response Body.
354func (client ServerCommunicationLinksClient) ListByServerResponder(resp *http.Response) (result ServerCommunicationLinkListResult, 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