zpa

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: 30 Imported by: 0

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 added in v3.0.11

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

func (*AuthToken) UnmarshalJSON added in v3.0.11

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 added in v3.0.11

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 added in v3.0.11

type ConfigSetter func(*Configuration)

func WithCache added in v3.0.11

func WithCache(cache bool) ConfigSetter

func WithCacheManager added in v3.0.11

func WithCacheManager(cacheManager cache.Cache) ConfigSetter

func WithCacheMaxSizeMB added in v3.0.11

func WithCacheMaxSizeMB(size int64) ConfigSetter

func WithCacheTti added in v3.0.11

func WithCacheTti(i time.Duration) ConfigSetter

func WithCacheTtl added in v3.0.11

func WithCacheTtl(i time.Duration) ConfigSetter

func WithDebug added in v3.0.11

func WithDebug(debug bool) ConfigSetter

func WithHttpClientPtr added in v3.0.11

func WithHttpClientPtr(httpClient *http.Client) ConfigSetter

WithHttpClient sets the HttpClient in the Config.

func WithProxyHost added in v3.0.11

func WithProxyHost(host string) ConfigSetter

func WithProxyPassword added in v3.0.11

func WithProxyPassword(pass string) ConfigSetter

func WithProxyPort added in v3.0.11

func WithProxyPort(i int32) ConfigSetter

func WithProxyUsername added in v3.0.11

func WithProxyUsername(username string) ConfigSetter

func WithRateLimitMaxRetries added in v3.0.11

func WithRateLimitMaxRetries(maxRetries int32) ConfigSetter

func WithRateLimitMaxWait added in v3.0.11

func WithRateLimitMaxWait(maxWait time.Duration) ConfigSetter

func WithRateLimitMinWait added in v3.0.11

func WithRateLimitMinWait(minWait time.Duration) ConfigSetter

func WithRequestTimeout added in v3.0.11

func WithRequestTimeout(requestTimeout time.Duration) ConfigSetter

func WithTestingDisableHttpsCheck added in v3.0.11

func WithTestingDisableHttpsCheck(httpsCheck bool) ConfigSetter

func WithUserAgentExtra added in v3.0.11

func WithUserAgentExtra(userAgent string) ConfigSetter

WithUserAgent sets the UserAgent in the Config.

func WithZPAClientID added in v3.0.11

func WithZPAClientID(clientID string) ConfigSetter

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

func WithZPAClientSecret added in v3.0.11

func WithZPAClientSecret(clientSecret string) ConfigSetter

WithClientSecret sets the ClientSecret in the Config.

func WithZPACloud added in v3.0.11

func WithZPACloud(cloud string) ConfigSetter

func WithZPACustomerID added in v3.0.11

func WithZPACustomerID(customerID string) ConfigSetter

func WithZPAMicrotenantID added in v3.0.11

func WithZPAMicrotenantID(microtenantID string) ConfigSetter

type Configuration added in v3.0.11

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 added in v3.0.11

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

func (*Configuration) AddDefaultHeader added in v3.0.11

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

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

type ScimClient added in v3.0.12

type ScimClient struct {
	ScimConfig *ScimConfig
}

func NewScimConfig added in v3.0.12

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

NewScimConfig initializes a configuration specifically for SCIM-based API endpoints

func (*ScimClient) DoRequest added in v3.0.12

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 added in v3.0.12

type ScimConfig struct {
	BaseURL *url.URL

	AuthToken string
	IDPId     string
	Logger    logger.Logger

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

type ScimConfigSetter added in v3.0.12

type ScimConfigSetter func(*ScimConfig)

func WithIDPId added in v3.0.12

func WithIDPId(idpId string) ScimConfigSetter

WithIDPId sets the IDP ID in the configuration.

func WithScimCloud added in v3.0.12

func WithScimCloud(baseURL string) ScimConfigSetter

WithScimBaseURL sets the SCIM BaseURL in the configuration.

func WithScimRateLimiter added in v3.0.12

func WithScimRateLimiter(rateLimiter *rl.RateLimiter) ScimConfigSetter

WithScimRateLimiter sets the rate limiter in the configuration.

func WithScimTimeout added in v3.0.12

func WithScimTimeout(timeout time.Duration) ScimConfigSetter

WithScimTimeout sets the HTTP client timeout in the configuration.

func WithScimToken added in v3.0.12

func WithScimToken(scimToken string) ScimConfigSetter

WithScimToken sets the SCIM token in the configuration.

func WithScimUserAgent added in v3.0.12

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