Skip to content

Commit

Permalink
Merge pull request #1250 from ashfall/trustmanager-move
Browse files Browse the repository at this point in the history
Move key import/export logic to trustmanager from utils
  • Loading branch information
endophage authored Oct 23, 2017
2 parents fab4c67 + bfc27a6 commit 5d55a30
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 23 deletions.
9 changes: 4 additions & 5 deletions cmd/notary/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/docker/notary/trustmanager"
"github.com/docker/notary/tuf/data"
tufutils "github.com/docker/notary/tuf/utils"
"github.com/docker/notary/utils"
)

var cmdKeyTemplate = usageTemplate{
Expand Down Expand Up @@ -524,7 +523,7 @@ func (k *keyCommander) importKeys(cmd *cobra.Command, args []string) error {
return err
}
defer from.Close()
if err = utils.ImportKeys(from, importers, k.importRole, k.keysImportGUN, k.getRetriever()); err != nil {
if err = trustmanager.ImportKeys(from, importers, k.importRole, k.keysImportGUN, k.getRetriever()); err != nil {
return err
}
}
Expand Down Expand Up @@ -566,15 +565,15 @@ func (k *keyCommander) exportKeys(cmd *cobra.Command, args []string) error {
return fmt.Errorf("Only the --gun or --key flag may be provided, not a mix of the two flags")
}
for _, gun := range k.exportGUNs {
return utils.ExportKeysByGUN(out, fileStore, gun)
return trustmanager.ExportKeysByGUN(out, fileStore, gun)
}
} else if len(k.exportKeyIDs) > 0 {
return utils.ExportKeysByID(out, fileStore, k.exportKeyIDs)
return trustmanager.ExportKeysByID(out, fileStore, k.exportKeyIDs)
}
// export everything
keys := fileStore.ListFiles()
for _, k := range keys {
err := utils.ExportKeys(out, fileStore, k)
err := trustmanager.ExportKeys(out, fileStore, k)
if err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/notary/keys_nonpkcs11.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@ import (
"github.com/docker/notary"
store "github.com/docker/notary/storage"
"github.com/docker/notary/trustmanager"
"github.com/docker/notary/utils"
)

func getYubiStore(fileKeyStore trustmanager.KeyStore, ret notary.PassRetriever) (trustmanager.KeyStore, error) {
return nil, errors.New("Not built with hardware support")
}

func getImporters(baseDir string, _ notary.PassRetriever) ([]utils.Importer, error) {
func getImporters(baseDir string, _ notary.PassRetriever) ([]trustmanager.Importer, error) {
fileStore, err := store.NewPrivateKeyFileStorage(baseDir, notary.KeyExtension)
if err != nil {
return nil, err
}
return []utils.Importer{fileStore}, nil
return []trustmanager.Importer{fileStore}, nil
}
5 changes: 2 additions & 3 deletions cmd/notary/keys_pkcs11.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ import (
store "github.com/docker/notary/storage"
"github.com/docker/notary/trustmanager"
"github.com/docker/notary/trustmanager/yubikey"
"github.com/docker/notary/utils"
)

func getYubiStore(fileKeyStore trustmanager.KeyStore, ret notary.PassRetriever) (*yubikey.YubiStore, error) {
return yubikey.NewYubiStore(fileKeyStore, ret)
}

func getImporters(baseDir string, ret notary.PassRetriever) ([]utils.Importer, error) {
func getImporters(baseDir string, ret notary.PassRetriever) ([]trustmanager.Importer, error) {

var importers []utils.Importer
var importers []trustmanager.Importer
if yubikey.IsAccessible() {
yubiStore, err := getYubiStore(nil, ret)
if err == nil {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion utils/keys.go → trustmanager/keys.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package utils
package trustmanager

import (
"encoding/pem"
Expand Down
12 changes: 1 addition & 11 deletions utils/keys_test.go → trustmanager/keys_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package utils
package trustmanager

import (
"bytes"
Expand All @@ -16,16 +16,6 @@ import (
"github.com/stretchr/testify/require"
)

const cannedPassphrase = "passphrase"

var passphraseRetriever = func(keyID string, alias string, createNew bool, numAttempts int) (string, bool, error) {
if numAttempts > 5 {
giveup := true
return "", giveup, errors.New("passPhraseRetriever failed after too many requests")
}
return cannedPassphrase, false, nil
}

type TestImportStore struct {
data map[string][]byte
}
Expand Down

0 comments on commit 5d55a30

Please sign in to comment.