1package desktopvirtualization 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// DesktopsClient is the client for the Desktops methods of the Desktopvirtualization service. 30type DesktopsClient struct { 31 BaseClient 32} 33 34// NewDesktopsClient creates an instance of the DesktopsClient client. 35func NewDesktopsClient(subscriptionID string) DesktopsClient { 36 return NewDesktopsClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewDesktopsClientWithBaseURI creates an instance of the DesktopsClient 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 NewDesktopsClientWithBaseURI(baseURI string, subscriptionID string) DesktopsClient { 42 return DesktopsClient{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// Get get a desktop. 46// Parameters: 47// resourceGroupName - the name of the resource group. The name is case insensitive. 48// applicationGroupName - the name of the application group 49// desktopName - the name of the desktop within the specified desktop group 50func (client DesktopsClient) Get(ctx context.Context, resourceGroupName string, applicationGroupName string, desktopName string) (result Desktop, err error) { 51 if tracing.IsEnabled() { 52 ctx = tracing.StartSpan(ctx, fqdn+"/DesktopsClient.Get") 53 defer func() { 54 sc := -1 55 if result.Response.Response != nil { 56 sc = result.Response.Response.StatusCode 57 } 58 tracing.EndSpan(ctx, sc, err) 59 }() 60 } 61 if err := validation.Validate([]validation.Validation{ 62 {TargetValue: client.SubscriptionID, 63 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 64 {TargetValue: resourceGroupName, 65 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 66 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 67 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, 68 {TargetValue: applicationGroupName, 69 Constraints: []validation.Constraint{{Target: "applicationGroupName", Name: validation.MaxLength, Rule: 24, Chain: nil}, 70 {Target: "applicationGroupName", Name: validation.MinLength, Rule: 3, Chain: nil}}}, 71 {TargetValue: desktopName, 72 Constraints: []validation.Constraint{{Target: "desktopName", Name: validation.MaxLength, Rule: 24, Chain: nil}, 73 {Target: "desktopName", Name: validation.MinLength, Rule: 3, Chain: nil}}}}); err != nil { 74 return result, validation.NewError("desktopvirtualization.DesktopsClient", "Get", err.Error()) 75 } 76 77 req, err := client.GetPreparer(ctx, resourceGroupName, applicationGroupName, desktopName) 78 if err != nil { 79 err = autorest.NewErrorWithError(err, "desktopvirtualization.DesktopsClient", "Get", nil, "Failure preparing request") 80 return 81 } 82 83 resp, err := client.GetSender(req) 84 if err != nil { 85 result.Response = autorest.Response{Response: resp} 86 err = autorest.NewErrorWithError(err, "desktopvirtualization.DesktopsClient", "Get", resp, "Failure sending request") 87 return 88 } 89 90 result, err = client.GetResponder(resp) 91 if err != nil { 92 err = autorest.NewErrorWithError(err, "desktopvirtualization.DesktopsClient", "Get", resp, "Failure responding to request") 93 } 94 95 return 96} 97 98// GetPreparer prepares the Get request. 99func (client DesktopsClient) GetPreparer(ctx context.Context, resourceGroupName string, applicationGroupName string, desktopName string) (*http.Request, error) { 100 pathParameters := map[string]interface{}{ 101 "applicationGroupName": autorest.Encode("path", applicationGroupName), 102 "desktopName": autorest.Encode("path", desktopName), 103 "resourceGroupName": autorest.Encode("path", resourceGroupName), 104 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 105 } 106 107 const APIVersion = "2019-09-24-preview" 108 queryParameters := map[string]interface{}{ 109 "api-version": APIVersion, 110 } 111 112 preparer := autorest.CreatePreparer( 113 autorest.AsGet(), 114 autorest.WithBaseURL(client.BaseURI), 115 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DesktopVirtualization/applicationGroups/{applicationGroupName}/desktops/{desktopName}", pathParameters), 116 autorest.WithQueryParameters(queryParameters)) 117 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 118} 119 120// GetSender sends the Get request. The method will close the 121// http.Response Body if it receives an error. 122func (client DesktopsClient) GetSender(req *http.Request) (*http.Response, error) { 123 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 124} 125 126// GetResponder handles the response to the Get request. The method always 127// closes the http.Response Body. 128func (client DesktopsClient) GetResponder(resp *http.Response) (result Desktop, err error) { 129 err = autorest.Respond( 130 resp, 131 client.ByInspecting(), 132 azure.WithErrorUnlessStatusCode(http.StatusOK), 133 autorest.ByUnmarshallingJSON(&result), 134 autorest.ByClosing()) 135 result.Response = autorest.Response{Response: resp} 136 return 137} 138 139// List list desktops. 140// Parameters: 141// resourceGroupName - the name of the resource group. The name is case insensitive. 142// applicationGroupName - the name of the application group 143func (client DesktopsClient) List(ctx context.Context, resourceGroupName string, applicationGroupName string) (result DesktopList, err error) { 144 if tracing.IsEnabled() { 145 ctx = tracing.StartSpan(ctx, fqdn+"/DesktopsClient.List") 146 defer func() { 147 sc := -1 148 if result.Response.Response != nil { 149 sc = result.Response.Response.StatusCode 150 } 151 tracing.EndSpan(ctx, sc, err) 152 }() 153 } 154 if err := validation.Validate([]validation.Validation{ 155 {TargetValue: client.SubscriptionID, 156 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 157 {TargetValue: resourceGroupName, 158 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 159 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 160 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, 161 {TargetValue: applicationGroupName, 162 Constraints: []validation.Constraint{{Target: "applicationGroupName", Name: validation.MaxLength, Rule: 24, Chain: nil}, 163 {Target: "applicationGroupName", Name: validation.MinLength, Rule: 3, Chain: nil}}}}); err != nil { 164 return result, validation.NewError("desktopvirtualization.DesktopsClient", "List", err.Error()) 165 } 166 167 req, err := client.ListPreparer(ctx, resourceGroupName, applicationGroupName) 168 if err != nil { 169 err = autorest.NewErrorWithError(err, "desktopvirtualization.DesktopsClient", "List", nil, "Failure preparing request") 170 return 171 } 172 173 resp, err := client.ListSender(req) 174 if err != nil { 175 result.Response = autorest.Response{Response: resp} 176 err = autorest.NewErrorWithError(err, "desktopvirtualization.DesktopsClient", "List", resp, "Failure sending request") 177 return 178 } 179 180 result, err = client.ListResponder(resp) 181 if err != nil { 182 err = autorest.NewErrorWithError(err, "desktopvirtualization.DesktopsClient", "List", resp, "Failure responding to request") 183 } 184 185 return 186} 187 188// ListPreparer prepares the List request. 189func (client DesktopsClient) ListPreparer(ctx context.Context, resourceGroupName string, applicationGroupName string) (*http.Request, error) { 190 pathParameters := map[string]interface{}{ 191 "applicationGroupName": autorest.Encode("path", applicationGroupName), 192 "resourceGroupName": autorest.Encode("path", resourceGroupName), 193 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 194 } 195 196 const APIVersion = "2019-09-24-preview" 197 queryParameters := map[string]interface{}{ 198 "api-version": APIVersion, 199 } 200 201 preparer := autorest.CreatePreparer( 202 autorest.AsGet(), 203 autorest.WithBaseURL(client.BaseURI), 204 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DesktopVirtualization/applicationGroups/{applicationGroupName}/desktops", pathParameters), 205 autorest.WithQueryParameters(queryParameters)) 206 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 207} 208 209// ListSender sends the List request. The method will close the 210// http.Response Body if it receives an error. 211func (client DesktopsClient) ListSender(req *http.Request) (*http.Response, error) { 212 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 213} 214 215// ListResponder handles the response to the List request. The method always 216// closes the http.Response Body. 217func (client DesktopsClient) ListResponder(resp *http.Response) (result DesktopList, err error) { 218 err = autorest.Respond( 219 resp, 220 client.ByInspecting(), 221 azure.WithErrorUnlessStatusCode(http.StatusOK), 222 autorest.ByUnmarshallingJSON(&result), 223 autorest.ByClosing()) 224 result.Response = autorest.Response{Response: resp} 225 return 226} 227 228// Update update a desktop. 229// Parameters: 230// resourceGroupName - the name of the resource group. The name is case insensitive. 231// applicationGroupName - the name of the application group 232// desktopName - the name of the desktop within the specified desktop group 233// desktop - object containing Desktop definitions. 234func (client DesktopsClient) Update(ctx context.Context, resourceGroupName string, applicationGroupName string, desktopName string, desktop *DesktopPatch) (result Desktop, err error) { 235 if tracing.IsEnabled() { 236 ctx = tracing.StartSpan(ctx, fqdn+"/DesktopsClient.Update") 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 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, 252 {TargetValue: applicationGroupName, 253 Constraints: []validation.Constraint{{Target: "applicationGroupName", Name: validation.MaxLength, Rule: 24, Chain: nil}, 254 {Target: "applicationGroupName", Name: validation.MinLength, Rule: 3, Chain: nil}}}, 255 {TargetValue: desktopName, 256 Constraints: []validation.Constraint{{Target: "desktopName", Name: validation.MaxLength, Rule: 24, Chain: nil}, 257 {Target: "desktopName", Name: validation.MinLength, Rule: 3, Chain: nil}}}}); err != nil { 258 return result, validation.NewError("desktopvirtualization.DesktopsClient", "Update", err.Error()) 259 } 260 261 req, err := client.UpdatePreparer(ctx, resourceGroupName, applicationGroupName, desktopName, desktop) 262 if err != nil { 263 err = autorest.NewErrorWithError(err, "desktopvirtualization.DesktopsClient", "Update", nil, "Failure preparing request") 264 return 265 } 266 267 resp, err := client.UpdateSender(req) 268 if err != nil { 269 result.Response = autorest.Response{Response: resp} 270 err = autorest.NewErrorWithError(err, "desktopvirtualization.DesktopsClient", "Update", resp, "Failure sending request") 271 return 272 } 273 274 result, err = client.UpdateResponder(resp) 275 if err != nil { 276 err = autorest.NewErrorWithError(err, "desktopvirtualization.DesktopsClient", "Update", resp, "Failure responding to request") 277 } 278 279 return 280} 281 282// UpdatePreparer prepares the Update request. 283func (client DesktopsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, applicationGroupName string, desktopName string, desktop *DesktopPatch) (*http.Request, error) { 284 pathParameters := map[string]interface{}{ 285 "applicationGroupName": autorest.Encode("path", applicationGroupName), 286 "desktopName": autorest.Encode("path", desktopName), 287 "resourceGroupName": autorest.Encode("path", resourceGroupName), 288 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 289 } 290 291 const APIVersion = "2019-09-24-preview" 292 queryParameters := map[string]interface{}{ 293 "api-version": APIVersion, 294 } 295 296 preparer := autorest.CreatePreparer( 297 autorest.AsContentType("application/json; charset=utf-8"), 298 autorest.AsPatch(), 299 autorest.WithBaseURL(client.BaseURI), 300 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DesktopVirtualization/applicationGroups/{applicationGroupName}/desktops/{desktopName}", pathParameters), 301 autorest.WithQueryParameters(queryParameters)) 302 if desktop != nil { 303 preparer = autorest.DecoratePreparer(preparer, 304 autorest.WithJSON(desktop)) 305 } 306 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 307} 308 309// UpdateSender sends the Update request. The method will close the 310// http.Response Body if it receives an error. 311func (client DesktopsClient) UpdateSender(req *http.Request) (*http.Response, error) { 312 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 313} 314 315// UpdateResponder handles the response to the Update request. The method always 316// closes the http.Response Body. 317func (client DesktopsClient) UpdateResponder(resp *http.Response) (result Desktop, err error) { 318 err = autorest.Respond( 319 resp, 320 client.ByInspecting(), 321 azure.WithErrorUnlessStatusCode(http.StatusOK), 322 autorest.ByUnmarshallingJSON(&result), 323 autorest.ByClosing()) 324 result.Response = autorest.Response{Response: resp} 325 return 326} 327