Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move key import/export logic to trustmanager from utils #1250

Merged
merged 1 commit into from
Oct 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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