// Create a Preparer by which to prepare the CheckNameAvailability request. func (client StorageAccountsClient) CheckNameAvailabilityRequestPreparer() autorest.Preparer { return autorest.CreatePreparer( autorest.AsJSON(), autorest.AsPost(), autorest.WithBaseURL(client.BaseUri), autorest.WithPath("/subscriptions/{subscriptionId}/providers/Microsoft.Storage/checkNameAvailability")) }
// Create a Preparer by which to prepare the RegenerateKey request. func (client StorageAccountsClient) RegenerateKeyRequestPreparer() autorest.Preparer { return autorest.CreatePreparer( autorest.AsJSON(), autorest.AsPost(), autorest.WithBaseURL(client.BaseUri), autorest.WithPath("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/regenerateKey")) }
// Create a Preparer by which to prepare the Run request. func (client JobsClient) RunRequestPreparer() autorest.Preparer { return autorest.CreatePreparer( autorest.AsJSON(), autorest.AsPost(), autorest.WithBaseURL(client.BaseUri), autorest.WithPath("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Scheduler/jobCollections/{jobCollectionName}/jobs/{jobName}/run")) }
// Create a Preparer by which to prepare the Register request. func (client FeaturesClient) RegisterRequestPreparer() autorest.Preparer { return autorest.CreatePreparer( autorest.AsJSON(), autorest.AsPost(), autorest.WithBaseURL(client.BaseUri), autorest.WithPath("/subscriptions/{subscriptionId}/providers/Microsoft.Features/providers/{resourceProviderNamespace}/features/{featureName}/register")) }
// Create a Preparer by which to prepare the RegenerateSecretKey request. func (client WorkflowAccessKeysClient) RegenerateSecretKeyRequestPreparer() autorest.Preparer { return autorest.CreatePreparer( autorest.AsJSON(), autorest.AsPost(), autorest.WithBaseURL(client.BaseUri), autorest.WithPath("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Logic/workflows/{workflowName}/accessKeys/{accessKeyName}/regenerate")) }
// Create a Preparer by which to prepare the Stop request. func (client ApplicationGatewaysClient) StopRequestPreparer() autorest.Preparer { return autorest.CreatePreparer( autorest.AsJSON(), autorest.AsPost(), autorest.WithBaseURL(client.BaseUri), autorest.WithPath("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/applicationGateways/{applicationGatewayName}/stop")) }
// Create a Preparer by which to prepare the Cancel request. func (client WorkflowRunsClient) CancelRequestPreparer() autorest.Preparer { return autorest.CreatePreparer( autorest.AsJSON(), autorest.AsPost(), autorest.WithBaseURL(client.BaseUri), autorest.WithPath("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Logic/workflows/{workflowName}/runs/{runName}/cancel")) }
// Create a Preparer by which to prepare the Reset request. func (client VirtualNetworkGatewaysClient) ResetRequestPreparer() autorest.Preparer { return autorest.CreatePreparer( autorest.AsJSON(), autorest.AsPost(), autorest.WithBaseURL(client.BaseUri), autorest.WithPath("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualnetworkgateways/{virtualNetworkGatewayName}/reset")) }
// Create a Preparer by which to prepare the List request. func (client AdminKeysClient) ListRequestPreparer() autorest.Preparer { return autorest.CreatePreparer( autorest.AsJSON(), autorest.AsPost(), autorest.WithBaseURL(client.BaseUri), autorest.WithPath("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Search/searchServices/{serviceName}/listAdminKeys")) }
// InitiateDeviceAuth initiates a device auth flow. It returns a DeviceCode // that can be used with CheckForUserCompletion or WaitForUserCompletion. func InitiateDeviceAuth(client *autorest.Client, oauthConfig OAuthConfig, clientID, resource string) (*DeviceCode, error) { req, _ := autorest.Prepare( &http.Request{}, autorest.AsPost(), autorest.AsFormURLEncoded(), autorest.WithBaseURL(oauthConfig.DeviceCodeEndpoint.String()), autorest.WithFormData(url.Values{ "client_id": []string{clientID}, "resource": []string{resource}, }), ) resp, err := client.Send(req) if err != nil { return nil, fmt.Errorf("%s %s: %s", logPrefix, errCodeSendingFails, err) } var code DeviceCode err = autorest.Respond( resp, autorest.WithErrorUnlessStatusCode(http.StatusOK), autorest.ByUnmarshallingJSON(&code), autorest.ByClosing()) if err != nil { return nil, fmt.Errorf("%s %s: %s", logPrefix, errCodeHandlingFails, err) } code.ClientID = clientID code.Resource = resource code.OAuthConfig = oauthConfig return &code, nil }
// Create a Preparer by which to prepare the Unregister request. func (client ProvidersClient) UnregisterRequestPreparer() autorest.Preparer { return autorest.CreatePreparer( autorest.AsJSON(), autorest.AsPost(), autorest.WithBaseURL(client.BaseUri), autorest.WithPath("/subscriptions/{subscriptionId}/providers/{resourceProviderNamespace}/unregister")) }
// Create a Preparer by which to prepare the Start request. func (client VirtualMachinesClient) StartRequestPreparer() autorest.Preparer { return autorest.CreatePreparer( autorest.AsJSON(), autorest.AsPost(), autorest.WithBaseURL(client.BaseUri), autorest.WithPath("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/start")) }
// Create a Preparer by which to prepare the MoveResources request. func (client ResourcesClient) MoveResourcesRequestPreparer() autorest.Preparer { return autorest.CreatePreparer( autorest.AsJSON(), autorest.AsPost(), autorest.WithBaseURL(client.BaseUri), autorest.WithPath("/subscriptions/{subscriptionId}/resourceGroups/{sourceResourceGroupName}/moveResources")) }
// Create a Preparer by which to prepare the Validate request. func (client DeploymentsClient) ValidateRequestPreparer() autorest.Preparer { return autorest.CreatePreparer( autorest.AsJSON(), autorest.AsPost(), autorest.WithBaseURL(client.BaseUri), autorest.WithPath("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/microsoft.resources/deployments/{deploymentName}/validate")) }
// Create a Preparer by which to prepare the Cancel request. func (client DeploymentsClient) CancelRequestPreparer() autorest.Preparer { return autorest.CreatePreparer( autorest.AsJSON(), autorest.AsPost(), autorest.WithBaseURL(client.BaseUri), autorest.WithPath("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/deployments/{deploymentName}/cancel")) }
// CreateUsersWithListInputPreparer prepares the CreateUsersWithListInput request. func (client ManagementClient) CreateUsersWithListInputPreparer(body []User) (*http.Request, error) { preparer := autorest.CreatePreparer( autorest.AsJSON(), autorest.AsPost(), autorest.WithBaseURL(client.BaseURI), autorest.WithPath("/user/createWithList")) if body != nil && len(body) > 0 { preparer = autorest.DecoratePreparer(preparer, autorest.WithJSON(body)) } return preparer.Prepare(&http.Request{}) }
// AddPetPreparer prepares the AddPet request. func (client ManagementClient) AddPetPreparer(body *Pet) (*http.Request, error) { preparer := autorest.CreatePreparer( autorest.AsJSON(), autorest.AsPost(), autorest.WithBaseURL(client.BaseURI), autorest.WithPath("/pet")) if body != nil { preparer = autorest.DecoratePreparer(preparer, autorest.WithJSON(body)) } return preparer.Prepare(&http.Request{}) }
// AddPetUsingByteArrayPreparer prepares the AddPetUsingByteArray request. func (client ManagementClient) AddPetUsingByteArrayPreparer(body string) (*http.Request, error) { preparer := autorest.CreatePreparer( autorest.AsJSON(), autorest.AsPost(), autorest.WithBaseURL(client.BaseURI), autorest.WithPath("/pet")) if len(body) > 0 { preparer = autorest.DecoratePreparer(preparer, autorest.WithJSON(body)) } return preparer.Prepare(&http.Request{}) }
// CheckNameAvailabilityPreparer prepares the CheckNameAvailability request. func (client NameAvailabilityClient) CheckNameAvailabilityPreparer(checkNameAvailabilityInput CheckNameAvailabilityInput) (*http.Request, error) { queryParameters := map[string]interface{}{ "api-version": APIVersion, } return autorest.Prepare(&http.Request{}, autorest.AsJSON(), autorest.AsPost(), autorest.WithBaseURL(client.BaseURI), autorest.WithPath("/providers/Microsoft.Cdn/checkNameAvailability"), autorest.WithJSON(checkNameAvailabilityInput), autorest.WithQueryParameters(queryParameters)) }
// UploadFilePreparer prepares the UploadFile request. func (client ManagementClient) UploadFilePreparer(petID int64, additionalMetadata string, file io.ReadCloser) (*http.Request, error) { pathParameters := map[string]interface{}{ "petId": autorest.Encode("path", petID), } formDataParameters := map[string]interface{}{} preparer := autorest.CreatePreparer( autorest.AsPost(), autorest.WithBaseURL(client.BaseURI), autorest.WithPathParameters("/pet/{petId}/uploadImage", pathParameters), autorest.WithMultiPartFormData(formDataParameters)) return preparer.Prepare(&http.Request{}) }
// UpdatePetWithFormPreparer prepares the UpdatePetWithForm request. func (client ManagementClient) UpdatePetWithFormPreparer(petID string, name string, status string) (*http.Request, error) { pathParameters := map[string]interface{}{ "petId": autorest.Encode("path", petID), } formDataParameters := map[string]interface{}{} preparer := autorest.CreatePreparer( autorest.AsPost(), autorest.WithBaseURL(client.BaseURI), autorest.WithPathParameters("/pet/{petId}", pathParameters), autorest.WithFormData(autorest.MapToValues(formDataParameters))) return preparer.Prepare(&http.Request{}) }
func (client ServicePrincipalsClient) CreatePreparer(parameters ServicePrincipalCreateParameters, cancel <-chan struct{}) (*http.Request, error) { queryParameters := map[string]interface{}{ "api-version": client.APIVersion, } preparer := autorest.CreatePreparer( autorest.AsJSON(), autorest.AsPost(), autorest.WithBaseURL(client.BaseURI), autorest.WithPath("/servicePrincipals"), autorest.WithJSON(parameters), autorest.WithQueryParameters(queryParameters)) return preparer.Prepare(&http.Request{Cancel: cancel}) }
func (spt *ServicePrincipalToken) refreshInternal(resource string) error { v := url.Values{} v.Set("client_id", spt.clientID) v.Set("resource", resource) if spt.RefreshToken != "" { v.Set("grant_type", OAuthGrantTypeRefreshToken) v.Set("refresh_token", spt.RefreshToken) } else { v.Set("grant_type", OAuthGrantTypeClientCredentials) err := spt.secret.SetAuthenticationValues(spt, &v) if err != nil { return err } } req, _ := autorest.Prepare(&http.Request{}, autorest.AsPost(), autorest.AsFormURLEncoded(), autorest.WithBaseURL(spt.oauthConfig.TokenEndpoint.String()), autorest.WithFormData(v)) resp, err := autorest.SendWithSender(spt.sender, req) if err != nil { return autorest.NewErrorWithError(err, "azure.ServicePrincipalToken", "Refresh", resp, "Failure sending request for Service Principal %s", spt.clientID) } var newToken Token err = autorest.Respond(resp, autorest.WithErrorUnlessOK(), autorest.ByUnmarshallingJSON(&newToken), autorest.ByClosing()) if err != nil { return autorest.NewErrorWithError(err, "azure.ServicePrincipalToken", "Refresh", resp, "Failure handling response to Service Principal %s request", spt.clientID) } spt.Token = newToken err = spt.InvokeRefreshCallbacks(newToken) if err != nil { // its already wrapped inside InvokeRefreshCallbacks return err } return nil }
// Refresh obtains a fresh token for the Service Principal. func (spt *ServicePrincipalToken) Refresh() error { p := map[string]interface{}{ "tenantID": spt.tenantID, "requestType": "token", } v := url.Values{} v.Set("client_id", spt.clientID) v.Set("grant_type", "client_credentials") v.Set("resource", spt.resource) err := spt.secret.SetAuthenticationValues(spt, &v) if err != nil { return err } req, err := autorest.Prepare(&http.Request{}, autorest.AsPost(), autorest.AsFormURLEncoded(), autorest.WithBaseURL(oauthURL), autorest.WithPathParameters(p), autorest.WithFormData(v)) if err != nil { return err } resp, err := autorest.SendWithSender(spt.sender, req) if err != nil { return autorest.NewErrorWithError(err, "azure.ServicePrincipalToken", "Refresh", "Failure sending request for Service Principal %s", spt.clientID) } var newToken Token err = autorest.Respond(resp, autorest.WithErrorUnlessOK(), autorest.ByUnmarshallingJSON(&newToken), autorest.ByClosing()) if err != nil { return autorest.NewErrorWithError(err, "azure.ServicePrincipalToken", "Refresh", "Failure handling response to Service Principal %s request", spt.clientID) } spt.Token = newToken return nil }
// GetDomainControlCenterSsoRequestPreparer prepares the GetDomainControlCenterSsoRequest request. func (client GlobalDomainRegistrationClient) GetDomainControlCenterSsoRequestPreparer() (*http.Request, error) { pathParameters := map[string]interface{}{ "subscriptionId": autorest.Encode("path", client.SubscriptionID), } queryParameters := map[string]interface{}{ "api-version": client.APIVersion, } preparer := autorest.CreatePreparer( autorest.AsPost(), autorest.WithBaseURL(client.BaseURI), autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.DomainRegistration/generateSsoRequest", pathParameters), autorest.WithQueryParameters(queryParameters)) return preparer.Prepare(&http.Request{}) }
// GetDomainControlCenterSsoRequestPreparer prepares the GetDomainControlCenterSsoRequest request. func (client GlobalDomainRegistrationClient) GetDomainControlCenterSsoRequestPreparer() (*http.Request, error) { pathParameters := map[string]interface{}{ "subscriptionId": url.QueryEscape(client.SubscriptionID), } queryParameters := map[string]interface{}{ "api-version": APIVersion, } return autorest.Prepare(&http.Request{}, autorest.AsJSON(), autorest.AsPost(), autorest.WithBaseURL(client.BaseURI), autorest.WithPath("/subscriptions/{subscriptionId}/providers/Microsoft.DomainRegistration/generateSsoRequest"), autorest.WithPathParameters(pathParameters), autorest.WithQueryParameters(queryParameters)) }
// UnregisterPreparer prepares the Unregister request. func (client ProvidersClient) UnregisterPreparer(resourceProviderNamespace string) (*http.Request, error) { pathParameters := map[string]interface{}{ "resourceProviderNamespace": autorest.Encode("path", resourceProviderNamespace), "subscriptionId": autorest.Encode("path", client.SubscriptionID), } queryParameters := map[string]interface{}{ "api-version": client.APIVersion, } preparer := autorest.CreatePreparer( autorest.AsPost(), autorest.WithBaseURL(client.BaseURI), autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/{resourceProviderNamespace}/unregister", pathParameters), autorest.WithQueryParameters(queryParameters)) return preparer.Prepare(&http.Request{}) }
// CheckForUserCompletion takes a DeviceCode and checks with the Azure AD OAuth endpoint // to see if the device flow has: been completed, timed out, or otherwise failed func CheckForUserCompletion(client *autorest.Client, code *DeviceCode) (*Token, error) { req, _ := autorest.Prepare( &http.Request{}, autorest.AsPost(), autorest.AsFormURLEncoded(), autorest.WithBaseURL(code.OAuthConfig.TokenEndpoint.String()), autorest.WithFormData(url.Values{ "client_id": []string{code.ClientID}, "code": []string{*code.DeviceCode}, "grant_type": []string{OAuthGrantTypeDeviceCode}, "resource": []string{code.Resource}, }), ) resp, err := client.Send(req) if err != nil { return nil, fmt.Errorf("%s %s: %s", logPrefix, errTokenSendingFails, err) } var token deviceToken err = autorest.Respond( resp, autorest.WithErrorUnlessStatusCode(http.StatusOK, http.StatusBadRequest), autorest.ByUnmarshallingJSON(&token), autorest.ByClosing()) if err != nil { return nil, fmt.Errorf("%s %s: %s", logPrefix, errTokenHandlingFails, err) } if token.Error == nil { return &token.Token, nil } switch *token.Error { case "authorization_pending": return nil, ErrDeviceAuthorizationPending case "slow_down": return nil, ErrDeviceSlowDown case "access_denied": return nil, ErrDeviceAccessDenied case "code_expired": return nil, ErrDeviceCodeExpired default: return nil, ErrDeviceGeneric } }
// ListEffectiveNetworkSecurityGroupsPreparer prepares the ListEffectiveNetworkSecurityGroups request. func (client InterfacesClient) ListEffectiveNetworkSecurityGroupsPreparer(resourceGroupName string, networkInterfaceName string, cancel <-chan struct{}) (*http.Request, error) { pathParameters := map[string]interface{}{ "networkInterfaceName": autorest.Encode("path", networkInterfaceName), "resourceGroupName": autorest.Encode("path", resourceGroupName), "subscriptionId": autorest.Encode("path", client.SubscriptionID), } queryParameters := map[string]interface{}{ "api-version": client.APIVersion, } preparer := autorest.CreatePreparer( autorest.AsPost(), autorest.WithBaseURL(client.BaseURI), autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkInterfaces/{networkInterfaceName}/effectiveNetworkSecurityGroups", pathParameters), autorest.WithQueryParameters(queryParameters)) return preparer.Prepare(&http.Request{Cancel: cancel}) }
// ListVhdsPreparer prepares the ListVhds request. func (client LabOperationsClient) ListVhdsPreparer(resourceGroupName string, name string) (*http.Request, error) { pathParameters := map[string]interface{}{ "name": autorest.Encode("path", name), "resourceGroupName": autorest.Encode("path", resourceGroupName), "subscriptionId": autorest.Encode("path", client.SubscriptionID), } queryParameters := map[string]interface{}{ "api-version": client.APIVersion, } preparer := autorest.CreatePreparer( autorest.AsPost(), autorest.WithBaseURL(client.BaseURI), autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}/listVhds", pathParameters), autorest.WithQueryParameters(queryParameters)) return preparer.Prepare(&http.Request{}) }