go-autorest: github.com/Azure/go-autorest/autorest/azure Index | Examples | Files | Directories

package azure

import "github.com/Azure/go-autorest/autorest/azure"

Package azure provides Azure-specific implementations used with AutoRest. See the included examples for more detail.

Index

Examples

Package Files

async.go azure.go environments.go metadata_environment.go rp.go

Constants

const (
    // HeaderClientID is the Azure extension header to set a user-specified request ID.
    HeaderClientID = "x-ms-client-request-id"

    // HeaderReturnClientID is the Azure extension header to set if the user-specified request ID
    // should be included in the response.
    HeaderReturnClientID = "x-ms-return-client-request-id"

    // HeaderRequestID is the Azure extension header of the service generated request ID returned
    // in the response.
    HeaderRequestID = "x-ms-request-id"
)
const EnvironmentFilepathName = "AZURE_ENVIRONMENT_FILEPATH"

EnvironmentFilepathName captures the name of the environment variable containing the path to the file to be used while populating the Azure Environment.

Variables

var (
    // PublicCloud is the default public Azure cloud environment
    PublicCloud = Environment{
        Name:                         "AzurePublicCloud",
        ManagementPortalURL:          "https://manage.windowsazure.com/",
        PublishSettingsURL:           "https://manage.windowsazure.com/publishsettings/index",
        ServiceManagementEndpoint:    "https://management.core.windows.net/",
        ResourceManagerEndpoint:      "https://management.azure.com/",
        ActiveDirectoryEndpoint:      "https://login.microsoftonline.com/",
        GalleryEndpoint:              "https://gallery.azure.com/",
        KeyVaultEndpoint:             "https://vault.azure.net/",
        GraphEndpoint:                "https://graph.windows.net/",
        ServiceBusEndpoint:           "https://servicebus.windows.net/",
        BatchManagementEndpoint:      "https://batch.core.windows.net/",
        StorageEndpointSuffix:        "core.windows.net",
        SQLDatabaseDNSSuffix:         "database.windows.net",
        TrafficManagerDNSSuffix:      "trafficmanager.net",
        KeyVaultDNSSuffix:            "vault.azure.net",
        ServiceBusEndpointSuffix:     "servicebus.windows.net",
        ServiceManagementVMDNSSuffix: "cloudapp.net",
        ResourceManagerVMDNSSuffix:   "cloudapp.azure.com",
        ContainerRegistryDNSSuffix:   "azurecr.io",
        TokenAudience:                "https://management.azure.com/",
    }

    // USGovernmentCloud is the cloud environment for the US Government
    USGovernmentCloud = Environment{
        Name:                         "AzureUSGovernmentCloud",
        ManagementPortalURL:          "https://manage.windowsazure.us/",
        PublishSettingsURL:           "https://manage.windowsazure.us/publishsettings/index",
        ServiceManagementEndpoint:    "https://management.core.usgovcloudapi.net/",
        ResourceManagerEndpoint:      "https://management.usgovcloudapi.net/",
        ActiveDirectoryEndpoint:      "https://login.microsoftonline.us/",
        GalleryEndpoint:              "https://gallery.usgovcloudapi.net/",
        KeyVaultEndpoint:             "https://vault.usgovcloudapi.net/",
        GraphEndpoint:                "https://graph.windows.net/",
        ServiceBusEndpoint:           "https://servicebus.usgovcloudapi.net/",
        BatchManagementEndpoint:      "https://batch.core.usgovcloudapi.net/",
        StorageEndpointSuffix:        "core.usgovcloudapi.net",
        SQLDatabaseDNSSuffix:         "database.usgovcloudapi.net",
        TrafficManagerDNSSuffix:      "usgovtrafficmanager.net",
        KeyVaultDNSSuffix:            "vault.usgovcloudapi.net",
        ServiceBusEndpointSuffix:     "servicebus.usgovcloudapi.net",
        ServiceManagementVMDNSSuffix: "usgovcloudapp.net",
        ResourceManagerVMDNSSuffix:   "cloudapp.windowsazure.us",
        ContainerRegistryDNSSuffix:   "azurecr.io",
        TokenAudience:                "https://management.usgovcloudapi.net/",
    }

    // ChinaCloud is the cloud environment operated in China
    ChinaCloud = Environment{
        Name:                         "AzureChinaCloud",
        ManagementPortalURL:          "https://manage.chinacloudapi.com/",
        PublishSettingsURL:           "https://manage.chinacloudapi.com/publishsettings/index",
        ServiceManagementEndpoint:    "https://management.core.chinacloudapi.cn/",
        ResourceManagerEndpoint:      "https://management.chinacloudapi.cn/",
        ActiveDirectoryEndpoint:      "https://login.chinacloudapi.cn/",
        GalleryEndpoint:              "https://gallery.chinacloudapi.cn/",
        KeyVaultEndpoint:             "https://vault.azure.cn/",
        GraphEndpoint:                "https://graph.chinacloudapi.cn/",
        ServiceBusEndpoint:           "https://servicebus.chinacloudapi.cn/",
        BatchManagementEndpoint:      "https://batch.chinacloudapi.cn/",
        StorageEndpointSuffix:        "core.chinacloudapi.cn",
        SQLDatabaseDNSSuffix:         "database.chinacloudapi.cn",
        TrafficManagerDNSSuffix:      "trafficmanager.cn",
        KeyVaultDNSSuffix:            "vault.azure.cn",
        ServiceBusEndpointSuffix:     "servicebus.chinacloudapi.cn",
        ServiceManagementVMDNSSuffix: "chinacloudapp.cn",
        ResourceManagerVMDNSSuffix:   "cloudapp.azure.cn",
        ContainerRegistryDNSSuffix:   "azurecr.io",
        TokenAudience:                "https://management.chinacloudapi.cn/",
    }

    // GermanCloud is the cloud environment operated in Germany
    GermanCloud = Environment{
        Name:                         "AzureGermanCloud",
        ManagementPortalURL:          "http://portal.microsoftazure.de/",
        PublishSettingsURL:           "https://manage.microsoftazure.de/publishsettings/index",
        ServiceManagementEndpoint:    "https://management.core.cloudapi.de/",
        ResourceManagerEndpoint:      "https://management.microsoftazure.de/",
        ActiveDirectoryEndpoint:      "https://login.microsoftonline.de/",
        GalleryEndpoint:              "https://gallery.cloudapi.de/",
        KeyVaultEndpoint:             "https://vault.microsoftazure.de/",
        GraphEndpoint:                "https://graph.cloudapi.de/",
        ServiceBusEndpoint:           "https://servicebus.cloudapi.de/",
        BatchManagementEndpoint:      "https://batch.cloudapi.de/",
        StorageEndpointSuffix:        "core.cloudapi.de",
        SQLDatabaseDNSSuffix:         "database.cloudapi.de",
        TrafficManagerDNSSuffix:      "azuretrafficmanager.de",
        KeyVaultDNSSuffix:            "vault.microsoftazure.de",
        ServiceBusEndpointSuffix:     "servicebus.cloudapi.de",
        ServiceManagementVMDNSSuffix: "azurecloudapp.de",
        ResourceManagerVMDNSSuffix:   "cloudapp.microsoftazure.de",
        ContainerRegistryDNSSuffix:   "azurecr.io",
        TokenAudience:                "https://management.microsoftazure.de/",
    }
)

