client

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2020 License: MIT Imports: 21 Imported by: 2

README

Client

PkgGoDev

This package contains Inertia's clientside interface to remote Inertia daemons. It can be imported for use if you don't like the CLI - for example:

package main

import (
	"context"

	"github.com/ubclaunchpad/inertia/cfg"
	"github.com/ubclaunchpad/inertia/client"
	"github.com/ubclaunchpad/inertia/client/bootstrap"
)

func main() {
	// set up a client to your remote
	inertia, _ := client.NewClient(
		&cfg.Remote{
			Version: "v0.6.0",
			Name:    "gcloud",
			IP:      "my.host.addr",
			/* ... */
		},
		client.Options{ /* ... */ })

	// bootstrap your remote
	bootstrap.Bootstrap(inertia, bootstrap.Options{ /* ... */ })

	// deploy your project!
	inertia.Up(context.Background(), client.UpRequest{
		Project: "my-project",
		URL:     "git@github.com:me/project.git",
		Profile: cfg.Profile{
			Name:   "default",
			Branch: "master",
			Build: &cfg.Build{
				Type:          cfg.DockerCompose,
				BuildFilePath: "Dockerfile",
			},
		},
	})
}

Documentation

Overview

Package client provides the interface through which Inertia communicates with a serverside daemon

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNeedTotp is used to indicate that a 2FA-enabled user has not provided a TOTP
	ErrNeedTotp = errors.New("TOTP is needed for user")
)
View Source
var MinDaemonVersion = semver.Version{Major: 0, Minor: 6, Patch: 2}

MinDaemonVersion is the minimum inertiad version supported by this library

Functions

This section is empty.

Types

type AuthenticateRequest added in v0.6.0

type AuthenticateRequest struct {
	User     string
	Password string
	TOTP     string
}

AuthenticateRequest denotes options for authenticating with the Inertia daemon

type Client added in v0.4.0

type Client struct {
	Remote *cfg.Remote
	// contains filtered or unexported fields
}

Client manages a deployment

func NewClient added in v0.4.0

func NewClient(remote *cfg.Remote, opts Options) (*Client, error)

NewClient sets up a client to communicate to the daemon at the given remote

func (*Client) Down added in v0.4.0

func (c *Client) Down(ctx context.Context) error

Down brings the project down on the remote VPS instance specified in the configuration object.

func (*Client) GetSSHClient added in v0.6.0

func (c *Client) GetSSHClient() (*SSHClient, error)

GetSSHClient instantiates an SSH client for Inertia-related commands

func (*Client) GetUserClient added in v0.6.0

func (c *Client) GetUserClient() *UserClient

GetUserClient instantiates an API client for Inertia user management commands

func (*Client) ListEnv added in v0.4.0

func (c *Client) ListEnv(ctx context.Context) ([]string, error)

ListEnv lists environment variables currently set on remote

func (*Client) Logs added in v0.4.0

func (c *Client) Logs(ctx context.Context, req LogsRequest) ([]string, error)

Logs get logs of given container

func (*Client) LogsWithOutput added in v0.6.0

func (c *Client) LogsWithOutput(ctx context.Context, req LogsRequest) error

LogsWithOutput opens a websocket connection to given container's logs and streams it to the given io.Writer

func (*Client) Prune added in v0.4.1

func (c *Client) Prune(ctx context.Context) error

Prune clears Docker ReadFiles on this remote.

func (*Client) Reset added in v0.4.0

func (c *Client) Reset(ctx context.Context) error

Reset shuts down deployment and deletes the contents of the deployment's project directory

func (*Client) Status added in v0.4.0

func (c *Client) Status(ctx context.Context) (*api.DeploymentStatus, error)

Status lists the currently active containers on the remote VPS instance

func (*Client) Token added in v0.5.0

func (c *Client) Token(ctx context.Context) (token string, err error)

Token generates token on this remote.

func (*Client) Up added in v0.4.0

func (c *Client) Up(ctx context.Context, req UpRequest) error

Up brings the project up on the remote VPS instance specified in the deployment object.

func (*Client) UpWithOutput added in v0.6.0

func (c *Client) UpWithOutput(ctx context.Context, req UpRequest) error

UpWithOutput blocks and streams 'up' output to the client's io.Writer

func (*Client) UpdateEnv added in v0.4.0

func (c *Client) UpdateEnv(ctx context.Context, name, value string, encrypt, remove bool) error

UpdateEnv updates environment variable

func (*Client) WithDebug added in v0.6.0

func (c *Client) WithDebug(debug bool)

WithDebug sets the client's debug mode

func (*Client) WithWriter added in v0.6.0

func (c *Client) WithWriter(out io.Writer)

WithWriter sets the given io.Writer as the client's default output

type LogsRequest added in v0.6.0

type LogsRequest struct {
	Container string
	Entries   int
}

LogsRequest denotes parameters for log querying

type Options added in v0.6.0

type Options struct {
	SSH   runner.SSHOptions
	Out   io.Writer
	Debug bool
}

Options denotes configuration options for a Client

type SSHClient added in v0.6.0

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

SSHClient implements Inertia's SSH commands

func (*SSHClient) AssignAPIToken added in v0.6.0

func (s *SSHClient) AssignAPIToken() error

AssignAPIToken generates an API token and assigns it to client.Remote

func (*SSHClient) DaemonDown added in v0.6.0

func (s *SSHClient) DaemonDown() error

DaemonDown brings the daemon down on the remote instance

func (*SSHClient) DaemonUp added in v0.6.0

func (s *SSHClient) DaemonUp() error

DaemonUp brings the daemon up on the remote instance.

func (*SSHClient) GenerateKeys added in v0.6.0

func (s *SSHClient) GenerateKeys() (string, error)

GenerateKeys creates a public-private key-pair on the remote vps and returns the public key.

func (*SSHClient) GetRunner added in v0.6.0

func (s *SSHClient) GetRunner() runner.SSHSession

GetRunner returns the SSH client's underlying session

func (*SSHClient) InstallDocker added in v0.6.0

func (s *SSHClient) InstallDocker() error

InstallDocker installs docker on a remote vps.

func (*SSHClient) UninstallInertia added in v0.6.0

func (s *SSHClient) UninstallInertia() error

UninstallInertia removes the inertia/ directory on the remote instance

type SocketReader added in v0.4.0

type SocketReader interface {
	ReadMessage() (messageType int, p []byte, err error)
	Close() error
}

SocketReader is an interface to a websocket connection

type UpRequest added in v0.6.0

type UpRequest struct {
	Project string
	URL     string
	Profile cfg.Profile
}

UpRequest declares parameters for project deployment

type UserClient added in v0.6.0

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

UserClient is used to access Inertia's /user APIs

func NewUserClient added in v0.6.0

func NewUserClient(c *Client) *UserClient

NewUserClient instantiates a new client for user management functions

func (*UserClient) AddUser added in v0.6.0

func (u *UserClient) AddUser(ctx context.Context, username, password string, admin bool) error

AddUser adds an authorized user for access to Inertia Web

func (*UserClient) Authenticate added in v0.6.0

func (u *UserClient) Authenticate(ctx context.Context, req AuthenticateRequest) (token string, err error)

Authenticate gets an access token for the user with the given credentials. Use "" for totp if none is required.

func (*UserClient) DisableTotp added in v0.6.0

func (u *UserClient) DisableTotp(ctx context.Context) error

DisableTotp disables Totp for a given user

func (*UserClient) EnableTotp added in v0.6.0

func (u *UserClient) EnableTotp(ctx context.Context, username, password string) (*api.TotpResponse, error)

EnableTotp enables Totp for a given user

func (*UserClient) ListUsers added in v0.6.0

func (u *UserClient) ListUsers(ctx context.Context) ([]string, error)

ListUsers lists all users on the remote.

func (*UserClient) RemoveUser added in v0.6.0

func (u *UserClient) RemoveUser(ctx context.Context, username string) error

RemoveUser prevents a user from accessing Inertia Web

func (*UserClient) ResetUsers added in v0.6.0

func (u *UserClient) ResetUsers(ctx context.Context) error

ResetUsers resets all users on the remote.

Directories

Path Synopsis
Package bootstrap provides Inertia's remote bootstrapping script, based off of inertia/client.Client
Package bootstrap provides Inertia's remote bootstrapping script, based off of inertia/client.Client
Package internal provides compiled scripts and other internal assets
Package internal provides compiled scripts and other internal assets
Package runner provides the Inertia client's low-level SSH command runner
Package runner provides the Inertia client's low-level SSH command runner
mocks
Package mocks provides mocked implmentations of interfaces in client/runner Code generated by counterfeiter.
Package mocks provides mocked implmentations of interfaces in client/runner Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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