1package keyvault 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// PrivateEndpointConnectionsClient is the the Azure management API provides a RESTful set of web services that 30// interact with Azure Key Vault. 31type PrivateEndpointConnectionsClient struct { 32 BaseClient 33} 34 35// NewPrivateEndpointConnectionsClient creates an instance of the PrivateEndpointConnectionsClient client. 36func NewPrivateEndpointConnectionsClient(subscriptionID string) PrivateEndpointConnectionsClient { 37 return NewPrivateEndpointConnectionsClientWithBaseURI(DefaultBaseURI, subscriptionID) 38} 39 40// NewPrivateEndpointConnectionsClientWithBaseURI creates an instance of the PrivateEndpointConnectionsClient client 41// using a custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign 42// clouds, Azure stack). 43func NewPrivateEndpointConnectionsClientWithBaseURI(baseURI string, subscriptionID string) PrivateEndpointConnectionsClient { 44 return PrivateEndpointConnectionsClient{NewWithBaseURI(baseURI, subscriptionID)} 45} 46 47// Delete deletes the specified private endpoint connection associated with the key vault. 48// Parameters: 49// resourceGroupName - name of the resource group that contains the key vault. 50// vaultName - the name of the key vault. 51// privateEndpointConnectionName - name of the private endpoint connection associated with the key vault. 52func (client PrivateEndpointConnectionsClient) Delete(ctx context.Context, resourceGroupName string, vaultName string, privateEndpointConnectionName string) (result PrivateEndpointConnectionsDeleteFuture, err error) { 53 if tracing.IsEnabled() { 54 ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointConnectionsClient.Delete") 55 defer func() { 56 sc := -1 57 if result.Response() != nil { 58 sc = result.Response().StatusCode 59 } 60 tracing.EndSpan(ctx, sc, err) 61 }() 62 } 63 if err := validation.Validate([]validation.Validation{ 64 {TargetValue: vaultName, 65 Constraints: []validation.Constraint{{Target: "vaultName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9-]{3,24}$`, Chain: nil}}}}); err != nil { 66 return result, validation.NewError("keyvault.PrivateEndpointConnectionsClient", "Delete", err.Error()) 67 } 68 69 req, err := client.DeletePreparer(ctx, resourceGroupName, vaultName, privateEndpointConnectionName) 70 if err != nil { 71 err = autorest.NewErrorWithError(err, "keyvault.PrivateEndpointConnectionsClient", "Delete", nil, "Failure preparing request") 72 return 73 } 74 75 result, err = client.DeleteSender(req) 76 if err != nil { 77 err = autorest.NewErrorWithError(err, "keyvault.PrivateEndpointConnectionsClient", "Delete", nil, "Failure sending request") 78 return 79 } 80 81 return 82} 83 84// DeletePreparer prepares the Delete request. 85func (client PrivateEndpointConnectionsClient) DeletePreparer(ctx context.Context, resourceGroupName string, vaultName string, privateEndpointConnectionName string) (*http.Request, error) { 86 pathParameters := map[string]interface{}{ 87 "privateEndpointConnectionName": autorest.Encode("path", privateEndpointConnectionName), 88 "resourceGroupName": autorest.Encode("path", resourceGroupName), 89 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 90 "vaultName": autorest.Encode("path", vaultName), 91 } 92 93 const APIVersion = "2019-09-01" 94 queryParameters := map[string]interface{}{ 95 "api-version": APIVersion, 96 } 97 98 preparer := autorest.CreatePreparer( 99 autorest.AsDelete(), 100 autorest.WithBaseURL(client.BaseURI), 101 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.KeyVault/vaults/{vaultName}/privateEndpointConnections/{privateEndpointConnectionName}", pathParameters), 102 autorest.WithQueryParameters(queryParameters)) 103 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 104} 105 106// DeleteSender sends the Delete request. The method will close the 107// http.Response Body if it receives an error. 108func (client PrivateEndpointConnectionsClient) DeleteSender(req *http.Request) (future PrivateEndpointConnectionsDeleteFuture, err error) { 109 var resp *http.Response 110 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 111 if err != nil { 112 return 113 } 114 var azf azure.Future 115 azf, err = azure.NewFutureFromResponse(resp) 116 future.FutureAPI = &azf 117 future.Result = func(client PrivateEndpointConnectionsClient) (pec PrivateEndpointConnection, err error) { 118 var done bool 119 done, err = future.DoneWithContext(context.Background(), client) 120 if err != nil { 121 err = autorest.NewErrorWithError(err, "keyvault.PrivateEndpointConnectionsDeleteFuture", "Result", future.Response(), "Polling failure") 122 return 123 } 124 if !done { 125 err = azure.NewAsyncOpIncompleteError("keyvault.PrivateEndpointConnectionsDeleteFuture") 126 return 127 } 128 sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 129 if pec.Response.Response, err = future.GetResult(sender); err == nil && pec.Response.Response.StatusCode != http.StatusNoContent { 130 pec, err = client.DeleteResponder(pec.Response.Response) 131 if err != nil { 132 err = autorest.NewErrorWithError(err, "keyvault.PrivateEndpointConnectionsDeleteFuture", "Result", pec.Response.Response, "Failure responding to request") 133 } 134 } 135 return 136 } 137 return 138} 139 140// DeleteResponder handles the response to the Delete request. The method always 141// closes the http.Response Body. 142func (client PrivateEndpointConnectionsClient) DeleteResponder(resp *http.Response) (result PrivateEndpointConnection, err error) { 143 err = autorest.Respond( 144 resp, 145 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 146 autorest.ByUnmarshallingJSON(&result), 147 autorest.ByClosing()) 148 result.Response = autorest.Response{Response: resp} 149 return 150} 151 152// Get gets the specified private endpoint connection associated with the key vault. 153// Parameters: 154// resourceGroupName - name of the resource group that contains the key vault. 155// vaultName - the name of the key vault. 156// privateEndpointConnectionName - name of the private endpoint connection associated with the key vault. 157func (client PrivateEndpointConnectionsClient) Get(ctx context.Context, resourceGroupName string, vaultName string, privateEndpointConnectionName string) (result PrivateEndpointConnection, err error) { 158 if tracing.IsEnabled() { 159 ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointConnectionsClient.Get") 160 defer func() { 161 sc := -1 162 if result.Response.Response != nil { 163 sc = result.Response.Response.StatusCode 164 } 165 tracing.EndSpan(ctx, sc, err) 166 }() 167 } 168 if err := validation.Validate([]validation.Validation{ 169 {TargetValue: vaultName, 170 Constraints: []validation.Constraint{{Target: "vaultName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9-]{3,24}$`, Chain: nil}}}}); err != nil { 171 return result, validation.NewError("keyvault.PrivateEndpointConnectionsClient", "Get", err.Error()) 172 } 173 174 req, err := client.GetPreparer(ctx, resourceGroupName, vaultName, privateEndpointConnectionName) 175 if err != nil { 176 err = autorest.NewErrorWithError(err, "keyvault.PrivateEndpointConnectionsClient", "Get", nil, "Failure preparing request") 177 return 178 } 179 180 resp, err := client.GetSender(req) 181 if err != nil { 182 result.Response = autorest.Response{Response: resp} 183 err = autorest.NewErrorWithError(err, "keyvault.PrivateEndpointConnectionsClient", "Get", resp, "Failure sending request") 184 return 185 } 186 187 result, err = client.GetResponder(resp) 188 if err != nil { 189 err = autorest.NewErrorWithError(err, "keyvault.PrivateEndpointConnectionsClient", "Get", resp, "Failure responding to request") 190 return 191 } 192 193 return 194} 195 196// GetPreparer prepares the Get request. 197func (client PrivateEndpointConnectionsClient) GetPreparer(ctx context.Context, resourceGroupName string, vaultName string, privateEndpointConnectionName string) (*http.Request, error) { 198 pathParameters := map[string]interface{}{ 199 "privateEndpointConnectionName": autorest.Encode("path", privateEndpointConnectionName), 200 "resourceGroupName": autorest.Encode("path", resourceGroupName), 201 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 202 "vaultName": autorest.Encode("path", vaultName), 203 } 204 205 const APIVersion = "2019-09-01" 206 queryParameters := map[string]interface{}{ 207 "api-version": APIVersion, 208 } 209 210 preparer := autorest.CreatePreparer( 211 autorest.AsGet(), 212 autorest.WithBaseURL(client.BaseURI), 213 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.KeyVault/vaults/{vaultName}/privateEndpointConnections/{privateEndpointConnectionName}", pathParameters), 214 autorest.WithQueryParameters(queryParameters)) 215 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 216} 217 218// GetSender sends the Get request. The method will close the 219// http.Response Body if it receives an error. 220func (client PrivateEndpointConnectionsClient) GetSender(req *http.Request) (*http.Response, error) { 221 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 222} 223 224// GetResponder handles the response to the Get request. The method always 225// closes the http.Response Body. 226func (client PrivateEndpointConnectionsClient) GetResponder(resp *http.Response) (result PrivateEndpointConnection, err error) { 227 err = autorest.Respond( 228 resp, 229 azure.WithErrorUnlessStatusCode(http.StatusOK), 230 autorest.ByUnmarshallingJSON(&result), 231 autorest.ByClosing()) 232 result.Response = autorest.Response{Response: resp} 233 return 234} 235 236// Put updates the specified private endpoint connection associated with the key vault. 237// Parameters: 238// resourceGroupName - name of the resource group that contains the key vault. 239// vaultName - the name of the key vault. 240// privateEndpointConnectionName - name of the private endpoint connection associated with the key vault. 241// properties - the intended state of private endpoint connection. 242func (client PrivateEndpointConnectionsClient) Put(ctx context.Context, resourceGroupName string, vaultName string, privateEndpointConnectionName string, properties PrivateEndpointConnection) (result PrivateEndpointConnection, err error) { 243 if tracing.IsEnabled() { 244 ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointConnectionsClient.Put") 245 defer func() { 246 sc := -1 247 if result.Response.Response != nil { 248 sc = result.Response.Response.StatusCode 249 } 250 tracing.EndSpan(ctx, sc, err) 251 }() 252 } 253 if err := validation.Validate([]validation.Validation{ 254 {TargetValue: vaultName, 255 Constraints: []validation.Constraint{{Target: "vaultName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9-]{3,24}$`, Chain: nil}}}}); err != nil { 256 return result, validation.NewError("keyvault.PrivateEndpointConnectionsClient", "Put", err.Error()) 257 } 258 259 req, err := client.PutPreparer(ctx, resourceGroupName, vaultName, privateEndpointConnectionName, properties) 260 if err != nil { 261 err = autorest.NewErrorWithError(err, "keyvault.PrivateEndpointConnectionsClient", "Put", nil, "Failure preparing request") 262 return 263 } 264 265 resp, err := client.PutSender(req) 266 if err != nil { 267 result.Response = autorest.Response{Response: resp} 268 err = autorest.NewErrorWithError(err, "keyvault.PrivateEndpointConnectionsClient", "Put", resp, "Failure sending request") 269 return 270 } 271 272 result, err = client.PutResponder(resp) 273 if err != nil { 274 err = autorest.NewErrorWithError(err, "keyvault.PrivateEndpointConnectionsClient", "Put", resp, "Failure responding to request") 275 return 276 } 277 278 return 279} 280 281// PutPreparer prepares the Put request. 282func (client PrivateEndpointConnectionsClient) PutPreparer(ctx context.Context, resourceGroupName string, vaultName string, privateEndpointConnectionName string, properties PrivateEndpointConnection) (*http.Request, error) { 283 pathParameters := map[string]interface{}{ 284 "privateEndpointConnectionName": autorest.Encode("path", privateEndpointConnectionName), 285 "resourceGroupName": autorest.Encode("path", resourceGroupName), 286 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 287 "vaultName": autorest.Encode("path", vaultName), 288 } 289 290 const APIVersion = "2019-09-01" 291 queryParameters := map[string]interface{}{ 292 "api-version": APIVersion, 293 } 294 295 preparer := autorest.CreatePreparer( 296 autorest.AsContentType("application/json; charset=utf-8"), 297 autorest.AsPut(), 298 autorest.WithBaseURL(client.BaseURI), 299 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.KeyVault/vaults/{vaultName}/privateEndpointConnections/{privateEndpointConnectionName}", pathParameters), 300 autorest.WithJSON(properties), 301 autorest.WithQueryParameters(queryParameters)) 302 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 303} 304 305// PutSender sends the Put request. The method will close the 306// http.Response Body if it receives an error. 307func (client PrivateEndpointConnectionsClient) PutSender(req *http.Request) (*http.Response, error) { 308 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 309} 310 311// PutResponder handles the response to the Put request. The method always 312// closes the http.Response Body. 313func (client PrivateEndpointConnectionsClient) PutResponder(resp *http.Response) (result PrivateEndpointConnection, err error) { 314 err = autorest.Respond( 315 resp, 316 azure.WithErrorUnlessStatusCode(http.StatusOK), 317 autorest.ByUnmarshallingJSON(&result), 318 autorest.ByClosing()) 319 result.Response = autorest.Response{Response: resp} 320 return 321} 322