mirror of https://github.com/docker/docs.git
Slight refactor of NotaryRepository.Initialize
Signed-off-by: Ying Li <ying.li@docker.com>
This commit is contained in:
parent
39d79d9844
commit
642cf7f353
|
@ -144,13 +144,17 @@ func (r *NotaryRepository) Initialize(rootKeyID string, serverManagedRoles ...st
|
||||||
}
|
}
|
||||||
|
|
||||||
// currently we only support server managing snapshots, and nothing else
|
// 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 {
|
for _, role := range serverManagedRoles {
|
||||||
switch role {
|
switch role {
|
||||||
case data.CanonicalTimestampRole:
|
case data.CanonicalTimestampRole:
|
||||||
continue // always support timestamp
|
continue // always support timestamp
|
||||||
case data.CanonicalSnapshotRole:
|
case data.CanonicalSnapshotRole:
|
||||||
managedRoles[data.CanonicalSnapshotRole] = true
|
rolesAreManaged[data.CanonicalSnapshotRole] = true
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"Notary does not support the server managing the %s key", role)
|
"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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, role := range data.ValidRoles {
|
for role, isManaged := range rolesAreManaged {
|
||||||
if role == data.CanonicalRootRole {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
var key data.PublicKey
|
var key data.PublicKey
|
||||||
if _, ok := managedRoles[role]; ok {
|
if isManaged {
|
||||||
// This key is generated by the remote server.
|
// This key is generated by the remote server.
|
||||||
key, err = getRemoteKey(r.baseURL, r.gun, role, r.roundTrip)
|
key, err = getRemoteKey(r.baseURL, r.gun, role, r.roundTrip)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -232,8 +233,7 @@ func (r *NotaryRepository) Initialize(rootKeyID string, serverManagedRoles ...st
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, dontSaveSnapshot := managedRoles[data.CanonicalSnapshotRole]
|
return r.saveMetadata(rolesAreManaged[data.CanonicalSnapshotRole])
|
||||||
return r.saveMetadata(dontSaveSnapshot)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddTarget adds a new target to the repository, forcing a timestamps check from TUF
|
// AddTarget adds a new target to the repository, forcing a timestamps check from TUF
|
||||||
|
|
Loading…
Reference in New Issue