1// Package documentdb implements the Azure ARM Documentdb service API version 2021-04-01-preview.
2//
3//
4package documentdb
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/autorest/validation"
17	"github.com/Azure/go-autorest/tracing"
18	"net/http"
19)
20
21const (
22	// DefaultBaseURI is the default URI used for the service Documentdb
23	DefaultBaseURI = "https://management.azure.com"
24)
25
26// BaseClient is the base client for Documentdb.
27type BaseClient struct {
28	autorest.Client
29	BaseURI        string
30	SubscriptionID string
31}
32
33// New creates an instance of the BaseClient client.
34func New(subscriptionID string) BaseClient {
35	return NewWithBaseURI(DefaultBaseURI, subscriptionID)
36}
37
38// NewWithBaseURI creates an instance of the BaseClient client using a custom endpoint.  Use this when interacting with
39// an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
40func NewWithBaseURI(baseURI string, subscriptionID string) BaseClient {
41	return BaseClient{
42		Client:         autorest.NewClientWithUserAgent(UserAgent()),
43		BaseURI:        baseURI,
44		SubscriptionID: subscriptionID,
45	}
46}
47
48// LocationGet get the properties of an existing Cosmos DB location
49// Parameters:
50// location - cosmos DB region, with spaces between words and each word capitalized.
51func (client BaseClient) LocationGet(ctx context.Context, location string) (result LocationGetResult, err error) {
52	if tracing.IsEnabled() {
53		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.LocationGet")
54		defer func() {
55			sc := -1
56			if result.Response.Response != nil {
57				sc = result.Response.Response.StatusCode
58			}
59			tracing.EndSpan(ctx, sc, err)
60		}()
61	}
62	if err := validation.Validate([]validation.Validation{
63		{TargetValue: client.SubscriptionID,
64			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
65		return result, validation.NewError("documentdb.BaseClient", "LocationGet", err.Error())
66	}
67
68	req, err := client.LocationGetPreparer(ctx, location)
69	if err != nil {
70		err = autorest.NewErrorWithError(err, "documentdb.BaseClient", "LocationGet", nil, "Failure preparing request")
71		return
72	}
73
74	resp, err := client.LocationGetSender(req)
75	if err != nil {
76		result.Response = autorest.Response{Response: resp}
77		err = autorest.NewErrorWithError(err, "documentdb.BaseClient", "LocationGet", resp, "Failure sending request")
78		return
79	}
80
81	result, err = client.LocationGetResponder(resp)
82	if err != nil {
83		err = autorest.NewErrorWithError(err, "documentdb.BaseClient", "LocationGet", resp, "Failure responding to request")
84		return
85	}
86
87	return
88}
89
90// LocationGetPreparer prepares the LocationGet request.
91func (client BaseClient) LocationGetPreparer(ctx context.Context, location string) (*http.Request, error) {
92	pathParameters := map[string]interface{}{
93		"location":       autorest.Encode("path", location),
94		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
95	}
96
97	const APIVersion = "2021-04-01-preview"
98	queryParameters := map[string]interface{}{
99		"api-version": APIVersion,
100	}
101
102	preparer := autorest.CreatePreparer(
103		autorest.AsGet(),
104		autorest.WithBaseURL(client.BaseURI),
105		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.DocumentDB/locations/{location}", pathParameters),
106		autorest.WithQueryParameters(queryParameters))
107	return preparer.Prepare((&http.Request{}).WithContext(ctx))
108}
109
110// LocationGetSender sends the LocationGet request. The method will close the
111// http.Response Body if it receives an error.
112func (client BaseClient) LocationGetSender(req *http.Request) (*http.Response, error) {
113	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
114}
115
116// LocationGetResponder handles the response to the LocationGet request. The method always
117// closes the http.Response Body.
118func (client BaseClient) LocationGetResponder(resp *http.Response) (result LocationGetResult, err error) {
119	err = autorest.Respond(
120		resp,
121		azure.WithErrorUnlessStatusCode(http.StatusOK),
122		autorest.ByUnmarshallingJSON(&result),
123		autorest.ByClosing())
124	result.Response = autorest.Response{Response: resp}
125	return
126}
127
128// LocationList list Cosmos DB locations and their properties
129func (client BaseClient) LocationList(ctx context.Context) (result LocationListResult, err error) {
130	if tracing.IsEnabled() {
131		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.LocationList")
132		defer func() {
133			sc := -1
134			if result.Response.Response != nil {
135				sc = result.Response.Response.StatusCode
136			}
137			tracing.EndSpan(ctx, sc, err)
138		}()
139	}
140	if err := validation.Validate([]validation.Validation{
141		{TargetValue: client.SubscriptionID,
142			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
143		return result, validation.NewError("documentdb.BaseClient", "LocationList", err.Error())
144	}
145
146	req, err := client.LocationListPreparer(ctx)
147	if err != nil {
148		err = autorest.NewErrorWithError(err, "documentdb.BaseClient", "LocationList", nil, "Failure preparing request")
149		return
150	}
151
152	resp, err := client.LocationListSender(req)
153	if err != nil {
154		result.Response = autorest.Response{Response: resp}
155		err = autorest.NewErrorWithError(err, "documentdb.BaseClient", "LocationList", resp, "Failure sending request")
156		return
157	}
158
159	result, err = client.LocationListResponder(resp)
160	if err != nil {
161		err = autorest.NewErrorWithError(err, "documentdb.BaseClient", "LocationList", resp, "Failure responding to request")
162		return
163	}
164
165	return
166}
167
168// LocationListPreparer prepares the LocationList request.
169func (client BaseClient) LocationListPreparer(ctx context.Context) (*http.Request, error) {
170	pathParameters := map[string]interface{}{
171		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
172	}
173
174	const APIVersion = "2021-04-01-preview"
175	queryParameters := map[string]interface{}{
176		"api-version": APIVersion,
177	}
178
179	preparer := autorest.CreatePreparer(
180		autorest.AsGet(),
181		autorest.WithBaseURL(client.BaseURI),
182		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.DocumentDB/locations", pathParameters),
183		autorest.WithQueryParameters(queryParameters))
184	return preparer.Prepare((&http.Request{}).WithContext(ctx))
185}
186
187// LocationListSender sends the LocationList request. The method will close the
188// http.Response Body if it receives an error.
189func (client BaseClient) LocationListSender(req *http.Request) (*http.Response, error) {
190	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
191}
192
193// LocationListResponder handles the response to the LocationList request. The method always
194// closes the http.Response Body.
195func (client BaseClient) LocationListResponder(resp *http.Response) (result LocationListResult, err error) {
196	err = autorest.Respond(
197		resp,
198		azure.WithErrorUnlessStatusCode(http.StatusOK),
199		autorest.ByUnmarshallingJSON(&result),
200		autorest.ByClosing())
201	result.Response = autorest.Response{Response: resp}
202	return
203}
204