internal

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInsecurePassword         = fmt.Errorf("provided password is insecure (use --insecure to ignore this message)")
	ErrInvalidAccountName       = fmt.Errorf("account name must be a consecutive string")
	ErrMissingValues            = fmt.Errorf("account is missing required values")
	ErrInvalidAccountNameSymbol = fmt.Errorf("account name invalid. Please avoid using '@' character")
)
View Source
var (
	ErrAccountExists          = fmt.Errorf("account for group already exists")
	ErrNoSuchAccount          = fmt.Errorf("account not found")
	ErrInvalidGroupName       = fmt.Errorf("group name must be a consecutive string")
	ErrInvalidGroupNameSymbol = fmt.Errorf("group name invalid. Please avoid using '@' character")
)
View Source
var (
	ErrNotSetup     = fmt.Errorf("sherlock needs to bee set-up first (use sherlock setup)")
	ErrNoSuchGroup  = fmt.Errorf("provided group cannot be found (use sherlock add group)")
	ErrWrongKey     = fmt.Errorf("wrong group key")
	ErrInvalidQuery = fmt.Errorf("invalid query. Query should be %q", "group@account")
)

Functions

func AutoGeneratePassword added in v0.3.2

func AutoGeneratePassword(passwordLength int) (string, error)

func FilterByTag

func FilterByTag(tag string) func(*account) bool

func NewAccount

func NewAccount(query, password, tag string, insecure bool) (*account, error)

NewAccount creates a new Account and if insecure=false checks the password strength returning an err if strength security.Low

func NewGroup

func NewGroup(name string) (*group, error)

func SplitQuery added in v0.3.2

func SplitQuery(query string) (string, string, error)

SplitQuery separates the user query into it pieces (group, account)

quires not following the format will result in a ErrInvalidQuery error format: group@account

Types

type FileSystem

type FileSystem interface {
	InitFs(initVault []byte) error
	CreateGroup(name string, initVault []byte) error
	GroupExists(name string) error
	VaultExists(group string) error
	ReadGroupVault(group string) ([]byte, error)
	Delete(ctx context.Context, gid string) error
	Write(ctx context.Context, gid string, data []byte) error
	ReadRegisteredGroups() ([]string, error)
}

FileSystem declares the functions sherlock requires to interact with the underlying file system

type Sherlock

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

func NewSherlock

func NewSherlock(fs FileSystem) *Sherlock

New return new Sherlock instance

func (*Sherlock) CheckGroupKey added in v0.3.2

func (sh *Sherlock) CheckGroupKey(ctx context.Context, query, groupKey string) error

CheckGroupKey performs a pre-check to check if groupKey is correct

it should only be used to verify that an inputed groupKey by the user is matching the group the user is trying to access.

func (*Sherlock) DeleteGroup added in v0.3.2

func (sh *Sherlock) DeleteGroup(ctx context.Context, gid string) error

DeleteGroup irreversible deletes a group from sherlock and the underlying file-system

func (Sherlock) GetAccount

func (sh Sherlock) GetAccount(query string, groupKey string) (*account, error)

GetAccount looks up the requested account

the lookup is performed through the query (group@account).

func (Sherlock) GroupExists

func (sh Sherlock) GroupExists(name string) error

GroupExists looks up if a group exists within sherlock

func (Sherlock) IsSetUp

func (sh Sherlock) IsSetUp() error

IsSetUp verifies that sherlock is operational

to be operational there must be a folder $HOME/.sherlock/group with the default group and an encrypted default vault for which the user has set a group password.

func (Sherlock) LoadGroup

func (sh Sherlock) LoadGroup(gid string, groupKey string) (*group, error)

LoadGroup loads a group

it wraps the reading of the group and the decryption functions together

func (Sherlock) ReadRegisteredGroups added in v0.3.2

func (sh Sherlock) ReadRegisteredGroups() ([]string, error)

ReadRegisteredGroups loads saved groups

func (*Sherlock) Setup

func (sh *Sherlock) Setup(groupKey string) error

Setup sets the sherlock environment up

the env requires to have an default group with an encrypted default vault sitting in $HOME/.sherlock/group.

func (Sherlock) SetupGroup

func (sh Sherlock) SetupGroup(name string, groupKey string, insecure bool) error

SetupGroup creates a new group in sherlock

a group creation will be rejected if the GID already exits, or the groupKey is to weak (if !insecure). The created group will be initialized with an encrypted default vault.

func (Sherlock) UpdateState added in v0.3.2

func (sh Sherlock) UpdateState(ctx context.Context, query, groupKey string, opt StateOption) error

UpdateState executes the passed in StateOption to perform state changes on a group

it allows to modify a group/account (adding accounts, changing account) through the passed StateOption.

type StateOption added in v0.3.2

type StateOption func(g *group, acc string) error

StateOption describes a function with can alter the state of a group.

func OptAccDelete added in v0.3.2

func OptAccDelete() StateOption

OptAccDelete returns a StateOption deleting an account if it exists

func OptAccName added in v0.3.2

func OptAccName(name string) StateOption

OptAccName returns a StateOption to change an account name

func OptAccPassword added in v0.3.2

func OptAccPassword(password string, insecure bool) StateOption

OptAccPassword returns a StateOption to change an account password

func OptAddAccount added in v0.3.2

func OptAddAccount(account *account) StateOption

OptAddAccount returns a StateOption allowing to append an account to an group

func OptsAccTag added in v0.3.2

func OptsAccTag(tag string) StateOption

OptsAccTag returns a StateOption with allows to change the tag field of an account

Jump to

Keyboard shortcuts

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