dto

package
v0.0.0-...-06858c0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserAgentVCSPlaceholder         = "<7 Git Hash>"
	UserAgentFilterTokenPlaceholder = "FilterToken"
)
View Source
const (
	FormatterText = "TextFormatter"
	FormatterJSON = "JSONFormatter"
)
View Source
const (
	KeyRunnerID            = "runner_id"
	KeyEnvironmentID       = "environment_id"
	KeyRunnerDestroyReason = "destroy_reason"
)

Keys to reference information (for logging or monitoring).

Variables

View Source
var (
	// UserAgentOut for outgoing requests (without libraries). The Git Hash will be replaced by main.go.
	UserAgentOut      = "Poseidon/" + UserAgentVCSPlaceholder + " Go-http-client/1.1"
	UserAgentFiltered = "Poseidon/" + UserAgentVCSPlaceholder + " (" + UserAgentFilterTokenPlaceholder + ") Go-http-client/1.1"
)
View Source
var (
	ErrUnknownWebSocketMessageType = errors.New("unknown WebSocket message type")
	// ErrOOMKilled is the exact message that CodeOcean expects to further handle these specific cases.
	ErrOOMKilled    = errors.New("the allocation was OOM Killed")
	ErrMissingType  = errors.New("type is missing")
	ErrMissingData  = errors.New("data is missing")
	ErrInvalidType  = errors.New("invalid type")
	ErrNotSupported = errors.New("not supported")
)

LoggedContextKeys defines which keys will be logged if a context is passed to logrus. See ContextHook.

Functions

func BashEscapeCommand

func BashEscapeCommand(command string) string

BashEscapeCommand escapes the passed command and surrounds it with double-quotes. The escaping includes the characters ", \, $, ` (comma-separated) as they are the exceptional characters that still have a special meaning with double quotes. See the Bash Manual - Chapter Quoting. We only handle the dollar-character and the backquote because the %q format already escapes the other two.

func WrapBashCommand

func WrapBashCommand(command string) string

WrapBashCommand escapes the passed command and wraps it into a new bash command.

Types

type ClientError

type ClientError struct {
	Message string `json:"message"`
}

ClientError is the response interface if the request is not valid.

type ContextKey

type ContextKey string

ContextKey is the type for keys in a request context that is used for passing data to the next handler.

type EntryType

type EntryType string

EntryType specifies the type of the object (file/link/directory/...)

const (
	EntryTypeRegularFile EntryType = "-"
	EntryTypeLink        EntryType = "l"
)

These are the common entry types. You find others in the man pages `info ls`.

type EnvironmentID

type EnvironmentID int

EnvironmentID is an id of an environment.

func NewEnvironmentID

func NewEnvironmentID(id string) (EnvironmentID, error)

NewEnvironmentID parses a string into an EnvironmentID.

func (EnvironmentID) ToString

func (e EnvironmentID) ToString() string

ToString pareses an EnvironmentID back to a string.

type ErrorCode

type ErrorCode string

ErrorCode is the type for error codes expected by CodeOcean.

const (
	ErrorNomadUnreachable         ErrorCode = "NOMAD_UNREACHABLE"
	ErrorNomadOverload            ErrorCode = "NOMAD_OVERLOAD"
	ErrorNomadInternalServerError ErrorCode = "NOMAD_INTERNAL_SERVER_ERROR"
	PrewarmingPoolDepleting       ErrorCode = "PREWARMING_POOL_DEPLETING"
	ErrorUnknown                  ErrorCode = "UNKNOWN"
)

type ExecutionEnvironmentData

type ExecutionEnvironmentData struct {
	ExecutionEnvironmentRequest
	ID int `json:"id"`
}

ExecutionEnvironmentData is the expected json structure of the response body for routes returning an execution environment.

type ExecutionEnvironmentRequest

type ExecutionEnvironmentRequest struct {
	PrewarmingPoolSize uint     `json:"prewarmingPoolSize"`
	CPULimit           uint     `json:"cpuLimit"`
	MemoryLimit        uint     `json:"memoryLimit"`
	Image              string   `json:"image"`
	NetworkAccess      bool     `json:"networkAccess"`
	ExposedPorts       []uint16 `json:"exposedPorts"`
}

ExecutionEnvironmentRequest is the expected json structure of the request body for the create execution environment function.

type ExecutionRequest

type ExecutionRequest struct {
	Command             string            `json:"command"`
	PrivilegedExecution bool              `json:"privilegedExecution"`
	TimeLimit           int               `json:"timeLimit"`
	Environment         map[string]string `json:"environment"`
}

ExecutionRequest is the expected json structure of the request body for the ExecuteCommand function.

func (*ExecutionRequest) FullCommand

func (er *ExecutionRequest) FullCommand() string

