api

package
v1.0.0-preview....-1d59768 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultRetryAfter

func DefaultRetryAfter() time.Duration

RetryAfterDefault returns a random duration between 5 and 10 seconds.

Types

type Auth

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

func NewAuthBase

func NewAuthBase(configValue *config.ProviderConfig) *Auth

func (*Auth) AuthenticateClientCertificate

func (client *Auth) AuthenticateClientCertificate(ctx context.Context, scopes []string) (string, time.Time, error)

func (*Auth) AuthenticateClientSecret

func (client *Auth) AuthenticateClientSecret(ctx context.Context, scopes []string) (string, time.Time, error)

func (*Auth) AuthenticateOIDC

func (client *Auth) AuthenticateOIDC(ctx context.Context, scopes []string) (string, time.Time, error)

func (*Auth) AuthenticateUsingCli

func (client *Auth) AuthenticateUsingCli(ctx context.Context, scopes []string) (string, time.Time, error)

func (*Auth) GetTokenForScopes

func (client *Auth) GetTokenForScopes(ctx context.Context, scopes []string) (*string, error)

type Client

type Client struct {
	Config   *config.ProviderConfig
	BaseAuth *Auth
}

Client is a base client for specific API clients implmented in services.

func NewApiClientBase

func NewApiClientBase(providerConfig *config.ProviderConfig, baseAuth *Auth) *Client

ApiHttpResponse is a wrapper around http.Response that provides additional helper methods.

func (*Client) DoWaitForLifecycleOperationStatus

func (client *Client) DoWaitForLifecycleOperationStatus(ctx context.Context, response *Response) (*LifecycleDto, error)

func (*Client) Execute

func (client *Client) Execute(ctx context.Context, scopes []string, method, url string, headers http.Header, body any, acceptableStatusCodes []int, responseObj any) (*Response, error)

Execute executes an HTTP request with the given method, url, headers, and body.

Parameters:

  • ctx: context.Context - Provides context for the request, allowing for timeout and cancellation control.
  • scopes: []string - A list of scopes that the request should be associated with. If no scopes are provided, the method attempts to infer the scope from the URL.
  • method: string - Specifies the HTTP method to be used for the request (e.g., "GET", "POST", "PATCH").
  • url: string - The URL to which the request is sent. This includes the scheme, host, path, and query parameters. The URL must be absolute and properly formatted.
  • headers: http.Header - A collection of HTTP headers to include in the request. Headers provide additional information about the request, such as content type, authorization tokens, and custom metadata.
  • body: any - The body of the request, which can be of any type. This is typically used for methods like POST and PATCH, where data needs to be sent to the server.
  • acceptableStatusCodes: []int - A list of HTTP status codes that are considered acceptable for the response. If the response status code is not in this list, the method treats it as an error.
  • responseObj: any - An optional parameter where the response body can be unmarshaled into. This is useful for directly obtaining a structured representation of the response data.

Returns:

  • *Response: The response from the HTTP request.
  • error: An error if the request fails. Possible error types include:
  • UrlFormatError: Returned if the URL is invalid or not absolute.
  • UnexpectedHttpStatusCodeError: Returned if the response status code is not acceptable.

If no scopes are provided, the method attempts to infer the scope from the URL. The URL is validated to ensure it is absolute and properly formatted. The HTTP request is then prepared and executed. The response status code is checked against the list of acceptable status codes. If the status code is not acceptable, an error is returned. If a responseObj is provided, the response body is unmarshaled into this object.

func (*Client) GetConfig

func (client *Client) GetConfig() *config.ProviderConfig

GetConfig returns the provider configuration.

func (*Client) SleepWithContext

func (client *Client) SleepWithContext(ctx context.Context, duration time.Duration) error

SleepWithContext sleeps for the given duration or until the context is canceled.

type LifecycleDto

type LifecycleDto struct {
	Id                 string                  `json:"id"`
	Links              LifecycleLinksDto       `json:"links"`
	State              LifecycleStateDto       `json:"state"`
	Type               LifecycleStateDto       `json:"type"`
	CreatedDateTime    string                  `json:"createdDateTime"`
	LastActionDateTime string                  `json:"lastActionDateTime"`
	RequestedBy        LifecycleRequestedByDto `json:"requestedBy"`
	Stages             []LifecycleStageDto     `json:"stages"`
}

type LifecycleLinkDto

type LifecycleLinkDto struct {
	Path string `json:"path"`
}

type LifecycleLinksDto

type LifecycleLinksDto struct {
	Self        LifecycleLinkDto `json:"self"`
	Environment LifecycleLinkDto `json:"environment"`
}

type LifecycleRequestedByDto

type LifecycleRequestedByDto struct {
	Id          string `json:"id"`
	DisplayName string `json:"displayName"`
	Type        string `json:"type"`
}

type LifecycleStageDto

type LifecycleStageDto struct {
	Id                  string            `json:"id"`
	Name                string            `json:"name"`
	State               LifecycleStateDto `json:"state"`
	FirstActionDateTime string            `json:"firstActionDateTime"`
	LastActionDateTime  string            `json:"lastActionDateTime"`
}

type LifecycleStateDto

type LifecycleStateDto struct {
	Id string `json:"id"`
}

type OidcCredential

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

func NewOidcCredential

func NewOidcCredential(options *OidcCredentialOptions) (*OidcCredential, error)

func (*OidcCredential) GetToken

type OidcCredentialOptions

type OidcCredentialOptions struct {
	azcore.ClientOptions
	TenantID      string
	ClientID      string
	RequestToken  string
	RequestUrl    string
	Token         string
	TokenFilePath string
}

type ProviderClient

type ProviderClient struct {
	Config *config.ProviderConfig
	Api    *Client
}

ProviderClient is a wrapper around the API client that provides additional helper methods.

type Response

type Response struct {
	HttpResponse *http.Response
	BodyAsBytes  []byte
}

func (*Response) GetHeader

func (apiResponse *Response) GetHeader(name string) string

func (*Response) MarshallTo

func (apiResponse *Response) MarshallTo(obj any) error

type TokenExpiredError

type TokenExpiredError struct {
	Message string
}

func (*TokenExpiredError) Error

func (e *TokenExpiredError) Error() string

Jump to

Keyboard shortcuts

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