mirror of https://github.com/docker/cli.git
Move the successful removal print
Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
This commit is contained in:
parent
5ebb7a65ab
commit
2b3361cc1a
|
@ -43,11 +43,9 @@ func removeSigner(cli command.Cli, options signerRemoveOptions) error {
|
||||||
var errRepos []string
|
var errRepos []string
|
||||||
for _, repo := range options.repos {
|
for _, repo := range options.repos {
|
||||||
fmt.Fprintf(cli.Out(), "Removing signer \"%s\" from %s...\n", options.signer, repo)
|
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")
|
fmt.Fprintln(cli.Err(), err.Error()+"\n")
|
||||||
errRepos = append(errRepos, repo)
|
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 {
|
if len(errRepos) > 0 {
|
||||||
|
@ -78,6 +76,8 @@ func isLastSignerForReleases(roleWithSig data.Role, allRoles []client.RoleWithSi
|
||||||
return counter < releasesRoleWithSigs.Threshold, nil
|
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) {
|
func removeSingleSigner(cli command.Cli, repoName, signerName string, forceYes bool) (bool, error) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, nil, image.AuthResolver(cli), repoName)
|
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
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Fprintf(cli.Out(), "Successfully removed %s from %s\n\n", signerName, repoName)
|
||||||
|
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,13 +71,13 @@ func TestTrustSignerRemoveErrors(t *testing.T) {
|
||||||
func TestRemoveSingleSigner(t *testing.T) {
|
func TestRemoveSingleSigner(t *testing.T) {
|
||||||
cli := test.NewFakeCli(&fakeClient{})
|
cli := test.NewFakeCli(&fakeClient{})
|
||||||
cli.SetNotaryClient(notaryfake.GetLoadedNotaryRepository)
|
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.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.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) {
|
func TestRemoveMultipleSigners(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue