Skip to content

Commit 8c0fd80

Browse files
committed
cmd/setec: add set-info subcommand and update info output
1 parent 0ad3d85 commit 8c0fd80

1 file changed

Lines changed: 32 additions & 2 deletions

File tree

cmd/setec/setec.go

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939
"golang.org/x/term"
4040
"tailscale.com/tsnet"
4141
"tailscale.com/tsweb"
42+
"tailscale.com/types/opt"
4243
)
4344

4445
func main() {
@@ -97,6 +98,13 @@ Most of the settings can be set via environment variables as well as flags.
9798
Help: "Get metadata for the specified secret.",
9899
Run: command.Adapt(runInfo),
99100
},
101+
{
102+
Name: "set-info",
103+
Usage: "<secret-name>",
104+
Help: `Set metadata for the specified secret.`,
105+
SetFlags: command.Flags(flax.MustBind, &setInfoArgs),
106+
Run: command.Adapt(runSetInfo),
107+
},
100108
{
101109
Name: "get",
102110
Usage: "<secret-name>",
@@ -327,7 +335,7 @@ func runList(env *command.Env) error {
327335
}
328336

329337
tw := newTabWriter(os.Stdout)
330-
io.WriteString(tw, "NAME\tACTIVE\tVERSIONS\tLAST ACCESSED\n")
338+
io.WriteString(tw, "NAME\tACTIVE\tVERSIONS\tLAST ACCESSED\tDESCRIPTION\n")
331339
for _, s := range secrets {
332340
vers := make([]string, 0, len(s.Versions))
333341
for _, v := range s.Versions {
@@ -337,7 +345,8 @@ func runList(env *command.Env) error {
337345
if !s.LastAccess.IsZero() {
338346
lastAccess = s.LastAccess.Format(time.RFC3339)
339347
}
340-
fmt.Fprintf(tw, "%s\t%s\t%s\t%s\n", s.Name, s.ActiveVersion, strings.Join(vers, ","), lastAccess)
348+
fmt.Fprintf(tw, "%s\t%s\t%s\t%s\t%s\n",
349+
s.Name, s.ActiveVersion, strings.Join(vers, ","), lastAccess, s.Description)
341350
}
342351
return tw.Flush()
343352
}
@@ -358,6 +367,9 @@ func runInfo(env *command.Env, name string) error {
358367
}
359368
tw := newTabWriter(os.Stdout)
360369
fmt.Fprintf(tw, "Name:\t%s\n", info.Name)
370+
if d := info.Description; d != "" {
371+
fmt.Fprintf(tw, "Description:\t%s\n", d)
372+
}
361373
fmt.Fprintf(tw, "Active version:\t%s\n", info.ActiveVersion)
362374
fmt.Fprintf(tw, "Versions:\t%s\n", strings.Join(vers, ", "))
363375
if !info.LastAccess.IsZero() {
@@ -366,6 +378,24 @@ func runInfo(env *command.Env, name string) error {
366378
return tw.Flush()
367379
}
368380

381+
var setInfoArgs struct {
382+
Description string `flag:"description,Set the human-readable description of the secret"`
383+
}
384+
385+
func runSetInfo(env *command.Env, name string) error {
386+
c, err := newClient()
387+
if err != nil {
388+
return err
389+
}
390+
391+
// If more metadata fields are added, this list will need to be extended.
392+
var update api.SecretInfoUpdate
393+
if env.IsFlagSet("description") {
394+
update.Description = opt.ValueOf(setInfoArgs.Description)
395+
}
396+
return c.SetInfo(env.Context(), name, update)
397+
}
398+
369399
var getArgs struct {
370400
IfChanged bool `flag:"if-changed,Get active version if changed from --version"`
371401
Version uint64 `flag:"version,Secret version to retrieve (default: the active version)"`

0 commit comments

Comments
 (0)