Documentation ¶
Index ¶
- Constants
- Variables
- func GetAPIBaseURL(cloud string) string
- type AuthToken
- type Client
- func (c *Client) BulkDelete(ctx context.Context, endpoint string, payload interface{}) (*http.Response, error)
- func (c *Client) Create(ctx context.Context, endpoint string, o interface{}) (interface{}, error)
- func (c *Client) CreateWithRawPayload(ctx context.Context, endpoint string, payload string) ([]byte, error)
- func (c *Client) CreateWithSlicePayload(ctx context.Context, endpoint string, slice interface{}) ([]byte, error)
- func (c *Client) Delete(ctx context.Context, endpoint string) error
- func (c *Client) ExecuteRequest(ctx context.Context, method, endpoint string, body io.Reader, ...) ([]byte, *http.Response, *http.Request, error)
- func (c *Client) GetCustomerID() string
- func (client *Client) GetLogger() logger.Logger
- func (c *Client) GetSandboxToken() string
- func (c *Client) GetSandboxURL() string
- func (client *Client) NewRequestDo(ctx context.Context, method, endpoint string, options, body, v interface{}) (*http.Response, error)
- func (client *Client) NewZccRequestDo(ctx context.Context, method, endpoint string, options, body, v interface{}) (*http.Response, error)
- func (c *Client) Read(ctx context.Context, endpoint string, o interface{}) error
- func (c *Client) Update(ctx context.Context, endpoint string, o interface{}) (interface{}, error)
- func (c *Client) UpdateWithPut(ctx context.Context, endpoint string, o interface{}) (interface{}, error)
- func (c *Client) UpdateWithSlicePayload(ctx context.Context, endpoint string, slice interface{}) ([]byte, error)
- type ConfigSetter
- func WithCache(cache bool) ConfigSetter
- func WithCacheManager(cacheManager cache.Cache) ConfigSetter
- func WithCacheMaxSizeMB(size int64) ConfigSetter
- func WithCacheTti(i time.Duration) ConfigSetter
- func WithCacheTtl(i time.Duration) ConfigSetter
- func WithClientID(clientID string) ConfigSetter
- func WithClientSecret(clientSecret string) ConfigSetter
- func WithDebug(debug bool) ConfigSetter
- func WithHttpClientPtr(httpClient *http.Client) ConfigSetter
- func WithLegacyClient(useLegacyClient bool) ConfigSetter
- func WithPrivateKey(privateKey string) ConfigSetter
- func WithPrivateKeySigner(signer jose.Signer) ConfigSetter
- func WithProxyHost(host string) ConfigSetter
- func WithProxyPassword(pass string) ConfigSetter
- func WithProxyPort(i int32) ConfigSetter
- func WithProxyUsername(username string) ConfigSetter
- func WithRateLimitMaxRetries(maxRetries int32) ConfigSetter
- func WithRateLimitMaxWait(maxWait time.Duration) ConfigSetter
- func WithRateLimitMinWait(minWait time.Duration) ConfigSetter
- func WithRequestTimeout(requestTimeout time.Duration) ConfigSetter
- func WithSandboxCloud(sandboxCloud string) ConfigSetter
- func WithSandboxToken(token string) ConfigSetter
- func WithTestingDisableHttpsCheck(httpsCheck bool) ConfigSetter
- func WithUserAgentExtra(userAgent string) ConfigSetter
- func WithVanityDomain(domain string) ConfigSetter
- func WithZPACustomerID(customerID string) ConfigSetter
- func WithZPAMicrotenantID(microtenantID string) ConfigSetter
- func WithZccLegacyClient(zccClient *zcc.Client) ConfigSetter
- func WithZiaLegacyClient(ziaClient *zia.Client) ConfigSetter
- func WithZpaLegacyClient(zpaClient *zpa.Client) ConfigSetter
- func WithZscalerCloud(cloud string) ConfigSetter
- type Configuration
- type LegacyClient
- type Service
- type SortField
- type SortOrder
- type UserAgent
Constants ¶
const ( VERSION = "3.0.0" ZSCALER_CLIENT_ID = "ZSCALER_CLIENT_ID" ZSCALER_CLIENT_SECRET = "ZSCALER_CLIENT_SECRET" ZSCALER_VANITY_DOMAIN = "ZSCALER_VANITY_DOMAIN" ZSCALER_PRIVATE_KEY = "ZSCALER_PRIVATE_KEY" ZSCALER_CLOUD = "ZSCALER_CLOUD" )
const ( MaxNumOfRetries = 100 RetryWaitMaxSeconds = 20 RetryWaitMinSeconds = 5 )
const ( ASCSortOrder SortOrder = "ASC" DESCSortOrder = "DESC" IDSortField SortField = "id" NameSortField = "name" CreationTimeSortField = "creationTime" ModifiedTimeSortField = "modifiedTime" )
Variables ¶
var (
// ContextAccessToken takes a string OAuth2 access token as authentication for the request.
ContextAccessToken = contextKey("access_token")
)
Functions ¶
func GetAPIBaseURL ¶
GetAPIBaseURL gets the appropriate base url based on the cloud and sandbox mode.
Types ¶
type AuthToken ¶
type AuthToken struct { TokenType string `json:"token_type"` AccessToken string `json:"access_token"` ExpiresIn int `json:"expires_in"` Expiry time.Time }
AuthToken represents the OAuth2 authentication token and its expiration time.
func Authenticate ¶
Authenticate performs OAuth2 authentication and retrieves an AuthToken.
type Client ¶
Client defines the ZIA client structure.
func (*Client) BulkDelete ¶
func (c *Client) BulkDelete(ctx context.Context, endpoint string, payload interface{}) (*http.Response, error)
BulkDelete sends a POST request for bulk deletion.
func (*Client) CreateWithRawPayload ¶
func (c *Client) CreateWithRawPayload(ctx context.Context, endpoint string, payload string) ([]byte, error)
CreateWithRawPayload sends an HTTP POST request with a raw string payload.
func (*Client) CreateWithSlicePayload ¶
func (*Client) ExecuteRequest ¶
func (*Client) GetCustomerID ¶
func (*Client) GetSandboxToken ¶
GetSandboxToken retrieves the sandbox token from the configuration or environment.
func (*Client) GetSandboxURL ¶
GetSandboxURL retrieves the sandbox URL for the ZIA service.
func (*Client) NewRequestDo ¶
func (*Client) NewZccRequestDo ¶
func (client *Client) NewZccRequestDo(ctx context.Context, method, endpoint string, options, body, v interface{}) (*http.Response, error)
NewRequestDo for ZCC with OAuth2 authentication and centralized request handling. This function is consistent with the ZPA request handler.
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 WithClientID ¶
func WithClientID(clientID string) ConfigSetter
ConfigSetter type defines a function that modifies a Config struct. WithClientID sets the ClientID in the Config.
func WithClientSecret ¶
func WithClientSecret(clientSecret string) ConfigSetter
WithClientSecret sets the ClientSecret in the Config.
func WithDebug ¶
func WithDebug(debug bool) ConfigSetter
func WithHttpClientPtr ¶
func WithHttpClientPtr(httpClient *http.Client) ConfigSetter
WithHttpClient sets the HttpClient in the Config.
func WithLegacyClient ¶ added in v3.0.8
func WithLegacyClient(useLegacyClient bool) ConfigSetter
func WithPrivateKey ¶
func WithPrivateKey(privateKey string) ConfigSetter
WithPrivateKey sets private key, privateKey can be the raw key value or a path to the pem file.
func WithPrivateKeySigner ¶
func WithPrivateKeySigner(signer jose.Signer) ConfigSetter
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 WithSandboxCloud ¶
func WithSandboxCloud(sandboxCloud string) ConfigSetter
func WithSandboxToken ¶
func WithSandboxToken(token string) ConfigSetter
WithSandboxToken is a ConfigSetter that sets the Sandbox token for the Zscaler Client.
func WithTestingDisableHttpsCheck ¶
func WithTestingDisableHttpsCheck(httpsCheck bool) ConfigSetter
func WithUserAgentExtra ¶
func WithUserAgentExtra(userAgent string) ConfigSetter
WithUserAgent sets the UserAgent in the Config.
func WithVanityDomain ¶
func WithVanityDomain(domain string) ConfigSetter
WithOauth2ProviderUrl sets the Oauth2ProviderUrl in the Config.
func WithZPACustomerID ¶
func WithZPACustomerID(customerID string) ConfigSetter
func WithZPAMicrotenantID ¶
func WithZPAMicrotenantID(microtenantID string) ConfigSetter
func WithZccLegacyClient ¶ added in v3.0.8
func WithZccLegacyClient(zccClient *zcc.Client) ConfigSetter
func WithZiaLegacyClient ¶ added in v3.0.8
func WithZiaLegacyClient(ziaClient *zia.Client) ConfigSetter
func WithZpaLegacyClient ¶ added in v3.0.8
func WithZpaLegacyClient(zpaClient *zpa.Client) ConfigSetter
func WithZscalerCloud ¶
func WithZscalerCloud(cloud string) ConfigSetter
type Configuration ¶
type Configuration struct { Logger logger.Logger HTTPClient *http.Client ZPAHTTPClient *http.Client ZIAHTTPClient *http.Client ZCCHTTPClient *http.Client DefaultHeader map[string]string `json:"defaultHeader,omitempty"` UserAgent string `json:"userAgent,omitempty"` Debug bool `json:"debug,omitempty"` UserAgentExtra string Context context.Context Zscaler struct { Client struct { ClientID string `yaml:"clientId" envconfig:"ZSCALER_CLIENT_ID"` ClientSecret string `yaml:"clientSecret" envconfig:"ZSCALER_CLIENT_SECRET"` VanityDomain string `yaml:"vanityDomain" envconfig:"ZSCALER_VANITY_DOMAIN"` Cloud string `yaml:"cloud" envconfig:"ZSCALER_CLOUD"` CustomerID string `yaml:"customerId" envconfig:"ZPA_CUSTOMER_ID"` MicrotenantID string `yaml:"microtenantId" envconfig:"ZPA_MICROTENANT_ID"` PrivateKey []byte `yaml:"privateKey" envconfig:"ZSCALER_PRIVATE_KEY"` AuthToken *AuthToken `yaml:"authToken"` AccessToken *AuthToken `yaml:"accessToken"` SandboxToken string `yaml:"sandboxToken" envconfig:"ZSCALER_SANDBOX_TOKEN"` SandboxCloud string `yaml:"sandboxCloud" envconfig:"ZSCALER_SANDBOX_CLOUD"` Cache struct { Enabled bool `yaml:"enabled" envconfig:"ZSCALER_CLIENT_CACHE_ENABLED"` DefaultTtl time.Duration `yaml:"defaultTtl" envconfig:"ZSCALER_CLIENT_CACHE_DEFAULT_TTL"` DefaultTti time.Duration `yaml:"defaultTti" envconfig:"ZSCALER_CLIENT_CACHE_DEFAULT_TTI"` DefaultCacheMaxSizeMB int64 `yaml:"defaultTti" envconfig:"ZSCALER_CLIENT_CACHE_DEFAULT_SIZE"` } `yaml:"cache"` Proxy struct { Port int32 `yaml:"port" envconfig:"ZSCALER_CLIENT_PROXY_PORT"` Host string `yaml:"host" envconfig:"ZSCALER_CLIENT_PROXY_HOST"` Username string `yaml:"username" envconfig:"ZSCALER_CLIENT_PROXY_USERNAME"` Password string `yaml:"password" envconfig:"ZSCALER_CLIENT_PROXY_PASSWORD"` } `yaml:"proxy"` RequestTimeout time.Duration `yaml:"requestTimeout" envconfig:"ZSCALER_CLIENT_REQUEST_TIMEOUT"` RateLimit struct { MaxRetries int32 `yaml:"maxRetries" envconfig:"ZSCALER_CLIENT_RATE_LIMIT_MAX_RETRIES"` RetryWaitMin time.Duration `yaml:"minWait" envconfig:"ZSCALER_CLIENT_RATE_LIMIT_MIN_WAIT"` RetryWaitMax time.Duration `yaml:"maxWait" envconfig:"ZSCALER_CLIENT_RATE_LIMIT_MAX_WAIT"` } `yaml:"rateLimit"` } `yaml:"client"` Testing struct { DisableHttpsCheck bool `yaml:"disableHttpsCheck" envconfig:"ZSCALER_TESTING_DISABLE_HTTPS_CHECK"` } `yaml:"testing"` } `yaml:"zscaler"` PrivateKeySigner jose.Signer CacheManager cache.Cache UseLegacyClient bool `yaml:"useLegacyClient" envconfig:"ZSCALER_USE_LEGACY_CLIENT"` LegacyClient *LegacyClient }
Configuration struct holds the config for ZIA, ZPA, and common fields like HTTPClient and AuthToken.
func NewConfiguration ¶
func NewConfiguration(conf ...ConfigSetter) (*Configuration, error)
NewConfiguration is the main configuration function, implementing the ConfigSetter pattern.
func (*Configuration) AddDefaultHeader ¶ added in v3.0.9
func (c *Configuration) AddDefaultHeader(key string, value string)
AddDefaultHeader adds a new HTTP header to the default header in the request
type LegacyClient ¶ added in v3.0.8
Legacy struct holds and instance of each legacy API client to support backwards compatibility
type Service ¶
type Service struct { Client *Client // use the common Zscaler OneAPI Client here LegacyClient *LegacyClient // for some resources SortOrder SortOrder SortBy SortField // contains filtered or unexported fields }
Service defines the structure that contains the common client
func NewOneAPIClient ¶
func NewOneAPIClient(config *Configuration) (*Service, error)
NewOneAPIClient creates a new client using OAuth2 authentication for any service.
func NewService ¶
func NewService(client *Client, legacyClient *LegacyClient) *Service
NewService is a generic function to instantiate a Service with the Zscaler OneAPI Client
func (*Service) MicroTenantID ¶
func (*Service) WithMicroTenant ¶
type UserAgent ¶
type UserAgent struct {
// contains filtered or unexported fields
}
func NewUserAgent ¶
func NewUserAgent(config *Configuration) UserAgent