kypo

package
v0.0.0-...-ad1f38c Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func NewClient(endpoint, clientId, username, password string) (*Client, error)

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

func NewClientWithToken(endpoint, clientId, token string) (*Client, error)

NewClientWithToken creates and returns a Client which uses an already created Bearer token.

func (*Client) AwaitAllocationRequestCreate

func (c *Client) AwaitAllocationRequestCreate(ctx context.Context, requestId int64, pollTime time.Duration) error

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

func (c *Client) CleanupSandboxPool(ctx context.Context, poolId int64, force bool) error

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

func (c *Client) CreateSandboxCleanupRequest(ctx context.Context, unitId int64) error

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

func (c *Client) DeleteSandboxDefinition(ctx context.Context, definitionID int64) error

DeleteSandboxDefinition deletes the given sandbox definition.

func (*Client) DeleteSandboxPool

func (c *Client) DeleteSandboxPool(ctx context.Context, poolId int64) error

DeleteSandboxPool deletes the given sandbox pool.

func (*Client) DeleteTrainingDefinition

func (c *Client) DeleteTrainingDefinition(ctx context.Context, definitionID int64) error

DeleteTrainingDefinition deletes the definition given by definitionID.

func (*Client) DeleteTrainingDefinitionAdaptive

func (c *Client) DeleteTrainingDefinitionAdaptive(ctx context.Context, definitionID int64) error

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

func (c *Client) GetSandboxPool(ctx context.Context, poolId int64) (*SandboxPool, error)

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 Error

type Error struct {
	ResourceName string
	Identifier   any
	Err          error
}

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type HardwareUsage

type HardwareUsage struct {
	Vcpu      string `json:"vcpu" tfsdk:"vcpu"`
	Ram       string `json:"ram" tfsdk:"ram"`
	Instances string `json:"instances" tfsdk:"instances"`
	Network   string `json:"network" tfsdk:"network"`
	Subnet    string `json:"subnet" tfsdk:"subnet"`
	Port      string `json:"port" tfsdk:"port"`
}

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 SandboxDefinition struct {
	Id        int64  `json:"id" tfsdk:"id"`
	Url       string `json:"url" tfsdk:"url"`
	Name      string `json:"name" tfsdk:"name"`
	Rev       string `json:"rev" tfsdk:"rev"`
	CreatedBy User   `json:"created_by" tfsdk:"created_by"`
}

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 SandboxRequest struct {
	Id               int64    `json:"id" tfsdk:"id"`
	AllocationUnitId int64    `json:"allocation_unit_id" tfsdk:"allocation_unit_id"`
	Created          string   `json:"created" tfsdk:"created"`
	Stages           []string `json:"stages" tfsdk:"stages"`
}

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"`
}

type TrainingDefinition

type TrainingDefinition struct {
	Id      int64  `json:"id" tfsdk:"id"`
	Content string `json:"content" tfsdk:"content"`
}

type TrainingDefinitionAdaptive

type TrainingDefinitionAdaptive struct {
	Id      int64  `json:"id" tfsdk:"id"`
	Content string `json:"content" tfsdk:"content"`
}

type User

type User struct {
	Id         int64  `json:"id" tfsdk:"id"`
	Sub        string `json:"sub" tfsdk:"sub"`
	FullName   string `json:"full_name" tfsdk:"full_name"`
	GivenName  string `json:"given_name" tfsdk:"given_name"`
	FamilyName string `json:"family_name" tfsdk:"family_name"`
	Mail       string `json:"mail" tfsdk:"mail"`
}

Jump to

Keyboard shortcuts

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