Documentation ¶
Overview ¶
Package azure provides Azure-specific implementations used with AutoRest.
See the included examples for more detail.
Index ¶
- Constants
- Variables
- func DoPollForAsynchronous(delay time.Duration) autorest.SendDecorator
- func ExtractClientID(resp *http.Response) string
- func ExtractRequestID(resp *http.Response) string
- func IsAzureError(e error) bool
- func WithClientID(uuid string) autorest.PrepareDecorator
- func WithErrorUnlessStatusCode(codes ...int) autorest.RespondDecorator
- func WithReturnClientID(b bool) autorest.PrepareDecorator
- func WithReturningClientID(uuid string) autorest.PrepareDecorator
- type Environment
- type RequestError
- type ServiceError
Examples ¶
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" )
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/", StorageEndpointSuffix: "core.windows.net", SQLDatabaseDNSSuffix: "database.windows.net", TrafficManagerDNSSuffix: "trafficmanager.net", KeyVaultDNSSuffix: "vault.azure.net", ServiceBusEndpointSuffix: "servicebus.azure.com", ServiceManagementVMDNSSuffix: "cloudapp.net", ResourceManagerVMDNSSuffix: "cloudapp.azure.com", ContainerRegistryDNSSuffix: "azurecr.io", } // 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.com/", GalleryEndpoint: "https://gallery.usgovcloudapi.net/", KeyVaultEndpoint: "https://vault.usgovcloudapi.net/", GraphEndpoint: "https://graph.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", } // 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/", StorageEndpointSuffix: "core.chinacloudapi.cn", SQLDatabaseDNSSuffix: "database.chinacloudapi.cn", TrafficManagerDNSSuffix: "trafficmanager.cn", KeyVaultDNSSuffix: "vault.azure.cn", ServiceBusEndpointSuffix: "servicebus.chinacloudapi.net", ServiceManagementVMDNSSuffix: "chinacloudapp.cn", ResourceManagerVMDNSSuffix: "cloudapp.azure.cn", ContainerRegistryDNSSuffix: "azurecr.io", } // 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/", 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", } )
Functions ¶
func DoPollForAsynchronous ¶
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 by closing the optional channel on the http.Request.
func ExtractClientID ¶
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 ¶
ExtractRequestID extracts the Azure server generated request identifier from the x-ms-request-id header.
func IsAzureError ¶
IsAzureError returns true if the passed error is an Azure Service error; false otherwise.
func WithClientID ¶
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").
Example ¶
Use a Client Inspector to set the request identifier.
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 ¶
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 ¶
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 ¶
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.
Types ¶
type Environment ¶
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"` 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"` }
Environment represents a set of endpoints for each of Azure's Clouds.
func EnvironmentFromName ¶
func EnvironmentFromName(name string) (Environment, error)
EnvironmentFromName returns an Environment based on the common name specified
type RequestError ¶
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 ¶
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 ¶
func (e RequestError) Error() string
Error returns a human-friendly error message from service error.
type ServiceError ¶
type ServiceError struct { Code string `json:"code"` Message string `json:"message"` Details *[]interface{} `json:"details"` }
ServiceError encapsulates the error response from an Azure service.
func (ServiceError) Error ¶
func (se ServiceError) Error() string