api

package
v0.0.0-...-35dcf12 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Overview

Package api provides primitives to interact with the openapi HTTP API.

Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.5.1 DO NOT EDIT.

Index

Constants

View Source
const (
	SigningReadOperation  = "read"
	SigningWriteOperation = "write"
)
View Source
const (
	// EncodingGzip is the gzip content encoding.
	EncodingGzip = "gzip"
	// EncodingIdentity means no encoding (passthrough).
	EncodingIdentity = "identity"
	// EncodingWildcard means any encoding is acceptable.
	EncodingWildcard = "*"
)
View Source
const (
	AccessTokenAuthScopes = "AccessTokenAuth.Scopes"
)

Variables

View Source
var (
	ErrAccessTokenMismatch           = errors.New("access token validation failed")
	ErrAccessTokenResetNotAuthorized = errors.New("access token reset not authorized")
)
View Source
var (
	ErrInvalidAddress       = errors.New("invalid IP address")
	ErrUnknownAddressFormat = errors.New("unknown IP address format")
)
View Source
var (
	ErrTokenNotSet = errors.New("access token not set")
	ErrTokenEmpty  = errors.New("empty token not allowed")
)
View Source
var ErrNoDiskSpace = fmt.Errorf("not enough disk space available")
View Source
var SupportedEncodings = []string{
	EncodingGzip,
}

SupportedEncodings lists the content encodings supported for file transfer. The order matters - encodings are checked in order of preference.

Functions

func Handler

func Handler(si ServerInterface) http.Handler

Handler creates http.Handler with routing matching OpenAPI spec.

func HandlerFromMux

func HandlerFromMux(si ServerInterface, r chi.Router) http.Handler

HandlerFromMux creates http.Handler with routing matching OpenAPI spec based on the provided mux.

func HandlerFromMuxWithBaseURL

func HandlerFromMuxWithBaseURL(si ServerInterface, r chi.Router, baseURL string) http.Handler

func HandlerWithOptions

func HandlerWithOptions(si ServerInterface, options ChiServerOptions) http.Handler

HandlerWithOptions creates http.Handler with additional options

Types

type API

type API struct {
	// contains filtered or unexported fields
}

func New

func New(l *zerolog.Logger, defaults *execcontext.Defaults, mmdsChan chan *host.MMDSOpts, isNotFC bool) *API

func (*API) GetEnvs

func (a *API) GetEnvs(w http.ResponseWriter, _ *http.Request)

func (*API) GetFiles

func (a *API) GetFiles(w http.ResponseWriter, r *http.Request, params GetFilesParams)

func (*API) GetHealth

func (a *API) GetHealth(w http.ResponseWriter, r *http.Request)

func (*API) GetMetrics

func (a *API) GetMetrics(w http.ResponseWriter, r *http.Request)

func (*API) PostFiles

func (a *API) PostFiles(w http.ResponseWriter, r *http.Request, params PostFilesParams)

func (*API) PostInit

func (a *API) PostInit(w http.ResponseWriter, r *http.Request)

func (*API) SetData

func (a *API) SetData(ctx context.Context, logger zerolog.Logger, data PostInitJSONBody) error

func (*API) SetupHyperloop

func (a *API) SetupHyperloop(address string)

func (*API) WithAuthorization

func (a *API) WithAuthorization(handler http.Handler) http.Handler

type ChiServerOptions

type ChiServerOptions struct {
	BaseURL          string
	BaseRouter       chi.Router
	Middlewares      []MiddlewareFunc
	ErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)
}

type DefaultMMDSClient

type DefaultMMDSClient struct{}

DefaultMMDSClient is the production implementation that calls the real MMDS endpoint.

func (*DefaultMMDSClient) GetAccessTokenHash

func (c *DefaultMMDSClient) GetAccessTokenHash(ctx context.Context) (string, error)

type EntryInfo

type EntryInfo struct {
	// Name Name of the file
	Name string `json:"name"`

	// Path Path to the file
	Path string `json:"path"`

	// Type Type of the file
	Type EntryInfoType `json:"type"`
}

EntryInfo defines model for EntryInfo.

type EntryInfoType

type EntryInfoType string

EntryInfoType Type of the file

const (
	File EntryInfoType = "file"
)

Defines values for EntryInfoType.

type EnvVars

type EnvVars map[string]string

EnvVars Environment variables to set

type Error

type Error struct {
	// Code Error code
	Code int `json:"code"`

	// Message Error message
	Message string `json:"message"`
}

Error defines model for Error.

type FileNotFound

type FileNotFound = Error

FileNotFound defines model for FileNotFound.

type FilePath

type FilePath = string

FilePath defines model for FilePath.

type GetFilesParams

type GetFilesParams struct {
	// Path Path to the file, URL encoded. Can be relative to user's home directory.
	Path *FilePath `form:"path,omitempty" json:"path,omitempty"`

	// Username User used for setting the owner, or resolving relative paths.
	Username *User `form:"username,omitempty" json:"username,omitempty"`

	// Signature Signature used for file access permission verification.
	Signature *Signature `form:"signature,omitempty" json:"signature,omitempty"`

	// SignatureExpiration Signature expiration used for defining the expiration time of the signature.
	SignatureExpiration *SignatureExpiration `form:"signature_expiration,omitempty" json:"signature_expiration,omitempty"`
}

GetFilesParams defines parameters for GetFiles.

type InternalServerError

type InternalServerError = Error

InternalServerError defines model for InternalServerError.

type InvalidParamFormatError

type InvalidParamFormatError struct {
	ParamName string
	Err       error
}

func (*InvalidParamFormatError) Error

func (e *InvalidParamFormatError) Error() string

func (*InvalidParamFormatError) Unwrap

func (e *InvalidParamFormatError) Unwrap() error

type InvalidPath

type InvalidPath = Error

InvalidPath defines model for InvalidPath.

type InvalidUser

type InvalidUser = Error

InvalidUser defines model for InvalidUser.

type MMDSClient

type MMDSClient interface {
	GetAccessTokenHash(ctx context.Context) (string, error)
}

MMDSClient provides access to MMDS metadata.

type Metrics

type Metrics struct {
	// CpuCount Number of CPU cores
	CpuCount *int `json:"cpu_count,omitempty"`

	// CpuUsedPct CPU usage percentage
	CpuUsedPct *float32 `json:"cpu_used_pct,omitempty"`

	// DiskTotal Total disk space in bytes
	DiskTotal *int `json:"disk_total,omitempty"`

	// DiskUsed Used disk space in bytes
	DiskUsed *int `json:"disk_used,omitempty"`

	// MemTotal Total virtual memory in bytes
	MemTotal *int `json:"mem_total,omitempty"`

	// MemUsed Used virtual memory in bytes
	MemUsed *int `json:"mem_used,omitempty"`

	// Ts Unix timestamp in UTC for current sandbox time
	Ts *int64 `json:"ts,omitempty"`
}

Metrics Resource usage metrics

type MiddlewareFunc

type MiddlewareFunc func(http.Handler) http.Handler

type NotEnoughDiskSpace

type NotEnoughDiskSpace = Error

NotEnoughDiskSpace defines model for NotEnoughDiskSpace.

type PostFilesMultipartBody

type PostFilesMultipartBody struct {
	File *openapi_types.File `json:"file,omitempty"`
}

PostFilesMultipartBody defines parameters for PostFiles.

type PostFilesMultipartRequestBody

type PostFilesMultipartRequestBody PostFilesMultipartBody

PostFilesMultipartRequestBody defines body for PostFiles for multipart/form-data ContentType.

type PostFilesParams

type PostFilesParams struct {
	// Path Path to the file, URL encoded. Can be relative to user's home directory.
	Path *FilePath `form:"path,omitempty" json:"path,omitempty"`

	// Username User used for setting the owner, or resolving relative paths.
	Username *User `form:"username,omitempty" json:"username,omitempty"`

	// Signature Signature used for file access permission verification.
	Signature *Signature `form:"signature,omitempty" json:"signature,omitempty"`

	// SignatureExpiration Signature expiration used for defining the expiration time of the signature.
	SignatureExpiration *SignatureExpiration `form:"signature_expiration,omitempty" json:"signature_expiration,omitempty"`
}

PostFilesParams defines parameters for PostFiles.

type PostInitJSONBody

type PostInitJSONBody struct {
	// AccessToken Access token for secure access to envd service
	AccessToken *SecureToken `json:"accessToken,omitempty"`

	// DefaultUser The default user to use for operations
	DefaultUser *string `json:"defaultUser,omitempty"`

	// DefaultWorkdir The default working directory to use for operations
	DefaultWorkdir *string `json:"defaultWorkdir,omitempty"`

	// EnvVars Environment variables to set
	EnvVars *EnvVars `json:"envVars,omitempty"`

	// HyperloopIP IP address of the hyperloop server to connect to
	HyperloopIP *string `json:"hyperloopIP,omitempty"`

	// Timestamp The current timestamp in RFC3339 format
	Timestamp    *time.Time     `json:"timestamp,omitempty"`
	VolumeMounts *[]VolumeMount `json:"volumeMounts,omitempty"`
}

PostInitJSONBody defines parameters for PostInit.

type PostInitJSONRequestBody

type PostInitJSONRequestBody PostInitJSONBody

PostInitJSONRequestBody defines body for PostInit for application/json ContentType.

type RequiredHeaderError

type RequiredHeaderError struct {
	ParamName string
	Err       error
}

func (*RequiredHeaderError) Error

func (e *RequiredHeaderError) Error() string

func (*RequiredHeaderError) Unwrap

func (e *RequiredHeaderError) Unwrap() error

type RequiredParamError

type RequiredParamError struct {
	ParamName string
}

func (*RequiredParamError) Error

func (e *RequiredParamError) Error() string

type SecureToken

type SecureToken struct {
	// contains filtered or unexported fields
}

SecureToken wraps memguard for secure token storage. It uses LockedBuffer which provides memory locking, guard pages, and secure zeroing on destroy.

func (*SecureToken) Bytes

func (s *SecureToken) Bytes() ([]byte, error)

Bytes returns a copy of the token bytes (for signature generation). The caller should zero the returned slice after use. Returns ErrTokenNotSet if the receiver is nil.

func (*SecureToken) Destroy

func (s *SecureToken) Destroy()

Destroy securely wipes the token from memory. No-op if the receiver is nil.

func (*SecureToken) Equals

func (s *SecureToken) Equals(token string) bool

Equals checks if token matches using constant-time comparison. Returns false if the receiver is nil.

func (*SecureToken) EqualsSecure

func (s *SecureToken) EqualsSecure(other *SecureToken) bool

EqualsSecure compares this token with another SecureToken using constant-time comparison. Returns false if either receiver or other is nil.

func (*SecureToken) IsSet

func (s *SecureToken) IsSet() bool

IsSet returns true if a token is stored. Returns false if the receiver is nil.

func (*SecureToken) Set

func (s *SecureToken) Set(token []byte) error

Set securely replaces the token, destroying the old one first. The old token memory is zeroed before the new token is stored. The input byte slice is wiped after copying to secure memory. Returns ErrTokenEmpty if token is empty - use Destroy() to clear the token instead.

func (*SecureToken) TakeFrom

func (s *SecureToken) TakeFrom(src *SecureToken)

TakeFrom transfers the token from src to this SecureToken, destroying any existing token. The source token is cleared after transfer. This avoids copying the underlying bytes.

func (*SecureToken) UnmarshalJSON

func (s *SecureToken) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler to securely parse a JSON string directly into memguard, wiping the input bytes after copying.

Access tokens are hex-encoded HMAC-SHA256 hashes (64 chars of [0-9a-f]), so they never contain JSON escape sequences.

type ServerInterface

type ServerInterface interface {
	// Get the environment variables
	// (GET /envs)
	GetEnvs(w http.ResponseWriter, r *http.Request)
	// Download a file
	// (GET /files)
	GetFiles(w http.ResponseWriter, r *http.Request, params GetFilesParams)
	// Upload a file and ensure the parent directories exist. If the file exists, it will be overwritten.
	// (POST /files)
	PostFiles(w http.ResponseWriter, r *http.Request, params PostFilesParams)
	// Check the health of the service
	// (GET /health)
	GetHealth(w http.ResponseWriter, r *http.Request)
	// Set initial vars, ensure the time and metadata is synced with the host
	// (POST /init)
	PostInit(w http.ResponseWriter, r *http.Request)
	// Get the stats of the service
	// (GET /metrics)
	GetMetrics(w http.ResponseWriter, r *http.Request)
}

ServerInterface represents all server handlers.

type ServerInterfaceWrapper

type ServerInterfaceWrapper struct {
	Handler            ServerInterface
	HandlerMiddlewares []MiddlewareFunc
	ErrorHandlerFunc   func(w http.ResponseWriter, r *http.Request, err error)
}

ServerInterfaceWrapper converts contexts to parameters.

func (*ServerInterfaceWrapper) GetEnvs

GetEnvs operation middleware

func (*ServerInterfaceWrapper) GetFiles

func (siw *ServerInterfaceWrapper) GetFiles(w http.ResponseWriter, r *http.Request)

GetFiles operation middleware

func (*ServerInterfaceWrapper) GetHealth

func (siw *ServerInterfaceWrapper) GetHealth(w http.ResponseWriter, r *http.Request)

GetHealth operation middleware

func (*ServerInterfaceWrapper) GetMetrics

func (siw *ServerInterfaceWrapper) GetMetrics(w http.ResponseWriter, r *http.Request)

GetMetrics operation middleware

func (*ServerInterfaceWrapper) PostFiles

func (siw *ServerInterfaceWrapper) PostFiles(w http.ResponseWriter, r *http.Request)

PostFiles operation middleware

func (*ServerInterfaceWrapper) PostInit

func (siw *ServerInterfaceWrapper) PostInit(w http.ResponseWriter, r *http.Request)

PostInit operation middleware

type Signature

type Signature = string

Signature defines model for Signature.

type SignatureExpiration

type SignatureExpiration = int

SignatureExpiration defines model for SignatureExpiration.

type TooManyValuesForParamError

type TooManyValuesForParamError struct {
	ParamName string
	Count     int
}

func (*TooManyValuesForParamError) Error

type UnescapedCookieParamError

type UnescapedCookieParamError struct {
	ParamName string
	Err       error
}

func (*UnescapedCookieParamError) Error

func (e *UnescapedCookieParamError) Error() string

func (*UnescapedCookieParamError) Unwrap

func (e *UnescapedCookieParamError) Unwrap() error

type Unimplemented

type Unimplemented struct{}

func (Unimplemented) GetEnvs

func (_ Unimplemented) GetEnvs(w http.ResponseWriter, r *http.Request)

Get the environment variables (GET /envs)

func (Unimplemented) GetFiles

func (_ Unimplemented) GetFiles(w http.ResponseWriter, r *http.Request, params GetFilesParams)

Download a file (GET /files)

func (Unimplemented) GetHealth

func (_ Unimplemented) GetHealth(w http.ResponseWriter, r *http.Request)

Check the health of the service (GET /health)

func (Unimplemented) GetMetrics

func (_ Unimplemented) GetMetrics(w http.ResponseWriter, r *http.Request)

Get the stats of the service (GET /metrics)

func (Unimplemented) PostFiles

func (_ Unimplemented) PostFiles(w http.ResponseWriter, r *http.Request, params PostFilesParams)

Upload a file and ensure the parent directories exist. If the file exists, it will be overwritten. (POST /files)

func (Unimplemented) PostInit

func (_ Unimplemented) PostInit(w http.ResponseWriter, r *http.Request)

Set initial vars, ensure the time and metadata is synced with the host (POST /init)

type UnmarshalingParamError

type UnmarshalingParamError struct {
	ParamName string
	Err       error
}

func (*UnmarshalingParamError) Error

func (e *UnmarshalingParamError) Error() string

func (*UnmarshalingParamError) Unwrap

func (e *UnmarshalingParamError) Unwrap() error

type UploadSuccess

type UploadSuccess = []EntryInfo

UploadSuccess defines model for UploadSuccess.

type User

type User = string

User defines model for User.

type VolumeMount

type VolumeMount struct {
	NfsTarget string `json:"nfs_target"`
	Path      string `json:"path"`
}

VolumeMount Volume

Jump to

Keyboard shortcuts

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