apiclient

package
v1.6.10 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2025 License: MIT Imports: 31 Imported by: 4

Documentation

Index

Constants

View Source
const (
	SubscriptionTypeEnterprise = "ENTERPRISE"
	SubscriptionTypeSecOps     = "SECOPS"
	SubscriptionTypeCommunity  = "COMMUNITY"
)
View Source
const TokenDBField = "apic_token"

Variables

View Source
var (
	InsecureSkipVerify = false
	Cert               *tls.Certificate
	CaCertPool         *x509.CertPool
)

Functions

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse verifies the API response and builds an appropriate Go error if necessary.

func InitLAPIClient added in v1.6.6

func InitLAPIClient(ctx context.Context, apiUrl string, papiUrl string, login string, password string, scenarios []string) error

Types

type APIKeyTransport

type APIKeyTransport struct {
	APIKey string
	// Transport is the underlying HTTP transport to use when making requests.
	// It will default to http.DefaultTransport if nil.
	Transport     http.RoundTripper
	URL           *url.URL
	VersionPrefix string
	UserAgent     string
}

func (*APIKeyTransport) Client

func (t *APIKeyTransport) Client() *http.Client

func (*APIKeyTransport) RoundTrip

func (t *APIKeyTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements the RoundTripper interface.

type AddOpts

type AddOpts struct {
}

type AlertsDeleteOpts

type AlertsDeleteOpts struct {
	ScopeEquals          string                  `url:"scope,omitempty"`
	ValueEquals          string                  `url:"value,omitempty"`
	ScenarioEquals       string                  `url:"scenario,omitempty"`
	IPEquals             string                  `url:"ip,omitempty"`
	RangeEquals          string                  `url:"range,omitempty"`
	Since                cstime.DurationWithDays `url:"since,omitempty"`
	Until                cstime.DurationWithDays `url:"until,omitempty"`
	OriginEquals         string                  `url:"origin,omitempty"`
	ActiveDecisionEquals *bool                   `url:"has_active_decision,omitempty"`
	SourceEquals         string                  `url:"alert_source,omitempty"`
	Contains             *bool                   `url:"contains,omitempty"`
	Limit                *int                    `url:"limit,omitempty"`
	ListOpts
}

type AlertsListOpts

type AlertsListOpts struct {
	ScopeEquals          string                  `url:"scope,omitempty"`
	ValueEquals          string                  `url:"value,omitempty"`
	ScenarioEquals       string                  `url:"scenario,omitempty"`
	IPEquals             string                  `url:"ip,omitempty"`
	RangeEquals          string                  `url:"range,omitempty"`
	OriginEquals         string                  `url:"origin,omitempty"`
	Since                cstime.DurationWithDays `url:"since,omitempty"`
	TypeEquals           string                  `url:"decision_type,omitempty"`
	Until                cstime.DurationWithDays `url:"until,omitempty"`
	IncludeSimulated     *bool                   `url:"simulated,omitempty"`
	ActiveDecisionEquals *bool                   `url:"has_active_decision,omitempty"`
	IncludeCAPI          *bool                   `url:"include_capi,omitempty"`
	Limit                *int                    `url:"limit,omitempty"`
	Contains             *bool                   `url:"contains,omitempty"`
	ListOpts
}

type AlertsService

type AlertsService service

func (*AlertsService) Add

func (*AlertsService) Delete

to demo query arguments

func (*AlertsService) DeleteOne added in v1.4.2

func (s *AlertsService) DeleteOne(ctx context.Context, alertID string) (*models.DeleteAlertsResponse, *Response, error)

func (*AlertsService) GetByID

func (s *AlertsService) GetByID(ctx context.Context, alertID int) (*models.Alert, *Response, error)

func (*AlertsService) List

to demo query arguments

type AllowlistGetOpts added in v1.6.6

type AllowlistGetOpts struct {
	WithContent bool `url:"with_content,omitempty"`
}

type AllowlistListOpts added in v1.6.6

type AllowlistListOpts struct {
	WithContent bool `url:"with_content,omitempty"`
}

type AllowlistsService added in v1.6.6

type AllowlistsService service

func (*AllowlistsService) CheckIfAllowlisted added in v1.6.6

func (s *AllowlistsService) CheckIfAllowlisted(ctx context.Context, value string) (bool, *Response, error)

func (*AllowlistsService) CheckIfAllowlistedBulk added in v1.6.9

func (s *AllowlistsService) CheckIfAllowlistedBulk(ctx context.Context, values []string) (*models.BulkCheckAllowlistResponse, *Response, error)

func (*AllowlistsService) CheckIfAllowlistedWithReason added in v1.6.6

func (s *AllowlistsService) CheckIfAllowlistedWithReason(ctx context.Context, value string) (*models.CheckAllowlistResponse, *Response, error)

func (*AllowlistsService) Get added in v1.6.6

func (*AllowlistsService) List added in v1.6.6

type ApiClient

type ApiClient struct {

	/*config stuff*/
	BaseURL   *url.URL
	PapiURL   *url.URL
	URLPrefix string
	UserAgent string
	/*exposed Services*/
	Decisions      *DecisionsService
	DecisionDelete *DecisionDeleteService
	Alerts         *AlertsService
	Allowlists     *AllowlistsService
	Auth           *AuthService
	Metrics        *MetricsService
	Signal         *SignalService
	HeartBeat      *HeartBeatService
	UsageMetrics   *UsageMetricsService
	// contains filtered or unexported fields
}

func GetLAPIClient added in v1.6.6

func GetLAPIClient() (*ApiClient, error)

func NewClient

func NewClient(config *Config) (*ApiClient, error)

func NewDefaultClient

func NewDefaultClient(url *url.URL, prefix string, userAgent string, client *http.Client) (*ApiClient, error)

func RegisterClient

func RegisterClient(ctx context.Context, config *Config, client *http.Client) (*ApiClient, error)

func (*ApiClient) Do

func (c *ApiClient) Do(ctx context.Context, req *http.Request, v any) (*Response, error)

func (*ApiClient) GetClient added in v1.5.0

func (c *ApiClient) GetClient() *http.Client

func (*ApiClient) GetSubscriptionType added in v1.6.9

func (c *ApiClient) GetSubscriptionType() string

func (*ApiClient) GetTokenRefreshChan added in v1.6.9

func (c *ApiClient) GetTokenRefreshChan() chan struct{}

func (*ApiClient) IsEnrolled added in v1.6.0

func (c *ApiClient) IsEnrolled() bool

func (*ApiClient) PrepareRequest added in v1.6.7

func (c *ApiClient) PrepareRequest(ctx context.Context, method, url string, body any) (*http.Request, error)

type AuthService

type AuthService service

func (*AuthService) AuthenticateWatcher

func (*AuthService) EnrollWatcher added in v1.1.0

func (s *AuthService) EnrollWatcher(ctx context.Context, enrollKey string, name string, tags []string, overwrite bool) (*Response, error)

func (*AuthService) RegisterWatcher

func (s *AuthService) RegisterWatcher(ctx context.Context, registration models.WatcherRegistrationRequest) (*Response, error)

func (*AuthService) UnregisterWatcher

func (s *AuthService) UnregisterWatcher(ctx context.Context) (*Response, error)

type Config

type Config struct {
	MachineID         string
	Password          strfmt.Password
	URL               *url.URL
	PapiURL           *url.URL
	VersionPrefix     string
	UserAgent         string
	RegistrationToken string
	UpdateScenario    func(context.Context) ([]string, error)
	TokenSave         func(context.Context, string, string) error
}

type DecisionDeleteService added in v1.5.0

type DecisionDeleteService service

func (*DecisionDeleteService) Add added in v1.5.0

func (d *DecisionDeleteService) Add(ctx context.Context, deletedDecisions *models.DecisionsDeleteRequest) (interface{}, *Response, error)

DecisionDeleteService purposely reuses AddSignalsRequestItemDecisions model

type DecisionsDeleteOpts

type DecisionsDeleteOpts struct {
	ScopeEquals  string `url:"scope,omitempty"`
	ValueEquals  string `url:"value,omitempty"`
	TypeEquals   string `url:"type,omitempty"`
	IPEquals     string `url:"ip,omitempty"`
	RangeEquals  string `url:"range,omitempty"`
	Contains     *bool  `url:"contains,omitempty"`
	OriginEquals string `url:"origin,omitempty"`
	//
	ScenarioEquals string `url:"scenario,omitempty"`
	ListOpts
}

type DecisionsListOpts

type DecisionsListOpts struct {
	ScopeEquals string `url:"scope,omitempty"`
	ValueEquals string `url:"value,omitempty"`
	TypeEquals  string `url:"type,omitempty"`
	IPEquals    string `url:"ip,omitempty"`
	RangeEquals string `url:"range,omitempty"`
	Contains    *bool  `url:"contains,omitempty"`
	ListOpts
}

type DecisionsService

type DecisionsService service

func (*DecisionsService) Delete

func (*DecisionsService) DeleteOne

func (s *DecisionsService) DeleteOne(ctx context.Context, decisionID string) (*models.DeleteDecisionResponse, *Response, error)

func (*DecisionsService) FetchV2Decisions added in v1.5.0

func (s *DecisionsService) FetchV2Decisions(ctx context.Context, url string) (*models.DecisionsStreamResponse, *Response, error)

func (*DecisionsService) FetchV3Decisions added in v1.5.0

func (s *DecisionsService) FetchV3Decisions(ctx context.Context, url string) (*models.DecisionsStreamResponse, *Response, error)

func (*DecisionsService) GetDecisionsFromBlocklist added in v1.5.0

func (s *DecisionsService) GetDecisionsFromBlocklist(ctx context.Context, blocklist *modelscapi.BlocklistLink, lastPullTimestamp string) ([]*models.Decision, bool, error)

func (*DecisionsService) GetDecisionsFromGroups added in v1.5.0

func (s *DecisionsService) GetDecisionsFromGroups(decisionsGroups []*modelscapi.GetDecisionsStreamResponseNewItem) []*models.Decision

func (*DecisionsService) GetStream

func (*DecisionsService) GetStreamV3 added in v1.5.0

func (*DecisionsService) List

to demo query arguments

func (*DecisionsService) StopStream

func (s *DecisionsService) StopStream(ctx context.Context) (*Response, error)

type DecisionsStreamOpts added in v1.3.3

type DecisionsStreamOpts struct {
	Startup                bool   `url:"startup,omitempty"`
	CommunityPull          bool   `url:"community_pull"`
	AdditionalPull         bool   `url:"additional_pull"`
	Scopes                 string `url:"scopes,omitempty"`
	ScenariosContaining    string `url:"scenarios_containing,omitempty"`
	ScenariosNotContaining string `url:"scenarios_not_containing,omitempty"`
	Origins                string `url:"origins,omitempty"`
}

type DeleteOpts

type DeleteOpts struct {
}

type ErrorResponse

type ErrorResponse struct {
	models.ErrorResponse
}

func (*ErrorResponse) Error

func (e *ErrorResponse) Error() string

type HeartBeatService added in v1.4.0

type HeartBeatService service

func (*HeartBeatService) Ping added in v1.4.0

func (h *HeartBeatService) Ping(ctx context.Context) (bool, *Response, error)

func (*HeartBeatService) StartHeartBeat added in v1.4.0

func (h *HeartBeatService) StartHeartBeat(ctx context.Context, t *tomb.Tomb)

type JWTTransport

type JWTTransport struct {
	MachineID     *string
	Password      *strfmt.Password
	Token         string
	Expiration    time.Time
	Scenarios     []string
	URL           *url.URL
	VersionPrefix string
	UserAgent     string
	RetryConfig   *RetryConfig
	// Transport is the underlying HTTP transport to use when making requests.
	// It will default to http.DefaultTransport if nil.
	Transport        http.RoundTripper
	UpdateScenario   func(context.Context) ([]string, error)
	TokenRefreshChan chan struct{} // will write to this channel when the token is refreshed

	TokenSave TokenSave
	// contains filtered or unexported fields
}

func (*JWTTransport) Client

func (t *JWTTransport) Client() *http.Client

func (*JWTTransport) ResetToken added in v1.5.0

func (t *JWTTransport) ResetToken()

func (*JWTTransport) RoundTrip

func (t *JWTTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements the RoundTripper interface.

type ListOpts

type ListOpts struct {
}

type MetricsService

type MetricsService service

func (*MetricsService) Add

func (s *MetricsService) Add(ctx context.Context, metrics *models.Metrics) (interface{}, *Response, error)

type Response

type Response struct {
	Response *http.Response
}

type RetryConfig added in v1.6.2

type RetryConfig struct {
	StatusCodeConfig map[int]StatusCodeConfig
}

func NewRetryConfig added in v1.6.2

func NewRetryConfig(options ...RetryConfigOption) *RetryConfig

type RetryConfigOption added in v1.6.2

type RetryConfigOption func(*RetryConfig)

func WithStatusCodeConfig added in v1.6.2

func WithStatusCodeConfig(statusCode int, maxAttempts int, backOff bool, invalidateToken bool) RetryConfigOption

type SignalService

type SignalService service

func (*SignalService) Add

func (s *SignalService) Add(ctx context.Context, signals *models.AddSignalsRequest) (interface{}, *Response, error)

type StatusCodeConfig added in v1.6.2

type StatusCodeConfig struct {
	MaxAttempts     int
	Backoff         bool
	InvalidateToken bool
}

type TokenSave added in v1.6.9

type TokenSave func(ctx context.Context, tokenKey string, token string) error

type UsageMetricsService added in v1.6.3

type UsageMetricsService service

func (*UsageMetricsService) Add added in v1.6.3

func (s *UsageMetricsService) Add(ctx context.Context, metrics *models.AllMetrics) (interface{}, *Response, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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