func getResourceGroups(client *autorest.Client) (*string, error) { var p map[string]interface{} var req *http.Request p = map[string]interface{}{ "subscription-id": subscriptionID, } q := map[string]interface{}{ "api-version": apiVersion, } req, _ = autorest.Prepare(&http.Request{}, autorest.AsGet(), autorest.WithBaseURL(resourceGroupURLTemplate), autorest.WithPathParameters(p), autorest.WithQueryParameters(q)) resp, err := client.Send(req, http.StatusOK) if err != nil { return nil, err } defer resp.Body.Close() contents, err := ioutil.ReadAll(resp.Body) if err != nil { return nil, err } contentsString := string(contents) return &contentsString, 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", resp.StatusCode, "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.StatusCode, "Failure handling response to Service Principal %s request", spt.clientID) } spt.Token = newToken return nil }
// ListPreparer prepares the List request. func (client AccountsClient) ListPreparer() (*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.AsGet(), autorest.WithBaseURL(client.BaseURI), autorest.WithPath("/subscriptions/{subscriptionId}/providers/Microsoft.Storage/storageAccounts"), autorest.WithPathParameters(pathParameters), autorest.WithQueryParameters(queryParameters)) }
// ListKeysPreparer prepares the ListKeys request. func (client AccountsClient) ListKeysPreparer(resourceGroupName string, accountName string) (*http.Request, error) { pathParameters := map[string]interface{}{ "accountName": url.QueryEscape(accountName), "resourceGroupName": url.QueryEscape(resourceGroupName), "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}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/listKeys"), autorest.WithPathParameters(pathParameters), autorest.WithQueryParameters(queryParameters)) }