func DoPollForAsynchronous Uses

func DoPollForAsynchronous(delay time.Duration) autorest.SendDecorator

DoPollForAsynchronous returns a SendDecorator that polls if the http.Response is for an Azure long-running operation. It will delay between requests for the duration specified in the RetryAfter header or, if the header is absent, the passed delay. Polling may be canceled via the context associated with the http.Request. Deprecated: Prefer using Futures to allow for non-blocking async operations.

func DoRetryWithRegistration Uses

func DoRetryWithRegistration(client autorest.Client) autorest.SendDecorator

DoRetryWithRegistration tries to register the resource provider in case it is unregistered. It also handles request retries

func ExtractClientID Uses

func ExtractClientID(resp *http.Response) string

ExtractClientID extracts the client identifier from the x-ms-client-request-id header set on the http.Request sent to the service (and returned in the http.Response)

func ExtractRequestID Uses

func ExtractRequestID(resp *http.Response) string

ExtractRequestID extracts the Azure server generated request identifier from the x-ms-request-id header.

func IsAzureError Uses

func IsAzureError(e error) bool

IsAzureError returns true if the passed error is an Azure Service error; false otherwise.

func WithClientID Uses

func WithClientID(uuid string) autorest.PrepareDecorator

WithClientID returns a PrepareDecorator that adds an HTTP extension header of x-ms-client-request-id whose value is passed, undecorated UUID (e.g., "0F39878C-5F76-4DB8-A25D-61D2C193C3CA").

Use a Client Inspector to set the request identifier.

Code:

uuid := "71FDB9F4-5E49-4C12-B266-DE7B4FD999A6"
req, _ := autorest.Prepare(&http.Request{},
    autorest.AsGet(),
    autorest.WithBaseURL("https://microsoft.com/a/b/c/"))

