1package apimanagement 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// TenantAccessGitClient is the apiManagement Client 30type TenantAccessGitClient struct { 31 BaseClient 32} 33 34// NewTenantAccessGitClient creates an instance of the TenantAccessGitClient client. 35func NewTenantAccessGitClient(subscriptionID string) TenantAccessGitClient { 36 return NewTenantAccessGitClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewTenantAccessGitClientWithBaseURI creates an instance of the TenantAccessGitClient client. 40func NewTenantAccessGitClientWithBaseURI(baseURI string, subscriptionID string) TenantAccessGitClient { 41 return TenantAccessGitClient{NewWithBaseURI(baseURI, subscriptionID)} 42} 43 44// Get gets the Git access configuration for the tenant. 45// Parameters: 46// resourceGroupName - the name of the resource group. 47// serviceName - the name of the API Management service. 48func (client TenantAccessGitClient) Get(ctx context.Context, resourceGroupName string, serviceName string) (result AccessInformationContract, err error) { 49 if tracing.IsEnabled() { 50 ctx = tracing.StartSpan(ctx, fqdn+"/TenantAccessGitClient.Get") 51 defer func() { 52 sc := -1 53 if result.Response.Response != nil { 54 sc = result.Response.Response.StatusCode 55 } 56 tracing.EndSpan(ctx, sc, err) 57 }() 58 } 59 if err := validation.Validate([]validation.Validation{ 60 {TargetValue: serviceName, 61 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 62 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 63 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}}); err != nil { 64 return result, validation.NewError("apimanagement.TenantAccessGitClient", "Get", err.Error()) 65 } 66 67 req, err := client.GetPreparer(ctx, resourceGroupName, serviceName) 68 if err != nil { 69 err = autorest.NewErrorWithError(err, "apimanagement.TenantAccessGitClient", "Get", nil, "Failure preparing request") 70 return 71 } 72 73 resp, err := client.GetSender(req) 74 if err != nil { 75 result.Response = autorest.Response{Response: resp} 76 err = autorest.NewErrorWithError(err, "apimanagement.TenantAccessGitClient", "Get", resp, "Failure sending request") 77 return 78 } 79 80 result, err = client.GetResponder(resp) 81 if err != nil { 82 err = autorest.NewErrorWithError(err, "apimanagement.TenantAccessGitClient", "Get", resp, "Failure responding to request") 83 } 84 85 return 86} 87 88// GetPreparer prepares the Get request. 89func (client TenantAccessGitClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string) (*http.Request, error) { 90 pathParameters := map[string]interface{}{ 91 "accessName": autorest.Encode("path", "access"), 92 "resourceGroupName": autorest.Encode("path", resourceGroupName), 93 "serviceName": autorest.Encode("path", serviceName), 94 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 95 } 96 97 const APIVersion = "2019-01-01" 98 queryParameters := map[string]interface{}{ 99 "api-version": APIVersion, 100 } 101 102 preparer := autorest.CreatePreparer( 103 autorest.AsGet(), 104 autorest.WithBaseURL(client.BaseURI), 105 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/tenant/{accessName}/git", pathParameters), 106 autorest.WithQueryParameters(queryParameters)) 107 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 108} 109 110// GetSender sends the Get request. The method will close the 111// http.Response Body if it receives an error. 112func (client TenantAccessGitClient) GetSender(req *http.Request) (*http.Response, error) { 113 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 114 return autorest.SendWithSender(client, req, sd...) 115} 116 117// GetResponder handles the response to the Get request. The method always 118// closes the http.Response Body. 119func (client TenantAccessGitClient) GetResponder(resp *http.Response) (result AccessInformationContract, err error) { 120 err = autorest.Respond( 121 resp, 122 client.ByInspecting(), 123 azure.WithErrorUnlessStatusCode(http.StatusOK), 124 autorest.ByUnmarshallingJSON(&result), 125 autorest.ByClosing()) 126 result.Response = autorest.Response{Response: resp} 127 return 128} 129 130// RegeneratePrimaryKey regenerate primary access key for GIT. 131// Parameters: 132// resourceGroupName - the name of the resource group. 133// serviceName - the name of the API Management service. 134func (client TenantAccessGitClient) RegeneratePrimaryKey(ctx context.Context, resourceGroupName string, serviceName string) (result autorest.Response, err error) { 135 if tracing.IsEnabled() { 136 ctx = tracing.StartSpan(ctx, fqdn+"/TenantAccessGitClient.RegeneratePrimaryKey") 137 defer func() { 138 sc := -1 139 if result.Response != nil { 140 sc = result.Response.StatusCode 141 } 142 tracing.EndSpan(ctx, sc, err) 143 }() 144 } 145 if err := validation.Validate([]validation.Validation{ 146 {TargetValue: serviceName, 147 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 148 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 149 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}}); err != nil { 150 return result, validation.NewError("apimanagement.TenantAccessGitClient", "RegeneratePrimaryKey", err.Error()) 151 } 152 153 req, err := client.RegeneratePrimaryKeyPreparer(ctx, resourceGroupName, serviceName) 154 if err != nil { 155 err = autorest.NewErrorWithError(err, "apimanagement.TenantAccessGitClient", "RegeneratePrimaryKey", nil, "Failure preparing request") 156 return 157 } 158 159 resp, err := client.RegeneratePrimaryKeySender(req) 160 if err != nil { 161 result.Response = resp 162 err = autorest.NewErrorWithError(err, "apimanagement.TenantAccessGitClient", "RegeneratePrimaryKey", resp, "Failure sending request") 163 return 164 } 165 166 result, err = client.RegeneratePrimaryKeyResponder(resp) 167 if err != nil { 168 err = autorest.NewErrorWithError(err, "apimanagement.TenantAccessGitClient", "RegeneratePrimaryKey", resp, "Failure responding to request") 169 } 170 171 return 172} 173 174// RegeneratePrimaryKeyPreparer prepares the RegeneratePrimaryKey request. 175func (client TenantAccessGitClient) RegeneratePrimaryKeyPreparer(ctx context.Context, resourceGroupName string, serviceName string) (*http.Request, error) { 176 pathParameters := map[string]interface{}{ 177 "accessName": autorest.Encode("path", "access"), 178 "resourceGroupName": autorest.Encode("path", resourceGroupName), 179 "serviceName": autorest.Encode("path", serviceName), 180 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 181 } 182 183 const APIVersion = "2019-01-01" 184 queryParameters := map[string]interface{}{ 185 "api-version": APIVersion, 186 } 187 188 preparer := autorest.CreatePreparer( 189 autorest.AsPost(), 190 autorest.WithBaseURL(client.BaseURI), 191 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/tenant/{accessName}/git/regeneratePrimaryKey", pathParameters), 192 autorest.WithQueryParameters(queryParameters)) 193 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 194} 195 196// RegeneratePrimaryKeySender sends the RegeneratePrimaryKey request. The method will close the 197// http.Response Body if it receives an error. 198func (client TenantAccessGitClient) RegeneratePrimaryKeySender(req *http.Request) (*http.Response, error) { 199 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 200 return autorest.SendWithSender(client, req, sd...) 201} 202 203// RegeneratePrimaryKeyResponder handles the response to the RegeneratePrimaryKey request. The method always 204// closes the http.Response Body. 205func (client TenantAccessGitClient) RegeneratePrimaryKeyResponder(resp *http.Response) (result autorest.Response, err error) { 206 err = autorest.Respond( 207 resp, 208 client.ByInspecting(), 209 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 210 autorest.ByClosing()) 211 result.Response = resp 212 return 213} 214 215// RegenerateSecondaryKey regenerate secondary access key for GIT. 216// Parameters: 217// resourceGroupName - the name of the resource group. 218// serviceName - the name of the API Management service. 219func (client TenantAccessGitClient) RegenerateSecondaryKey(ctx context.Context, resourceGroupName string, serviceName string) (result autorest.Response, err error) { 220 if tracing.IsEnabled() { 221 ctx = tracing.StartSpan(ctx, fqdn+"/TenantAccessGitClient.RegenerateSecondaryKey") 222 defer func() { 223 sc := -1 224 if result.Response != nil { 225 sc = result.Response.StatusCode 226 } 227 tracing.EndSpan(ctx, sc, err) 228 }() 229 } 230 if err := validation.Validate([]validation.Validation{ 231 {TargetValue: serviceName, 232 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 233 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 234 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}}); err != nil { 235 return result, validation.NewError("apimanagement.TenantAccessGitClient", "RegenerateSecondaryKey", err.Error()) 236 } 237 238 req, err := client.RegenerateSecondaryKeyPreparer(ctx, resourceGroupName, serviceName) 239 if err != nil { 240 err = autorest.NewErrorWithError(err, "apimanagement.TenantAccessGitClient", "RegenerateSecondaryKey", nil, "Failure preparing request") 241 return 242 } 243 244 resp, err := client.RegenerateSecondaryKeySender(req) 245 if err != nil { 246 result.Response = resp 247 err = autorest.NewErrorWithError(err, "apimanagement.TenantAccessGitClient", "RegenerateSecondaryKey", resp, "Failure sending request") 248 return 249 } 250 251 result, err = client.RegenerateSecondaryKeyResponder(resp) 252 if err != nil { 253 err = autorest.NewErrorWithError(err, "apimanagement.TenantAccessGitClient", "RegenerateSecondaryKey", resp, "Failure responding to request") 254 } 255 256 return 257} 258 259// RegenerateSecondaryKeyPreparer prepares the RegenerateSecondaryKey request. 260func (client TenantAccessGitClient) RegenerateSecondaryKeyPreparer(ctx context.Context, resourceGroupName string, serviceName string) (*http.Request, error) { 261 pathParameters := map[string]interface{}{ 262 "accessName": autorest.Encode("path", "access"), 263 "resourceGroupName": autorest.Encode("path", resourceGroupName), 264 "serviceName": autorest.Encode("path", serviceName), 265 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 266 } 267 268 const APIVersion = "2019-01-01" 269 queryParameters := map[string]interface{}{ 270 "api-version": APIVersion, 271 } 272 273 preparer := autorest.CreatePreparer( 274 autorest.AsPost(), 275 autorest.WithBaseURL(client.BaseURI), 276 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/tenant/{accessName}/git/regenerateSecondaryKey", pathParameters), 277 autorest.WithQueryParameters(queryParameters)) 278 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 279} 280 281// RegenerateSecondaryKeySender sends the RegenerateSecondaryKey request. The method will close the 282// http.Response Body if it receives an error. 283func (client TenantAccessGitClient) RegenerateSecondaryKeySender(req *http.Request) (*http.Response, error) { 284 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 285 return autorest.SendWithSender(client, req, sd...) 286} 287 288// RegenerateSecondaryKeyResponder handles the response to the RegenerateSecondaryKey request. The method always 289// closes the http.Response Body. 290func (client TenantAccessGitClient) RegenerateSecondaryKeyResponder(resp *http.Response) (result autorest.Response, err error) { 291 err = autorest.Respond( 292 resp, 293 client.ByInspecting(), 294 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 295 autorest.ByClosing()) 296 result.Response = resp 297 return 298} 299