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",
			},
		},
	})
}
Expand ▾ Collapse ▴

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

      type AuthenticateRequest struct {
      	User     string
      	Password string
      	TOTP     string
      }

        AuthenticateRequest denotes options for authenticating with the Inertia daemon

        type Client

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

          Client manages a deployment

          func NewClient

          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

            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

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

                GetSSHClient instantiates an SSH client for Inertia-related commands

                func (*Client) GetUserClient

                func (c *Client) GetUserClient() *UserClient

                  GetUserClient instantiates an API client for Inertia user management commands

                  func (*Client) ListEnv

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

                    ListEnv lists environment variables currently set on remote

                    func (*Client) Logs

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

                      Logs get logs of given container

                      func (*Client) LogsWithOutput

                      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

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

                          Prune clears Docker ReadFiles on this remote.

                          func (*Client) Reset

                          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

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

                              Status lists the currently active containers on the remote VPS instance

                              func (*Client) Token

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

                                Token generates token on this remote.

                                func (*Client) Up

                                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

                                  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

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

                                      UpdateEnv updates environment variable

                                      func (*Client) WithDebug

                                      func (c *Client) WithDebug(debug bool)

                                        WithDebug sets the client's debug mode

                                        func (*Client) WithWriter

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

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

                                          type LogsRequest

                                          type LogsRequest struct {
                                          	Container string
                                          	Entries   int
                                          }

                                            LogsRequest denotes parameters for log querying

                                            type Options

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

                                              Options denotes configuration options for a Client

                                              type SSHClient

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

                                                SSHClient implements Inertia's SSH commands

                                                func (*SSHClient) AssignAPIToken

                                                func (s *SSHClient) AssignAPIToken() error

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

                                                  func (*SSHClient) DaemonDown

                                                  func (s *SSHClient) DaemonDown() error

                                                    DaemonDown brings the daemon down on the remote instance

                                                    func (*SSHClient) DaemonUp

                                                    func (s *SSHClient) DaemonUp() error

                                                      DaemonUp brings the daemon up on the remote instance.

                                                      func (*SSHClient) GenerateKeys

                                                      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

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

                                                          GetRunner returns the SSH client's underlying session

                                                          func (*SSHClient) InstallDocker

                                                          func (s *SSHClient) InstallDocker() error

                                                            InstallDocker installs docker on a remote vps.

                                                            func (*SSHClient) UninstallInertia

                                                            func (s *SSHClient) UninstallInertia() error

                                                              UninstallInertia removes the inertia/ directory on the remote instance

                                                              type SocketReader

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

                                                                SocketReader is an interface to a websocket connection

                                                                type UpRequest

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

                                                                  UpRequest declares parameters for project deployment

                                                                  type UserClient

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

                                                                    UserClient is used to access Inertia's /user APIs

                                                                    func NewUserClient

                                                                    func NewUserClient(c *Client) *UserClient

                                                                      NewUserClient instantiates a new client for user management functions

                                                                      func (*UserClient) AddUser

                                                                      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

                                                                        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

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

                                                                            DisableTotp disables Totp for a given user

                                                                            func (*UserClient) EnableTotp

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

                                                                              EnableTotp enables Totp for a given user

                                                                              func (*UserClient) ListUsers

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

                                                                                ListUsers lists all users on the remote.

                                                                                func (*UserClient) RemoveUser

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

                                                                                  RemoveUser prevents a user from accessing Inertia Web

                                                                                  func (*UserClient) ResetUsers

                                                                                  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 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.
                                                                                    Package internal provides compiled scripts and other internal assets
                                                                                    Package internal provides compiled scripts and other internal assets