zpa

package
v3.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2025 License: MIT Imports: 30 Imported by: 2

Documentation

Index

Constants

View Source
const (
	ZPA_SCIM_TOKEN = "ZPA_SCIM_TOKEN"
	ZPA_IDP_ID     = "ZPA_IDP_ID"
	ZPA_SCIM_CLOUD = "ZPA_SCIM_CLOUD"
)
View Source
const (
	MaxNumOfRetries     = 100
	RetryWaitMaxSeconds = 20
	RetryWaitMinSeconds = 5
)
View Source
const (
	VERSION           = "3.0.0"
	ZPA_CLIENT_ID     = "ZPA_CLIENT_ID"
	ZPA_CLIENT_SECRET = "ZPA_CLIENT_SECRET"
	ZPA_CUSTOMER_ID   = "ZPA_CUSTOMER_ID"
	ZPA_CLOUD         = "ZPA_CLOUD"
)

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 AuthToken

type AuthToken struct {
	TokenType    string `json:"token_type"`
	AccessToken  string `json:"access_token"`
	ExpiresIn    int    `json:"-"` // Skip direct JSON unmarshaling
	Expiry       time.Time
	RawExpiresIn string `json:"expires_in"`
}

func Authenticate

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

func (*AuthToken) UnmarshalJSON

func (t *AuthToken) UnmarshalJSON(data []byte) error

UnmarshalJSON ensures proper unmarshaling of the AuthToken struct.

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
	// contains filtered or unexported fields
}

func NewClient

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

func (*Client) GetLogger

func (client *Client) GetLogger() logger.Logger

func (*Client) NewRequestDo

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

type ConfigSetter

type ConfigSetter func(*Configuration)

func WithCache

func WithCache(cache bool) ConfigSetter

func WithCacheManager

func WithCacheManager(cacheManager cache.Cache) ConfigSetter

func WithCacheMaxSizeMB

func WithCacheMaxSizeMB(size int64) ConfigSetter

func WithCacheTti

func WithCacheTti(i time.Duration) ConfigSetter

func WithCacheTtl

func WithCacheTtl(i time.Duration) ConfigSetter

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 WithZPAClientID

func WithZPAClientID(clientID string) ConfigSetter

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

func WithZPAClientSecret

func WithZPAClientSecret(clientSecret string) ConfigSetter

WithClientSecret sets the ClientSecret in the Config.

func WithZPACloud

func WithZPACloud(cloud string) ConfigSetter

func WithZPACustomerID

func WithZPACustomerID(customerID string) ConfigSetter

func WithZPAMicrotenantID

func WithZPAMicrotenantID(microtenantID 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
	ZPA            struct {
		Client struct {
			ZPAClientID      string     `yaml:"clientId" envconfig:"ZPA_CLIENT_ID"`
			ZPAClientSecret  string     `yaml:"clientSecret" envconfig:"ZPA_CLIENT_SECRET"`
			ZPACustomerID    string     `yaml:"customerId" envconfig:"ZPA_CUSTOMER_ID"`
			ZPACloud         string     `yaml:"cloud" envconfig:"ZPA_CLOUD"`
			ZPAMicrotenantID string     `yaml:"microtenantId" envconfig:"ZPA_MICROTENANT_ID"`
			AuthToken        *AuthToken `yaml:"authToken"`
			AccessToken      *AuthToken `yaml:"accessToken"`
			Cache            struct {
				Enabled               bool          `yaml:"enabled" envconfig:"ZPA_CLIENT_CACHE_ENABLED"`
				DefaultTtl            time.Duration `yaml:"defaultTtl" envconfig:"ZPA_CLIENT_CACHE_DEFAULT_TTL"`
				DefaultTti            time.Duration `yaml:"defaultTti" envconfig:"ZPA_CLIENT_CACHE_DEFAULT_TTI"`
				DefaultCacheMaxSizeMB int64         `yaml:"defaultTti" envconfig:"ZPA_CLIENT_CACHE_DEFAULT_SIZE"`
			} `yaml:"cache"`
			Proxy struct {
				Port     int32  `yaml:"port" envconfig:"ZPA_CLIENT_PROXY_PORT"`
				Host     string `yaml:"host" envconfig:"ZPA_CLIENT_PROXY_HOST"`
				Username string `yaml:"username" envconfig:"ZPA_CLIENT_PROXY_USERNAME"`
				Password string `yaml:"password" envconfig:"ZPA_CLIENT_PROXY_PASSWORD"`
			} `yaml:"proxy"`
			RequestTimeout time.Duration `yaml:"requestTimeout" envconfig:"ZPA_CLIENT_REQUEST_TIMEOUT"`
			RateLimit      struct {
				MaxRetries   int32         `yaml:"maxRetries" envconfig:"ZPA_CLIENT_RATE_LIMIT_MAX_RETRIES"`
				RetryWaitMin time.Duration `yaml:"minWait" envconfig:"ZPA_CLIENT_RATE_LIMIT_MIN_WAIT"`
				RetryWaitMax time.Duration `yaml:"maxWait" envconfig:"ZPA_CLIENT_RATE_LIMIT_MAX_WAIT"`
			} `yaml:"rateLimit"`
		} `yaml:"client"`
		Testing struct {
			DisableHttpsCheck bool `yaml:"disableHttpsCheck" envconfig:"ZPA_TESTING_DISABLE_HTTPS_CHECK"`
		} `yaml:"testing"`
	} `yaml:"zpa"`
	CacheManager cache.Cache
}

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

type ScimClient

type ScimClient struct {
	ScimConfig *ScimConfig
}

func NewScimConfig

func NewScimConfig(setters ...ScimConfigSetter) (*ScimClient, error)

NewScimConfig initializes a configuration specifically for SCIM-based API endpoints

func (*ScimClient) DoRequest

func (c *ScimClient) DoRequest(ctx context.Context, method, endpoint string, payload interface{}, target interface{}) (*http.Response, error)

DoRequest performs an HTTP request specifically for SCIM endpoints with enhanced logging

type ScimConfig

type ScimConfig struct {
	BaseURL *url.URL

	AuthToken string
	IDPId     string
	Logger    logger.Logger

	BackoffConf *BackoffConfig
	UserAgent   string
	// contains filtered or unexported fields
}

type ScimConfigSetter

type ScimConfigSetter func(*ScimConfig)

func WithIDPId

func WithIDPId(idpId string) ScimConfigSetter

WithIDPId sets the IDP ID in the configuration.

func WithScimCloud

func WithScimCloud(baseURL string) ScimConfigSetter

WithScimBaseURL sets the SCIM BaseURL in the configuration.

func WithScimRateLimiter

func WithScimRateLimiter(rateLimiter *rl.RateLimiter) ScimConfigSetter

WithScimRateLimiter sets the rate limiter in the configuration.

func WithScimTimeout

func WithScimTimeout(timeout time.Duration) ScimConfigSetter

WithScimTimeout sets the HTTP client timeout in the configuration.

func WithScimToken

func WithScimToken(scimToken string) ScimConfigSetter

WithScimToken sets the SCIM token in the configuration.

func WithScimUserAgent

func WithScimUserAgent(userAgent string) ScimConfigSetter

WithScimUserAgent sets the User-Agent in the configuration.

Jump to

Keyboard shortcuts

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