store

package
v2.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2024 License: Apache-2.0 Imports: 21 Imported by: 1

Documentation

Index

Constants

View Source
const Accounts = "accounts"
View Source
const CredsDir = "creds"
View Source
const CredsExtension = ".creds"
View Source
const Empty = ""
View Source
const KeysDir = "keys"
View Source
const NKeyExtension = ".nk"
View Source
const NKeysPathEnv = "NKEYS_PATH"
View Source
const NSCFile = ".nsc"
View Source
const NoStoreSetError = "no store set"
View Source
const Users = "users"
View Source
const Version = "1"

Variables

View Source
var ErrNoStoreSet = errors.New(NoStoreSetError)
View Source
var ErrNotExist = errors.New("resource does not exist")
View Source
var ErrSkipChildren = errors.New("skip node")
View Source
var ErrStopWalking = errors.New("found node")
View Source
var KeyStorePath string
View Source
var NscNotGitIgnore bool

Functions

func AbbrevHomePaths

func AbbrevHomePaths(fp string) string

func AddGitIgnore

func AddGitIgnore(dir string) error

func ExtractSeed

func ExtractSeed(s string) (nkeys.KeyPair, error)

func GetKeyPath

func GetKeyPath(pubkey string) string

func GetKeysDir

func GetKeysDir() string

func IndentMessage

func IndentMessage(s string, prefix string) string

func IsAccountServerURL added in v2.8.3

func IsAccountServerURL(u string) bool

func IsJwtName

func IsJwtName(name string) bool

func IsNatsUrl

func IsNatsUrl(url string) bool

func IsNotExist

func IsNotExist(err error) bool

func IsOldKeyRing

func IsOldKeyRing(dir string) (bool, error)

func IsPublicKey

func IsPublicKey(kind nkeys.PrefixByte, key string) bool

func IsReport

func IsReport(s Status) bool

func IsResolverURL added in v2.8.3

func IsResolverURL(u string) bool

func JwtName

func JwtName(name string) string

func KeyPairTypeOk

func KeyPairTypeOk(kind nkeys.PrefixByte, kp nkeys.KeyPair) bool

func KeyType

func KeyType(kp nkeys.KeyPair) (nkeys.PrefixByte, error)

func KeysNeedMigration

func KeysNeedMigration() (bool, error)

func Match

func Match(pubkey string, kp nkeys.KeyPair) bool

func MaybeMakeDir

func MaybeMakeDir(dir string) error

func Migrate

func Migrate() (string, error)

func NewAccountNotExistErr

func NewAccountNotExistErr(name string) error

func NewOperatorNotExistErr

func NewOperatorNotExistErr(name string) error

func NewResourceNotExistErr

func NewResourceNotExistErr(kind string, name string) error

func NewUserNotExistErr

func NewUserNotExistErr(name string) error

func PlainName

func PlainName(name string) string

func PubKeyType

func PubKeyType(pk string) (nkeys.PrefixByte, error)

func ResolveKey

func ResolveKey(value string) (nkeys.KeyPair, error)

Resolve a key value provided as a flag - value could be an actual nkey or a path to an nkey

func SafeName

func SafeName(n string) string

func StoreKey

func StoreKey(kp nkeys.KeyPair) (string, error)

func Walk

func Walk(root *Node, walkFn WalkFunc) error

func Write

func Write(name string, data []byte) error

Types

type Context

type Context struct {
	Operator Entity
	Account  Entity
	KeyStore KeyStore
	Store    *Store
}

func (*Context) DefaultUser

func (ctx *Context) DefaultUser(accountName string) *string

Returns an user name for the account if there's only one user

func (*Context) DefaultUserClaim

func (ctx *Context) DefaultUserClaim(accountName string) (*jwt.UserClaims, error)

func (*Context) GetAccountKeys

func (ctx *Context) GetAccountKeys(name string) ([]string, error)

GetAccountKeys returns the public keys for the named account followed by its signing keys

func (*Context) GetOperatorKeys

func (ctx *Context) GetOperatorKeys() ([]string, error)

GetOperatorKeys returns the public keys for the operator followed by its signing keys

func (*Context) ResolveKey

func (ctx *Context) ResolveKey(flagValue string, kinds ...nkeys.PrefixByte) (nkeys.KeyPair, error)

func (*Context) SetContext

func (ctx *Context) SetContext(name string, pub string) error

type Entity

type Entity struct {
	Name      string
	PublicKey string
}

type Formatter

type Formatter interface {
	Format(indent string) string
}

type IStore added in v2.8.1

