Skip to content

Commit

Permalink
interface: GetCryptoService
Browse files Browse the repository at this point in the history
Signed-off-by: Riyaz Faizullabhoy <[email protected]>
  • Loading branch information
riyazdf committed Sep 7, 2017
1 parent 0c55e81 commit b28e526
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions client/backwards_compatibility_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,10 @@ func Test0Dot1RepoFormat(t *testing.T) {
require.Len(t, targets, 2)

// Also check that we can add/remove keys by rotating keys
oldTargetsKeys := repo.CryptoService().ListKeys(data.CanonicalTargetsRole)
oldTargetsKeys := repo.GetCryptoService().ListKeys(data.CanonicalTargetsRole)
require.NoError(t, repo.RotateKey(data.CanonicalTargetsRole, false, nil))
require.NoError(t, repo.Publish())
newTargetsKeys := repo.CryptoService().ListKeys(data.CanonicalTargetsRole)
newTargetsKeys := repo.GetCryptoService().ListKeys(data.CanonicalTargetsRole)

require.Len(t, oldTargetsKeys, 1)
require.Len(t, newTargetsKeys, 1)
Expand Down Expand Up @@ -292,10 +292,10 @@ func Test0Dot3RepoFormat(t *testing.T) {
require.Equal(t, data.RoleName("targets/releases"), delegations[0].Name)

// Also check that we can add/remove keys by rotating keys
oldTargetsKeys := repo.CryptoService().ListKeys(data.CanonicalTargetsRole)
oldTargetsKeys := repo.GetCryptoService().ListKeys(data.CanonicalTargetsRole)
require.NoError(t, repo.RotateKey(data.CanonicalTargetsRole, false, nil))
require.NoError(t, repo.Publish())
newTargetsKeys := repo.CryptoService().ListKeys(data.CanonicalTargetsRole)
newTargetsKeys := repo.GetCryptoService().ListKeys(data.CanonicalTargetsRole)

require.Len(t, oldTargetsKeys, 1)
require.Len(t, newTargetsKeys, 1)
Expand Down
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func rootCertKey(gun data.GUN, privKey data.PrivateKey) (data.PublicKey, error)
}

// CryptoService is the getter for the repository's CryptoService
func (r *NotaryRepository) CryptoService() signed.CryptoService {
func (r *NotaryRepository) GetCryptoService() signed.CryptoService {
return r.cryptoService
}

Expand Down
2 changes: 1 addition & 1 deletion client/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type Repository interface {
// Key Operations
RotateKey(role data.RoleName, serverManagesKey bool, keyList []string) error

CryptoService() signed.CryptoService
GetCryptoService() signed.CryptoService
SetLegacyVersions(int)
GetGUN() data.GUN
}
2 changes: 1 addition & 1 deletion cmd/notary/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ func (k *keyCommander) keysRotate(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
err = nRepo.CryptoService().AddKey(rotateKeyRole, gun, privKey)
err = nRepo.GetCryptoService().AddKey(rotateKeyRole, gun, privKey)
if err != nil {
return fmt.Errorf("Error importing key: %v", err)
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/notary/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,13 +337,13 @@ func setUpRepo(t *testing.T, tempBaseDir string, gun data.GUN, ret notary.PassRe
tempBaseDir, gun, ts.URL, http.DefaultTransport, ret, trustpinning.TrustPinConfig{})
require.NoError(t, err, "error creating repo: %s", err)

rootPubKey, err := repo.CryptoService().Create(data.CanonicalRootRole, "", data.ECDSAKey)
rootPubKey, err := repo.GetCryptoService().Create(data.CanonicalRootRole, "", data.ECDSAKey)
require.NoError(t, err, "error generating root key: %s", err)

err = repo.Initialize([]string{rootPubKey.ID()})
require.NoError(t, err)

return ts, repo.CryptoService().ListAllKeys()
return ts, repo.GetCryptoService().ListAllKeys()
}

// The command line uses NotaryRepository's RotateKey - this is just testing
Expand Down Expand Up @@ -383,7 +383,7 @@ func TestRotateKeyRemoteServerManagesKey(t *testing.T) {
require.NoError(t, err, "unable to get changelist: %v", err)
require.Len(t, cl.List(), 0, "expected the changes to have been published")

finalKeys := repo.CryptoService().ListAllKeys()
finalKeys := repo.GetCryptoService().ListAllKeys()
// no keys have been created, since a remote key was specified
if role == data.CanonicalSnapshotRole.String() {
require.Len(t, finalKeys, 2)
Expand Down Expand Up @@ -438,7 +438,7 @@ func TestRotateKeyBothKeys(t *testing.T) {
require.Len(t, cl.List(), 0)

// two new keys have been created, and the old keys should still be gone
newKeys := repo.CryptoService().ListAllKeys()
newKeys := repo.GetCryptoService().ListAllKeys()
// there should be 3 keys - snapshot, targets, and root
require.Len(t, newKeys, 3)

Expand Down Expand Up @@ -499,7 +499,7 @@ func TestRotateKeyRootIsInteractive(t *testing.T) {
require.NoError(t, err, "error creating repo: %s", err)

// There should still just be one root key (and one targets and one snapshot)
allKeys := repo.CryptoService().ListAllKeys()
allKeys := repo.GetCryptoService().ListAllKeys()
require.Len(t, allKeys, 3)
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/notary/tuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,13 +418,13 @@ func importRootKey(cmd *cobra.Command, rootKey string, nRepo notaryclient.Reposi
return nil, err
}
// add root key to repo
err = nRepo.CryptoService().AddKey(data.CanonicalRootRole, "", privKey)
err = nRepo.GetCryptoService().AddKey(data.CanonicalRootRole, "", privKey)
if err != nil {
return nil, fmt.Errorf("Error importing key: %v", err)
}
rootKeyList = []string{privKey.ID()}
} else {
rootKeyList = nRepo.CryptoService().ListKeys(data.CanonicalRootRole)
rootKeyList = nRepo.GetCryptoService().ListKeys(data.CanonicalRootRole)
}

if len(rootKeyList) > 0 {
Expand Down

0 comments on commit b28e526

Please sign in to comment.