Move the successful removal print

Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
This commit is contained in:
Nassim 'Nass' Eddequiouaq 2018-06-08 09:21:36 -07:00
parent 5ebb7a65ab
commit 2b3361cc1a
2 changed files with 9 additions and 7 deletions

View File

@ -43,11 +43,9 @@ func removeSigner(cli command.Cli, options signerRemoveOptions) error {
var errRepos []string
for _, repo := range options.repos {
fmt.Fprintf(cli.Out(), "Removing signer \"%s\" from %s...\n", options.signer, repo)
if didRemove, err := removeSingleSigner(cli, repo, options.signer, options.forceYes); err != nil {
if _, err := removeSingleSigner(cli, repo, options.signer, options.forceYes); err != nil {
fmt.Fprintln(cli.Err(), err.Error()+"\n")
errRepos = append(errRepos, repo)
} else if didRemove {
fmt.Fprintf(cli.Out(), "Successfully removed %s from %s\n\n", options.signer, repo)
}
}
if len(errRepos) > 0 {
@ -78,6 +76,8 @@ func isLastSignerForReleases(roleWithSig data.Role, allRoles []client.RoleWithSi
return counter < releasesRoleWithSigs.Threshold, nil
}
// removeSingleSigner returns whether the signer has been removed during this operation and an error
// Note: the signer not being removed doesn't necessarily raise an error (eg. User saying "No" to the confirmation prompt)
func removeSingleSigner(cli command.Cli, repoName, signerName string, forceYes bool) (bool, error) {
ctx := context.Background()
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, nil, image.AuthResolver(cli), repoName)
@ -136,5 +136,7 @@ func removeSingleSigner(cli command.Cli, repoName, signerName string, forceYes b
return false, err
}
fmt.Fprintf(cli.Out(), "Successfully removed %s from %s\n\n", signerName, repoName)
return true, nil
}

View File

@ -71,13 +71,13 @@ func TestTrustSignerRemoveErrors(t *testing.T) {
func TestRemoveSingleSigner(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{})
cli.SetNotaryClient(notaryfake.GetLoadedNotaryRepository)
didRemove, err := removeSingleSigner(cli, "signed-repo", "test", true)
removed, err := removeSingleSigner(cli, "signed-repo", "test", true)
assert.Error(t, err, "No signer test for repository signed-repo")
assert.Equal(t, didRemove, false, "No signer should be removed")
assert.Equal(t, removed, false, "No signer should be removed")
_, err = removeSingleSigner(cli, "signed-repo", "releases", true)
removed, err = removeSingleSigner(cli, "signed-repo", "releases", true)
assert.Error(t, err, "releases is a reserved keyword and cannot be removed")
assert.Equal(t, didRemove, false, "No signer should be removed")
assert.Equal(t, removed, false, "No signer should be removed")
}
func TestRemoveMultipleSigners(t *testing.T) {