Documentation ¶
Index ¶
- Variables
- func DataPath() (string, error)
- func ValidateName(name string) bool
- type Auth
- type Client
- func (cc *Client) Auth() (*Auth, error)
- func (cc *Client) AuthKeyPaths() []string
- func (cc *Client) AuthedRequest(method string, host string, port int, path string, reqBody interface{}, ...) error
- func (cc *Client) AuthorizedKeys() (string, error)
- func (cc *Client) AuthorizedKeysWithMetadata() (*Keys, error)
- func (cc *Client) Bio() (*User, error)
- func (cc *Client) Decrypt(gid string, content []byte) ([]byte, error)
- func (cc *Client) DeleteMarkdown(markdownID int) error
- func (cc *Client) Encrypt(content []byte) ([]byte, string, error)
- func (cc *Client) EncryptWithKey(id string, content []byte) ([]byte, string, error)
- func (cc *Client) GetNews(page int) ([]*Markdown, error)
- func (cc *Client) GetNewsMarkdown(markdownID int) (*Markdown, error)
- func (cc *Client) GetStash(page int) ([]*Markdown, error)
- func (cc *Client) GetStashMarkdown(markdownID int) (*Markdown, error)
- func (cc *Client) ID() (string, error)
- func (cc *Client) InvalidateAuth()
- func (cc *Client) JWT() (string, error)
- func (cc *Client) Link(lh LinkHandler, code string) error
- func (cc *Client) LinkGen(lh LinkHandler) error
- func (cc *Client) SetMarkdownNote(markdownID int, note string) error
- func (cc *Client) SetName(name string) (*User, error)
- func (cc *Client) StashMarkdown(note string, body string) (*Markdown, error)
- func (cc *Client) SyncEncryptKeys() error
- func (cc *Client) UnlinkAuthorizedKey(key string) error
- type Config
- type EncryptKey
- type ErrAuthFailed
- type Fingerprint
- type Key
- type Keys
- type Link
- type LinkHandler
- type LinkStatus
- type LinkerMessage
- type Markdown
- type MarkdownsByCreatedAtDesc
- type User
Constants ¶
This section is empty.
Variables ¶
var ErrCouldNotUnlinkKey = errors.New("could not unlink key")
ErrCouldNotUnlinkKey is used when a key can't be deleted.
var ErrMalformedKey = errors.New("malformed key; is it missing the algorithm type at the beginning?")
ErrMalformedKey parsing error for bad ssh key.
var ErrMissingSSHAuth = errors.New("missing ssh auth")
ErrMissingSSHAuth is used when the user is missing SSH credentials.
var ErrNameInvalid = errors.New("invalid name")
ErrNameInvalid is used when a username is invalid.
var ErrNameTaken = errors.New("name already taken")
ErrNameTaken is used when a user attempts to set a username and that username is already taken.
var ErrorPageOutOfBounds = errors.New("page must be a value of 1 or greater")
ErrorPageOutOfBounds is an error for an invalid page number.
Functions ¶
Types ¶
type Auth ¶
type Auth struct { CharmID string `json:"charm_id"` JWT string `json:"jwt"` PublicKey string `json:"public_key"` EncryptKeys []*EncryptKey `json:"encrypt_keys"` // contains filtered or unexported fields }
Auth is the authenticated user's charm id and jwt returned from the ssh server.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the Charm client.
func (*Client) Auth ¶
Auth returns the Auth struct for a client session. It will renew and cache the Charm ID JWT.
func (*Client) AuthKeyPaths ¶
AuthKeyPaths returns the full file path of the Charm auth SSH keys.
func (*Client) AuthedRequest ¶
func (cc *Client) AuthedRequest(method string, host string, port int, path string, reqBody interface{}, respBody interface{}) error
AuthedRequest sends an authorized request to the Charm and Glow HTTP servers.
func (*Client) AuthorizedKeys ¶
AuthorizedKeys returns the keys linked to a user's account.
func (*Client) AuthorizedKeysWithMetadata ¶
AuthorizedKeysWithMetadata fetches keys linked to a user's account, with metadata.
func (*Client) DeleteMarkdown ¶
DeleteMarkdown deletes the stash markdown for the given ID.
func (*Client) Encrypt ¶
Encrypt encrypts bytes with the default encrypt key, returning the encrypted bytes, encrypt key ID and error.
func (*Client) EncryptWithKey ¶
EncryptWithKey encrypts bytes with a given encrypt key ID, returning the encrypted bytes, encrypt key ID and error.
func (*Client) GetNewsMarkdown ¶
GetNewsMarkdown returns the Markdown struct for the given news markdown ID.
func (*Client) GetStash ¶
GetStash returns the paginated user stash for the authenticated Charm user.
func (*Client) GetStashMarkdown ¶
GetStashMarkdown returns the Markdown struct for the given stash markdown ID.
func (*Client) InvalidateAuth ¶
func (cc *Client) InvalidateAuth()
InvalidateAuth clears the JWT auth cache, forcing subsequent Auth() to fetch a new JWT from the server.
func (*Client) Link ¶
func (cc *Client) Link(lh LinkHandler, code string) error
Link joins in on a linking session initiated by LinkGen.
func (*Client) LinkGen ¶
func (cc *Client) LinkGen(lh LinkHandler) error
LinkGen initiates a linking session.
func (*Client) SetMarkdownNote ¶
SetMarkdownNote updates the note for a given stash markdown ID.
func (*Client) StashMarkdown ¶
StashMarkdown encrypts and stashes a new markdown file with note.
func (*Client) SyncEncryptKeys ¶
SyncEncryptKeys re-encodes all of the encrypt keys associated for this public key with all other linked publick keys.
func (*Client) UnlinkAuthorizedKey ¶
UnlinkAuthorizedKey removes an authorized key from the user's Charm account.
type Config ¶
type Config struct { IDHost string `env:"CHARM_ID_HOST" default:"id.charm.sh"` IDPort int `env:"CHARM_ID_PORT" default:"22"` BioHost string `env:"CHARM_BIO_HOST" default:"https://bio.charm.sh"` BioPort int `env:"CHARM_BIO_PORT" default:"443"` GlowHost string `env:"CHARM_GLOW_HOST" default:"https://glow.charm.sh"` GlowPort int `env:"CHARM_GLOW_PORT" default:"443"` JWTKey string `env:"CHARM_JWT_KEY" default:""` Debug bool `env:"CHARM_DEBUG" default:"false"` Logfile string `env:"CHARM_LOGFILE" default:""` }
Config contains the Charm client configuration.
func ConfigFromEnv ¶
ConfigFromEnv loads the configuration from the environment.
type EncryptKey ¶
type EncryptKey struct { GlobalID string `json:"global_id"` Key string `json:"key"` PublicKey string `json:"public_key,omitempty"` }
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.
type Fingerprint ¶
Fingerprint is the fingerprint of an SSH key.
func (Fingerprint) String ¶
func (f Fingerprint) String() string
String outputs a string representation of the fingerprint.
type Key ¶
Key contains data and metadata for an SSH key.
func (Key) FingerprintSHA256 ¶
func (k Key) FingerprintSHA256() (Fingerprint, error)
FingerprintSHA256 returns the algorithm and SHA256 fingerprint for the given key.
type Keys ¶
Keys is a server response returned when the user queries for the keys linked to her account.
type Link ¶
type Link struct { Token string `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.
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 )
type LinkerMessage ¶
type LinkerMessage struct {
Message string `json:"message"`
}
LinkerMessage is used for communicating errors and data in the linking process.
type Markdown ¶
type Markdown struct { ID int `json:"id"` EncryptKeyID string `json:"encrypt_key_id"` Note string `json:"note"` Body string `json:"body,omitempty"` CreatedAt time.Time `json:"created_at"` }
Markdown is the struct that contains the markdown and note data. If EncryptKeyID is not blank, the content should be assumed to be encrypted. Once decrypted, that field will be blanked.
type MarkdownsByCreatedAtDesc ¶
type MarkdownsByCreatedAtDesc []*Markdown
MarkdownsByCreatedAtDesc sorts markdown documents by date in descending order. It implements sort.Interface for []Markdown based on the CreatedAt field.
func (MarkdownsByCreatedAtDesc) Len ¶
func (m MarkdownsByCreatedAtDesc) Len() int
Sort implementation for MarkdownByCreatedAt.
func (MarkdownsByCreatedAtDesc) Less ¶
func (m MarkdownsByCreatedAtDesc) Less(i, j int) bool
func (MarkdownsByCreatedAtDesc) Swap ¶
func (m MarkdownsByCreatedAtDesc) Swap(i, j int)