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