mirror of https://github.com/docker/docs.git
updating list targets to list across multiple roles
Signed-off-by: David Lawrence <david.lawrence@docker.com> (github: endophage)
This commit is contained in:
parent
8f7e7adcef
commit
377b72a54f
|
@ -420,13 +420,13 @@ func (r *NotaryRepository) ListTargets(roles ...string) ([]*Target, error) {
|
|||
}
|
||||
|
||||
var targetList []*Target
|
||||
for _, r := range roles {
|
||||
tgts, ok := r.tufRepo.Targets[r]
|
||||
for _, role := range roles {
|
||||
tgts, ok := r.tufRepo.Targets[role]
|
||||
if !ok {
|
||||
// not every role has to exist
|
||||
continue
|
||||
}
|
||||
for name, meta := range r.tufRepo.Targets[r].Signed.Targets {
|
||||
for name, meta := range tgts.Signed.Targets {
|
||||
target := &Target{Name: name, Hashes: meta.Hashes, Length: meta.Length}
|
||||
targetList = append(targetList, target)
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ func validateRootSuccessfully(t *testing.T, rootType string) {
|
|||
assert.Len(t, repo.CertManager.TrustedCertificateStore().GetCertificates(), 0)
|
||||
|
||||
// This list targets is expected to succeed and the certificate store to have the new certificate
|
||||
_, err = repo.ListTargets()
|
||||
_, err = repo.ListTargets(data.CanonicalTargetsRole)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, repo.CertManager.TrustedCertificateStore().GetCertificates(), 1)
|
||||
|
||||
|
@ -78,7 +78,7 @@ func validateRootSuccessfully(t *testing.T, rootType string) {
|
|||
|
||||
// This list targets is expected to fail, since there already exists a certificate
|
||||
// in the store for the dnsName docker.com/notary, so TOFUS doesn't apply
|
||||
_, err = repo.ListTargets()
|
||||
_, err = repo.ListTargets(data.CanonicalTargetsRole)
|
||||
if assert.Error(t, err, "An error was expected") {
|
||||
assert.Equal(t, err, &certs.ErrValidationFail{
|
||||
Reason: "failed to validate data with current trusted certificates",
|
||||
|
|
|
@ -768,7 +768,7 @@ func testListEmptyTargets(t *testing.T, rootType string) {
|
|||
|
||||
repo, _ := initializeRepo(t, rootType, tempBaseDir, gun, ts.URL, false)
|
||||
|
||||
_, err = repo.ListTargets()
|
||||
_, err = repo.ListTargets(data.CanonicalTargetsRole)
|
||||
assert.Error(t, err) // no trust data
|
||||
}
|
||||
|
||||
|
@ -869,7 +869,7 @@ func testListTarget(t *testing.T, rootType string) {
|
|||
|
||||
fakeServerData(t, repo, mux, keys)
|
||||
|
||||
targets, err := repo.ListTargets()
|
||||
targets, err := repo.ListTargets(data.CanonicalTargetsRole)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Should be two targets
|
||||
|
@ -1056,7 +1056,7 @@ func assertPublishSucceeds(t *testing.T, repo1 *NotaryRepository) {
|
|||
|
||||
// Should be two targets
|
||||
for _, repo := range []*NotaryRepository{repo1, repo2} {
|
||||
targets, err := repo.ListTargets()
|
||||
targets, err := repo.ListTargets(data.CanonicalTargetsRole)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Len(t, targets, 2, "unexpected number of targets returned by ListTargets")
|
||||
|
@ -1113,7 +1113,7 @@ func testPublishAfterPullServerHasSnapshotKey(t *testing.T, rootType string) {
|
|||
assertRepoHasExpectedMetadata(t, repo, data.CanonicalSnapshotRole, false)
|
||||
|
||||
// list, so that the snapshot metadata is pulled from server
|
||||
targets, err := repo.ListTargets()
|
||||
targets, err := repo.ListTargets(data.CanonicalTargetsRole)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, []*Target{published}, targets)
|
||||
// listing downloaded the timestamp and snapshot metadata info
|
||||
|
@ -1436,7 +1436,7 @@ func TestRemoteServerUnavailableNoLocalCache(t *testing.T) {
|
|||
ts.URL, http.DefaultTransport, passphraseRetriever)
|
||||
assert.NoError(t, err, "error creating repo: %s", err)
|
||||
|
||||
_, err = repo.ListTargets()
|
||||
_, err = repo.ListTargets(data.CanonicalTargetsRole)
|
||||
assert.Error(t, err)
|
||||
assert.IsType(t, store.ErrServerUnavailable{}, err)
|
||||
|
||||
|
|
|
@ -164,7 +164,7 @@ func tufList(cmd *cobra.Command, args []string) {
|
|||
}
|
||||
|
||||
// Retreive the remote list of signed targets
|
||||
targetList, err := nRepo.ListTargets()
|
||||
targetList, err := nRepo.ListTargets(data.CanonicalTargetsRole, "targets/releases")
|
||||
if err != nil {
|
||||
fatalf(err.Error())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue