1// Package network implements the Azure ARM Network service API version .
2//
3// Network Client
4package network
5
6// Copyright (c) Microsoft Corporation. All rights reserved.
7// Licensed under the MIT License. See License.txt in the project root for license information.
8//
9// Code generated by Microsoft (R) AutoRest Code Generator.
10// Changes may cause incorrect behavior and will be lost if the code is regenerated.
11
12import (
13	"context"
14	"github.com/Azure/go-autorest/autorest"
15	"github.com/Azure/go-autorest/autorest/azure"
16	"github.com/Azure/go-autorest/tracing"
17	"net/http"
18)
19
20const (
21	// DefaultBaseURI is the default URI used for the service Network
22	DefaultBaseURI = "https://management.azure.com"
23)
24
25// BaseClient is the base client for Network.
26type BaseClient struct {
27	autorest.Client
28	BaseURI        string
29	SubscriptionID string
30}
31
32// New creates an instance of the BaseClient client.
33func New(subscriptionID string) BaseClient {
34	return NewWithBaseURI(DefaultBaseURI, subscriptionID)
35}
36
37// NewWithBaseURI creates an instance of the BaseClient client using a custom endpoint.  Use this when interacting with
38// an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
39func NewWithBaseURI(baseURI string, subscriptionID string) BaseClient {
40	return BaseClient{
41		Client:         autorest.NewClientWithUserAgent(UserAgent()),
42		BaseURI:        baseURI,
43		SubscriptionID: subscriptionID,
44	}
45}
46
47// CheckDNSNameAvailability checks whether a domain name in the cloudapp.azure.com zone is available for use.
48// Parameters:
49// location - the location of the domain name.
50// domainNameLabel - the domain name to be verified. It must conform to the following regular expression:
51// ^[a-z][a-z0-9-]{1,61}[a-z0-9]$.
52func (client BaseClient) CheckDNSNameAvailability(ctx context.Context, location string, domainNameLabel string) (result DNSNameAvailabilityResult, err error) {
53	if tracing.IsEnabled() {
54		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.CheckDNSNameAvailability")
55		defer func() {
56			sc := -1
57			if result.Response.Response != nil {
58				sc = result.Response.Response.StatusCode
59			}
60			tracing.EndSpan(ctx, sc, err)
61		}()
62	}
63	req, err := client.CheckDNSNameAvailabilityPreparer(ctx, location, domainNameLabel)
64	if err != nil {
65		err = autorest.NewErrorWithError(err, "network.BaseClient", "CheckDNSNameAvailability", nil, "Failure preparing request")
66		return
67	}
68
69	resp, err := client.CheckDNSNameAvailabilitySender(req)
70	if err != nil {
71		result.Response = autorest.Response{Response: resp}
72		err = autorest.NewErrorWithError(err, "network.BaseClient", "CheckDNSNameAvailability", resp, "Failure sending request")
73		return
74	}
75
76	result, err = client.CheckDNSNameAvailabilityResponder(resp)
77	if err != nil {
78		err = autorest.NewErrorWithError(err, "network.BaseClient", "CheckDNSNameAvailability", resp, "Failure responding to request")
79		return
80	}
81
82	return
83}
84
85// CheckDNSNameAvailabilityPreparer prepares the CheckDNSNameAvailability request.
86func (client BaseClient) CheckDNSNameAvailabilityPreparer(ctx context.Context, location string, domainNameLabel string) (*http.Request, error) {
87	pathParameters := map[string]interface{}{
88		"location":       autorest.Encode("path", location),
89		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
90	}
91
92	const APIVersion = "2018-10-01"
93	queryParameters := map[string]interface{}{
94		"api-version":     APIVersion,
95		"domainNameLabel": autorest.Encode("query", domainNameLabel),
96	}
97
98	preparer := autorest.CreatePreparer(
99		autorest.AsGet(),
100		autorest.WithBaseURL(client.BaseURI),
101		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Network/locations/{location}/CheckDnsNameAvailability", pathParameters),
102		autorest.WithQueryParameters(queryParameters))
103	return preparer.Prepare((&http.Request{}).WithContext(ctx))
104}
105
106// CheckDNSNameAvailabilitySender sends the CheckDNSNameAvailability request. The method will close the
107// http.Response Body if it receives an error.
108func (client BaseClient) CheckDNSNameAvailabilitySender(req *http.Request) (*http.Response, error) {
109	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
110}
111
112// CheckDNSNameAvailabilityResponder handles the response to the CheckDNSNameAvailability request. The method always
113// closes the http.Response Body.
114func (client BaseClient) CheckDNSNameAvailabilityResponder(resp *http.Response) (result DNSNameAvailabilityResult, err error) {
115	err = autorest.Respond(
116		resp,
117		azure.WithErrorUnlessStatusCode(http.StatusOK),
118		autorest.ByUnmarshallingJSON(&result),
119		autorest.ByClosing())
120	result.Response = autorest.Response{Response: resp}
121	return
122}
123
124// SupportedSecurityProviders gives the supported security providers for the virtual wan.
125// Parameters:
126// resourceGroupName - the resource group name.
127// virtualWANName - the name of the VirtualWAN for which supported security providers are needed.
128func (client BaseClient) SupportedSecurityProviders(ctx context.Context, resourceGroupName string, virtualWANName string) (result VirtualWanSecurityProviders, err error) {
129	if tracing.IsEnabled() {
130		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.SupportedSecurityProviders")
131		defer func() {
132			sc := -1
133			if result.Response.Response != nil {
134				sc = result.Response.Response.StatusCode
135			}
136			tracing.EndSpan(ctx, sc, err)
137		}()
138	}
139	req, err := client.SupportedSecurityProvidersPreparer(ctx, resourceGroupName, virtualWANName)
140	if err != nil {
141		err = autorest.NewErrorWithError(err, "network.BaseClient", "SupportedSecurityProviders", nil, "Failure preparing request")
142		return
143	}
144
145	resp, err := client.SupportedSecurityProvidersSender(req)
146	if err != nil {
147		result.Response = autorest.Response{Response: resp}
148		err = autorest.NewErrorWithError(err, "network.BaseClient", "SupportedSecurityProviders", resp, "Failure sending request")
149		return
150	}
151
152	result, err = client.SupportedSecurityProvidersResponder(resp)
153	if err != nil {
154		err = autorest.NewErrorWithError(err, "network.BaseClient", "SupportedSecurityProviders", resp, "Failure responding to request")
155		return
156	}
157
158	return
159}
160
161// SupportedSecurityProvidersPreparer prepares the SupportedSecurityProviders request.
162func (client BaseClient) SupportedSecurityProvidersPreparer(ctx context.Context, resourceGroupName string, virtualWANName string) (*http.Request, error) {
163	pathParameters := map[string]interface{}{
164		"resourceGroupName": autorest.Encode("path", resourceGroupName),
165		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
166		"virtualWANName":    autorest.Encode("path", virtualWANName),
167	}
168
169	const APIVersion = "2018-10-01"
170	queryParameters := map[string]interface{}{
171		"api-version": APIVersion,
172	}
173
174	preparer := autorest.CreatePreparer(
175		autorest.AsGet(),
176		autorest.WithBaseURL(client.BaseURI),
177		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualWans/{virtualWANName}/supportedSecurityProviders", pathParameters),
178		autorest.WithQueryParameters(queryParameters))
179	return preparer.Prepare((&http.Request{}).WithContext(ctx))
180}
181
182// SupportedSecurityProvidersSender sends the SupportedSecurityProviders request. The method will close the
183// http.Response Body if it receives an error.
184func (client BaseClient) SupportedSecurityProvidersSender(req *http.Request) (*http.Response, error) {
185	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
186}
187
188// SupportedSecurityProvidersResponder handles the response to the SupportedSecurityProviders request. The method always
189// closes the http.Response Body.
190func (client BaseClient) SupportedSecurityProvidersResponder(resp *http.Response) (result VirtualWanSecurityProviders, err error) {
191	err = autorest.Respond(
192		resp,
193		azure.WithErrorUnlessStatusCode(http.StatusOK),
194		autorest.ByUnmarshallingJSON(&result),
195		autorest.ByClosing())
196	result.Response = autorest.Response{Response: resp}
197	return
198}
199