zwa

package
v3.0.12 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2025 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JSessionIDTimeout = 30 // minutes.

	MaxNumOfRetries     = 100
	RetryWaitMaxSeconds = 20
	RetryWaitMinSeconds = 5
)
View Source
const (
	VERSION        = "3.0.0"
	ZWA_API_KEY_ID = "ZWA_API_KEY_ID"
	ZWA_API_SECRET = "ZWA_API_SECRET"
)

Variables

View Source
var (
	// ContextAccessToken takes a string OAuth2 access token as authentication for the request.
	ContextAccessToken = contextKey("access_token")
)

Functions

This section is empty.

Types

type ApiErr

type ApiErr struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

type AuthRequest

type AuthRequest struct {
	APIKeyID     string `json:"key_id"`
	APIKeySecret string `json:"key_secret"`
	Timestamp    int64  `json:"timestamp"`
}

type AuthToken

type AuthToken struct {
	TokenType   string `json:"token_type"`
	AccessToken string `json:"token"`
	ExpiresIn   int    `json:"expires_in"`
}

func Authenticate

func Authenticate(ctx context.Context, cfg *Configuration, logger logger.Logger) (*AuthToken, error)

type BackoffConfig

type BackoffConfig struct {
	Enabled             bool // Set to true to enable backoff and retry mechanism
	RetryWaitMinSeconds int  // Minimum time to wait
	RetryWaitMaxSeconds int  // Maximum time to wait
	MaxNumOfRetries     int  // Maximum number of retries
}

type Client

type Client struct {
	sync.Mutex
	Config *Configuration
}

func NewClient

func NewClient(config *Configuration) (*Client, error)

func (*Client) NewRequestDo

func (client *Client) NewRequestDo(ctx context.Context, method, urlStr string, options, body, v interface{}) (*http.Response, error)

type ConfigSetter

type ConfigSetter func(*Configuration)

func WithDebug

func WithDebug(debug bool) ConfigSetter

func WithHttpClientPtr

func WithHttpClientPtr(httpClient *http.Client) ConfigSetter

WithHttpClient sets the HttpClient in the Config.

func WithProxyHost

func WithProxyHost(host string) ConfigSetter

func WithProxyPassword

func WithProxyPassword(pass string) ConfigSetter

func WithProxyPort

func WithProxyPort(i int32) ConfigSetter

func WithProxyUsername

func WithProxyUsername(username string) ConfigSetter

func WithRateLimitMaxRetries

func WithRateLimitMaxRetries(maxRetries int32) ConfigSetter

func WithRateLimitMaxWait

func WithRateLimitMaxWait(maxWait time.Duration) ConfigSetter

func WithRateLimitMinWait

func WithRateLimitMinWait(minWait time.Duration) ConfigSetter

func WithRequestTimeout

func WithRequestTimeout(requestTimeout time.Duration) ConfigSetter

func WithTestingDisableHttpsCheck

func WithTestingDisableHttpsCheck(httpsCheck bool) ConfigSetter

func WithUserAgentExtra

func WithUserAgentExtra(userAgent string) ConfigSetter

WithUserAgent sets the UserAgent in the Config.

func WithZWAAPIKeyID

func WithZWAAPIKeyID(keyID string) ConfigSetter

ConfigSetter type defines a function that modifies a Config struct. WithClientID sets the ClientID in the Config.

func WithZWAAPISecret

func WithZWAAPISecret(apiSecret string) ConfigSetter

WithClientSecret sets the ClientSecret in the Config.

func WithZWACloud

func WithZWACloud(cloud string) ConfigSetter

type Configuration

type Configuration struct {
	sync.Mutex
	Logger         logger.Logger
	HTTPClient     *http.Client
	BaseURL        *url.URL
	DefaultHeader  map[string]string `json:"defaultHeader,omitempty"`
	UserAgent      string            `json:"userAgent,omitempty"`
	Debug          bool              `json:"debug,omitempty"`
	UserAgentExtra string
	Context        context.Context
	ZWA            struct {
		Client struct {
			ZWAAPIKeyID  string     `yaml:"key_id" envconfig:"ZWA_API_KEY_ID"`
			ZWAAPISecret string     `yaml:"key_secret" envconfig:"ZWA_API_SECRET"`
			ZWACloud     string     `yaml:"cloud" envconfig:"ZWA_CLOUD"`
			AuthToken    *AuthToken `yaml:"authToken"`
			AccessToken  *AuthToken `yaml:"accessToken"`
			Proxy        struct {
				Port     int32  `yaml:"port" envconfig:"ZWA_CLIENT_PROXY_PORT"`
				Host     string `yaml:"host" envconfig:"ZWA_CLIENT_PROXY_HOST"`
				Username string `yaml:"username" envconfig:"ZWA_CLIENT_PROXY_USERNAME"`
				Password string `yaml:"password" envconfig:"ZWA_CLIENT_PROXY_PASSWORD"`
			} `yaml:"proxy"`
			RequestTimeout time.Duration `yaml:"requestTimeout" envconfig:"ZWA_CLIENT_REQUEST_TIMEOUT"`
			RateLimit      struct {
				MaxRetries   int32         `yaml:"maxRetries" envconfig:"ZWA_CLIENT_RATE_LIMIT_MAX_RETRIES"`
				RetryWaitMin time.Duration `yaml:"minWait" envconfig:"ZWA_CLIENT_RATE_LIMIT_MIN_WAIT"`
				RetryWaitMax time.Duration `yaml:"maxWait" envconfig:"ZZWA_CLIENT_RATE_LIMIT_MAX_WAIT"`
				BackoffConf  *BackoffConfig
			} `yaml:"rateLimit"`
		} `yaml:"client"`
		Testing struct {
			DisableHttpsCheck bool `yaml:"disableHttpsCheck" envconfig:"ZWA_TESTING_DISABLE_HTTPS_CHECK"`
		} `yaml:"testing"`
	} `yaml:"zwa"`
}

func NewConfiguration

func NewConfiguration(conf ...ConfigSetter) (*Configuration, error)

func (*Configuration) AddDefaultHeader

func (c *Configuration) AddDefaultHeader(key string, value string)

AddDefaultHeader adds a new HTTP header to the default header in the request

func (*Configuration) SetBackoffConfig

func (cfg *Configuration) SetBackoffConfig(backoffConf *BackoffConfig)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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