1 package documentdb
2
3
4
5
6
7
8
9 import (
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
19 type GraphResourcesClient struct {
20 BaseClient
21 }
22
23
24 func NewGraphResourcesClient(subscriptionID string) GraphResourcesClient {
25 return NewGraphResourcesClientWithBaseURI(DefaultBaseURI, subscriptionID)
26 }
27
28
29
30 func NewGraphResourcesClientWithBaseURI(baseURI string, subscriptionID string) GraphResourcesClient {
31 return GraphResourcesClient{NewWithBaseURI(baseURI, subscriptionID)}
32 }
33
34
35
36
37
38
39
40 func (client GraphResourcesClient) CreateUpdateGraph(ctx context.Context, resourceGroupName string, accountName string, graphName string, createUpdateGraphParameters GraphResourceCreateUpdateParameters) (result GraphResourcesCreateUpdateGraphFuture, err error) {
41 if tracing.IsEnabled() {
42 ctx = tracing.StartSpan(ctx, fqdn+"/GraphResourcesClient.CreateUpdateGraph")
43 defer func() {
44 sc := -1
45 if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
46 sc = result.FutureAPI.Response().StatusCode
47 }
48 tracing.EndSpan(ctx, sc, err)
49 }()
50 }
51 if err := validation.Validate([]validation.Validation{
52 {TargetValue: client.SubscriptionID,
53 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
54 {TargetValue: resourceGroupName,
55 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
56 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
57 {TargetValue: accountName,
58 Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
59 {Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
60 {Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}},
61 {TargetValue: createUpdateGraphParameters,
62 Constraints: []validation.Constraint{{Target: "createUpdateGraphParameters.GraphResourceCreateUpdateProperties", Name: validation.Null, Rule: true,
63 Chain: []validation.Constraint{{Target: "createUpdateGraphParameters.GraphResourceCreateUpdateProperties.Resource", Name: validation.Null, Rule: true,
64 Chain: []validation.Constraint{{Target: "createUpdateGraphParameters.GraphResourceCreateUpdateProperties.Resource.ID", Name: validation.Null, Rule: true, Chain: nil}}},
65 }}}}}); err != nil {
66 return result, validation.NewError("documentdb.GraphResourcesClient", "CreateUpdateGraph", err.Error())
67 }
68
69 req, err := client.CreateUpdateGraphPreparer(ctx, resourceGroupName, accountName, graphName, createUpdateGraphParameters)
70 if err != nil {
71 err = autorest.NewErrorWithError(err, "documentdb.GraphResourcesClient", "CreateUpdateGraph", nil, "Failure preparing request")
72 return
73 }
74
75 result, err = client.CreateUpdateGraphSender(req)
76 if err != nil {
77 err = autorest.NewErrorWithError(err, "documentdb.GraphResourcesClient", "CreateUpdateGraph", result.Response(), "Failure sending request")
78 return
79 }
80
81 return
82 }
83
84
85 func (client GraphResourcesClient) CreateUpdateGraphPreparer(ctx context.Context, resourceGroupName string, accountName string, graphName string, createUpdateGraphParameters GraphResourceCreateUpdateParameters) (*http.Request, error) {
86 pathParameters := map[string]interface{}{
87 "accountName": autorest.Encode("path", accountName),
88 "graphName": autorest.Encode("path", graphName),
89 "resourceGroupName": autorest.Encode("path", resourceGroupName),
90 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
91 }
92
93 const APIVersion = "2021-11-15-preview"
94 queryParameters := map[string]interface{}{
95 "api-version": APIVersion,
96 }
97
98 preparer := autorest.CreatePreparer(
99 autorest.AsContentType("application/json; charset=utf-8"),
100 autorest.AsPut(),
101 autorest.WithBaseURL(client.BaseURI),
102 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/graphs/{graphName}", pathParameters),
103 autorest.WithJSON(createUpdateGraphParameters),
104 autorest.WithQueryParameters(queryParameters))
105 return preparer.Prepare((&http.Request{}).WithContext(ctx))
106 }
107
108
109
110 func (client GraphResourcesClient) CreateUpdateGraphSender(req *http.Request) (future GraphResourcesCreateUpdateGraphFuture, err error) {
111 var resp *http.Response
112 future.FutureAPI = &azure.Future{}
113 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
114 if err != nil {
115 return
116 }
117 var azf azure.Future
118 azf, err = azure.NewFutureFromResponse(resp)
119 future.FutureAPI = &azf
120 future.Result = future.result
121 return
122 }
123
124
125
126 func (client GraphResourcesClient) CreateUpdateGraphResponder(resp *http.Response) (result GraphResourceGetResults, err error) {
127 err = autorest.Respond(
128 resp,
129 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
130 autorest.ByUnmarshallingJSON(&result),
131 autorest.ByClosing())
132 result.Response = autorest.Response{Response: resp}
133 return
134 }
135
136
137
138
139
140
141 func (client GraphResourcesClient) DeleteGraphResource(ctx context.Context, resourceGroupName string, accountName string, graphName string) (result GraphResourcesDeleteGraphResourceFuture, err error) {
142 if tracing.IsEnabled() {
143 ctx = tracing.StartSpan(ctx, fqdn+"/GraphResourcesClient.DeleteGraphResource")
144 defer func() {
145 sc := -1
146 if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
147 sc = result.FutureAPI.Response().StatusCode
148 }
149 tracing.EndSpan(ctx, sc, err)
150 }()
151 }
152 if err := validation.Validate([]validation.Validation{
153 {TargetValue: client.SubscriptionID,
154 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
155 {TargetValue: resourceGroupName,
156 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
157 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
158 {TargetValue: accountName,
159 Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
160 {Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
161 {Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
162 return result, validation.NewError("documentdb.GraphResourcesClient", "DeleteGraphResource", err.Error())
163 }
164
165 req, err := client.DeleteGraphResourcePreparer(ctx, resourceGroupName, accountName, graphName)
166 if err != nil {
167 err = autorest.NewErrorWithError(err, "documentdb.GraphResourcesClient", "DeleteGraphResource", nil, "Failure preparing request")
168 return
169 }
170
171 result, err = client.DeleteGraphResourceSender(req)
172 if err != nil {
173 err = autorest.NewErrorWithError(err, "documentdb.GraphResourcesClient", "DeleteGraphResource", result.Response(), "Failure sending request")
174 return
175 }
176
177 return
178 }
179
180
181 func (client GraphResourcesClient) DeleteGraphResourcePreparer(ctx context.Context, resourceGroupName string, accountName string, graphName string) (*http.Request, error) {
182 pathParameters := map[string]interface{}{
183 "accountName": autorest.Encode("path", accountName),
184 "graphName": autorest.Encode("path", graphName),
185 "resourceGroupName": autorest.Encode("path", resourceGroupName),
186 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
187 }
188
189 const APIVersion = "2021-11-15-preview"
190 queryParameters := map[string]interface{}{
191 "api-version": APIVersion,
192 }
193
194 preparer := autorest.CreatePreparer(
195 autorest.AsDelete(),
196 autorest.WithBaseURL(client.BaseURI),
197 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/graphs/{graphName}", pathParameters),
198 autorest.WithQueryParameters(queryParameters))
199 return preparer.Prepare((&http.Request{}).WithContext(ctx))
200 }
201
202
203
204 func (client GraphResourcesClient) DeleteGraphResourceSender(req *http.Request) (future GraphResourcesDeleteGraphResourceFuture, err error) {
205 var resp *http.Response
206 future.FutureAPI = &azure.Future{}
207 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
208 if err != nil {
209 return
210 }
211 var azf azure.Future
212 azf, err = azure.NewFutureFromResponse(resp)
213 future.FutureAPI = &azf
214 future.Result = future.result
215 return
216 }
217
218
219
220 func (client GraphResourcesClient) DeleteGraphResourceResponder(resp *http.Response) (result autorest.Response, err error) {
221 err = autorest.Respond(
222 resp,
223 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
224 autorest.ByClosing())
225 result.Response = resp
226 return
227 }
228
229
230
231
232
233
234 func (client GraphResourcesClient) GetGraph(ctx context.Context, resourceGroupName string, accountName string, graphName string) (result GraphResourceGetResults, err error) {
235 if tracing.IsEnabled() {
236 ctx = tracing.StartSpan(ctx, fqdn+"/GraphResourcesClient.GetGraph")
237 defer func() {
238 sc := -1
239 if result.Response.Response != nil {
240 sc = result.Response.Response.StatusCode
241 }
242 tracing.EndSpan(ctx, sc, err)
243 }()
244 }
245 if err := validation.Validate([]validation.Validation{
246 {TargetValue: client.SubscriptionID,
247 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
248 {TargetValue: resourceGroupName,
249 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
250 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
251 {TargetValue: accountName,
252 Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
253 {Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
254 {Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
255 return result, validation.NewError("documentdb.GraphResourcesClient", "GetGraph", err.Error())
256 }
257
258 req, err := client.GetGraphPreparer(ctx, resourceGroupName, accountName, graphName)
259 if err != nil {
260 err = autorest.NewErrorWithError(err, "documentdb.GraphResourcesClient", "GetGraph", nil, "Failure preparing request")
261 return
262 }
263
264 resp, err := client.GetGraphSender(req)
265 if err != nil {
266 result.Response = autorest.Response{Response: resp}
267 err = autorest.NewErrorWithError(err, "documentdb.GraphResourcesClient", "GetGraph", resp, "Failure sending request")
268 return
269 }
270
271 result, err = client.GetGraphResponder(resp)
272 if err != nil {
273 err = autorest.NewErrorWithError(err, "documentdb.GraphResourcesClient", "GetGraph", resp, "Failure responding to request")
274 return
275 }
276
277 return
278 }
279
280
281 func (client GraphResourcesClient) GetGraphPreparer(ctx context.Context, resourceGroupName string, accountName string, graphName string) (*http.Request, error) {
282 pathParameters := map[string]interface{}{
283 "accountName": autorest.Encode("path", accountName),
284 "graphName": autorest.Encode("path", graphName),
285 "resourceGroupName": autorest.Encode("path", resourceGroupName),
286 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
287 }
288
289 const APIVersion = "2021-11-15-preview"
290 queryParameters := map[string]interface{}{
291 "api-version": APIVersion,
292 }
293
294 preparer := autorest.CreatePreparer(
295 autorest.AsGet(),
296 autorest.WithBaseURL(client.BaseURI),
297 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/graphs/{graphName}", pathParameters),
298 autorest.WithQueryParameters(queryParameters))
299 return preparer.Prepare((&http.Request{}).WithContext(ctx))
300 }
301
302
303
304 func (client GraphResourcesClient) GetGraphSender(req *http.Request) (*http.Response, error) {
305 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
306 }
307
308
309
310 func (client GraphResourcesClient) GetGraphResponder(resp *http.Response) (result GraphResourceGetResults, err error) {
311 err = autorest.Respond(
312 resp,
313 azure.WithErrorUnlessStatusCode(http.StatusOK),
314 autorest.ByUnmarshallingJSON(&result),
315 autorest.ByClosing())
316 result.Response = autorest.Response{Response: resp}
317 return
318 }
319
320
321
322
323
324 func (client GraphResourcesClient) ListGraphs(ctx context.Context, resourceGroupName string, accountName string) (result GraphResourcesListResult, err error) {
325 if tracing.IsEnabled() {
326 ctx = tracing.StartSpan(ctx, fqdn+"/GraphResourcesClient.ListGraphs")
327 defer func() {
328 sc := -1
329 if result.Response.Response != nil {
330 sc = result.Response.Response.StatusCode
331 }
332 tracing.EndSpan(ctx, sc, err)
333 }()
334 }
335 if err := validation.Validate([]validation.Validation{
336 {TargetValue: client.SubscriptionID,
337 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
338 {TargetValue: resourceGroupName,
339 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
340 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
341 {TargetValue: accountName,
342 Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
343 {Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
344 {Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
345 return result, validation.NewError("documentdb.GraphResourcesClient", "ListGraphs", err.Error())
346 }
347
348 req, err := client.ListGraphsPreparer(ctx, resourceGroupName, accountName)
349 if err != nil {
350 err = autorest.NewErrorWithError(err, "documentdb.GraphResourcesClient", "ListGraphs", nil, "Failure preparing request")
351 return
352 }
353
354 resp, err := client.ListGraphsSender(req)
355 if err != nil {
356 result.Response = autorest.Response{Response: resp}
357 err = autorest.NewErrorWithError(err, "documentdb.GraphResourcesClient", "ListGraphs", resp, "Failure sending request")
358 return
359 }
360
361 result, err = client.ListGraphsResponder(resp)
362 if err != nil {
363 err = autorest.NewErrorWithError(err, "documentdb.GraphResourcesClient", "ListGraphs", resp, "Failure responding to request")
364 return
365 }
366
367 return
368 }
369
370
371 func (client GraphResourcesClient) ListGraphsPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) {
372 pathParameters := map[string]interface{}{
373 "accountName": autorest.Encode("path", accountName),
374 "resourceGroupName": autorest.Encode("path", resourceGroupName),
375 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
376 }
377
378 const APIVersion = "2021-11-15-preview"
379 queryParameters := map[string]interface{}{
380 "api-version": APIVersion,
381 }
382
383 preparer := autorest.CreatePreparer(
384 autorest.AsGet(),
385 autorest.WithBaseURL(client.BaseURI),
386 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/graphs", pathParameters),
387 autorest.WithQueryParameters(queryParameters))
388 return preparer.Prepare((&http.Request{}).WithContext(ctx))
389 }
390
391
392
393 func (client GraphResourcesClient) ListGraphsSender(req *http.Request) (*http.Response, error) {
394 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
395 }
396
397
398
399 func (client GraphResourcesClient) ListGraphsResponder(resp *http.Response) (result GraphResourcesListResult, err error) {
400 err = autorest.Respond(
401 resp,
402 azure.WithErrorUnlessStatusCode(http.StatusOK),
403 autorest.ByUnmarshallingJSON(&result),
404 autorest.ByClosing())
405 result.Response = autorest.Response{Response: resp}
406 return
407 }
408
View as plain text