Documentation
¶
Overview ¶
Package api is the client of the owner HTTP API of the mai server. It reads the configuration file of the CLI and the owner key from the key file. It never prints or logs a key.
Index ¶
- Constants
- Variables
- func Code(err error) string
- func Open(store KeySource) (*Client, Config, error)
- type Agent
- type Client
- func (c *Client) AddAgent(ctx context.Context, name string) (NewAgent, error)
- func (c *Client) EndSession(ctx context.Context, login string) error
- func (c *Client) Health(ctx context.Context) (Health, error)
- func (c *Client) ListAgents(ctx context.Context) ([]Agent, error)
- func (c *Client) ListLeases(ctx context.Context) ([]Lease, error)
- func (c *Client) ListSessions(ctx context.Context) ([]Session, error)
- func (c *Client) NewSession(ctx context.Context, agent, label string) (SessionState, error)
- func (c *Client) NewSessions(ctx context.Context, agent string, count int) ([]SessionState, error)
- func (c *Client) RemoveAgent(ctx context.Context, name string) error
- func (c *Client) RevokeSession(ctx context.Context, login string) (SessionState, error)
- func (c *Client) RotateAgentKey(ctx context.Context, name string) (string, error)
- func (c *Client) RotateSession(ctx context.Context, login string) (SessionState, error)
- func (c *Client) SetUI(ctx context.Context, enabled bool) (bool, error)
- func (c *Client) UI(ctx context.Context) (bool, error)
- func (c *Client) UITicket(ctx context.Context) (Ticket, error)
- func (c *Client) Version(ctx context.Context) (VersionInfo, error)
- type Config
- type Error
- type Health
- type KeySource
- type Lease
- type NewAgent
- type Session
- type SessionState
- type Ticket
- type VersionInfo
Constants ¶
const ConfigFile = "config.json"
ConfigFile is the name of the configuration file in the configuration folder.
Variables ¶
var ErrNoOwnerKey = errors.New("api: no owner key in the key file; run mai start first")
ErrNoOwnerKey means that the key file has no owner key for the instance.
Functions ¶
Types ¶
type Agent ¶
type Agent struct {
Name string `json:"name"`
Sessions int `json:"sessions"`
Leases int `json:"leases"`
}
Agent is one agent in GET /api/agents.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client calls the owner API. The owner key is only in the memory of the client.
func (*Client) AddAgent ¶
AddAgent calls POST /api/agents. The answer holds the agent key one time only.
func (*Client) EndSession ¶
EndSession calls DELETE /api/sessions/{login}/lease.
func (*Client) ListAgents ¶
ListAgents calls GET /api/agents.
func (*Client) ListLeases ¶
ListLeases calls GET /api/leases.
func (*Client) ListSessions ¶
ListSessions calls GET /api/sessions.
func (*Client) NewSession ¶ added in v3.1.0
NewSession calls POST /api/sessions with a label and returns the named session AGENT.LABEL. The server gives BAD_LABEL, AGENT_UNKNOWN, or SESSION_EXISTS on an error.
func (*Client) NewSessions ¶ added in v3.1.0
NewSessions calls POST /api/sessions with a count. The server makes each session of AGENT.s1 to AGENT.sN that does not exist, and returns only these sessions.
func (*Client) RemoveAgent ¶
RemoveAgent calls DELETE /api/agents/{name}.
func (*Client) RevokeSession ¶ added in v3.1.0
RevokeSession calls POST /api/sessions/{login}/revoke. The server ends the lease of the session and refuses each subsequent lease request with SESSION_REVOKED.
func (*Client) RotateAgentKey ¶
RotateAgentKey calls POST /api/agents/{name}/key and returns the new agent key.
func (*Client) RotateSession ¶ added in v3.1.0
RotateSession calls POST /api/sessions/{login}/rotate. The server makes a new internal secret for the session and ends its lease. The answer holds no secret.
type Config ¶
type Config struct {
Instance string `json:"instance"`
Port int `json:"port"`
Image string `json:"image"`
DataDir string `json:"data_dir"`
}
Config is the configuration file of the CLI. A missing file or a missing field gives the default value.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns the configuration with each default value.
func LoadConfig ¶
LoadConfig reads config.json in the configuration folder dir.
type Error ¶
type Error struct {
Status int `json:"-"`
Code string `json:"code"`
Message string `json:"message"`
}
Error is the error object of the server: {"error":{"code":"CODE","message":"..."}}.
type KeySource ¶ added in v3.2.0
KeySource gives the key of an account. The key file of the CLI (keys.File) is one.
type Lease ¶
type Lease struct {
Session string `json:"session"`
Agent string `json:"agent"`
App string `json:"app"`
Folder string `json:"folder"`
PID int `json:"pid"`
StartedAt string `json:"started_at"`
LastSeenAt string `json:"last_seen_at"`
}
Lease is one lease in GET /api/leases.
type Session ¶
type Session struct {
Login string `json:"login"`
Agent string `json:"agent"`
Label string `json:"label"`
Status string `json:"status"`
Leased bool `json:"leased"`
App string `json:"app"`
Folder string `json:"folder"`
PID int `json:"pid"`
LastSeenAt string `json:"last_seen_at"`
}
Session is one session in GET /api/sessions. The lease fields are empty when the session has no lease. No field holds a secret.
type SessionState ¶ added in v3.1.0
type SessionState struct {
Login string `json:"login"`
Agent string `json:"agent,omitempty"`
Label string `json:"label,omitempty"`
Status string `json:"status"`
}
SessionState is the answer of POST /api/sessions, and of the rotate and the revoke of a session. It holds no secret.
type VersionInfo ¶
VersionInfo is the answer of GET /api/version.