type IStore interface {
	IsManaged() bool
	Resolve(name ...string) string
	Has(name ...string) bool
	HasAccount(name string) bool
	Read(name ...string) ([]byte, error)
	Write(data []byte, name ...string) error
	Delete(name ...string) error
	ListSubContainers(name ...string) ([]string, error)
	ListEntries(name ...string) ([]string, error)
	StoreClaim(data []byte) (*Report, error)
	StoreRaw(data []byte) error
	GetName() string
	LoadClaim(name ...string) (*jwt.GenericClaims, error)
	ReadOperatorClaim() (*jwt.OperatorClaims, error)
	ReadRawOperatorClaim() ([]byte, error)
	ReadAccountClaim(name string) (*jwt.AccountClaims, error)
	ReadRawAccountClaim(name string) ([]byte, error)
	ReadUserClaim(accountName string, name string) (*jwt.UserClaims, error)
	ReadRawUserClaim(accountName string, name string) ([]byte, error)
}

type Info

type Info struct {
	Managed bool   `json:"managed"`
	Name    string `json:"name"`
	Kind    string `json:"kind"`
	Version string `json:"version"`
}

func (*Info) String

func (i *Info) String() string

type JobStatus

type JobStatus struct {
	Warn string
	OK   string
	Err  error
}

func (*JobStatus) Message

func (js *JobStatus) Message() string

type KeyStore

type KeyStore struct {
	Env string
}

func NewKeyStore

func NewKeyStore(environmentName string) KeyStore

func (*KeyStore) AllKeys

func (k *KeyStore) AllKeys() ([]string, error)

func (*KeyStore) CalcAccountCredsDir

func (k *KeyStore) CalcAccountCredsDir(account string) string

func (*KeyStore) CalcUserCredsPath

func (k *KeyStore) CalcUserCredsPath(account string, user string) string

func (*KeyStore) GetKeyPair

func (k *KeyStore) GetKeyPair(pubkey string) (nkeys.KeyPair, error)

func (*KeyStore) GetKeyPath

func (k *KeyStore) GetKeyPath(pubkey string) string

func (*KeyStore) GetPublicKey

func (k *KeyStore) GetPublicKey(pubkey string) (string, error)

func (*KeyStore) GetSeed

func (k *KeyStore) GetSeed(pubkey string) (string, error)

func (*KeyStore) GetUserCredsPath

func (k *KeyStore) GetUserCredsPath(account string, user string) string

func (*KeyStore) HasPrivateKey

func (k *KeyStore) HasPrivateKey(pubkey string) bool

func (*KeyStore) MaybeStoreUserCreds

func (k *KeyStore) MaybeStoreUserCreds(account string, user string, data []byte) (string, error)

func (*KeyStore) Read

func (k *KeyStore) Read(path string) (nkeys.KeyPair, error)

func (*KeyStore) Remove

func (k *KeyStore) Remove(pubkey string) error

func (*KeyStore) Store

func (k *KeyStore) Store(kp nkeys.KeyPair) (string, error)

type KeyTypeFn

type KeyTypeFn func(string) bool

type MultiJob

type MultiJob []Status

func (MultiJob) Code

func (mj MultiJob) Code() StatusCode

func (MultiJob) Message

func (mj MultiJob) Message() string

func (MultiJob) Summary

func (mj MultiJob) Summary() (string, error)

type NKeyFactory

type NKeyFactory func() (nkeys.KeyPair, error)

type NamedKey

type NamedKey struct {
	Name string
	KP   nkeys.KeyPair
}

type Node

type Node struct {
	Parent   *Node
	Data     interface{}
	Children []*Node
}

func NewNode

func NewNode(data interface{}) *Node

func (*Node) Add

func (n *Node) Add(cn *Node) *Node

func (*Node) Delete

func (n *Node) Delete()

type PrintOption

type PrintOption int
const (
	ALL PrintOption = iota
	DetailsOnly
	DetailsOnErrorOrWarning
)

type Report

type Report struct {
	Label      string
	StatusCode StatusCode
	Details    []Status
	Opt        PrintOption
	Data       []byte
	ReportSum  bool
}

func NewDetailedReport

func NewDetailedReport(summary bool) *Report

func NewReport

func NewReport(code StatusCode, format string, args ...interface{}) *Report

func ToReport

func ToReport(s Status) *Report

func (*Report) Add

func (r *Report) Add(status ...Status)

func (*Report) AddError

func (r *Report) AddError(format string, args ...interface{}) *Report

func (*Report) AddFromError

func (r *Report) AddFromError(err error)

func (*Report) AddOK

func (r *Report) AddOK(format string, args ...interface{}) *Report

func (*Report) AddStatus

func (r *Report) AddStatus(code StatusCode, format string, args ...interface{}) *Report

func (*Report) AddWarning

func (r *Report) AddWarning(format string, args ...interface{}) *Report

func (*Report) Code

func (r *Report) Code() StatusCode

func (*Report) Format

func (r *Report) Format(indent string) string

func (*Report) HasErrors

func (r *Report) HasErrors() bool

func (*Report) HasNoErrors

func (r *Report) HasNoErrors() bool

func (*Report) HasServerMessages

func (r *Report) HasServerMessages() bool

func (*Report) Message

