connections

package
v0.0.0-...-141c82c Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConnectionHasBeenClosed                       = errors.New("the connection has been closed")
	ErrExpirationDurationMustBeGreaterThan0          = errors.New("the expiration duration must be greater than 0")
	ErrHostnamesMismatchForThisToken                 = errors.New("the hostname from the request does not match the one that initiated the connection")
	ErrInvalidTokenFormat                            = errors.New("the token has not a valid format")
	ErrNoConnectionAssociatedThisAuthenticationToken = errors.New("there is no connection associated to this authentication token")
	ErrTokenDoesNotExist                             = errors.New("the token does not exist")
	ErrTokenHasExpired                               = errors.New("the token has expired")
	ErrTokenIsRequired                               = errors.New("the token is required")
	ErrWalletNameIsRequired                          = errors.New("the wallet name is required")
	ErrWalletPassphraseIsRequired                    = errors.New("the wallet passphrase is required")
)

Functions

func DeleteAPIToken

func DeleteAPIToken(tokenStore TokenStore, rawToken string) error

Types

type GenerateAPITokenHandler

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

func NewGenerateAPITokenHandler

func NewGenerateAPITokenHandler(
	walletStore api.WalletStore,
	tokenStore TokenStore,
	timeService TimeService,
) *GenerateAPITokenHandler

func (*GenerateAPITokenHandler) Handle

type GenerateAPITokenParams

type GenerateAPITokenParams struct {
	Description string                       `json:"name"`
	ExpiresIn   *time.Duration               `json:"expireIn"`
	Wallet      GenerateAPITokenWalletParams `json:"wallet"`
}

type GenerateAPITokenWalletParams

type GenerateAPITokenWalletParams struct {
	Name       string `json:"name"`
	Passphrase string `json:"passphrase"`
}

type ListAPITokensResult

type ListAPITokensResult struct {
	Tokens []TokenSummary `json:"tokens"`
}

func ListAPITokens

func ListAPITokens(tokenStore TokenStore) (ListAPITokensResult, error)

type Manager

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

Manager holds the opened connections between the third-party applications and the wallets.

func NewManager

func NewManager(timeService TimeService, walletStore WalletStore, tokenStore TokenStore) (*Manager, error)

func (*Manager) ConnectedWallet

func (m *Manager) ConnectedWallet(hostname string, token Token) (api.ConnectedWallet, error)

ConnectedWallet retrieves the wallet associated to the specified token.

func (*Manager) EndAllSessionConnections

func (m *Manager) EndAllSessionConnections()

func (*Manager) EndSessionConnection

func (m *Manager) EndSessionConnection(hostname, walletName string)

func (*Manager) EndSessionConnectionWithToken

func (m *Manager) EndSessionConnectionWithToken(token Token)

func (*Manager) ListSessionConnections

func (m *Manager) ListSessionConnections() []api.Connection

ListSessionConnections lists all the session connections as a list of pairs of hostname/wallet name. The list is sorted, first, by hostname, and, then, by wallet name.

func (*Manager) StartSession

func (m *Manager) StartSession(hostname string, w wallet.Wallet) (Token, error)

StartSession initializes a connection between a wallet and a third-party application. If a connection already exists, it's disconnected and a new token is generated.

type TimeService

type TimeService interface {
	Now() time.Time
}

type Token

type Token string

func AsToken

func AsToken(token string) (Token, error)

func GenerateToken

func GenerateToken() Token

func (Token) Short

func (t Token) Short() string

func (Token) String

func (t Token) String() string

type TokenDescription

type TokenDescription struct {
	Description    string            `json:"description"`
	CreationDate   time.Time         `json:"creationDate"`
	ExpirationDate *time.Time        `json:"expirationDate"`
	Token          Token             `json:"token"`
	Wallet         WalletCredentials `json:"wallet"`
}

func DescribeAPIToken

func DescribeAPIToken(tokenStore TokenStore, rawToken string) (TokenDescription, error)

type TokenStore

type TokenStore interface {
	TokenExists(token Token) (bool, error)
	ListTokens() ([]TokenSummary, error)
	DescribeToken(token Token) (TokenDescription, error)
	SaveToken(tokenConfig TokenDescription) error
	DeleteToken(token Token) error
	OnUpdate(callbackFn func(ctx context.Context, tokens ...TokenDescription))
}

TokenStore is the component used to retrieve and update the API tokens from the computer.

type TokenSummary

type TokenSummary struct {
	Description    string     `json:"description"`
	Token          Token      `json:"token"`
	CreationDate   time.Time  `json:"creationDate"`
	ExpirationDate *time.Time `json:"expirationDate"`
}

type WalletCredentials

type WalletCredentials struct {
	Name       string `json:"name"`
	Passphrase string `json:"passphrase"`
}

type WalletStore

type WalletStore interface {
	UnlockWallet(ctx context.Context, name, passphrase string) error
	GetWallet(ctx context.Context, name string) (wallet.Wallet, error)
	OnUpdate(callbackFn func(context.Context, wallet.Event))
}

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
store
v1

Jump to

Keyboard shortcuts

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