Skip to content

Commit

Permalink
Create wizard (gopasspw#2064)
Browse files Browse the repository at this point in the history
RELEASE_NOTES=[ENHANCEMENT] Template support for the create wizard

Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
  • Loading branch information
dominikschulz authored Dec 24, 2021
1 parent ffaa9e3 commit 03aa36b
Show file tree
Hide file tree
Showing 11 changed files with 577 additions and 558 deletions.
62 changes: 62 additions & 0 deletions docs/commands/create.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# `create` command

The `create` command creates a new secret using a set of built-in or custom templates.
It implements a wizard that guides inexperienced users through the secret creating.

The main design goal of this command was to guide users through the creation of a secret
and asking for the necessary information to create a reasonable secret location.

## Synopsis

```
$ gopass create
$ gopass create --store=foo
```

## Modes of operation

* Create a new secret using a wizard

## Templates

`gopass create` will look for files ending in `.yml` in the folder `.gopass/create` inside
the selected store (by default the root store).

To add new templates to the wizard add templates to this folder.

Example:

```
$ cat $(gopass config path)/.gopass/create/aws.yml
---
priority: 5
name: "AWS"
prefix: "aws"
name_from:
- "org"
- "user"
welcome: "🧪 Creating AWS credentials"
attributes:
org:
type: "string"
prompt: "Organization"
min: 1
user:
type: "string"
prompt: "User"
min: 1
password:
type: "password"
prompt: "Password"
comment:
type: "string"
prompt: "Comments"
```

## Flags

Flag | Aliases | Description
---- | ------- | -----------
`--store` | `-s` | Select the store to use. Will be used to look up user templates.
`--force` | `-f` | For overwriting existing entries.
`--print` | `-p` | Print the password to STDOUT.
6 changes: 6 additions & 0 deletions internal/action/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ func (s *Action) Config(c *cli.Context) error {
func (s *Action) printConfigValues(ctx context.Context, needles ...string) {
m := s.cfg.ConfigMap()
for _, k := range filterMap(m, needles) {
// if only a single key is requested, print only the value
// useful for scriping, e.g. `$ cd $(gopass config path)`
if len(needles) == 1 {
out.Printf(ctx, "%s", m[k])
continue
}
out.Printf(ctx, "%s: %s", k, m[k])
}
for alias, path := range s.cfg.Mounts {
Expand Down
8 changes: 4 additions & 4 deletions internal/action/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ parsing: true
defer buf.Reset()

assert.NoError(t, act.setConfigValue(ctx, "nopager", "true"))
assert.Equal(t, "nopager: true", strings.TrimSpace(buf.String()), "action.setConfigValue")
assert.Equal(t, "true", strings.TrimSpace(buf.String()), "action.setConfigValue")
})

t.Run("set invalid config value", func(t *testing.T) {
Expand All @@ -70,7 +70,7 @@ parsing: true

act.printConfigValues(ctx, "nopager")

want := "nopager: true"
want := "true"
assert.Equal(t, want, strings.TrimSpace(buf.String()), "action.printConfigValues")
})

Expand Down Expand Up @@ -98,15 +98,15 @@ parsing: true

c := gptest.CliCtx(ctx, t, "autoimport")
assert.NoError(t, act.Config(c))
assert.Equal(t, "autoimport: true", strings.TrimSpace(buf.String()))
assert.Equal(t, "true", strings.TrimSpace(buf.String()))
})

t.Run("disable autoimport", func(t *testing.T) {
defer buf.Reset()

c := gptest.CliCtx(ctx, t, "autoimport", "false")
assert.NoError(t, act.Config(c))
assert.Equal(t, "autoimport: false", strings.TrimSpace(buf.String()))
assert.Equal(t, "false", strings.TrimSpace(buf.String()))
})

t.Run("complete config items", func(t *testing.T) {
Expand Down
Loading

0 comments on commit 03aa36b

Please sign in to comment.