c := autorest.Client{Sender: mocks.NewSender()}
c.RequestInspector = WithReturningClientID(uuid)

autorest.SendWithSender(c, req)
fmt.Printf("Inspector added the %s header with the value %s\n",
    HeaderClientID, req.Header.Get(HeaderClientID))
fmt.Printf("Inspector added the %s header with the value %s\n",
    HeaderReturnClientID, req.Header.Get(HeaderReturnClientID))

Output:

Inspector added the x-ms-client-request-id header with the value 71FDB9F4-5E49-4C12-B266-DE7B4FD999A6
Inspector added the x-ms-return-client-request-id header with the value true

func WithErrorUnlessStatusCode Uses

func WithErrorUnlessStatusCode(codes ...int) autorest.RespondDecorator

WithErrorUnlessStatusCode returns a RespondDecorator that emits an azure.RequestError by reading the response body unless the response HTTP status code is among the set passed.

If there is a chance service may return responses other than the Azure error format and the response cannot be parsed into an error, a decoding error will be returned containing the response body. In any case, the Responder will return an error if the status code is not satisfied.

If this Responder returns an error, the response body will be replaced with an in-memory reader, which needs no further closing.

func WithReturnClientID Uses

func WithReturnClientID(b bool) autorest.PrepareDecorator

WithReturnClientID returns a PrepareDecorator that adds an HTTP extension header of x-ms-return-client-request-id whose boolean value indicates if the value of the x-ms-client-request-id header should be included in the http.Response.

func WithReturningClientID Uses

func WithReturningClientID(uuid string) autorest.PrepareDecorator

WithReturningClientID returns a PrepareDecorator that adds an HTTP extension header of x-ms-client-request-id whose value is the passed, undecorated UUID (e.g., "0F39878C-5F76-4DB8-A25D-61D2C193C3CA"). It also sets the x-ms-return-client-request-id header to true such that UUID accompanies the http.Response.

type AsyncOpIncompleteError Uses

type AsyncOpIncompleteError struct {
    // FutureType is the name of the type composed of a azure.Future.
    FutureType string
}

AsyncOpIncompleteError is the type that's returned from a future that has not completed.

func NewAsyncOpIncompleteError Uses

func NewAsyncOpIncompleteError(futureType string) AsyncOpIncompleteError

NewAsyncOpIncompleteError creates a new AsyncOpIncompleteError with the specified parameters.

func (AsyncOpIncompleteError) Error Uses

func (e AsyncOpIncompleteError) Error() string

Error returns an error message including the originating type name of the error.

type Environment Uses

type Environment struct {
    Name                         string `json:"name"`
    ManagementPortalURL          string `json:"managementPortalURL"`
    PublishSettingsURL           string `json:"publishSettingsURL"`
    ServiceManagementEndpoint    string `json:"serviceManagementEndpoint"`
    ResourceManagerEndpoint      string `json:"resourceManagerEndpoint"`
    ActiveDirectoryEndpoint      string `json:"activeDirectoryEndpoint"`
    GalleryEndpoint              string `json:"galleryEndpoint"`
    KeyVaultEndpoint             string `json:"keyVaultEndpoint"`
    GraphEndpoint                string `json:"graphEndpoint"`
    ServiceBusEndpoint           string `json:"serviceBusEndpoint"`
    BatchManagementEndpoint      string `json:"batchManagementEndpoint"`
    StorageEndpointSuffix        string `json:"storageEndpointSuffix"`
    SQLDatabaseDNSSuffix         string `json:"sqlDatabaseDNSSuffix"`
    TrafficManagerDNSSuffix      string `json:"trafficManagerDNSSuffix"`
    KeyVaultDNSSuffix            string `json:"keyVaultDNSSuffix"`
    ServiceBusEndpointSuffix     string `json:"serviceBusEndpointSuffix"`
    ServiceManagementVMDNSSuffix string `json:"serviceManagementVMDNSSuffix"`
    ResourceManagerVMDNSSuffix   string `json:"resourceManagerVMDNSSuffix"`
    ContainerRegistryDNSSuffix   string `json:"containerRegistryDNSSuffix"`
    TokenAudience                string `json:"tokenAudience"`
}

Environment represents a set of endpoints for each of Azure's Clouds.

func EnvironmentFromFile Uses

func EnvironmentFromFile(location string) (unmarshaled Environment, err error)

EnvironmentFromFile loads an Environment from a configuration file available on disk. This function is particularly useful in the Hybrid Cloud model, where one must define their own endpoints.

func EnvironmentFromName Uses

func EnvironmentFromName(name string) (Environment, error)

EnvironmentFromName returns an Environment based on the common name specified.

