zscaler

package
v3.0.7 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
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"
)
View Source
const (
	MaxNumOfRetries     = 100
	RetryWaitMaxSeconds = 20
	RetryWaitMinSeconds = 5
)
View Source
const (
	ASCSortOrder          SortOrder = "ASC"
	DESCSortOrder                   = "DESC"
	IDSortField           SortField = "id"
	NameSortField                   = "name"
	CreationTimeSortField           = "creationTime"
	ModifiedTimeSortField           = "modifiedTime"
)

Variables

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

Functions

func GetAPIBaseURL

func GetAPIBaseURL(cloud string) string

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

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

Authenticate performs OAuth2 authentication and retrieves an AuthToken.

type Client

type Client struct {
	sync.Mutex
	// contains filtered or unexported fields
}

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) Create

func (c *Client) Create(ctx context.Context, endpoint string, o interface{}) (interface{}, error)

Create sends a POST request to create an object.

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 (c *Client) CreateWithSlicePayload(ctx context.Context, endpoint string, slice interface{}) ([]byte, error)

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, endpoint string) error

Delete sends a DELETE request to the specified endpoint.

func (*Client) ExecuteRequest

func (c *Client) ExecuteRequest(ctx context.Context, method, endpoint string, body io.Reader, urlParams url.Values, contentType string) ([]byte, *http.Response, *http.Request, error)

func (*Client) GetCustomerID

func (c *Client) GetCustomerID() string

func (*Client) GetFullPath

func (client *Client) GetFullPath(endpoint string) (string, error)

func (*Client) GetLogger

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

func (*Client) GetSandboxToken

func (c *Client) GetSandboxToken() string

GetSandboxToken retrieves the sandbox token from the configuration or environment.

func (*Client) GetSandboxURL

func (c *Client) GetSandboxURL() string

GetSandboxURL retrieves the sandbox URL for the ZIA service.

func (*Client) NewRequestDo

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

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.

func (*Client) Read

func (c *Client) Read(ctx context.Context, endpoint string, o interface{}) error

Read ...

func (*Client) Update

func (c *Client) Update(ctx context.Context, endpoint string, o interface{}) (interface{}, error)

Update sends an update (PATCH request) with the given object.

func (*Client) UpdateWithPut

func (c *Client) UpdateWithPut(ctx context.Context, endpoint string, o interface{}) (interface{}, error)

UpdateWithPut sends an update (PUT request) with the given object.

func (*Client) UpdateWithSlicePayload

func (c *Client) UpdateWithSlicePayload(ctx context.Context, endpoint string, slice interface{}) ([]byte, 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 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 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 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
	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"`
			}
			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"`
			}
			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"`
			}
		}
		Testing struct {
			DisableHttpsCheck bool `yaml:"disableHttpsCheck" envconfig:"ZSCALER_TESTING_DISABLE_HTTPS_CHECK"`
		}
	}
	PrivateKeySigner jose.Signer
	CacheManager     cache.Cache
}

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.

type ErrorResponse

type ErrorResponse struct {
	Response *http.Response
	Err      error
	Message  string
}

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

func (ErrorResponse) IsObjectNotFound

func (r ErrorResponse) IsObjectNotFound() bool

IsObjectNotFound returns true on missing object error (404).

type Service

type Service struct {
	Client *Client // use the common Zscaler OneAPI Client here

	// 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) *Service

NewService is a generic function to instantiate a Service with the Zscaler OneAPI Client

func (*Service) MicroTenantID

func (service *Service) MicroTenantID() *string

func (*Service) WithMicroTenant

func (service *Service) WithMicroTenant(microTenantID string) *Service

func (*Service) WithSort

func (service *Service) WithSort(sortBy SortField, sortOrder SortOrder) *Service

type SortField

type SortField string

type SortOrder

type SortOrder string

type UserAgent

type UserAgent struct {
	// contains filtered or unexported fields
}

func NewUserAgent

func NewUserAgent(config *Configuration) UserAgent

func (UserAgent) String

func (ua UserAgent) String() string

Directories

Path Synopsis
zcc
zdx
zia
zpa

Jump to

Keyboard shortcuts

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