genericarmclient

package
v2.0.0-...-a7294fb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AsyncOperationHeader = "Azure-Asyncoperation"
	LocationHeader       = "Location"
)
View Source
const (
	CreatePollerID = "GenericClient.CreateOrUpdateByID"
	DeletePollerID = "GenericClient.DeleteByID"
)

Variables

This section is empty.

Functions

func AddToUserAgent

func AddToUserAgent(suffix string)

AddToUserAgent appends the given suffix to the default user agent.

func GetRetryAfter

func GetRetryAfter(resp *http.Response) time.Duration

func GetSubscription

func GetSubscription(path string) (string, error)

GetSubscription uses resource ID to extract and return subscription ID out of it.

func IsNotFoundError

func IsNotFoundError(err error) bool

func ListByContainerID

func ListByContainerID[T any](
	ctx context.Context,
	client *GenericClient,
	containerID string,
	apiVersion string,
) ([]T, error)

ListByContainerID returns all the resources of a given type under a specified parent. If the operation fails it returns the *CloudError error type. ctx is the context of the request. client is the GenericClient to use for the request (can't declare generic methods, so this is standalone). containerID is the unique ID of the container in which the resources are contained. apiVersion is the API version to use for the request. createResource is a function that returns a new instance of the resource type.

func MakeResourceGroupID

func MakeResourceGroupID(subscription string, resourceGroup string) string

MakeResourceGroupID makes an ARM ID representing a resource group. This has the format: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/<rgName> This is "special" because there is no provider at all - but that is what creating/getting a resourceGroup expects.

func MakeResourceGroupScopeARMID

func MakeResourceGroupScopeARMID(subscription string, resourceGroup string, provider string, params ...string) (string, error)

MakeResourceGroupScopeARMID makes an ARM ID at the resource group scope. This has the format: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/<rgName>/providers/<provider>/<resourceType>/<resourceName>/...

func MakeSubscriptionID

func MakeSubscriptionID(subscription string) string

MakeSubscriptionID makes an ARM ID representing a subscription. This has the format: /subscriptions/00000000-0000-0000-0000-000000000000 This is "special" because there is no provider at all

func MakeSubscriptionScopeARMID

func MakeSubscriptionScopeARMID(subscription string, provider string, params ...string) (string, error)

MakeSubscriptionScopeARMID makes an ARM ID at the subscription scope. This has the format: /subscriptions/00000000-0000-0000-0000-000000000000/providers/<provider>/<resourceType>/<resourceName>/...

func MakeTenantScopeARMID

func MakeTenantScopeARMID(provider string, params ...string) (string, error)

MakeTenantScopeARMID makes an ARM ID at the tenant scope. This has the format: /providers/<provider>/<resourceType>/<resourceName>/...

func NewRPRegistrationPolicy

func NewRPRegistrationPolicy(cred azcore.TokenCredential, o *azpolicy.ClientOptions) (azpolicy.Policy, error)

NewRPRegistrationPolicy creates a policy object configured using the specified options. The policy controls whether an unregistered resource provider should automatically be registered. See https://aka.ms/rps-not-found for more information.

func NewUserAgentPolicy

func NewUserAgentPolicy(userAgent string) policy.Policy

NewUserAgentPolicy creates a new policy.Policy appending the specified user agent to each request

Types

type CloudError

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

CloudError - An error response for a resource management request We have to support two different formats for the error as some services do things differently.

The ARM spec says that error details should be nested inside an `error` element. See https://github.com/Azure/azure-resource-manager-rpc/blob/master/v1.0/common-api-details.md#error-response-content

However, some services put the code & message at the top level instead. This is common enough that the Azure Python SDK has specific handling to promote a nested error to the top level. See https://github.com/Azure/azure-sdk-for-python/blob/9791fb5bc4cb6001768e6e1fb986b8d8f8326c43/sdk/core/azure-core/azure/core/exceptions.py#L153

func NewCloudError

func NewCloudError(err error) *CloudError

NewCloudError returns a new CloudError

func NewTestCloudError

func NewTestCloudError(code string, message string) *CloudError

func (CloudError) Code

func (e CloudError) Code() string

Code returns the error code from the message, if present, or UnknownErrorCode if not.

func (CloudError) Details

func (e CloudError) Details() []*ErrorResponse

Details returns the details of the error, if present, or an empty slice if not

func (CloudError) Error

func (e CloudError) Error() string

Error implements the error interface for type CloudError. The contents of the error text are not contractual and subject to change.

func (CloudError) Message

func (e CloudError) Message() string

Message returns the message from the error, if present, or UnknownErrorMessage if not.

func (CloudError) Target

func (e CloudError) Target() string

Target returns the target of the error, if present, or an empty string if not.

func (*CloudError) UnmarshalJSON

func (e *CloudError) UnmarshalJSON(data []byte) error

func (CloudError) Unwrap

func (e CloudError) Unwrap() error

type ErrorAdditionalInfo

type ErrorAdditionalInfo struct {
	// READ-ONLY; The additional info.
	Info map[string]interface{} `json:"info,omitempty" azure:"ro"`

	// READ-ONLY; The additional info type.
	Type *string `json:"type,omitempty" azure:"ro"`
}

ErrorAdditionalInfo - The resource management error additional info.

type ErrorResponse

type ErrorResponse struct {
	// READ-ONLY; The error additional info.
	AdditionalInfo []*ErrorAdditionalInfo `json:"additionalInfo,omitempty" azure:"ro"`

	// READ-ONLY; The error code.
	Code *string `json:"code,omitempty" azure:"ro"`

	// READ-ONLY; The error details.
	Details []*ErrorResponse `json:"details,omitempty" azure:"ro"`

	// READ-ONLY; The error message.
	Message *string `json:"message,omitempty" azure:"ro"`

	// READ-ONLY; The error target.
	Target *string `json:"target,omitempty" azure:"ro"`
}

ErrorResponse - Common error response for all Azure Resource Manager APIs to return error details for failed operations.

type GenericClient

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

func NewGenericClient

func NewGenericClient(
	cloudCfg cloud.Configuration,
	creds azcore.TokenCredential,
	options *GenericClientOptions,
) (*GenericClient, error)

NewGenericClient creates a new instance of GenericClient

func (*GenericClient) BeginCreateOrUpdateByID

func (client *GenericClient) BeginCreateOrUpdateByID(
	ctx context.Context,
	resourceID string,
	apiVersion string,
	resource interface{},
) (*PollerResponse[GenericResource], error)

func (*GenericClient) BeginDeleteByID

func (client *GenericClient) BeginDeleteByID(ctx context.Context, resourceID string, apiVersion string) (*PollerResponse[GenericDeleteResponse], error)

BeginDeleteByID - Deletes a resource by ID. If the operation fails it returns the *CloudError error type.

func (*GenericClient) CheckExistenceByID

func (client *GenericClient) CheckExistenceByID(
	ctx context.Context,
	resourceID string,
	apiVersion string,
) (bool, time.Duration, error)

CheckExistenceByID - Heads a resource by ID. If the operation fails it returns the *CloudError error type.

func (*GenericClient) CheckExistenceWithGetByID

func (client *GenericClient) CheckExistenceWithGetByID(ctx context.Context, resourceID string, apiVersion string) (bool, time.Duration, error)

func (*GenericClient) ClientOptions

func (client *GenericClient) ClientOptions() *arm.ClientOptions

ClientOptions returns the arm.ClientOptions used by this client. These options include the HTTP pipeline. If these options are used to create a new client, it will share the configured HTTP pipeline.

func (*GenericClient) Creds

func (client *GenericClient) Creds() azcore.TokenCredential

Creds returns the credentials used by this client

func (*GenericClient) GetByID

func (client *GenericClient) GetByID(
	ctx context.Context,
	resourceID string,
	apiVersion string,
	resource interface{},
) (time.Duration, error)

GetByID - Gets a resource by ID. If the operation fails it returns the *CloudError error type.

func (*GenericClient) ResumeCreatePoller

func (client *GenericClient) ResumeCreatePoller(id string) *PollerResponse[GenericResource]

func (*GenericClient) ResumeDeletePoller

func (client *GenericClient) ResumeDeletePoller(id string) *PollerResponse[GenericDeleteResponse]

type GenericClientOptions

type GenericClientOptions struct {
	HttpClient *http.Client
	Metrics    *metrics.ARMClientMetrics
	UserAgent  string
}

type GenericDeleteResponse

type GenericDeleteResponse struct {
}

type GenericResource

type GenericResource struct {
	// The kind of the resource.
	Kind *string `json:"kind,omitempty"`

	// READ-ONLY; Resource ID
	ID *string `json:"id,omitempty"`

	// READ-ONLY; Resource name
	Name *string `json:"name,omitempty"`

	// READ-ONLY; Resource type
	Type *string `json:"type,omitempty"`
}

GenericResource is used as a response type for poller. This is a shortened version of https://github.com/Azure/azure-sdk-for-go/blob/5659d929cb5966c1296568cb33410d12e0ee06c6/sdk/resourcemanager/resources/armresources/zz_generated_models.go#L922

type PollerResponse

type PollerResponse[T any] struct {
	// Poller contains an initialized poller.
	Poller *azcoreruntime.Poller[T]

	// ID is the ID of the poller (not the ID of the resource). This is used to prevent another kind of poller from
	// being resumed with this pollers URL (which would cause deserialization issues and other problems).
	ID string

	// RawResponse contains the underlying HTTP response.
	RawResponse *http.Response

	ErrorHandler func(resp *http.Response) error
}

func (*PollerResponse[T]) Resume

func (l *PollerResponse[T]) Resume(ctx context.Context, client *GenericClient, token string) error

Resume rehydrates a CreateOrUpdatePollerResponse from the provided client and resume token.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL