Help us shape the future of Go! Take the 2026 Go Developer Survey

webspaced

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2021 License: GPL-3.0 Imports: 22 Imported by: 2

README

Go API client for webspaced

API for managing next-gen webspaces.

Overview

This API client was generated by the OpenAPI Generator project. By using the OpenAPI-spec from a remote server, you can easily generate an API client.

  • API version: 1.2.0
  • Package version: 1.0.0
  • Build package: org.openapitools.codegen.languages.GoClientCodegen

Installation

Install the following dependencies:

go get github.com/stretchr/testify/assert
go get golang.org/x/oauth2
go get golang.org/x/net/context
go get github.com/antihax/optional

Put the package under your project folder and add the following in import:

import "./webspaced"

Documentation for API Endpoints

All URIs are relative to https://webspaced.netsoc.ie/v1

Class Method HTTP request Description
ConfigApi Create Post /webspace/{username} Initialize webspace
ConfigApi Delete Delete /webspace/{username} Destroy webspace
ConfigApi Get Get /webspace/{username} Retrieve all webspace information
ConfigApi GetConfig Get /webspace/{username}/config Retrieve webspace configuration
ConfigApi UpdateConfig Patch /webspace/{username}/config Change webspace config options
ConsoleApi ClearLog Delete /webspace/{username}/log Clear webspace console log
ConsoleApi Console Get /webspace/{username}/console Attach to webspace console
ConsoleApi Exec Post /webspace/{username}/exec Execute command non-interactively
ConsoleApi ExecInteractive Get /webspace/{username}/exec Execute a command interactively
ConsoleApi GetLog Get /webspace/{username}/log Retrieve webspace console log
DomainsApi AddDomain Post /webspace/{username}/domains/{domain} Add custom domain
DomainsApi GetDomains Get /webspace/{username}/domains Retrieve webspace domains
DomainsApi RemoveDomain Delete /webspace/{username}/domains/{domain} Delete custom domain
ImagesApi GetImages Get /images List images
PortsApi AddPort Post /webspace/{username}/ports/{ePort}/{iPort} Add port forward
PortsApi AddRandomPort Post /webspace/{username}/ports/{iPort} Add random port forward
PortsApi GetPorts Get /webspace/{username}/ports Retrieve webspace port forwards
PortsApi RemovePort Delete /webspace/{username}/ports/{ePort} Delete port forward
StateApi GetState Get /webspace/{username}/state Retrieve webspace state
StateApi Reboot Put /webspace/{username}/state Reboot webspace container
StateApi Shutdown Delete /webspace/{username}/state Shut down webspace container
StateApi Start Post /webspace/{username}/state Start webspace container
StateApi Sync Patch /webspace/{username}/state Re-generate webspace backend config

Documentation For Models

Documentation For Authorization

jwt

  • Type: HTTP basic authentication

Example

auth := context.WithValue(context.Background(), sw.ContextBasicAuth, sw.BasicAuth{
    UserName: "username",
    Password: "password",
})
r, err := client.Service.Operation(auth, args)

jwt_admin

  • Type: HTTP basic authentication

Example

auth := context.WithValue(context.Background(), sw.ContextBasicAuth, sw.BasicAuth{
    UserName: "username",
    Password: "password",
})
r, err := client.Service.Operation(auth, args)

Author

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ContextOAuth2 takes an oauth2.TokenSource as authentication for the request.
	ContextOAuth2 = contextKey("token")

	// ContextBasicAuth takes BasicAuth as authentication for the request.
	ContextBasicAuth = contextKey("basic")

	// ContextAccessToken takes a string oauth2 access token as authentication for the request.
	ContextAccessToken = contextKey("accesstoken")

	// ContextAPIKey takes an APIKey as authentication for the request
	ContextAPIKey = contextKey("apikey")
)

Functions

func CacheExpires

func CacheExpires(r *http.Response) time.Time

CacheExpires helper function to determine remaining time before repeating a request.

Types

type APIClient

type APIClient struct {
	ConfigApi *ConfigApiService

	ConsoleApi *ConsoleApiService

	DomainsApi *DomainsApiService

	ImagesApi *ImagesApiService

	PortsApi *PortsApiService

	StateApi *StateApiService
	// contains filtered or unexported fields
}

APIClient manages communication with the Netsoc webspaced API v1.2.0 In most cases there should be only one, shared, APIClient.

func NewAPIClient

func NewAPIClient(cfg *Configuration) *APIClient

NewAPIClient creates a new API client. Requires a userAgent string describing your application. optionally a custom http.Client to allow for advanced features such as caching.

func (*APIClient) ChangeBasePath

func (c *APIClient) ChangeBasePath(path string)

ChangeBasePath changes base path to allow switching to mocks

func (*APIClient) GetConfig

func (c *APIClient) GetConfig() *Configuration

Allow modification of underlying config for alternate implementations and testing Caution: modifying the configuration while live can cause data races and potentially unwanted behavior

type APIKey

type APIKey struct {
	Key    string
	Prefix string
}

APIKey provides API key based authentication to a request passed via context using ContextAPIKey

type APIResponse

type APIResponse struct {
	*http.Response `json:"-"`
	Message        string `json:"message,omitempty"`
	// Operation is the name of the OpenAPI operation.
	Operation string `json:"operation,omitempty"`
	// RequestURL is the request URL. This value is always available, even if the
	// embedded *http.Response is nil.
	RequestURL string `json:"url,omitempty"`
	// Method is the HTTP method used for the request.  This value is always
	// available, even if the embedded *http.Response is nil.
	Method string `json:"method,omitempty"`
	// Payload holds the contents of the response body (which may be nil or empty).
	// This is provided here as the raw response.Body() reader will have already
	// been drained.
	Payload []byte `json:"-"`
}

APIResponse stores the API response returned by the server.

func NewAPIResponse

func NewAPIResponse(r *http.Response) *APIResponse

NewAPIResponse returns a new APIResonse object.

func NewAPIResponseWithError

func NewAPIResponseWithError(errorMessage string) *APIResponse

NewAPIResponseWithError returns a new APIResponse object with the provided error message.

type AddRandomPortResponse

type AddRandomPortResponse struct {
	// Network port
	EPort int32 `json:"ePort"`
}

AddRandomPortResponse struct for AddRandomPortResponse

type BasicAuth

type BasicAuth struct {
	UserName string `json:"userName,omitempty"`
	Password string `json:"password,omitempty"`
}

BasicAuth provides basic http authentication to a request passed via context using ContextBasicAuth

type Config

type Config struct {
	// How many seconds to delay incoming connections to a webspace while starting the container
	StartupDelay float64 `json:"startupDelay,omitempty"`
	// Incoming SSL-terminated HTTP requests (and SNI passthrough HTTPS connections) will be forwarded to this port
	HttpPort int32 `json:"httpPort,omitempty"`
	// If true, SSL termination will be disabled and HTTPS connections will forwarded directly
	SniPassthrough bool `json:"sniPassthrough,omitempty"`
}

Config Webspace configuration

type ConfigApiService

type ConfigApiService service

ConfigApiService ConfigApi service

func (*ConfigApiService) Create

func (a *ConfigApiService) Create(ctx _context.Context, username string, initRequest InitRequest) (Webspace, *_nethttp.Response, error)

Create Initialize webspace

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param username User's username. Can be `self` to indicate the currently authenticated user.
  • @param initRequest

@return Webspace

func (*ConfigApiService) Delete

func (a *ConfigApiService) Delete(ctx _context.Context, username string) (*_nethttp.Response, error)

Delete Destroy webspace

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param username User's username. Can be `self` to indicate the currently authenticated user.

func (*ConfigApiService) Get

Get Retrieve all webspace information Retrieve all information about a webspace (except for its current state)

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param username User's username. Can be `self` to indicate the currently authenticated user.

@return Webspace

func (*ConfigApiService) GetConfig

func (a *ConfigApiService) GetConfig(ctx _context.Context, username string) (Config, *_nethttp.Response, error)

GetConfig Retrieve webspace configuration

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param username User's username. Can be `self` to indicate the currently authenticated user.

@return Config

func (*ConfigApiService) UpdateConfig

func (a *ConfigApiService) UpdateConfig(ctx _context.Context, username string, config Config) (Config, *_nethttp.Response, error)

UpdateConfig Change webspace config options

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param username User's username. Can be `self` to indicate the currently authenticated user.
  • @param config

@return Config

type Configuration

type Configuration struct {
	BasePath      string            `json:"basePath,omitempty"`
	Host          string            `json:"host,omitempty"`
	Scheme        string            `json:"scheme,omitempty"`
	DefaultHeader map[string]string `json:"defaultHeader,omitempty"`
	UserAgent     string            `json:"userAgent,omitempty"`
	Debug         bool              `json:"debug,omitempty"`
	Servers       []ServerConfiguration
	HTTPClient    *http.Client
}

Configuration stores the configuration of the API client

func NewConfiguration

func NewConfiguration() *Configuration

NewConfiguration returns a new Configuration object

func (*Configuration) AddDefaultHeader

func (c *Configuration) AddDefaultHeader(key string, value string)

AddDefaultHeader adds a new HTTP header to the default header in the request

func (*Configuration) ServerUrl

func (c *Configuration) ServerUrl(index int, variables map[string]string) (string, error)

ServerUrl returns URL based on server settings

type ConsoleApiService

type ConsoleApiService service

ConsoleApiService ConsoleApi service

func (*ConsoleApiService) ClearLog added in v1.0.4

func (a *ConsoleApiService) ClearLog(ctx _context.Context, username string) (*_nethttp.Response, error)

ClearLog Clear webspace console log

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param username User's username. Can be `self` to indicate the currently authenticated user.

func (*ConsoleApiService) Console added in v1.1.0

func (a *ConsoleApiService) Console(ctx _context.Context, username string) (*_nethttp.Response, error)

Console Attach to webspace console _IMPORTANT_: This endpoint uses a websocket. On connection, a single text message should be sent with integers for terminal `width` and `height` (as JSON, see `ResizeRequest` e.g. `{\"width\": 80, \"height\": 24}`). Following this, binary messages to and from the socket will be routed to the console TTY. Any other text messages will also be treated as resize events (same format).

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param username User's username. Can be `self` to indicate the currently authenticated user.

func (*ConsoleApiService) Exec added in v1.1.2

func (a *ConsoleApiService) Exec(ctx _context.Context, username string, execRequest ExecRequest) (ExecResponse, *_nethttp.Response, error)

Exec Execute command non-interactively Runs a command non-interactively (no TTY, waits for completion and returns complete stdout and stderr).

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param username User's username. Can be `self` to indicate the currently authenticated user.
  • @param execRequest

@return ExecResponse

func (*ConsoleApiService) ExecInteractive added in v1.1.2

func (a *ConsoleApiService) ExecInteractive(ctx _context.Context, username string) (*_nethttp.Response, error)

ExecInteractive Execute a command interactively _IMPORTANT_: This endpoint uses a websocket. On connection, a single text message should be sent (as JSON), this message is of the form `ExecInteractiveRequest`. Following this, binary messages to and from the socket will be routed to the process PTY. Any other text messages will be treated as `ExecInteractiveControl` messages. Pass a signal number to send a signal to the process, and non-zero values for `width` and `height` to resize. Upon command completion, the close message will be the exit code of the process.

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param username User's username. Can be `self` to indicate the currently authenticated user.

func (*ConsoleApiService) GetLog

func (a *ConsoleApiService) GetLog(ctx _context.Context, username string) (string, *_nethttp.Response, error)

GetLog Retrieve webspace console log

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param username User's username. Can be `self` to indicate the currently authenticated user.

@return string

type DomainsApiService

type DomainsApiService service

DomainsApiService DomainsApi service

func (*DomainsApiService) AddDomain

func (a *DomainsApiService) AddDomain(ctx _context.Context, username string, domain string) (*_nethttp.Response, error)

AddDomain Add custom domain Domain will be verified by looking for a `TXT` record of the format `webspace:id:<user id>`

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param username User's username. Can be `self` to indicate the currently authenticated user.
  • @param domain

func (*DomainsApiService) GetDomains

func (a *DomainsApiService) GetDomains(ctx _context.Context, username string) ([]string, *_nethttp.Response, error)

GetDomains Retrieve webspace domains

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param username User's username. Can be `self` to indicate the currently authenticated user.

@return []string

func (*DomainsApiService) RemoveDomain

func (a *DomainsApiService) RemoveDomain(ctx _context.Context, username string, domain string) (*_nethttp.Response, error)

RemoveDomain Delete custom domain

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param username User's username. Can be `self` to indicate the currently authenticated user.
  • @param domain

type Error

type Error struct {
	// Message explaining the error
	Message string `json:"message"`
}

Error struct for Error

type ExecInteractiveControl added in v1.1.2

type ExecInteractiveControl struct {
	Resize ResizeRequest `json:"resize,omitempty"`
	// Signal to send to process
	Signal int32 `json:"signal,omitempty"`
}

ExecInteractiveControl struct for ExecInteractiveControl

type ExecInteractiveRequest added in v1.1.2

type ExecInteractiveRequest struct {
	Command []string `json:"command"`
	// User ID to run as
	User int32 `json:"user,omitempty"`
	// Group ID to run as
	Group int32 `json:"group,omitempty"`
	// Additional environment variables to pass to process
	Environment map[string]string `json:"environment,omitempty"`
	// Width of terminal (columns)
	Width int32 `json:"width"`
	// Height of terminal (rows)
	Height           int32  `json:"height"`
	WorkingDirectory string `json:"workingDirectory,omitempty"`
}

ExecInteractiveRequest struct for ExecInteractiveRequest

type ExecRequest added in v1.1.2

type ExecRequest struct {
	Command string `json:"command"`
}

ExecRequest struct for ExecRequest

type ExecResponse added in v1.1.2

type ExecResponse struct {
	// Process stdout
	Stdout string `json:"stdout"`
	// Process stderr
	Stderr string `json:"stderr"`
	// Process exit code
	ExitCode int32 `json:"exitCode"`
}

ExecResponse struct for ExecResponse

type GenericOpenAPIError

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

GenericOpenAPIError Provides access to the body, error and model on returned errors.

func (GenericOpenAPIError) Body

func (e GenericOpenAPIError) Body() []byte

Body returns the raw bytes of the response

func (GenericOpenAPIError) Error

func (e GenericOpenAPIError) Error() string

Error returns non-empty string if there was an error.

func (GenericOpenAPIError) Model

func (e GenericOpenAPIError) Model() interface{}

Model returns the unpacked model of the error

type Image

type Image struct {
	Aliases []ImageAlias `json:"aliases"`
	// SHA-256 hash of the image
	Fingerprint string `json:"fingerprint"`
	// Arbitrary properties
	Properties map[string]string `json:"properties"`
	// Size in bytes
	Size int64 `json:"size"`
}

