Slight refactor of NotaryRepository.Initialize

Signed-off-by: Ying Li <ying.li@docker.com>
This commit is contained in:
Ying Li 2015-12-08 16:53:32 -08:00
parent 39d79d9844
commit 642cf7f353
1 changed files with 9 additions and 9 deletions

View File

@ -144,13 +144,17 @@ func (r *NotaryRepository) Initialize(rootKeyID string, serverManagedRoles ...st
}
// currently we only support server managing snapshots, and nothing else
managedRoles := map[string]bool{data.CanonicalTimestampRole: true}
rolesAreManaged := map[string]bool{
data.CanonicalTimestampRole: true,
data.CanonicalSnapshotRole: false,
data.CanonicalTargetsRole: false,
}
for _, role := range serverManagedRoles {
switch role {
case data.CanonicalTimestampRole:
continue // always support timestamp
case data.CanonicalSnapshotRole:
managedRoles[data.CanonicalSnapshotRole] = true
rolesAreManaged[data.CanonicalSnapshotRole] = true
default:
return fmt.Errorf(
"Notary does not support the server managing the %s key", role)
@ -188,12 +192,9 @@ func (r *NotaryRepository) Initialize(rootKeyID string, serverManagedRoles ...st
return err
}
for _, role := range data.ValidRoles {
if role == data.CanonicalRootRole {
continue
}
for role, isManaged := range rolesAreManaged {
var key data.PublicKey
if _, ok := managedRoles[role]; ok {
if isManaged {
// This key is generated by the remote server.
key, err = getRemoteKey(r.baseURL, r.gun, role, r.roundTrip)
if err != nil {
@ -232,8 +233,7 @@ func (r *NotaryRepository) Initialize(rootKeyID string, serverManagedRoles ...st
return err
}
_, dontSaveSnapshot := managedRoles[data.CanonicalSnapshotRole]
return r.saveMetadata(dontSaveSnapshot)
return r.saveMetadata(rolesAreManaged[data.CanonicalSnapshotRole])
}
// AddTarget adds a new target to the repository, forcing a timestamps check from TUF