func (r *Report) Message() string

func (*Report) OK

func (r *Report) OK() bool

func (*Report) Summary

func (r *Report) Summary() (string, error)

type ResourceErr

type ResourceErr struct {
	Kind     string
	Resource string
	Err      error
}

func (*ResourceErr) Error

func (e *ResourceErr) Error() string

type ServerMessage

type ServerMessage struct {
	SrvMessage string
}

func (*ServerMessage) Code

func (s *ServerMessage) Code() StatusCode

func (*ServerMessage) Format

func (s *ServerMessage) Format(prefix string) string

func (*ServerMessage) Message

func (s *ServerMessage) Message() string

type Status

type Status interface {
	Code() StatusCode
	Message() string
}

func ErrorStatus

func ErrorStatus(format string, args ...interface{}) Status

func FromError

func FromError(err error) Status

func HoistChildren

func HoistChildren(s Status) []Status

func NewServerMessage

func NewServerMessage(format string, args ...interface{}) Status

func OKStatus

func OKStatus(format string, args ...interface{}) Status

func PullAccount

func PullAccount(u string) (Status, error)

func PullReport

func PullReport(code int, data []byte) Status

func PushAccount

func PushAccount(u string, data []byte) (Status, error)

func PushReport

func PushReport(code int, data []byte) Status

func WarningStatus

func WarningStatus(format string, args ...interface{}) Status

type StatusCode

type StatusCode int
const (
	NONE StatusCode = iota
	OK
	WARN
	ERR
)

type Statuses

type Statuses []Status

func (Statuses) Message

func (ms Statuses) Message() string

type Store

type Store struct {
	sync.Mutex
	Dir            string
	Info           Info
	DefaultAccount string
}

Store is a directory that contains nsc assets

func CreateStore

func CreateStore(env string, operatorsDir string, operator *NamedKey) (*Store, error)

CreateStore creates a new Store in the specified directory. CreateStore will create the necessary directories and store the public key.

func LoadStore

func LoadStore(dir string) (*Store, error)

LoadStore loads a store from the specified directory path.

func (*Store) ClaimType

func (s *Store) ClaimType(data []byte) (jwt.ClaimType, error)

func (*Store) Delete

func (s *Store) Delete(name ...string) error

Delete the specified file name or subpath from the store

func (*Store) GetContext

func (s *Store) GetContext() (*Context, error)

func (*Store) GetName

func (s *Store) GetName() string

func (*Store) GetRootPublicKey

func (s *Store) GetRootPublicKey() (string, error)

func (*Store) Has

func (s *Store) Has(name ...string) bool

Has returns true if the specified asset exists

func (*Store) HasAccount

func (s *Store) HasAccount(name string) bool

func (*Store) IsManaged

func (s *Store) IsManaged() bool

func (*Store) List

func (s *Store) List(path ...string) ([]fs.DirEntry, error)

func (*Store) ListEntries

func (s *Store) ListEntries(name ...string) ([]string, error)

func (*Store) ListSubContainers

func (s *Store) ListSubContainers(name ...string) ([]string, error)

func (*Store) LoadClaim

func (s *Store) LoadClaim(name ...string) (*jwt.GenericClaims, error)

func (*Store) LoadDefaultEntity

func (s *Store) LoadDefaultEntity(kind string) (*jwt.GenericClaims, error)

func (*Store) LoadRootClaim

func (s *Store) LoadRootClaim() (*jwt.GenericClaims, error)

func (*Store) Read

func (s *Store) Read(name ...string) ([]byte, error)

Read reads the specified file name or subpath from the store

func (*Store) ReadAccountClaim

func (s *Store) ReadAccountClaim(name string) (*jwt.AccountClaims, error)

func (*Store) ReadOperatorClaim

func (s *Store) ReadOperatorClaim() (*jwt.OperatorClaims, error)

func (*Store) ReadRawAccountClaim

func (s *Store) ReadRawAccountClaim(name string) ([]byte, error)

func (*Store) ReadRawOperatorClaim

func (s *Store) ReadRawOperatorClaim() ([]byte, error)

func (*Store) ReadRawUserClaim

func (s *Store) ReadRawUserClaim(accountName string, name string) ([]byte, error)

func (*Store) ReadUserClaim

func (s *Store) ReadUserClaim(accountName string, name string) (*jwt.UserClaims, error)

func (*Store) Resolve

func (s *Store) Resolve(name ...string) string

func (*Store) StoreClaim

func (s *Store) StoreClaim(data []byte) (*Report, error)

func (*Store) StoreRaw

func (s *Store) StoreRaw(data []byte) error

func (*Store) Write

func (s *Store) Write(data []byte, name ...string) error

Write writes the specified file name or subpath in the store

type Summarizer

type Summarizer interface {
	Summary() (string, error)
}

type WalkFunc

type WalkFunc func(*Node) error

Jump to

Keyboard shortcuts

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