1package purview 2 3// Copyright (c) Microsoft Corporation. All rights reserved. 4// Licensed under the MIT License. See License.txt in the project root for license information. 5// 6// Code generated by Microsoft (R) AutoRest Code Generator. 7// Changes may cause incorrect behavior and will be lost if the code is regenerated. 8 9import ( 10 "context" 11 "github.com/Azure/go-autorest/autorest" 12 "github.com/Azure/go-autorest/autorest/azure" 13 "github.com/Azure/go-autorest/tracing" 14 "github.com/gofrs/uuid" 15 "net/http" 16) 17 18// DefaultAccountsClient is the creates a Microsoft.Purview management client. 19type DefaultAccountsClient struct { 20 BaseClient 21} 22 23// NewDefaultAccountsClient creates an instance of the DefaultAccountsClient client. 24func NewDefaultAccountsClient(subscriptionID string) DefaultAccountsClient { 25 return NewDefaultAccountsClientWithBaseURI(DefaultBaseURI, subscriptionID) 26} 27 28// NewDefaultAccountsClientWithBaseURI creates an instance of the DefaultAccountsClient client using a custom endpoint. 29// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 30func NewDefaultAccountsClientWithBaseURI(baseURI string, subscriptionID string) DefaultAccountsClient { 31 return DefaultAccountsClient{NewWithBaseURI(baseURI, subscriptionID)} 32} 33 34// Get get the default account for the scope. 35// Parameters: 36// scopeTenantID - the tenant ID. 37// scopeType - the scope for the default account. 38// scope - the Id of the scope object, for example if the scope is "Subscription" then it is the ID of that 39// subscription. 40func (client DefaultAccountsClient) Get(ctx context.Context, scopeTenantID uuid.UUID, scopeType ScopeType, scope string) (result DefaultAccountPayload, err error) { 41 if tracing.IsEnabled() { 42 ctx = tracing.StartSpan(ctx, fqdn+"/DefaultAccountsClient.Get") 43 defer func() { 44 sc := -1 45 if result.Response.Response != nil { 46 sc = result.Response.Response.StatusCode 47 } 48 tracing.EndSpan(ctx, sc, err) 49 }() 50 } 51 req, err := client.GetPreparer(ctx, scopeTenantID, scopeType, scope) 52 if err != nil { 53 err = autorest.NewErrorWithError(err, "purview.DefaultAccountsClient", "Get", nil, "Failure preparing request") 54 return 55 } 56 57 resp, err := client.GetSender(req) 58 if err != nil { 59 result.Response = autorest.Response{Response: resp} 60 err = autorest.NewErrorWithError(err, "purview.DefaultAccountsClient", "Get", resp, "Failure sending request") 61 return 62 } 63 64 result, err = client.GetResponder(resp) 65 if err != nil { 66 err = autorest.NewErrorWithError(err, "purview.DefaultAccountsClient", "Get", resp, "Failure responding to request") 67 return 68 } 69 70 return 71} 72 73// GetPreparer prepares the Get request. 74func (client DefaultAccountsClient) GetPreparer(ctx context.Context, scopeTenantID uuid.UUID, scopeType ScopeType, scope string) (*http.Request, error) { 75 const APIVersion = "2021-07-01" 76 queryParameters := map[string]interface{}{ 77 "api-version": APIVersion, 78 "scopeTenantId": autorest.Encode("query", scopeTenantID), 79 "scopeType": autorest.Encode("query", scopeType), 80 } 81 if len(scope) > 0 { 82 queryParameters["scope"] = autorest.Encode("query", scope) 83 } 84 85 preparer := autorest.CreatePreparer( 86 autorest.AsGet(), 87 autorest.WithBaseURL(client.BaseURI), 88 autorest.WithPath("/providers/Microsoft.Purview/getDefaultAccount"), 89 autorest.WithQueryParameters(queryParameters)) 90 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 91} 92 93// GetSender sends the Get request. The method will close the 94// http.Response Body if it receives an error. 95func (client DefaultAccountsClient) GetSender(req *http.Request) (*http.Response, error) { 96 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 97} 98 99// GetResponder handles the response to the Get request. The method always 100// closes the http.Response Body. 101func (client DefaultAccountsClient) GetResponder(resp *http.Response) (result DefaultAccountPayload, err error) { 102 err = autorest.Respond( 103 resp, 104 azure.WithErrorUnlessStatusCode(http.StatusOK), 105 autorest.ByUnmarshallingJSON(&result), 106 autorest.ByClosing()) 107 result.Response = autorest.Response{Response: resp} 108 return 109} 110 111// Remove removes the default account from the scope. 112// Parameters: 113// scopeTenantID - the tenant ID. 114// scopeType - the scope for the default account. 115// scope - the Id of the scope object, for example if the scope is "Subscription" then it is the ID of that 116// subscription. 117func (client DefaultAccountsClient) Remove(ctx context.Context, scopeTenantID uuid.UUID, scopeType ScopeType, scope string) (result autorest.Response, err error) { 118 if tracing.IsEnabled() { 119 ctx = tracing.StartSpan(ctx, fqdn+"/DefaultAccountsClient.Remove") 120 defer func() { 121 sc := -1 122 if result.Response != nil { 123 sc = result.Response.StatusCode 124 } 125 tracing.EndSpan(ctx, sc, err) 126 }() 127 } 128 req, err := client.RemovePreparer(ctx, scopeTenantID, scopeType, scope) 129 if err != nil { 130 err = autorest.NewErrorWithError(err, "purview.DefaultAccountsClient", "Remove", nil, "Failure preparing request") 131 return 132 } 133 134 resp, err := client.RemoveSender(req) 135 if err != nil { 136 result.Response = resp 137 err = autorest.NewErrorWithError(err, "purview.DefaultAccountsClient", "Remove", resp, "Failure sending request") 138 return 139 } 140 141 result, err = client.RemoveResponder(resp) 142 if err != nil { 143 err = autorest.NewErrorWithError(err, "purview.DefaultAccountsClient", "Remove", resp, "Failure responding to request") 144 return 145 } 146 147 return 148} 149 150// RemovePreparer prepares the Remove request. 151func (client DefaultAccountsClient) RemovePreparer(ctx context.Context, scopeTenantID uuid.UUID, scopeType ScopeType, scope string) (*http.Request, error) { 152 const APIVersion = "2021-07-01" 153 queryParameters := map[string]interface{}{ 154 "api-version": APIVersion, 155 "scopeTenantId": autorest.Encode("query", scopeTenantID), 156 "scopeType": autorest.Encode("query", scopeType), 157 } 158 if len(scope) > 0 { 159 queryParameters["scope"] = autorest.Encode("query", scope) 160 } 161 162 preparer := autorest.CreatePreparer( 163 autorest.AsPost(), 164 autorest.WithBaseURL(client.BaseURI), 165 autorest.WithPath("/providers/Microsoft.Purview/removeDefaultAccount"), 166 autorest.WithQueryParameters(queryParameters)) 167 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 168} 169 170// RemoveSender sends the Remove request. The method will close the 171// http.Response Body if it receives an error. 172func (client DefaultAccountsClient) RemoveSender(req *http.Request) (*http.Response, error) { 173 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 174} 175 176// RemoveResponder handles the response to the Remove request. The method always 177// closes the http.Response Body. 178func (client DefaultAccountsClient) RemoveResponder(resp *http.Response) (result autorest.Response, err error) { 179 err = autorest.Respond( 180 resp, 181 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 182 autorest.ByClosing()) 183 result.Response = resp 184 return 185} 186 187// Set sets the default account for the scope. 188// Parameters: 189// defaultAccountPayload - the payload containing the default account information and the scope. 190func (client DefaultAccountsClient) Set(ctx context.Context, defaultAccountPayload DefaultAccountPayload) (result DefaultAccountPayload, err error) { 191 if tracing.IsEnabled() { 192 ctx = tracing.StartSpan(ctx, fqdn+"/DefaultAccountsClient.Set") 193 defer func() { 194 sc := -1 195 if result.Response.Response != nil { 196 sc = result.Response.Response.StatusCode 197 } 198 tracing.EndSpan(ctx, sc, err) 199 }() 200 } 201 req, err := client.SetPreparer(ctx, defaultAccountPayload) 202 if err != nil { 203 err = autorest.NewErrorWithError(err, "purview.DefaultAccountsClient", "Set", nil, "Failure preparing request") 204 return 205 } 206 207 resp, err := client.SetSender(req) 208 if err != nil { 209 result.Response = autorest.Response{Response: resp} 210 err = autorest.NewErrorWithError(err, "purview.DefaultAccountsClient", "Set", resp, "Failure sending request") 211 return 212 } 213 214 result, err = client.SetResponder(resp) 215 if err != nil { 216 err = autorest.NewErrorWithError(err, "purview.DefaultAccountsClient", "Set", resp, "Failure responding to request") 217 return 218 } 219 220 return 221} 222 223// SetPreparer prepares the Set request. 224func (client DefaultAccountsClient) SetPreparer(ctx context.Context, defaultAccountPayload DefaultAccountPayload) (*http.Request, error) { 225 const APIVersion = "2021-07-01" 226 queryParameters := map[string]interface{}{ 227 "api-version": APIVersion, 228 } 229 230 preparer := autorest.CreatePreparer( 231 autorest.AsContentType("application/json; charset=utf-8"), 232 autorest.AsPost(), 233 autorest.WithBaseURL(client.BaseURI), 234 autorest.WithPath("/providers/Microsoft.Purview/setDefaultAccount"), 235 autorest.WithJSON(defaultAccountPayload), 236 autorest.WithQueryParameters(queryParameters)) 237 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 238} 239 240// SetSender sends the Set request. The method will close the 241// http.Response Body if it receives an error. 242func (client DefaultAccountsClient) SetSender(req *http.Request) (*http.Response, error) { 243 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 244} 245 246// SetResponder handles the response to the Set request. The method always 247// closes the http.Response Body. 248func (client DefaultAccountsClient) SetResponder(resp *http.Response) (result DefaultAccountPayload, err error) { 249 err = autorest.Respond( 250 resp, 251 azure.WithErrorUnlessStatusCode(http.StatusOK), 252 autorest.ByUnmarshallingJSON(&result), 253 autorest.ByClosing()) 254 result.Response = autorest.Response{Response: resp} 255 return 256} 257