mirror of https://github.com/containers/podman.git
secret: add support for `--ignore` with rm
Signed-off-by: danishprakash <danish.prakash@suse.com>
This commit is contained in:
parent
608f484e9b
commit
bfd2a8cad3
|
@ -29,6 +29,7 @@ func init() {
|
|||
})
|
||||
flags := rmCmd.Flags()
|
||||
flags.BoolVarP(&rmOptions.All, "all", "a", false, "Remove all secrets")
|
||||
flags.BoolVarP(&rmOptions.Ignore, "ignore", "i", false, "Ignore errors when a specified secret is missing")
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
|
@ -26,6 +26,9 @@ Remove all existing secrets.
|
|||
|
||||
Print usage statement.
|
||||
|
||||
#### **--ignore**, **-i**
|
||||
Ignore errors when specified secrets are not present.
|
||||
|
||||
## EXAMPLES
|
||||
|
||||
```
|
||||
|
|
|
@ -34,7 +34,8 @@ type SecretListReport struct {
|
|||
}
|
||||
|
||||
type SecretRmOptions struct {
|
||||
All bool
|
||||
All bool
|
||||
Ignore bool
|
||||
}
|
||||
|
||||
type SecretRmReport struct {
|
||||
|
|
|
@ -167,10 +167,12 @@ func (ic *ContainerEngine) SecretRm(ctx context.Context, nameOrIDs []string, opt
|
|||
for _, nameOrID := range toRemove {
|
||||
deletedID, err := manager.Delete(nameOrID)
|
||||
if err == nil || strings.Contains(err.Error(), "no such secret") {
|
||||
reports = append(reports, &entities.SecretRmReport{
|
||||
Err: err,
|
||||
ID: deletedID,
|
||||
})
|
||||
if !options.Ignore {
|
||||
reports = append(reports, &entities.SecretRmReport{
|
||||
Err: err,
|
||||
ID: deletedID,
|
||||
})
|
||||
}
|
||||
continue
|
||||
} else {
|
||||
return nil, err
|
||||
|
|
|
@ -77,10 +77,12 @@ func (ic *ContainerEngine) SecretRm(ctx context.Context, nameOrIDs []string, opt
|
|||
return nil, err
|
||||
}
|
||||
if errModel.ResponseCode == 404 {
|
||||
allRm = append(allRm, &entities.SecretRmReport{
|
||||
Err: fmt.Errorf("no secret with name or id %q: no such secret ", name),
|
||||
ID: "",
|
||||
})
|
||||
if !options.Ignore {
|
||||
allRm = append(allRm, &entities.SecretRmReport{
|
||||
Err: fmt.Errorf("no secret with name or id %q: no such secret ", name),
|
||||
ID: "",
|
||||
})
|
||||
}
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
|
|
@ -336,6 +336,18 @@ var _ = Describe("Podman secret", func() {
|
|||
Expect(session.OutputToStringArray()).To(HaveLen(1))
|
||||
})
|
||||
|
||||
It("podman secret rm --ignore", func() {
|
||||
remove := podmanTest.Podman([]string{"secret", "rm", "non-existent-secret"})
|
||||
remove.WaitWithDefaultTimeout()
|
||||
Expect(remove).Should(Not(Exit(0)))
|
||||
Expect(remove.ErrorToString()).To(Equal("Error: no secret with name or id \"non-existent-secret\": no such secret"))
|
||||
|
||||
ignoreRm := podmanTest.Podman([]string{"secret", "rm", "--ignore", "non-existent-secret"})
|
||||
ignoreRm.WaitWithDefaultTimeout()
|
||||
Expect(ignoreRm).Should(Exit(0))
|
||||
Expect(ignoreRm.ErrorToString()).To(BeEmpty())
|
||||
})
|
||||
|
||||
It("podman secret creates from environment variable", func() {
|
||||
// no env variable set, should fail
|
||||
session := podmanTest.Podman([]string{"secret", "create", "--env", "a", "MYENVVAR"})
|
||||
|
|
Loading…
Reference in New Issue