/
secret-ids.go
61 lines (50 loc) · 1.27 KB
/
secret-ids.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2022 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package jujuc
import (
"github.com/juju/cmd/v3"
"github.com/juju/gnuflag"
jujucmd "github.com/juju/juju/cmd"
)
type secretIdsCommand struct {
cmd.CommandBase
ctx Context
out cmd.Output
}
// NewSecretIdsCommand returns a command to list the IDs and labels of secrets.
// created by this app.
func NewSecretIdsCommand(ctx Context) (cmd.Command, error) {
return &secretIdsCommand{ctx: ctx}, nil
}
func (c *secretIdsCommand) SetFlags(f *gnuflag.FlagSet) {
c.out.AddFlags(f, "smart", cmd.DefaultFormatters.Formatters())
}
// Info implements cmd.Command.
func (c *secretIdsCommand) Info() *cmd.Info {
doc := `
Returns the secret ids for secrets owned by the application.
Examples:
secret-ids
`
return jujucmd.Info(&cmd.Info{
Name: "secret-ids",
Purpose: "print secret ids",
Doc: doc,
})
}
// Init implements cmd.Command.
func (c *secretIdsCommand) Init(args []string) error {
return cmd.CheckEmpty(args)
}
// Run implements cmd.Command.
func (c *secretIdsCommand) Run(ctx *cmd.Context) error {
result, err := c.ctx.SecretMetadata()
if err != nil {
return err
}
var out []string
for id := range result {
out = append(out, id)
}
return c.out.Write(ctx, out)
}