Documentation ¶
Index ¶
- Constants
- Variables
- func BashEscapeCommand(command string) string
- func WrapBashCommand(command string) string
- type ClientError
- type ContextKey
- type EntryType
- type EnvironmentID
- type ErrorCode
- type ExecutionEnvironmentData
- type ExecutionEnvironmentRequest
- type ExecutionRequest
- type ExecutionResponse
- type File
- type FileHeader
- type FilePath
- type Formatter
- type InternalServerError
- type ListFileSystemResponse
- type MappedPort
- type RunnerRequest
- type RunnerResponse
- type StatisticalExecutionEnvironmentData
- type UpdateFileSystemRequest
- type WebSocketMessage
- type WebSocketMessageType
Constants ¶
const ( UserAgentVCSPlaceholder = "<7 Git Hash>" UserAgentFilterTokenPlaceholder = "FilterToken" )
const ( FormatterText = "TextFormatter" FormatterJSON = "JSONFormatter" )
const ( KeyRunnerID = "runner_id" KeyEnvironmentID = "environment_id" KeyRunnerDestroyReason = "destroy_reason" )
Keys to reference information (for logging or monitoring).
Variables ¶
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" )
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") )
var LoggedContextKeys = []ContextKey{KeyRunnerID, KeyEnvironmentID, KeyRunnerDestroyReason}
LoggedContextKeys defines which keys will be logged if a context is passed to logrus. See ContextHook.
Functions ¶
func BashEscapeCommand ¶
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 ¶
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/...)
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 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 ¶
File is a DTO for transmitting file contents. It is part of the UpdateFileSystemRequest.
func (File) ByteContent ¶
ByteContent returns the content of the File. If the File is a directory, the content will be empty.
func (File) CleanedPath ¶
CleanedPath returns the cleaned path of the file.
func (File) IsDirectory ¶
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.
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 ¶
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" )