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// ActiveApplicationsClient is the client for the ActiveApplications methods of the Desktopvirtualization service. 30type ActiveApplicationsClient struct { 31 BaseClient 32} 33 34// NewActiveApplicationsClient creates an instance of the ActiveApplicationsClient client. 35func NewActiveApplicationsClient(subscriptionID string) ActiveApplicationsClient { 36 return NewActiveApplicationsClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewActiveApplicationsClientWithBaseURI creates an instance of the ActiveApplicationsClient client using a custom 40// endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure 41// stack). 42func NewActiveApplicationsClientWithBaseURI(baseURI string, subscriptionID string) ActiveApplicationsClient { 43 return ActiveApplicationsClient{NewWithBaseURI(baseURI, subscriptionID)} 44} 45 46// ListBySessionHost list applications for the given session host. 47// Parameters: 48// resourceGroupName - the name of the resource group. The name is case insensitive. 49// hostPoolName - the name of the host pool within the specified resource group 50// sessionHostName - the name of the session host within the specified host pool 51// filter - oData filter expression. Valid properties for filtering are userprincipalname and sessionstate. 52func (client ActiveApplicationsClient) ListBySessionHost(ctx context.Context, resourceGroupName string, hostPoolName string, sessionHostName string, filter string) (result ApplicationListPage, err error) { 53 if tracing.IsEnabled() { 54 ctx = tracing.StartSpan(ctx, fqdn+"/ActiveApplicationsClient.ListBySessionHost") 55 defer func() { 56 sc := -1 57 if result.al.Response.Response != nil { 58 sc = result.al.Response.Response.StatusCode 59 } 60 tracing.EndSpan(ctx, sc, err) 61 }() 62 } 63 if err := validation.Validate([]validation.Validation{ 64 {TargetValue: client.SubscriptionID, 65 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 66 {TargetValue: resourceGroupName, 67 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 68 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 69 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, 70 {TargetValue: hostPoolName, 71 Constraints: []validation.Constraint{{Target: "hostPoolName", Name: validation.MaxLength, Rule: 24, Chain: nil}, 72 {Target: "hostPoolName", Name: validation.MinLength, Rule: 3, Chain: nil}}}, 73 {TargetValue: sessionHostName, 74 Constraints: []validation.Constraint{{Target: "sessionHostName", Name: validation.MaxLength, Rule: 48, Chain: nil}, 75 {Target: "sessionHostName", Name: validation.MinLength, Rule: 3, Chain: nil}}}}); err != nil { 76 return result, validation.NewError("desktopvirtualization.ActiveApplicationsClient", "ListBySessionHost", err.Error()) 77 } 78 79 result.fn = client.listBySessionHostNextResults 80 req, err := client.ListBySessionHostPreparer(ctx, resourceGroupName, hostPoolName, sessionHostName, filter) 81 if err != nil { 82 err = autorest.NewErrorWithError(err, "desktopvirtualization.ActiveApplicationsClient", "ListBySessionHost", nil, "Failure preparing request") 83 return 84 } 85 86 resp, err := client.ListBySessionHostSender(req) 87 if err != nil { 88 result.al.Response = autorest.Response{Response: resp} 89 err = autorest.NewErrorWithError(err, "desktopvirtualization.ActiveApplicationsClient", "ListBySessionHost", resp, "Failure sending request") 90 return 91 } 92 93 result.al, err = client.ListBySessionHostResponder(resp) 94 if err != nil { 95 err = autorest.NewErrorWithError(err, "desktopvirtualization.ActiveApplicationsClient", "ListBySessionHost", resp, "Failure responding to request") 96 } 97 98 return 99} 100 101// ListBySessionHostPreparer prepares the ListBySessionHost request. 102func (client ActiveApplicationsClient) ListBySessionHostPreparer(ctx context.Context, resourceGroupName string, hostPoolName string, sessionHostName string, filter string) (*http.Request, error) { 103 pathParameters := map[string]interface{}{ 104 "hostPoolName": autorest.Encode("path", hostPoolName), 105 "resourceGroupName": autorest.Encode("path", resourceGroupName), 106 "sessionHostName": autorest.Encode("path", sessionHostName), 107 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 108 } 109 110 const APIVersion = "2019-09-24-preview" 111 queryParameters := map[string]interface{}{ 112 "api-version": APIVersion, 113 } 114 if len(filter) > 0 { 115 queryParameters["$filter"] = autorest.Encode("query", filter) 116 } 117 118 preparer := autorest.CreatePreparer( 119 autorest.AsGet(), 120 autorest.WithBaseURL(client.BaseURI), 121 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DesktopVirtualization/hostPools/{hostPoolName}/sessionHosts/{sessionHostName}/activeApplications", pathParameters), 122 autorest.WithQueryParameters(queryParameters)) 123 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 124} 125 126// ListBySessionHostSender sends the ListBySessionHost request. The method will close the 127// http.Response Body if it receives an error. 128func (client ActiveApplicationsClient) ListBySessionHostSender(req *http.Request) (*http.Response, error) { 129 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 130} 131 132// ListBySessionHostResponder handles the response to the ListBySessionHost request. The method always 133// closes the http.Response Body. 134func (client ActiveApplicationsClient) ListBySessionHostResponder(resp *http.Response) (result ApplicationList, err error) { 135 err = autorest.Respond( 136 resp, 137 client.ByInspecting(), 138 azure.WithErrorUnlessStatusCode(http.StatusOK), 139 autorest.ByUnmarshallingJSON(&result), 140 autorest.ByClosing()) 141 result.Response = autorest.Response{Response: resp} 142 return 143} 144 145// listBySessionHostNextResults retrieves the next set of results, if any. 146func (client ActiveApplicationsClient) listBySessionHostNextResults(ctx context.Context, lastResults ApplicationList) (result ApplicationList, err error) { 147 req, err := lastResults.applicationListPreparer(ctx) 148 if err != nil { 149 return result, autorest.NewErrorWithError(err, "desktopvirtualization.ActiveApplicationsClient", "listBySessionHostNextResults", nil, "Failure preparing next results request") 150 } 151 if req == nil { 152 return 153 } 154 resp, err := client.ListBySessionHostSender(req) 155 if err != nil { 156 result.Response = autorest.Response{Response: resp} 157 return result, autorest.NewErrorWithError(err, "desktopvirtualization.ActiveApplicationsClient", "listBySessionHostNextResults", resp, "Failure sending next results request") 158 } 159 result, err = client.ListBySessionHostResponder(resp) 160 if err != nil { 161 err = autorest.NewErrorWithError(err, "desktopvirtualization.ActiveApplicationsClient", "listBySessionHostNextResults", resp, "Failure responding to next results request") 162 } 163 return 164} 165 166// ListBySessionHostComplete enumerates all values, automatically crossing page boundaries as required. 167func (client ActiveApplicationsClient) ListBySessionHostComplete(ctx context.Context, resourceGroupName string, hostPoolName string, sessionHostName string, filter string) (result ApplicationListIterator, err error) { 168 if tracing.IsEnabled() { 169 ctx = tracing.StartSpan(ctx, fqdn+"/ActiveApplicationsClient.ListBySessionHost") 170 defer func() { 171 sc := -1 172 if result.Response().Response.Response != nil { 173 sc = result.page.Response().Response.Response.StatusCode 174 } 175 tracing.EndSpan(ctx, sc, err) 176 }() 177 } 178 result.page, err = client.ListBySessionHost(ctx, resourceGroupName, hostPoolName, sessionHostName, filter) 179 return 180} 181