Skip to content

Commit

Permalink
keystore: resolve linting problems. Improve godocs.
Browse files Browse the repository at this point in the history
  • Loading branch information
hsanjuan authored and Stebalien committed Mar 14, 2020
1 parent e9e5af3 commit 4554c16
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
11 changes: 8 additions & 3 deletions keystore/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ type Keystore interface {
List() ([]string, error)
}

// ErrNoSuchKey is an error message returned when no key of a given name was found.
var ErrNoSuchKey = fmt.Errorf("no key by the given name was found")

// ErrKeyExists is an error message returned when a key already exists
var ErrKeyExists = fmt.Errorf("key by that name already exists, refusing to overwrite")

// FSKeystore is a keystore backed by files in a given directory stored on disk.
Expand All @@ -54,12 +57,13 @@ func validateName(name string) error {
return nil
}

// NewKeystore is a factory for getting instance of Keystore interface implementation
// NewKeystore returns a Keystore using the default implementation.
func NewKeystore(dir string) (Keystore, error) {
return NewEncodedFSKeystore(dir)
}

// NewEncodedFSKeystore is a factory for getting instance of EncodedFSKeystore
// NewEncodedFSKeystore is returns a filesystem-backed keystore which encodes
// key names using base32.
func NewEncodedFSKeystore(dir string) (*EncodedFSKeystore, error) {
keystore, err := NewFSKeystore(dir)

Expand All @@ -70,6 +74,7 @@ func NewEncodedFSKeystore(dir string) (*EncodedFSKeystore, error) {
return &EncodedFSKeystore{keystore}, nil
}

// NewFSKeystore returns a new filesystem-backed keystore.
func NewFSKeystore(dir string) (*FSKeystore, error) {
_, err := os.Stat(dir)
if err != nil {
Expand Down Expand Up @@ -291,7 +296,7 @@ func (ks *EncodedFSKeystore) List() ([]string, error) {
if err == nil {
list = append(list, decodedName)
} else {
log.Warningf("Ignoring keyfile with invalid encoded filename: %s", name)
log.Warnf("Ignoring keyfile with invalid encoded filename: %s", name)
}
}

Expand Down
4 changes: 2 additions & 2 deletions keystore/keystore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,12 @@ func TestMakeKeystoreNoDir(t *testing.T) {
}

func assertGetKey(ks Keystore, name string, exp ci.PrivKey) error {
out_k, err := ks.Get(name)
outK, err := ks.Get(name)
if err != nil {
return err
}

if !out_k.Equals(exp) {
if !outK.Equals(exp) {
return fmt.Errorf("key we got out didnt match expectation")
}

Expand Down
1 change: 1 addition & 0 deletions keystore/memkeystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type MemKeystore struct {
keys map[string]ci.PrivKey
}

// NewMemKeystore creates a MemKeystore.
func NewMemKeystore() *MemKeystore {
return &MemKeystore{make(map[string]ci.PrivKey)}
}
Expand Down

0 comments on commit 4554c16

Please sign in to comment.