client

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: 28 Imported by: 7

Documentation

Overview

Package client manages authorization, identity and keys for a Charm Cloud user. It also offers low-level HTTP and SSH APIs for accessing the Charm Cloud server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RandomArt

func RandomArt(k charm.PublicKey) (string, error)

RandomArt returns the randomart for the given key.

func ValidateName

func ValidateName(name string) bool

ValidateName validates a given name.

Types

type Client

type Client struct {
	Config *Config
	// contains filtered or unexported fields
}

Client is the Charm client.

func NewClient

func NewClient(cfg *Config) (*Client, error)

NewClient creates a new Charm client.

func NewClientWithDefaults

func NewClientWithDefaults() (*Client, error)

NewClientWithDefaults creates a new Charm client with default values.

func (*Client) Auth

func (cc *Client) Auth() (*charm.Auth, error)

Auth will authenticate a client and cache the result. It will return a proto.Auth with the JWT and encryption keys for a user.

func (*Client) AuthKeyPaths

func (cc *Client) AuthKeyPaths() []string

AuthKeyPaths returns the full file path of the Charm auth SSH keys.

func (*Client) AuthedJSONRequest

func (cc *Client) AuthedJSONRequest(method string, path string, reqBody interface{}, respBody interface{}) error

AuthedRequest sends an authorized JSON request to the Charm and Glow HTTP servers.

func (*Client) AuthedRawRequest

func (cc *Client) AuthedRawRequest(method string, path string) (*http.Response, error)

AuthedRawRequest sends an authorized request with no request body to the Charm and Glow HTTP servers.

func (*Client) AuthedRequest

func (cc *Client) AuthedRequest(method string, path string, headers http.Header, reqBody io.Reader) (*http.Response, error)

AuthedRequest sends an authorized request to the Charm and Glow HTTP servers.

func (*Client) AuthorizedKeys

func (cc *Client) AuthorizedKeys() (string, error)

AuthorizedKeys returns the keys linked to a user's account.

func (*Client) AuthorizedKeysWithMetadata

func (cc *Client) AuthorizedKeysWithMetadata() (*charm.Keys, error)

AuthorizedKeysWithMetadata fetches keys linked to a user's account, with metadata.

func (*Client) Bio

func (cc *Client) Bio() (*charm.User, error)

Bio returns the user's profile.

func (*Client) DataPath added in v0.11.0

func (cc *Client) DataPath() (string, error)

DataPath return the directory a Charm user's data is stored. It will default to XDG-HOME/$CHARM_HOST.

func (*Client) DefaultEncryptKey

func (cc *Client) DefaultEncryptKey() (*charm.EncryptKey, error)

DefaultEncryptKey returns the default EncryptKey for an authed user.

func (*Client) EncryptKeys added in v0.10.0

func (cc *Client) EncryptKeys() ([]*charm.EncryptKey, error)

EncryptKeys returns all of the symmetric encrypt keys for the authed user.

func (*Client) ID

func (cc *Client) ID() (string, error)

ID returns the user's 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) JWT

func (cc *Client) JWT(aud ...string) (string, error)

JWT returns a JSON web token for the user.

func (*Client) KeyForID

func (cc *Client) KeyForID(gid string) (*charm.EncryptKey, error)

KeyForID returns the decrypted EncryptKey for a given key ID.

func (cc *Client) Link(lh charm.LinkHandler, code string) error

Link joins in on a linking session initiated by LinkGen.

func (*Client) LinkGen

func (cc *Client) LinkGen(lh charm.LinkHandler) error

LinkGen initiates a linking session.

func (*Client) News

func (cc *Client) News(id string) (*charm.News, error)

News shows a given news.

func (*Client) NewsList

func (cc *Client) NewsList(tags []string, page int) ([]*charm.News, error)

NewsList lists the server news.

func (*Client) SetName

func (cc *Client) SetName(name string) (*charm.User, error)

SetName sets the account's username.

func (*Client) SyncEncryptKeys

func (cc *Client) SyncEncryptKeys() error

SyncEncryptKeys re-encodes all of the encrypt keys associated for this public key with all other linked public keys.

func (*Client) UnlinkAuthorizedKey

func (cc *Client) UnlinkAuthorizedKey(key string) error

UnlinkAuthorizedKey removes an authorized key from the user's Charm account.

type Config

type Config struct {
	Host        string `env:"CHARM_HOST" envDefault:"cloud.charm.sh"`
	SSHPort     int    `env:"CHARM_SSH_PORT" envDefault:"35353"`
	HTTPPort    int    `env:"CHARM_HTTP_PORT" envDefault:"35354"`
	Debug       bool   `env:"CHARM_DEBUG" envDefault:"false"`
	Logfile     string `env:"CHARM_LOGFILE" envDefault:""`
	KeyType     string `env:"CHARM_KEY_TYPE" envDefault:"ed25519"`
	DataDir     string `env:"CHARM_DATA_DIR" envDefault:""`
	IdentityKey string `env:"CHARM_IDENTITY_KEY" envDefault:""`
}

Config contains the Charm client configuration.

func ConfigFromEnv

func ConfigFromEnv() (*Config, error)

ConfigFromEnv loads the configuration from the environment.

func (*Config) KeygenType added in v0.10.0

func (cfg *Config) KeygenType() keygen.KeyType

KeygenType returns the keygen key type.

type ErrRequestTooLarge

type ErrRequestTooLarge struct {
	Size  int64
	Limit int64
}

ErrRequestTooLarge is an error for a request that is too large.

func (ErrRequestTooLarge) Error

func (err ErrRequestTooLarge) Error() string

type Fingerprint

type Fingerprint struct {
	Algorithm string
	Type      string
	Value     string
}

Fingerprint is the fingerprint of an SSH key.

func FingerprintSHA256

func FingerprintSHA256(k charm.PublicKey) (Fingerprint, error)

FingerprintSHA256 returns the algorithm and SHA256 fingerprint for the given key.

func (Fingerprint) String

func (f Fingerprint) String() string

String outputs a string representation of the fingerprint.

Jump to

Keyboard shortcuts

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