func EnvironmentFromURL Uses

func EnvironmentFromURL(resourceManagerEndpoint string, properties ...OverrideProperty) (environment Environment, err error)

EnvironmentFromURL loads an Environment from a URL This function is particularly useful in the Hybrid Cloud model, where one may define their own endpoints.

type EnvironmentProperty Uses

type EnvironmentProperty string

EnvironmentProperty represent property names that clients can override

const (
    // EnvironmentName ...
    EnvironmentName EnvironmentProperty = "name"
    // EnvironmentManagementPortalURL ..
    EnvironmentManagementPortalURL EnvironmentProperty = "managementPortalURL"
    // EnvironmentPublishSettingsURL ...
    EnvironmentPublishSettingsURL EnvironmentProperty = "publishSettingsURL"
    // EnvironmentServiceManagementEndpoint ...
    EnvironmentServiceManagementEndpoint EnvironmentProperty = "serviceManagementEndpoint"
    // EnvironmentResourceManagerEndpoint ...
    EnvironmentResourceManagerEndpoint EnvironmentProperty = "resourceManagerEndpoint"
    // EnvironmentActiveDirectoryEndpoint ...
    EnvironmentActiveDirectoryEndpoint EnvironmentProperty = "activeDirectoryEndpoint"
    // EnvironmentGalleryEndpoint ...
    EnvironmentGalleryEndpoint EnvironmentProperty = "galleryEndpoint"
    // EnvironmentKeyVaultEndpoint ...
    EnvironmentKeyVaultEndpoint EnvironmentProperty = "keyVaultEndpoint"
    // EnvironmentGraphEndpoint ...
    EnvironmentGraphEndpoint EnvironmentProperty = "graphEndpoint"
    // EnvironmentServiceBusEndpoint ...
    EnvironmentServiceBusEndpoint EnvironmentProperty = "serviceBusEndpoint"
    // EnvironmentBatchManagementEndpoint ...
    EnvironmentBatchManagementEndpoint EnvironmentProperty = "batchManagementEndpoint"
    // EnvironmentStorageEndpointSuffix ...
    EnvironmentStorageEndpointSuffix EnvironmentProperty = "storageEndpointSuffix"
    // EnvironmentSQLDatabaseDNSSuffix ...
    EnvironmentSQLDatabaseDNSSuffix EnvironmentProperty = "sqlDatabaseDNSSuffix"
    // EnvironmentTrafficManagerDNSSuffix ...
    EnvironmentTrafficManagerDNSSuffix EnvironmentProperty = "trafficManagerDNSSuffix"
    // EnvironmentKeyVaultDNSSuffix ...
    EnvironmentKeyVaultDNSSuffix EnvironmentProperty = "keyVaultDNSSuffix"
    // EnvironmentServiceBusEndpointSuffix ...
    EnvironmentServiceBusEndpointSuffix EnvironmentProperty = "serviceBusEndpointSuffix"
    // EnvironmentServiceManagementVMDNSSuffix ...
    EnvironmentServiceManagementVMDNSSuffix EnvironmentProperty = "serviceManagementVMDNSSuffix"
    // EnvironmentResourceManagerVMDNSSuffix ...
    EnvironmentResourceManagerVMDNSSuffix EnvironmentProperty = "resourceManagerVMDNSSuffix"
    // EnvironmentContainerRegistryDNSSuffix ...
    EnvironmentContainerRegistryDNSSuffix EnvironmentProperty = "containerRegistryDNSSuffix"
    // EnvironmentTokenAudience ...
    EnvironmentTokenAudience EnvironmentProperty = "tokenAudience"
)

type Future Uses

type Future struct {
    // contains filtered or unexported fields
}

Future provides a mechanism to access the status and results of an asynchronous request. Since futures are stateful they should be passed by value to avoid race conditions.

func NewFuture Uses

func NewFuture(req *http.Request) Future

NewFuture returns a new Future object initialized with the specified request. Deprecated: Please use NewFutureFromResponse instead.

func NewFutureFromResponse Uses

func NewFutureFromResponse(resp *http.Response) (Future, error)

NewFutureFromResponse returns a new Future object initialized with the initial response from an asynchronous operation.

func (*Future) Done Uses

func (f *Future) Done(sender autorest.Sender) (bool, error)

Done queries the service to see if the operation has completed. Deprecated: Use DoneWithContext()

func (*Future) DoneWithContext Uses

func (f *Future) DoneWithContext(ctx context.Context, sender autorest.Sender) (done bool, err error)

DoneWithContext queries the service to see if the operation has completed.

func (Future) GetPollingDelay Uses