Image LXD image (summarised version of https://linuxcontainers.org/lxd/docs/master/rest-api#10imagesfingerprint)

type ImageAlias

type ImageAlias struct {
	Name        string `json:"name,omitempty"`
	Description string `json:"description,omitempty"`
}

ImageAlias LXD image alias

type ImagesApiService

type ImagesApiService service

ImagesApiService ImagesApi service

func (*ImagesApiService) GetImages

func (a *ImagesApiService) GetImages(ctx _context.Context) ([]Image, *_nethttp.Response, error)

GetImages List images

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().

@return []Image

type InitRequest

type InitRequest struct {
	// Image alias or fingerprint
	Image string `json:"image"`
	// Password for root user
	Password string `json:"password,omitempty"`
	// Whether or not to install an SSH server (and create a port forward for it). Requires the user to have an SSH key on their account.
	Ssh bool `json:"ssh,omitempty"`
}

InitRequest struct for InitRequest

type InterfaceAddress

type InterfaceAddress struct {
	Family  string `json:"family"`
	Address string `json:"address"`
	Netmask string `json:"netmask"`
	Scope   string `json:"scope,omitempty"`
}

InterfaceAddress Network interface address

type InterfaceCounters

type InterfaceCounters struct {
	BytesReceived   int64 `json:"bytesReceived"`
	BytesSent       int64 `json:"bytesSent"`
	PacketsReceived int64 `json:"packetsReceived"`
	PacketsSent     int64 `json:"packetsSent"`
}

InterfaceCounters Counters for a network interface

type NetworkInterface

type NetworkInterface struct {
	// MAC address
	Mac       string             `json:"mac"`
	Mtu       int32              `json:"mtu"`
	State     string             `json:"state"`
	Counters  InterfaceCounters  `json:"counters"`
	Addresses []InterfaceAddress `json:"addresses"`
}

NetworkInterface Webspace network interface status

type PortsApiService

type PortsApiService service

PortsApiService PortsApi service

func (*PortsApiService) AddPort

func (a *PortsApiService) AddPort(ctx _context.Context, username string, ePort int32, iPort int32) (*_nethttp.Response, error)

AddPort Add port forward

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param username User's username. Can be `self` to indicate the currently authenticated user.
  • @param ePort
  • @param iPort

func (*PortsApiService) AddRandomPort

func (a *PortsApiService) AddRandomPort(ctx _context.Context, username string, iPort int32) (AddRandomPortResponse, *_nethttp.Response, error)

AddRandomPort Add random port forward Add port forward from random free port to internal port

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param username User's username. Can be `self` to indicate the currently authenticated user.
  • @param iPort

@return AddRandomPortResponse

func (*PortsApiService) GetPorts

func (a *PortsApiService) GetPorts(ctx _context.Context, username string) (map[string]int32, *_nethttp.Response, error)

GetPorts Retrieve webspace port forwards

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param username User's username. Can be `self` to indicate the currently authenticated user.

@return map[string]int32

func (*PortsApiService) RemovePort

func (a *PortsApiService) RemovePort(ctx _context.Context, username string, ePort int32) (*_nethttp.Response, error)

RemovePort Delete port forward

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param username User's username. Can be `self` to indicate the currently authenticated user.
  • @param ePort

type ResizeRequest added in v1.1.2

type ResizeRequest struct {
	// Width of terminal (columns)
	Width int32 `json:"width"`
	// Height of terminal (rows)
	Height int32 `json:"height"`
}

ResizeRequest struct for ResizeRequest

type ServerConfiguration

type ServerConfiguration struct {
	Url         string
	Description string
	Variables   map[string]ServerVariable
}

ServerConfiguration stores the information about a server

type ServerVariable

type ServerVariable struct {
	Description  string
	DefaultValue string
	EnumValues   []string
}

ServerVariable stores the information about a server variable

type State

type State struct {
	Running bool `json:"running"`
	// Length of time for which container has been running (seconds)
	Uptime            float64                     `json:"uptime"`
	Usage             Usage                       `json:"usage"`
	NetworkInterfaces map[string]NetworkInterface `json:"networkInterfaces"`
}

State Webspace state

type StateApiService

type StateApiService service

StateApiService StateApi service

func (*StateApiService) GetState

func (a *StateApiService) GetState(ctx _context.Context, username string) (State, *_nethttp.Response, error)

GetState Retrieve webspace state Retrieve webspace state

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param username User's username. Can be `self` to indicate the currently authenticated user.

@return State

func (*StateApiService) Reboot

func (a *StateApiService) Reboot(ctx _context.Context, username string) (*_nethttp.Response, error)

Reboot Reboot webspace container

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param username User's username. Can be `self` to indicate the currently authenticated user.

func (*StateApiService) Shutdown

func (a *StateApiService) Shutdown(ctx _context.Context, username string) (*_nethttp.Response, error)

Shutdown Shut down webspace container

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param username User's username. Can be `self` to indicate the currently authenticated user.

func (*StateApiService) Start

func (a *StateApiService) Start(ctx _context.Context, username string) (*_nethttp.Response, error)

Start Start webspace container

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param username User's username. Can be `self` to indicate the currently authenticated user.

func (*StateApiService) Sync added in v1.0.1

func (a *StateApiService) Sync(ctx _context.Context, username string) (*_nethttp.Response, error)

Sync Re-generate webspace backend config Forces a reload of reverse proxy and port forwarding configuration

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param username User's username. Can be `self` to indicate the currently authenticated user.

type Usage

type Usage struct {
	// CPU time (nanoseconds)
	Cpu   int64            `json:"cpu"`
	Disks map[string]int64 `json:"disks"`
	// Memory usage in bytes
	Memory int64 `json:"memory"`
	// Number of processes
	Processes int64 `json:"processes"`
}

Usage Website resource usage

type Webspace

type Webspace struct {
	// Unique database identifier, not modifiable.
	User   int32  `json:"user,omitempty"`
	Config Config `json:"config,omitempty"`
	// List of webspace custom domains
	Domains []string `json:"domains,omitempty"`
	// Mapping of external ports to internal container ports (port forwarding)
	Ports map[string]int32 `json:"ports,omitempty"`
}

Webspace Netsoc webspace object

Jump to

Keyboard shortcuts

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