Skip to content

Commit

Permalink
Fix sub store config propagation (#837)
Browse files Browse the repository at this point in the history
Fixes #836
  • Loading branch information
dominikschulz authored Jun 3, 2018
1 parent 64b7266 commit 2caea48
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 6 deletions.
1 change: 1 addition & 0 deletions pkg/action/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
// Audit validates passwords against common flaws
func (s *Action) Audit(ctx context.Context, c *cli.Context) error {
filter := c.Args().First()
ctx = s.Store.WithConfig(ctx, filter)

out.Print(ctx, "Auditing passwords for common flaws ...")

Expand Down
4 changes: 3 additions & 1 deletion pkg/action/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import (

// Find a string in the secret file's name
func (s *Action) Find(ctx context.Context, c *cli.Context) error {
ctx = WithClip(ctx, c.Bool("clip"))
if c.IsSet("clip") {
ctx = WithClip(ctx, c.Bool("clip"))
}

if !c.Args().Present() {
return ExitError(ctx, ExitUsage, nil, "Usage: %s find <NEEDLE>", s.Name)
Expand Down
2 changes: 2 additions & 0 deletions pkg/action/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ func (s *Action) Generate(ctx context.Context, c *cli.Context) error {
}
}

ctx = s.Store.WithConfig(ctx, name)

// ask for confirmation before overwriting existing entry
if !force { // don't check if it's force anyway
if s.Store.Exists(ctx, name) && key == "" && !termio.AskForConfirmation(ctx, fmt.Sprintf("An entry already exists for %s. Overwrite the current password?", name)) {
Expand Down
1 change: 1 addition & 0 deletions pkg/action/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func (s *Action) Show(ctx context.Context, c *cli.Context) error {
name := c.Args().First()
key := c.Args().Get(1)

ctx = s.Store.WithConfig(ctx, name)
ctx = WithClip(ctx, c.Bool("clip"))
ctx = WithForce(ctx, c.Bool("force"))
ctx = WithPrintQR(ctx, c.Bool("qr"))
Expand Down
16 changes: 11 additions & 5 deletions pkg/config/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,35 @@ func (c StoreConfig) WithContext(ctx context.Context) context.Context {
if !ctxutil.HasAskForMore(ctx) {
ctx = ctxutil.WithAskForMore(ctx, c.AskForMore)
}
if !ctxutil.HasAutoClip(ctx) {
ctx = ctxutil.WithAutoClip(ctx, c.AutoClip)
}
if !c.AutoImport {
ctx = sub.WithImportFunc(ctx, nil)
}
if !sub.HasAutoSync(ctx) {
ctx = sub.WithAutoSync(ctx, c.AutoSync)
}
if !ctxutil.HasEditRecipients(ctx) {
ctx = ctxutil.WithEditRecipients(ctx, c.EditRecipients)
}
if !ctxutil.HasClipTimeout(ctx) {
ctx = ctxutil.WithClipTimeout(ctx, c.ClipTimeout)
}
if !ctxutil.HasConcurrency(ctx) {
ctx = ctxutil.WithConcurrency(ctx, c.Concurrency)
}
if !ctxutil.HasEditRecipients(ctx) {
ctx = ctxutil.WithEditRecipients(ctx, c.EditRecipients)
}
if !ctxutil.HasNoConfirm(ctx) {
ctx = ctxutil.WithNoConfirm(ctx, c.NoConfirm)
}
if !ctxutil.HasNoPager(ctx) {
ctx = ctxutil.WithNoPager(ctx, c.NoPager)
}
if !ctxutil.HasShowSafeContent(ctx) {
ctx = ctxutil.WithShowSafeContent(ctx, c.SafeContent)
}
if !ctxutil.HasAutoClip(ctx) {
ctx = ctxutil.WithAutoClip(ctx, c.AutoClip)
if !ctxutil.HasUseSymbols(ctx) {
ctx = ctxutil.WithUseSymbols(ctx, c.UseSymbols)
}
return ctx
}
10 changes: 10 additions & 0 deletions pkg/store/root/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@ func (r *Store) getStore(ctx context.Context, name string) (context.Context, sto
return r.cfg.Root.WithContext(ctx), r.store, name
}

// WithConfig populates the context with the substore config
func (r *Store) WithConfig(ctx context.Context, name string) context.Context {
name = strings.TrimSuffix(name, "/")
mp := r.MountPoint(name)
if _, found := r.mounts[mp]; found {
return r.cfg.Mounts[mp].WithContext(ctx)
}
return r.cfg.Root.WithContext(ctx)
}

// GetSubStore returns an exact match for a mount point or an error if this
// mount point does not exist
func (r *Store) GetSubStore(name string) (store.Store, error) {
Expand Down

0 comments on commit 2caea48

Please sign in to comment.