1package storagesync 2 3// Copyright (c) Microsoft and contributors. All rights reserved. 4// 5// Licensed under the Apache License, Version 2.0 (the "License"); 6// you may not use this file except in compliance with the License. 7// You may obtain a copy of the License at 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// 14// See the License for the specific language governing permissions and 15// limitations under the License. 16// 17// Code generated by Microsoft (R) AutoRest Code Generator. 18// Changes may cause incorrect behavior and will be lost if the code is regenerated. 19 20import ( 21 "context" 22 "github.com/Azure/go-autorest/autorest" 23 "github.com/Azure/go-autorest/autorest/azure" 24 "github.com/Azure/go-autorest/autorest/validation" 25 "github.com/Azure/go-autorest/tracing" 26 "net/http" 27) 28 29// SyncGroupsClient is the microsoft Storage Sync Service API 30type SyncGroupsClient struct { 31 BaseClient 32} 33 34// NewSyncGroupsClient creates an instance of the SyncGroupsClient client. 35func NewSyncGroupsClient(subscriptionID string) SyncGroupsClient { 36 return NewSyncGroupsClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewSyncGroupsClientWithBaseURI creates an instance of the SyncGroupsClient client using a custom endpoint. Use this 40// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 41func NewSyncGroupsClientWithBaseURI(baseURI string, subscriptionID string) SyncGroupsClient { 42 return SyncGroupsClient{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// Create create a new SyncGroup. 46// Parameters: 47// resourceGroupName - the name of the resource group. The name is case insensitive. 48// storageSyncServiceName - name of Storage Sync Service resource. 49// syncGroupName - name of Sync Group resource. 50// parameters - sync Group Body 51func (client SyncGroupsClient) Create(ctx context.Context, resourceGroupName string, storageSyncServiceName string, syncGroupName string, parameters SyncGroupCreateParameters) (result SyncGroup, err error) { 52 if tracing.IsEnabled() { 53 ctx = tracing.StartSpan(ctx, fqdn+"/SyncGroupsClient.Create") 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}}}, 65 {TargetValue: resourceGroupName, 66 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 67 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 68 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { 69 return result, validation.NewError("storagesync.SyncGroupsClient", "Create", err.Error()) 70 } 71 72 req, err := client.CreatePreparer(ctx, resourceGroupName, storageSyncServiceName, syncGroupName, parameters) 73 if err != nil { 74 err = autorest.NewErrorWithError(err, "storagesync.SyncGroupsClient", "Create", nil, "Failure preparing request") 75 return 76 } 77 78 resp, err := client.CreateSender(req) 79 if err != nil { 80 result.Response = autorest.Response{Response: resp} 81 err = autorest.NewErrorWithError(err, "storagesync.SyncGroupsClient", "Create", resp, "Failure sending request") 82 return 83 } 84 85 result, err = client.CreateResponder(resp) 86 if err != nil { 87 err = autorest.NewErrorWithError(err, "storagesync.SyncGroupsClient", "Create", resp, "Failure responding to request") 88 } 89 90 return 91} 92 93// CreatePreparer prepares the Create request. 94func (client SyncGroupsClient) CreatePreparer(ctx context.Context, resourceGroupName string, storageSyncServiceName string, syncGroupName string, parameters SyncGroupCreateParameters) (*http.Request, error) { 95 pathParameters := map[string]interface{}{ 96 "resourceGroupName": autorest.Encode("path", resourceGroupName), 97 "storageSyncServiceName": autorest.Encode("path", storageSyncServiceName), 98 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 99 "syncGroupName": autorest.Encode("path", syncGroupName), 100 } 101 102 const APIVersion = "2018-04-02" 103 queryParameters := map[string]interface{}{ 104 "api-version": APIVersion, 105 } 106 107 preparer := autorest.CreatePreparer( 108 autorest.AsContentType("application/json; charset=utf-8"), 109 autorest.AsPut(), 110 autorest.WithBaseURL(client.BaseURI), 111 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorageSync/storageSyncServices/{storageSyncServiceName}/syncGroups/{syncGroupName}", pathParameters), 112 autorest.WithJSON(parameters), 113 autorest.WithQueryParameters(queryParameters)) 114 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 115} 116 117// CreateSender sends the Create request. The method will close the 118// http.Response Body if it receives an error. 119func (client SyncGroupsClient) CreateSender(req *http.Request) (*http.Response, error) { 120 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 121} 122 123// CreateResponder handles the response to the Create request. The method always 124// closes the http.Response Body. 125func (client SyncGroupsClient) CreateResponder(resp *http.Response) (result SyncGroup, err error) { 126 err = autorest.Respond( 127 resp, 128 client.ByInspecting(), 129 azure.WithErrorUnlessStatusCode(http.StatusOK), 130 autorest.ByUnmarshallingJSON(&result), 131 autorest.ByClosing()) 132 result.Response = autorest.Response{Response: resp} 133 return 134} 135 136// Delete delete a given SyncGroup. 137// Parameters: 138// resourceGroupName - the name of the resource group. The name is case insensitive. 139// storageSyncServiceName - name of Storage Sync Service resource. 140// syncGroupName - name of Sync Group resource. 141func (client SyncGroupsClient) Delete(ctx context.Context, resourceGroupName string, storageSyncServiceName string, syncGroupName string) (result autorest.Response, err error) { 142 if tracing.IsEnabled() { 143 ctx = tracing.StartSpan(ctx, fqdn+"/SyncGroupsClient.Delete") 144 defer func() { 145 sc := -1 146 if result.Response != nil { 147 sc = result.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 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { 159 return result, validation.NewError("storagesync.SyncGroupsClient", "Delete", err.Error()) 160 } 161 162 req, err := client.DeletePreparer(ctx, resourceGroupName, storageSyncServiceName, syncGroupName) 163 if err != nil { 164 err = autorest.NewErrorWithError(err, "storagesync.SyncGroupsClient", "Delete", nil, "Failure preparing request") 165 return 166 } 167 168 resp, err := client.DeleteSender(req) 169 if err != nil { 170 result.Response = resp 171 err = autorest.NewErrorWithError(err, "storagesync.SyncGroupsClient", "Delete", resp, "Failure sending request") 172 return 173 } 174 175 result, err = client.DeleteResponder(resp) 176 if err != nil { 177 err = autorest.NewErrorWithError(err, "storagesync.SyncGroupsClient", "Delete", resp, "Failure responding to request") 178 } 179 180 return 181} 182 183// DeletePreparer prepares the Delete request. 184func (client SyncGroupsClient) DeletePreparer(ctx context.Context, resourceGroupName string, storageSyncServiceName string, syncGroupName string) (*http.Request, error) { 185 pathParameters := map[string]interface{}{ 186 "resourceGroupName": autorest.Encode("path", resourceGroupName), 187 "storageSyncServiceName": autorest.Encode("path", storageSyncServiceName), 188 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 189 "syncGroupName": autorest.Encode("path", syncGroupName), 190 } 191 192 const APIVersion = "2018-04-02" 193 queryParameters := map[string]interface{}{ 194 "api-version": APIVersion, 195 } 196 197 preparer := autorest.CreatePreparer( 198 autorest.AsDelete(), 199 autorest.WithBaseURL(client.BaseURI), 200 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorageSync/storageSyncServices/{storageSyncServiceName}/syncGroups/{syncGroupName}", pathParameters), 201 autorest.WithQueryParameters(queryParameters)) 202 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 203} 204 205// DeleteSender sends the Delete request. The method will close the 206// http.Response Body if it receives an error. 207func (client SyncGroupsClient) DeleteSender(req *http.Request) (*http.Response, error) { 208 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 209} 210 211// DeleteResponder handles the response to the Delete request. The method always 212// closes the http.Response Body. 213func (client SyncGroupsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 214 err = autorest.Respond( 215 resp, 216 client.ByInspecting(), 217 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 218 autorest.ByClosing()) 219 result.Response = resp 220 return 221} 222 223// Get get a given SyncGroup. 224// Parameters: 225// resourceGroupName - the name of the resource group. The name is case insensitive. 226// storageSyncServiceName - name of Storage Sync Service resource. 227// syncGroupName - name of Sync Group resource. 228func (client SyncGroupsClient) Get(ctx context.Context, resourceGroupName string, storageSyncServiceName string, syncGroupName string) (result SyncGroup, err error) { 229 if tracing.IsEnabled() { 230 ctx = tracing.StartSpan(ctx, fqdn+"/SyncGroupsClient.Get") 231 defer func() { 232 sc := -1 233 if result.Response.Response != nil { 234 sc = result.Response.Response.StatusCode 235 } 236 tracing.EndSpan(ctx, sc, err) 237 }() 238 } 239 if err := validation.Validate([]validation.Validation{ 240 {TargetValue: client.SubscriptionID, 241 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 242 {TargetValue: resourceGroupName, 243 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 244 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 245 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { 246 return result, validation.NewError("storagesync.SyncGroupsClient", "Get", err.Error()) 247 } 248 249 req, err := client.GetPreparer(ctx, resourceGroupName, storageSyncServiceName, syncGroupName) 250 if err != nil { 251 err = autorest.NewErrorWithError(err, "storagesync.SyncGroupsClient", "Get", nil, "Failure preparing request") 252 return 253 } 254 255 resp, err := client.GetSender(req) 256 if err != nil { 257 result.Response = autorest.Response{Response: resp} 258 err = autorest.NewErrorWithError(err, "storagesync.SyncGroupsClient", "Get", resp, "Failure sending request") 259 return 260 } 261 262 result, err = client.GetResponder(resp) 263 if err != nil { 264 err = autorest.NewErrorWithError(err, "storagesync.SyncGroupsClient", "Get", resp, "Failure responding to request") 265 } 266 267 return 268} 269 270// GetPreparer prepares the Get request. 271func (client SyncGroupsClient) GetPreparer(ctx context.Context, resourceGroupName string, storageSyncServiceName string, syncGroupName string) (*http.Request, error) { 272 pathParameters := map[string]interface{}{ 273 "resourceGroupName": autorest.Encode("path", resourceGroupName), 274 "storageSyncServiceName": autorest.Encode("path", storageSyncServiceName), 275 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 276 "syncGroupName": autorest.Encode("path", syncGroupName), 277 } 278 279 const APIVersion = "2018-04-02" 280 queryParameters := map[string]interface{}{ 281 "api-version": APIVersion, 282 } 283 284 preparer := autorest.CreatePreparer( 285 autorest.AsGet(), 286 autorest.WithBaseURL(client.BaseURI), 287 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorageSync/storageSyncServices/{storageSyncServiceName}/syncGroups/{syncGroupName}", pathParameters), 288 autorest.WithQueryParameters(queryParameters)) 289 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 290} 291 292// GetSender sends the Get request. The method will close the 293// http.Response Body if it receives an error. 294func (client SyncGroupsClient) GetSender(req *http.Request) (*http.Response, error) { 295 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 296} 297 298// GetResponder handles the response to the Get request. The method always 299// closes the http.Response Body. 300func (client SyncGroupsClient) GetResponder(resp *http.Response) (result SyncGroup, err error) { 301 err = autorest.Respond( 302 resp, 303 client.ByInspecting(), 304 azure.WithErrorUnlessStatusCode(http.StatusOK), 305 autorest.ByUnmarshallingJSON(&result), 306 autorest.ByClosing()) 307 result.Response = autorest.Response{Response: resp} 308 return 309} 310 311// ListByStorageSyncService get a SyncGroup List. 312// Parameters: 313// resourceGroupName - the name of the resource group. The name is case insensitive. 314// storageSyncServiceName - name of Storage Sync Service resource. 315func (client SyncGroupsClient) ListByStorageSyncService(ctx context.Context, resourceGroupName string, storageSyncServiceName string) (result SyncGroupArray, err error) { 316 if tracing.IsEnabled() { 317 ctx = tracing.StartSpan(ctx, fqdn+"/SyncGroupsClient.ListByStorageSyncService") 318 defer func() { 319 sc := -1 320 if result.Response.Response != nil { 321 sc = result.Response.Response.StatusCode 322 } 323 tracing.EndSpan(ctx, sc, err) 324 }() 325 } 326 if err := validation.Validate([]validation.Validation{ 327 {TargetValue: client.SubscriptionID, 328 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 329 {TargetValue: resourceGroupName, 330 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 331 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 332 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { 333 return result, validation.NewError("storagesync.SyncGroupsClient", "ListByStorageSyncService", err.Error()) 334 } 335 336 req, err := client.ListByStorageSyncServicePreparer(ctx, resourceGroupName, storageSyncServiceName) 337 if err != nil { 338 err = autorest.NewErrorWithError(err, "storagesync.SyncGroupsClient", "ListByStorageSyncService", nil, "Failure preparing request") 339 return 340 } 341 342 resp, err := client.ListByStorageSyncServiceSender(req) 343 if err != nil { 344 result.Response = autorest.Response{Response: resp} 345 err = autorest.NewErrorWithError(err, "storagesync.SyncGroupsClient", "ListByStorageSyncService", resp, "Failure sending request") 346 return 347 } 348 349 result, err = client.ListByStorageSyncServiceResponder(resp) 350 if err != nil { 351 err = autorest.NewErrorWithError(err, "storagesync.SyncGroupsClient", "ListByStorageSyncService", resp, "Failure responding to request") 352 } 353 354 return 355} 356 357// ListByStorageSyncServicePreparer prepares the ListByStorageSyncService request. 358func (client SyncGroupsClient) ListByStorageSyncServicePreparer(ctx context.Context, resourceGroupName string, storageSyncServiceName string) (*http.Request, error) { 359 pathParameters := map[string]interface{}{ 360 "resourceGroupName": autorest.Encode("path", resourceGroupName), 361 "storageSyncServiceName": autorest.Encode("path", storageSyncServiceName), 362 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 363 } 364 365 const APIVersion = "2018-04-02" 366 queryParameters := map[string]interface{}{ 367 "api-version": APIVersion, 368 } 369 370 preparer := autorest.CreatePreparer( 371 autorest.AsGet(), 372 autorest.WithBaseURL(client.BaseURI), 373 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorageSync/storageSyncServices/{storageSyncServiceName}/syncGroups", pathParameters), 374 autorest.WithQueryParameters(queryParameters)) 375 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 376} 377 378// ListByStorageSyncServiceSender sends the ListByStorageSyncService request. The method will close the 379// http.Response Body if it receives an error. 380func (client SyncGroupsClient) ListByStorageSyncServiceSender(req *http.Request) (*http.Response, error) { 381 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 382} 383 384// ListByStorageSyncServiceResponder handles the response to the ListByStorageSyncService request. The method always 385// closes the http.Response Body. 386func (client SyncGroupsClient) ListByStorageSyncServiceResponder(resp *http.Response) (result SyncGroupArray, err error) { 387 err = autorest.Respond( 388 resp, 389 client.ByInspecting(), 390 azure.WithErrorUnlessStatusCode(http.StatusOK), 391 autorest.ByUnmarshallingJSON(&result), 392 autorest.ByClosing()) 393 result.Response = autorest.Response{Response: resp} 394 return 395} 396