service

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DBInit   DBVerb = "init"
	DBLock   DBVerb = "lock"
	DBUnlock DBVerb = "unlock"
	DBStatus DBVerb = "status"
	DBRotate DBVerb = "rotate"
	GET      Verb   = "GET"
	POST     Verb   = "POST"
	DELETE   Verb   = "DELETE"
)
View Source
const (
	Bucket = "piggybank"
)

Variables

View Source
var SubjectVerbs = map[DBVerb]string{
	DBInit:   fmt.Sprintf("%s.%s", databaseSubject, databaseInitSubject),
	DBLock:   fmt.Sprintf("%s.%s", databaseSubject, databaseLockSubject),
	DBUnlock: fmt.Sprintf("%s.%s", databaseSubject, databaseUnlockSubject),
	DBStatus: fmt.Sprintf("%s.%s", databaseSubject, databaseStatusSubject),
	DBRotate: fmt.Sprintf("%s.%s", databaseSubject, databaseRotateSubject),
}

Functions

func AddRecord

func AddRecord(r micro.Request, app AppContext) error

func AppGroup added in v0.1.1

func AppGroup(svc micro.Service, logger *logr.Logger, appCtx AppContext)

func AppHandler

func AppHandler(logger *logr.Logger, h AppHandlerFunc, app AppContext) micro.HandlerFunc

ErrorHandler wraps a normal micro endpoint and allows for returning errors natively. Errors are checked and if an error is a client error, details are returned, otherwise a 500 is returned and logged

func DBGroup added in v0.1.1

func DBGroup(svc micro.Service, logger *logr.Logger, appCtx AppContext)

func DeleteRecord

func DeleteRecord(r micro.Request, app AppContext) error

func GetClientDBVerbs added in v0.1.1

func GetClientDBVerbs() []string

func GetRecord

func GetRecord(r micro.Request, app AppContext) error

func HashPassword

func HashPassword(s string) string

func Initialize

func Initialize(r micro.Request, app AppContext) error

func Lock

func Lock(r micro.Request, app AppContext) error

func RotateKey added in v0.3.0

func RotateKey(r micro.Request, app AppContext) error

func SanitizeKey added in v0.3.0

func SanitizeKey(k string) string

func Status

func Status(r micro.Request, app AppContext) error

Wrap Status in secret handler so it will catch locked requests

func Unlock

func Unlock(r micro.Request, app AppContext) error

func WatchForConfig

func WatchForConfig(logger *logr.Logger, js nats.JetStreamContext)

Types

type AppContext

type AppContext struct {
	KV nats.KeyValue
	// contains filtered or unexported fields
}

func (*AppContext) AddRecord

func (a *AppContext) AddRecord(k KV) error

func (*AppContext) DeleteRecord

func (a *AppContext) DeleteRecord(k KV) error

func (*AppContext) GetRecord

func (a *AppContext) GetRecord(k KV) ([]byte, error)

func (*AppContext) Rotate added in v0.3.0

func (a *AppContext) Rotate(currentKey string) ([]byte, error)

func (*AppContext) Unlock

func (a *AppContext) Unlock(k KV) error

type AppHandlerFunc

type AppHandlerFunc func(micro.Request, AppContext) error

func SecretHandler

func SecretHandler(a AppHandlerFunc) AppHandlerFunc

SecretHandler wraps any secret handlers to check if database is currently locked

type Backend

type Backend interface {
	Watcher
}

type Client added in v0.1.1

type Client struct {
	Conn *nats.Conn
}

func (*Client) Delete added in v0.2.0

func (c *Client) Delete(key string) (string, error)

func (*Client) Do added in v0.1.1

func (c *Client) Do(request Request) (string, error)

func (*Client) Get added in v0.2.0

func (c *Client) Get(key string) (string, error)

func (*Client) Post added in v0.2.0

func (c *Client) Post(key string, data []byte) (string, error)

type ClientError

type ClientError struct {
	Code    int
	Details string
}

func NewClientError

func NewClientError(err error, code int) ClientError

func (ClientError) As

func (c ClientError) As(target any) bool

func (*ClientError) Body

func (c *ClientError) Body() []byte

func (*ClientError) CodeString

func (c *ClientError) CodeString() string

func (ClientError) Error

func (c ClientError) Error() string

type DBVerb added in v0.1.1

type DBVerb string

func (DBVerb) String added in v0.1.1

func (d DBVerb) String() string

type DatabaseKey

type DatabaseKey struct {
	DBKey string `json:"database_key"`
}

type DbRequest added in v0.1.1

type DbRequest struct {
	Verb DBVerb
	Key  string
}

type JetStreamRecord

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

func NewJSRecord

func NewJSRecord() *JetStreamRecord

NewJSRecord returns a new JetStreamRecord

func (*JetStreamRecord) Bucket

func (j *JetStreamRecord) Bucket() string

Bucket returns the Bucket value for the JetStreamRecord

func (*JetStreamRecord) Decrypt

func (j *JetStreamRecord) Decrypt() ([]byte, error)

Decrypt decrypts the value of the JetStreamRecord using the encryption key stored in the record

func (*JetStreamRecord) Encrypt

func (j *JetStreamRecord) Encrypt() error

Encrypt encrypts the value of the JetStreamRecord using the encryption key stored in the record

func (*JetStreamRecord) Key

func (j *JetStreamRecord) Key() string

Key returns the Key for the JetStreamRecord

func (*JetStreamRecord) Value

func (j *JetStreamRecord) Value() []byte

Value returns the JetStreamRecord value

type KV

type KV interface {
	Bucket() string
	Key() string
	Value() []byte
	Encrypt() error
}

type Password

type Password struct {
	PlainText string `json:"password"`
	// contains filtered or unexported fields
}

func NewPassword

func NewPassword() *Password

NewPassword returns a pointer to a new password.

type Request added in v0.1.1

type Request struct {
	Subject string
	Data    []byte
}

func NewDBRequest added in v0.1.1

func NewDBRequest(verb DBVerb, key string) (Request, error)

func NewRequest added in v0.2.0

func NewRequest(verb Verb, key string) (Request, error)

type ResponseError added in v0.2.1

type ResponseError struct {
	Error string `json:"error"`
}

type ResponseMessage

type ResponseMessage struct {
	Details string `json:"details,omitempty"`
}

ResponseMessage holds a response to the caller

type RotateRequest added in v0.3.0

type RotateRequest struct {
	CurrentKey string `json:"current_key"`
}

type Verb added in v0.2.0

type Verb string

type Watcher

type Watcher interface {
	Watch()
}

Jump to

Keyboard shortcuts

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