client

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package client provides a base client implementation for interacting with EdgeCast CDN APIs. Configuration and authentication types are also provided.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthorizationHeaderProvider

type AuthorizationHeaderProvider interface {
	GetAuthorizationHeader() (string, error)
}

AuthorizationHeaderProvider defines structs that can provide Authorization headers

type Client

type Client struct {
	// Config holds the configuration values for this client
	Config ClientConfig

	// Internal HTTP client
	HTTPClient *retryablehttp.Client
}

Client is the primary means for services to interact with the EdgeCast API

func NewClient

func NewClient(config ClientConfig) *Client

Creates a new client pointing to EdgeCast APIs

func (*Client) BuildRequest

func (c *Client) BuildRequest(method, path string, body interface{}) (*retryablehttp.Request, error)

BuildRequest creates a new Request for the Edgecast API, adding appropriate headers

func (*Client) SendRequest

func (c *Client) SendRequest(req *retryablehttp.Request, parsedResponse interface{}) (*http.Response, error)

SendRequest sends an HTTP request and, if applicable, sets the response to parsedResponse

func (*Client) SendRequestWithStringResponse

func (c *Client) SendRequestWithStringResponse(req *retryablehttp.Request) (*string, error)

SendRequest sends an HTTP request and, if applicable, sets the response to parsedResponse

type ClientConfig

type ClientConfig struct {
	// Generates Authorization Header values for HTTP requests
	AuthHeaderProvider AuthorizationHeaderProvider

	// APIURL contains the base URL for the target API
	BaseAPIURL *url.URL

	// The User Agent specifed for HTTP requests
	UserAgent string

	// Logger -
	Logger edgecast.Logger
}

ClientConfig provides configuration for the base client

func NewAPIClientConfig

func NewAPIClientConfig(credentials IDSCredentials) (*ClientConfig, error)

NewAPIClientConfig creates a new ClientConfig for targeting the EdgeCast API The EdgeCast API uses OAuth 2.0 credentials

func NewLegacyAPIClientConfig

func NewLegacyAPIClientConfig(apiToken string) (*ClientConfig, error)

NewLegacyAPIClientConfig creates a new ClientConfig for targeting the legacy EdgeCast API The legacy APIs use an API Token

type DefaultIDSClient

type DefaultIDSClient struct {
	IDSBaseUrl *url.URL
}

Calls the IDS token endpoint

func NewDefaultIDSClient

func NewDefaultIDSClient() DefaultIDSClient

NewDefaultIDSClient -

func (DefaultIDSClient) GetIDSToken

func (c DefaultIDSClient) GetIDSToken(credentials IDSCredentials) (*GetIDSTokenResponse, error)

Gets a new token from the IDS Token Endpoint

type GetIDSTokenResponse

type GetIDSTokenResponse struct {
	AccessToken string  `json:"access_token"`
	ExpiresIn   float64 `json:"expires_in"`
	TokenType   string  `json:"token_type"`
	Scope       string  `json:"scope"`
}

GetIDSTokenResponse -

type IDSAuthorizationHeaderProvider

type IDSAuthorizationHeaderProvider struct {
	// The latest IDS token. May be expired.
	CurrentToken *IDSToken

	// Calls the IDS token endpoint for new tokens
	IDSClient IDSClient

	Credentials IDSCredentials
}

Generates IDS Authoriation Header values

func NewIDSAuthorizationHeaderProvider

func NewIDSAuthorizationHeaderProvider(credentials IDSCredentials) (*IDSAuthorizationHeaderProvider, error)

Creates a new IDSAuthorizationHeaderProvider with the given credentials

func (*IDSAuthorizationHeaderProvider) GetAuthorizationHeader

func (ip *IDSAuthorizationHeaderProvider) GetAuthorizationHeader() (string, error)

GetAuthorizationHeader creates an authorization value for the current token, refreshing it if it has expired. Used for EdgeCast APIs that use IDS OAuth 2.0 tokens.

type IDSClient

type IDSClient interface {
	GetIDSToken(credentials IDSCredentials) (*GetIDSTokenResponse, error)
}

Defines a way of getting an IDS Token

type IDSCredentials

type IDSCredentials struct {
	ClientID     string
	ClientSecret string
	Scope        string
}

Holds a customer's IDS Credentials

type IDSToken

type IDSToken struct {
	AccessToken    string
	ExpirationTime time.Time
}

IDSToken holds the OAuth 2.0 token for calling EdgeCast APIs

type LegacyAuthorizationHeaderProvider

type LegacyAuthorizationHeaderProvider struct {
	APIToken string
}

LegacyAuthorizationHeaderProvider creates authorization header values for legacy EdgeCast API calls

func NewLegacyAuthorizationHeaderProvider

func NewLegacyAuthorizationHeaderProvider(apiToken string) (*LegacyAuthorizationHeaderProvider, error)

NewLegacyAuthorizationHeaderProvider -

func (*LegacyAuthorizationHeaderProvider) GetAuthorizationHeader

func (lp *LegacyAuthorizationHeaderProvider) GetAuthorizationHeader() (string, error)

GetAuthorizationHeader gets the authorization header value for legacy EdgeCast API calls

type LiteralResponse

type LiteralResponse struct {
	Value interface{}
}

LiteralResponse is used for unmarshaling response data that is in an unrecognized format

Jump to

Keyboard shortcuts

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