func (f Future) GetPollingDelay() (time.Duration, bool)

GetPollingDelay returns a duration the application should wait before checking the status of the asynchronous request and true; this value is returned from the service via the Retry-After response header. If the header wasn't returned then the function returns the zero-value time.Duration and false.

func (Future) GetResult Uses

func (f Future) GetResult(sender autorest.Sender) (*http.Response, error)

GetResult should be called once polling has completed successfully. It makes the final GET call to retrieve the resultant payload.

func (Future) MarshalJSON Uses

func (f Future) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Future) PollingMethod Uses

func (f Future) PollingMethod() PollingMethodType

PollingMethod returns the method used to monitor the status of the asynchronous operation.

func (Future) PollingURL Uses

func (f Future) PollingURL() string

PollingURL returns the URL used for retrieving the status of the long-running operation.

func (Future) Response Uses

func (f Future) Response() *http.Response

Response returns the last HTTP response.

func (Future) Status Uses

func (f Future) Status() string

Status returns the last status message of the operation.

func (*Future) UnmarshalJSON Uses

func (f *Future) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (Future) WaitForCompletion Uses

func (f Future) WaitForCompletion(ctx context.Context, client autorest.Client) error

WaitForCompletion will return when one of the following conditions is met: the long running operation has completed, the provided context is cancelled, or the client's polling duration has been exceeded. It will retry failed polling attempts based on the retry value defined in the client up to the maximum retry attempts. Deprecated: Please use WaitForCompletionRef() instead.

func (*Future) WaitForCompletionRef Uses

func (f *Future) WaitForCompletionRef(ctx context.Context, client autorest.Client) (err error)

WaitForCompletionRef will return when one of the following conditions is met: the long running operation has completed, the provided context is cancelled, or the client's polling duration has been exceeded. It will retry failed polling attempts based on the retry value defined in the client up to the maximum retry attempts.

type OverrideProperty Uses

type OverrideProperty struct {
    Key   EnvironmentProperty
    Value string
}

OverrideProperty represents property name and value that clients can override

type PollingMethodType Uses

type PollingMethodType string

PollingMethodType defines a type used for enumerating polling mechanisms.

const (
    // PollingAsyncOperation indicates the polling method uses the Azure-AsyncOperation header.
    PollingAsyncOperation PollingMethodType = "AsyncOperation"

    // PollingLocation indicates the polling method uses the Location header.
    PollingLocation PollingMethodType = "Location"

    // PollingRequestURI indicates the polling method uses the original request URI.
    PollingRequestURI PollingMethodType = "RequestURI"

    // PollingUnknown indicates an unknown polling method and is the default value.
    PollingUnknown PollingMethodType = ""
)

type RequestError Uses

type RequestError struct {
    autorest.DetailedError

    // The error returned by the Azure service.
    ServiceError *ServiceError `json:"error"`

    // The request id (from the x-ms-request-id-header) of the request.
    RequestID string
}

RequestError describes an error response returned by Azure service.

func NewErrorWithError Uses

func NewErrorWithError(original error, packageType string, method string, resp *http.Response, message string, args ...interface{}) RequestError

NewErrorWithError creates a new Error conforming object from the passed packageType, method, statusCode of the given resp (UndefinedStatusCode if resp is nil), message, and original error. message is treated as a format string to which the optional args apply.

func (RequestError) Error Uses

func (e RequestError) Error() string

Error returns a human-friendly error message from service error.

type Resource Uses

type Resource struct {
    SubscriptionID string
    ResourceGroup  string
    Provider       string
    ResourceType   string
    ResourceName   string
}

Resource contains details about an Azure resource.

func ParseResourceID Uses

func ParseResourceID(resourceID string) (Resource, error)

ParseResourceID parses a resource ID into a ResourceDetails struct. See https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-template-functions-resource#return-value-4.

type ServiceError Uses

type ServiceError struct {
    Code           string                   `json:"code"`
    Message        string                   `json:"message"`
    Target         *string                  `json:"target"`
    Details        []map[string]interface{} `json:"details"`
    InnerError     map[string]interface{}   `json:"innererror"`
    AdditionalInfo []map[string]interface{} `json:"additionalInfo"`
}

ServiceError encapsulates the error response from an Azure service. It adhears to the OData v4 specification for error responses.

func (ServiceError) Error Uses

func (se ServiceError) Error() string

func (*ServiceError) UnmarshalJSON Uses

func (se *ServiceError) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for the ServiceError type.

Directories

PathSynopsis
auth
cli
example

Package azure imports 15 packages (graph) and is imported by 1012 packages. Updated 2019-01-16. Refresh now. Tools for package owners.