FullCommand joins the environment variables. It does not handle the TimeLimit or the PrivilegedExecution flag.

type ExecutionResponse

type ExecutionResponse struct {
	WebSocketURL string `json:"websocketUrl"`
}

ExecutionResponse is the expected response when creating an execution for a runner.

type File

type File struct {
	Path    FilePath `json:"path"`
	Content []byte   `json:"content"`
}

File is a DTO for transmitting file contents. It is part of the UpdateFileSystemRequest.

func (File) ByteContent

func (f File) ByteContent() []byte

ByteContent returns the content of the File. If the File is a directory, the content will be empty.

func (File) CleanedPath

func (f File) CleanedPath() string

CleanedPath returns the cleaned path of the file.

func (File) IsDirectory

func (f File) IsDirectory() bool

IsDirectory returns true iff the path of the File ends with a /.

type FileHeader

type FileHeader struct {
	Name             FilePath  `json:"name"`
	EntryType        EntryType `json:"entryType"`
	LinkTarget       FilePath  `json:"linkTarget,omitempty"`
	Size             int       `json:"size"`
	ModificationTime int       `json:"modificationTime"`
	Permissions      string    `json:"permissions"`
	Owner            string    `json:"owner"`
	Group            string    `json:"group"`
}

FileHeader specifies the information provided for listing a File.

type FilePath

type FilePath string

FilePath specifies the path of a file and is part of the UpdateFileSystemRequest.

func (FilePath) Cleaned

func (f FilePath) Cleaned() string

Cleaned returns the cleaned path of the FilePath.

type Formatter

type Formatter string

Formatter mirrors the available Formatters of logrus for configuration purposes.

type InternalServerError

type InternalServerError struct {
	Message   string    `json:"message"`
	ErrorCode ErrorCode `json:"errorCode"`
}

InternalServerError is the response interface that is returned when an error occurs.

type ListFileSystemResponse

type ListFileSystemResponse struct {
	Files []FileHeader `json:"files"`
}

ListFileSystemResponse is the expected response when listing the file system.

type MappedPort

type MappedPort struct {
	ExposedPort uint   `json:"exposedPort"`
	HostAddress string `json:"hostAddress"`
}

MappedPort contains the mapping from exposed port inside the container to the host address outside the container.

type RunnerRequest

type RunnerRequest struct {
	ExecutionEnvironmentID int `json:"executionEnvironmentId"`
	InactivityTimeout      int `json:"inactivityTimeout"`
}

RunnerRequest is the expected json structure of the request body for the ProvideRunner function.

type RunnerResponse

type RunnerResponse struct {
	ID          string        `json:"runnerId"`
	MappedPorts []*MappedPort `json:"mappedPorts"`
}

RunnerResponse is the expected response when providing a runner.

type StatisticalExecutionEnvironmentData

type StatisticalExecutionEnvironmentData struct {
	ID                 int  `json:"id"`
	PrewarmingPoolSize uint `json:"prewarmingPoolSize"`
	IdleRunners        uint `json:"idleRunners"`
	UsedRunners        uint `json:"usedRunners"`
}

StatisticalExecutionEnvironmentData is the expected json structure of the response body for routes returning statistics about execution environments.

type UpdateFileSystemRequest

type UpdateFileSystemRequest struct {
	Delete []FilePath `json:"delete"`
	Copy   []File     `json:"copy"`
}

UpdateFileSystemRequest is the expected json structure of the request body for the update file system route.

type WebSocketMessage

type WebSocketMessage struct {
	Type     WebSocketMessageType
	Data     string
	ExitCode uint8
}

WebSocketMessage is the type for all messages send in the WebSocket to the client. Depending on the MessageType the Data or ExitCode might not be included in the marshaled json message.

func (*WebSocketMessage) MarshalJSON

func (m *WebSocketMessage) MarshalJSON() (res []byte, err error)

MarshalJSON implements the json.Marshaler interface. This converts the WebSocketMessage into the expected schema (see docs/websocket.schema.json).

func (*WebSocketMessage) UnmarshalJSON

func (m *WebSocketMessage) UnmarshalJSON(rawMessage []byte) error

UnmarshalJSON implements the json.Unmarshaler interface. It is used by tests in order to ReceiveNextWebSocketMessage.

type WebSocketMessageType

type WebSocketMessageType string

WebSocketMessageType is the type for the messages from Poseidon to the client.

const (
	WebSocketOutputStdout WebSocketMessageType = "stdout"
	WebSocketOutputStderr WebSocketMessageType = "stderr"
	WebSocketOutputError  WebSocketMessageType = "error"
	WebSocketMetaStart    WebSocketMessageType = "start"
	WebSocketMetaTimeout  WebSocketMessageType = "timeout"
	WebSocketExit         WebSocketMessageType = "exit"
)

Jump to

Keyboard shortcuts

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