proto

package
v0.12.6 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2023 License: MIT Imports: 5 Imported by: 2

Documentation

Overview

Package proto contains structs used for client/server communication.

Index

Constants

View Source
const LinkTimeout = time.Minute

LinkTimeout is the length of time a Token is valid for.

Variables

View Source
var ErrCouldNotUnlinkKey = errors.New("could not unlink key")

ErrCouldNotUnlinkKey is used when a key can't be deleted.

View Source
var ErrMalformedKey = errors.New("malformed key; is it missing the algorithm type at the beginning?")

ErrMalformedKey parsing error for bad ssh key.

View Source
var ErrMissingSSHAuth = errors.New("missing ssh auth")

ErrMissingSSHAuth is used when the user is missing SSH credentials.

View Source
var ErrMissingUser = errors.New("no user found")

ErrMissingUser is used when no user record is found.

View Source
var ErrNameInvalid = errors.New("invalid name")

ErrNameInvalid is used when a username is invalid.

View Source
var ErrNameTaken = errors.New("name already taken")

ErrNameTaken is used when a user attempts to set a username and that username is already taken.

View Source
var ErrPageOutOfBounds = errors.New("page must be a value of 1 or greater")

ErrPageOutOfBounds is an error for an invalid page number.

View Source
var ErrTokenExists = errors.New("token already exists")

ErrTokenExists is used when attempting to create a token that already exists.

View Source
var ErrUserExists = errors.New("user already exists for that key")

ErrUserExists is used when attempting to create a user with an existing global id.

Functions

func AddExecPermsForMkDir

func AddExecPermsForMkDir(mode fs.FileMode) fs.FileMode

Add execute permissions to an fs.FileMode to mirror read permissions.

func PublicKeySha

func PublicKeySha(key string) string

PublicKeySha returns the SHA for a public key in hex format.

Types

type Auth

type Auth struct {
	JWT         string        `json:"jwt"`
	ID          string        `json:"charm_id"`
	HTTPScheme  string        `json:"http_scheme"`
	PublicKey   string        `json:"public_key,omitempty"`
	EncryptKeys []*EncryptKey `json:"encrypt_keys,omitempty"`
}

Auth is the response to an authenticated connection. It contains tokens and keys required to access Charm Cloud services.

type EncryptKey

type EncryptKey struct {
	ID        string     `json:"id"`
	Key       string     `json:"key"`
	PublicKey string     `json:"public_key,omitempty"`
	CreatedAt *time.Time `json:"created_at"`
}

EncryptKey is the symmetric key used to encrypt data for a Charm user. An encrypt key will be encoded for every public key associated with a user's Charm account.

type ErrAuthFailed

type ErrAuthFailed struct {
	Err error
}

ErrAuthFailed indicates an authentication failure. The underlying error is wrapped.

func (ErrAuthFailed) Error

func (e ErrAuthFailed) Error() string

Error returns the boxed error string.

func (ErrAuthFailed) Unwrap

func (e ErrAuthFailed) Unwrap() error

Unwrap returns the boxed error.

type FileInfo

type FileInfo struct {
	Name    string      `json:"name"`
	IsDir   bool        `json:"is_dir"`
	Size    int64       `json:"size"`
	ModTime time.Time   `json:"modtime"`
	Mode    fs.FileMode `json:"mode"`
	Files   []FileInfo  `json:"files,omitempty"`
}

FileInfo describes a file and is returned by Stat.

type Keys

type Keys struct {
	ActiveKey int          `json:"active_key"`
	Keys      []*PublicKey `json:"keys"`
}

Keys is the response returned when the user queries for the keys linked to their account.

type Link struct {
	Token         Token      `json:"token"`
	RequestPubKey string     `json:"request_pub_key"`
	RequestAddr   string     `json:"request_addr"`
	Host          string     `json:"host"`
	Port          int        `json:"port"`
	Status        LinkStatus `json:"status"`
}

Link is the struct used to communicate state during the account linking process.

type LinkHandler

type LinkHandler interface {
	TokenCreated(*Link)
	TokenSent(*Link)
	ValidToken(*Link)
	InvalidToken(*Link)
	Request(*Link) bool
	RequestDenied(*Link)
	SameUser(*Link)
	Success(*Link)
	Timeout(*Link)
	Error(*Link)
}

LinkHandler handles linking operations for the key to be linked.

type LinkQueue added in v0.10.0

type LinkQueue interface {
	InitLinkRequest(t Token)
	WaitLinkRequest(t Token) (chan *Link, error)
	SendLinkRequest(lt LinkTransport, lc chan *Link, l *Link)
	ValidateLinkRequest(t Token) bool
	DeleteLinkRequest(t Token)
}

LinkQueue handles creating, validating, and sending link requests.

type LinkStatus

type LinkStatus int

LinkStatus represents a state in the linking process.

const (
	LinkStatusInit LinkStatus = iota
	LinkStatusTokenCreated
	LinkStatusTokenSent
	LinkStatusRequested
	LinkStatusRequestDenied
	LinkStatusSameUser
	LinkStatusDifferentUser
	LinkStatusSuccess
	LinkStatusTimedOut
	LinkStatusError
	LinkStatusValidTokenRequest
	LinkStatusInvalidTokenRequest
)

LinkStatus values.

type LinkTransport

type LinkTransport interface {
	TokenCreated(Token)
	TokenSent(*Link)
	Requested(*Link) (bool, error)
	LinkedSameUser(*Link)
	LinkedDifferentUser(*Link)
	Success(*Link)
	TimedOut(*Link)
	Error(*Link)
	RequestStart(*Link)
	RequestDenied(*Link)
	RequestInvalidToken(*Link)
	RequestValidToken(*Link)
	User() *User
}

LinkTransport handles linking operations for the link generation.

type Message

type Message struct {
	Message string `json:"message"`
}

Message is used as a wrapper for simple client/server messages.

type News

type News struct {
	ID        string    `json:"id"`
	Subject   string    `json:"subject"`
	Tag       string    `json:"tag"`
	Body      string    `json:"body,omitempty"`
	CreatedAt time.Time `json:"created_at"`
}

News entity.

type PublicKey

type PublicKey struct {
	ID        int        `json:"id"`
	UserID    int        `json:"user_id,omitempty"`
	Key       string     `json:"key"`
	CreatedAt *time.Time `json:"created_at"`
}

PublicKey represents to public SSH key for a Charm user.

func (*PublicKey) Sha

func (pk *PublicKey) Sha() string

Sha returns the SHA for the public key in hex format.

type SeqMsg

type SeqMsg struct {
	Seq uint64 `json:"seq"`
}

SeqMsg represents the results of a named sequence.

type Token

type Token string

Token represent the confirmation code generated during linking.

type UnlinkRequest

type UnlinkRequest struct {
	Key string `json:"key"`
}

UnlinkRequest is the message for unlinking an account from a key.

type User

type User struct {
	ID        int        `json:"id"`
	CharmID   string     `json:"charm_id"`
	PublicKey *PublicKey `json:"public_key,omitempty"`
	Name      string     `json:"name"`
	Email     string     `json:"email"`
	Bio       string     `json:"bio"`
	CreatedAt *time.Time `json:"created_at"`
}

User represents a Charm user account.

Jump to

Keyboard shortcuts

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