Documentation
¶
Index ¶
- Variables
- type Client
- func (c *Client) AwaitAllocationRequestCreate(ctx context.Context, requestId int64, pollTime time.Duration) error
- func (c *Client) CancelSandboxAllocationRequest(ctx context.Context, allocationRequestId int64) error
- func (c *Client) CleanupSandboxPool(ctx context.Context, poolId int64, force bool) error
- func (c *Client) CreateSandboxAllocationUnitAwait(ctx context.Context, poolId int64, pollTime time.Duration) (*SandboxAllocationUnit, error)
- func (c *Client) CreateSandboxAllocationUnits(ctx context.Context, poolId, count int64) ([]SandboxAllocationUnit, error)
- func (c *Client) CreateSandboxCleanupRequest(ctx context.Context, unitId int64) error
- func (c *Client) CreateSandboxCleanupRequestAwait(ctx context.Context, unitId int64, pollTime time.Duration) error
- func (c *Client) CreateSandboxDefinition(ctx context.Context, url, rev string) (*SandboxDefinition, error)
- func (c *Client) CreateSandboxPool(ctx context.Context, definitionId, maxSize int64) (*SandboxPool, error)
- func (c *Client) CreateTrainingDefinition(ctx context.Context, content string) (*TrainingDefinition, error)
- func (c *Client) CreateTrainingDefinitionAdaptive(ctx context.Context, content string) (*TrainingDefinitionAdaptive, error)
- func (c *Client) DeleteSandboxDefinition(ctx context.Context, definitionID int64) error
- func (c *Client) DeleteSandboxPool(ctx context.Context, poolId int64) error
- func (c *Client) DeleteTrainingDefinition(ctx context.Context, definitionID int64) error
- func (c *Client) DeleteTrainingDefinitionAdaptive(ctx context.Context, definitionID int64) error
- func (c *Client) GetSandboxAllocationUnit(ctx context.Context, unitId int64) (*SandboxAllocationUnit, error)
- func (c *Client) GetSandboxDefinition(ctx context.Context, definitionID int64) (*SandboxDefinition, error)
- func (c *Client) GetSandboxPool(ctx context.Context, poolId int64) (*SandboxPool, error)
- func (c *Client) GetSandboxRequestAnsibleOutputs(ctx context.Context, sandboxRequestId, page, pageSize int64, outputType string) (*SandboxRequestStageOutput, error)
- func (c *Client) GetTrainingDefinition(ctx context.Context, definitionID int64) (*TrainingDefinition, error)
- func (c *Client) GetTrainingDefinitionAdaptive(ctx context.Context, definitionID int64) (*TrainingDefinitionAdaptive, error)
- func (c *Client) PollRequestFinished(ctx context.Context, unitId int64, pollTime time.Duration, requestType string) (*SandboxRequest, error)
- type Error
- type HardwareUsage
- type Pagination
- type SandboxAllocationUnit
- type SandboxDefinition
- type SandboxPool
- type SandboxRequest
- type SandboxRequestStageOutput
- type TrainingDefinition
- type TrainingDefinitionAdaptive
- type User
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("not found")
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { // Endpoint of the KYPO instance to connect to. For example `https://your.kypo.ex`. Endpoint string // ClientID used by the KYPO instance OIDC provider. ClientID string // HTTPClient which is used to do requests. HTTPClient *http.Client // Bearer Token which is used for authentication to the KYPO instance. Is set by NewClient function. Token string // Time when Token expires, used to refresh it automatically when required. Is set by NewClient function. // Is used only with KYPO instances using Keycloak OIDC provider. TokenExpiryTime time.Time // Username of the user to login as. Username string // Password of the user to login as. Password string // How many times should a failed HTTP request be retried. There is a delay of 100ms before the first retry. // The delay is doubled before each following retry. RetryCount int }
Client struct stores information for authentication to the KYPO API. All functions are methods of this struct
func NewClient ¶
NewClient creates and returns a Client which uses username and password for authentication. The username and password is used to login to Keycloak of the KYPO instance. If the login fails, login to the legacy CSIRT-MU dummy OIDC issuer is attempted.
func NewClientWithToken ¶
NewClientWithToken creates and returns a Client which uses an already created Bearer token.
func (*Client) AwaitAllocationRequestCreate ¶
func (*Client) CancelSandboxAllocationRequest ¶
func (c *Client) CancelSandboxAllocationRequest(ctx context.Context, allocationRequestId int64) error
CancelSandboxAllocationRequest sends a request to cancel the given allocation request.
func (*Client) CleanupSandboxPool ¶
CleanupSandboxPool creates a cleanup request for all allocation units in the pool.
func (*Client) CreateSandboxAllocationUnitAwait ¶
func (c *Client) CreateSandboxAllocationUnitAwait(ctx context.Context, poolId int64, pollTime time.Duration) (*SandboxAllocationUnit, error)
CreateSandboxAllocationUnitAwait creates a single sandbox allocation unit and waits until its allocation finishes. Once the allocation is started, the status is checked once every `pollTime` elapses.
func (*Client) CreateSandboxAllocationUnits ¶
func (c *Client) CreateSandboxAllocationUnits(ctx context.Context, poolId, count int64) ([]SandboxAllocationUnit, error)
CreateSandboxAllocationUnits starts the allocation of `count` sandboxes in the sandbox pool specified by `poolId`.
func (*Client) CreateSandboxCleanupRequest ¶
CreateSandboxCleanupRequest starts a cleanup request for the specified sandbox allocation unit.
func (*Client) CreateSandboxCleanupRequestAwait ¶
func (c *Client) CreateSandboxCleanupRequestAwait(ctx context.Context, unitId int64, pollTime time.Duration) error
CreateSandboxCleanupRequestAwait starts the cleanup request for the given sandbox allocation unit and waits until it finishes. Once the cleanup is started, the status is checked once every `pollTime` elapses.
func (*Client) CreateSandboxDefinition ¶
func (c *Client) CreateSandboxDefinition(ctx context.Context, url, rev string) (*SandboxDefinition, error)
CreateSandboxDefinition creates a sandbox definition. The `url` must be a URL to a GitLab repository where the sandbox definition is hosted. The `rev` specifies the Git revision to be used.
func (*Client) CreateSandboxPool ¶
func (c *Client) CreateSandboxPool(ctx context.Context, definitionId, maxSize int64) (*SandboxPool, error)
CreateSandboxPool creates a sandbox pool from given sandbox definition id and the maximum size of the pool.
func (*Client) CreateTrainingDefinition ¶
func (c *Client) CreateTrainingDefinition(ctx context.Context, content string) (*TrainingDefinition, error)
CreateTrainingDefinition imports a JSON string content as a training definition. The JSON string must be a previously exported training definition. Since KYPO returns an answer with a definition in a different format than the exported definition, only the Id is read and the input content is set as the returned TrainingDefinition.Content.
func (*Client) CreateTrainingDefinitionAdaptive ¶
func (c *Client) CreateTrainingDefinitionAdaptive(ctx context.Context, content string) (*TrainingDefinitionAdaptive, error)
CreateTrainingDefinitionAdaptive imports a JSON string content as a adaptive training definition. The JSON string must be a previously exported adaptive training definition. Since KYPO returns an answer with a definition in a different format than the exported definition, only the Id is read and the input content is set as the returned TrainingDefinition.Content.
func (*Client) DeleteSandboxDefinition ¶
DeleteSandboxDefinition deletes the given sandbox definition.
func (*Client) DeleteSandboxPool ¶
DeleteSandboxPool deletes the given sandbox pool.
func (*Client) DeleteTrainingDefinition ¶
DeleteTrainingDefinition deletes the definition given by definitionID.
func (*Client) DeleteTrainingDefinitionAdaptive ¶
DeleteTrainingDefinitionAdaptive deletes the adaptive definition given by definitionID.
func (*Client) GetSandboxAllocationUnit ¶
func (c *Client) GetSandboxAllocationUnit(ctx context.Context, unitId int64) (*SandboxAllocationUnit, error)
GetSandboxAllocationUnit reads a sandbox allocation unit based on its id.
func (*Client) GetSandboxDefinition ¶
func (c *Client) GetSandboxDefinition(ctx context.Context, definitionID int64) (*SandboxDefinition, error)
GetSandboxDefinition reads the given sandbox definition.
func (*Client) GetSandboxPool ¶
GetSandboxPool reads the given sandbox pool.
func (*Client) GetSandboxRequestAnsibleOutputs ¶
func (c *Client) GetSandboxRequestAnsibleOutputs(ctx context.Context, sandboxRequestId, page, pageSize int64, outputType string) (*SandboxRequestStageOutput, error)
GetSandboxRequestAnsibleOutputs reads the output of given allocation request stage. The `outputType` should be one of `user-ansible`, `networking-ansible` or `terraform`.
func (*Client) GetTrainingDefinition ¶
func (c *Client) GetTrainingDefinition(ctx context.Context, definitionID int64) (*TrainingDefinition, error)
GetTrainingDefinition reads the definition given by definitionID.
func (*Client) GetTrainingDefinitionAdaptive ¶
func (c *Client) GetTrainingDefinitionAdaptive(ctx context.Context, definitionID int64) (*TrainingDefinitionAdaptive, error)
GetTrainingDefinitionAdaptive reads the adaptive definition given by definitionID.
func (*Client) PollRequestFinished ¶
func (c *Client) PollRequestFinished(ctx context.Context, unitId int64, pollTime time.Duration, requestType string) (*SandboxRequest, error)
PollRequestFinished periodically checks whether the specified request on given allocation unit has finished. The `requestType` should be one of `allocation` or `cleanup`. The check is done once every `pollTime` elapses.
type HardwareUsage ¶
type Pagination ¶
type Pagination[T any] struct { Page int64 `json:"page" tfsdk:"page"` PageSize int64 `json:"page_size" tfsdk:"page_size"` PageCount int64 `json:"page_count" tfsdk:"page_count"` Count int64 `json:"count" tfsdk:"line_count"` TotalCount int64 `json:"total_count" tfsdk:"total_count"` Results T `json:"results" tfsdk:"results"` }
type SandboxAllocationUnit ¶
type SandboxAllocationUnit struct { Id int64 `json:"id" tfsdk:"id"` PoolId int64 `json:"pool_id" tfsdk:"pool_id"` AllocationRequest SandboxRequest `json:"allocation_request" tfsdk:"allocation_request"` CleanupRequest SandboxRequest `json:"cleanup_request" tfsdk:"cleanup_request"` CreatedBy User `json:"created_by" tfsdk:"created_by"` Locked bool `json:"locked" tfsdk:"locked"` }
type SandboxDefinition ¶
type SandboxPool ¶
type SandboxPool struct { Id int64 `json:"id" tfsdk:"id"` Size int64 `json:"size" tfsdk:"size"` MaxSize int64 `json:"max_size" tfsdk:"max_size"` LockId int64 `json:"lock_id" tfsdk:"lock_id"` Rev string `json:"rev" tfsdk:"rev"` RevSha string `json:"rev_sha" tfsdk:"rev_sha"` CreatedBy User `json:"created_by" tfsdk:"created_by"` HardwareUsage HardwareUsage `json:"hardware_usage" tfsdk:"hardware_usage"` Definition SandboxDefinition `json:"definition" tfsdk:"definition"` }
type SandboxRequest ¶
type SandboxRequestStageOutput ¶
type SandboxRequestStageOutput struct { Page int64 `json:"page" tfsdk:"page"` PageSize int64 `json:"page_size" tfsdk:"page_size"` PageCount int64 `json:"page_count" tfsdk:"page_count"` Count int64 `json:"count" tfsdk:"line_count"` TotalCount int64 `json:"total_count" tfsdk:"total_count"` Result string `json:"result" tfsdk:"result"` }