Skip to content

Commit

Permalink
Simplify configuration (#213)
Browse files Browse the repository at this point in the history
* Simplify configuration

Fixes #206

* Fix recipient tests

* Fix integration tests
  • Loading branch information
dominikschulz authored Jul 25, 2017
1 parent 639e1e0 commit 9e0f323
Show file tree
Hide file tree
Showing 15 changed files with 156 additions and 278 deletions.
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -566,20 +566,12 @@ There are several configuration options available through the command line inter

| **Option** | *Type* | Description |
| ------------- | --------- | ----------- |
| `alwaystrust` | `bool` | Always trust public keys when encrypting. This trades some security against easier use. Use with caution. |
| `askformore` | `bool` | If enabled - it will ask to add more data after use of `generate` command. |
| `autoimport` | `bool` | Import missing keys stored in the pass repo (see `persistkeys`) without asking. |
| `autopull` | `bool` | Always do a `git pull` before a `git push`. Reduces the chance of git rejections. |
| `autopush` | `bool` | Always do a `git push` after a commit to the store. Makes sure your local changes are always available on your git remote. |
| `autosync` | `bool` | Always do a `git push` after a commit to the store. Makes sure your local changes are always available on your git remote. |
| `cliptimeout` | `int` | How many seconds the secret is stored when using `-c`. |
| `gitrecurse` | `bool` | Automatically recurse any git operation to mounted sub-stores? |
| `loadkeys` | `bool` | Import missing keys store in the pass repo (see `persistkeys` and `autoimport`). |
| `debug` | `bool` | Enable debug output. |
| `nocolor` | `bool` | Disable colored output even on terminals. |
| `noconfirm` | `bool` | Do not confirm recipient list when encrypting. |
| `nopager` | `bool` | Disable the pager feature when printing multi-page output. |
| `path` | `string` | Path to the root store. |
| `persistkeys` | `bool` | Store every recipients public keys in the store. Makes it easier to set up an new machine or user. |
| `safecontent` | `bool` | Only output _safe content_ (i.e. everything but the first line of a secret) to the terminal. Use _copy_ (`-c`) to retrieve the password in the clipboard. |

## Environment Variables
Expand Down
2 changes: 1 addition & 1 deletion action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func New(sv semver.Version) *Action {

act.gpg = gpgcli.New(gpgcli.Config{
Debug: cfg.Debug,
AlwaysTrust: cfg.AlwaysTrust,
AlwaysTrust: true,
})

return act
Expand Down
6 changes: 3 additions & 3 deletions action/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
// Git runs git commands inside the store or mounts
func (s *Action) Git(c *cli.Context) error {
store := c.String("store")
recurse := s.Store.GitRecurse()
if c.IsSet("recurse") {
recurse = c.Bool("recurse")
recurse := true
if c.IsSet("no-recurse") {
recurse = !c.Bool("no-recurse")
}
force := c.Bool("force")
return s.Store.Git(store, recurse, force, c.Args()...)
Expand Down
57 changes: 21 additions & 36 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,47 +23,32 @@ var (

// Config is the gopass config structure
type Config struct {
AlwaysTrust bool `json:"alwaystrust"` // always trust public keys when encrypting
AskForMore bool `json:"askformore"` // ask for more data on generate
AutoImport bool `json:"autoimport"` // import missing public keys w/o asking
AutoPull bool `json:"autopull"` // pull from git before push
AutoPush bool `json:"autopush"` // push to git remote after commit
CheckRecipients bool `json:"checkrecipients"` // only encrypt to valid recipients
ClipTimeout int `json:"cliptimeout"` // clear clipboard after seconds
Debug bool `json:"debug"` // enable debug output
FsckFunc store.FsckCallback `json:"-"`
GitRecurse bool `json:"gitrecurse"`
ImportFunc store.ImportCallback `json:"-"`
LoadKeys bool `json:"loadkeys"` // load missing keys from store
Mounts map[string]string `json:"mounts,omitempty"`
NoColor bool `json:"nocolor"` // disable colors in output
NoConfirm bool `json:"noconfirm"` // do not confirm recipients when encrypting
NoPager bool `json:"nopager"` // do not start a pager for longer output
Path string `json:"path"` // path to the root store
PersistKeys bool `json:"persistkeys"` // store recipient keys in store
SafeContent bool `json:"safecontent"` // avoid showing passwords in terminal
Version string `json:"version"`
AskForMore bool `json:"askformore"` // ask for more data on generate
AutoImport bool `json:"autoimport"` // import missing public keys w/o asking
AutoSync bool `json:"autosync"` // push to git remote after commit, pull before push if necessary
ClipTimeout int `json:"cliptimeout"` // clear clipboard after seconds
Debug bool `json:"-"`
FsckFunc store.FsckCallback `json:"-"`
ImportFunc store.ImportCallback `json:"-"`
Mounts map[string]string `json:"mounts,omitempty"`
NoColor bool `json:"-"`
NoPager bool `json:"-"`
NoConfirm bool `json:"noconfirm"` // do not confirm recipients when encrypting
Path string `json:"path"` // path to the root store
SafeContent bool `json:"safecontent"` // avoid showing passwords in terminal
Version string `json:"version"`
}

// New creates a new config with sane default values
func New() *Config {
return &Config{
AlwaysTrust: true,
AskForMore: false,
AutoImport: true,
AutoPull: true,
AutoPush: true,
CheckRecipients: true,
ClipTimeout: 45,
Debug: false,
GitRecurse: true,
LoadKeys: true,
Mounts: make(map[string]string),
NoColor: false,
NoConfirm: false,
NoPager: false,
PersistKeys: true,
SafeContent: false,
AskForMore: false,
AutoImport: true,
ClipTimeout: 45,
Mounts: make(map[string]string),
NoConfirm: false,
SafeContent: false,
Version: "",
}
}

Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ func main() {
Usage: "Store to operate on",
},
cli.BoolFlag{
Name: "recurse, r",
Usage: "Recurse to mounted sub-stores",
Name: "no-recurse, n",
Usage: "Do not recurse to mounted sub-stores",
},
cli.BoolFlag{
Name: "force, f",
Expand Down
67 changes: 20 additions & 47 deletions store/root/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,18 @@ import (
// Config returns this root stores config as a config struct
func (s *Store) Config() *config.Config {
c := &config.Config{
AlwaysTrust: s.alwaysTrust,
AskForMore: s.askForMore,
AutoImport: s.autoImport,
AutoPull: s.autoPull,
AutoPush: s.autoPush,
CheckRecipients: s.checkRecipients,
ClipTimeout: s.clipTimeout,
Debug: s.debug,
GitRecurse: s.gitRecurse,
LoadKeys: s.loadKeys,
Mounts: make(map[string]string, len(s.mounts)),
NoColor: s.noColor,
NoConfirm: s.noConfirm,
NoPager: s.noPager,
Path: s.path,
PersistKeys: s.persistKeys,
SafeContent: s.safeContent,
Version: s.version,
AskForMore: s.askForMore,
AutoImport: s.autoImport,
AutoSync: s.autoSync,
ClipTimeout: s.clipTimeout,
Debug: s.debug,
Mounts: make(map[string]string, len(s.mounts)),
NoColor: s.noColor,
NoConfirm: s.noConfirm,
NoPager: s.noPager,
Path: s.path,
SafeContent: s.safeContent,
Version: s.version,
}
for alias, sub := range s.mounts {
c.Mounts[alias] = sub.Path()
Expand All @@ -40,21 +34,15 @@ func (s *Store) UpdateConfig(cfg *config.Config) error {
if cfg == nil {
return fmt.Errorf("invalid config")
}
s.alwaysTrust = cfg.AlwaysTrust
s.askForMore = cfg.AskForMore
s.autoImport = cfg.AutoImport
s.autoPull = cfg.AutoPull
s.autoPush = cfg.AutoPush
s.debug = cfg.Debug
s.checkRecipients = cfg.CheckRecipients
s.autoSync = cfg.AutoSync
s.clipTimeout = cfg.ClipTimeout
s.gitRecurse = cfg.GitRecurse
s.loadKeys = cfg.LoadKeys
s.debug = cfg.Debug
s.noColor = cfg.NoColor
s.noConfirm = cfg.NoConfirm
s.noPager = cfg.NoPager
s.path = cfg.Path
s.persistKeys = cfg.PersistKeys
s.safeContent = cfg.SafeContent

// add any missing mounts
Expand Down Expand Up @@ -89,24 +77,9 @@ func (s *Store) Alias() string {
return ""
}

// NoConfirm returns true if no recipients should be confirmed on encryption
func (s *Store) NoConfirm() bool {
return s.noConfirm
}

// AutoPush returns the value of auto push
func (s *Store) AutoPush() bool {
return s.autoPush
}

// AutoPull returns the value of auto pull
func (s *Store) AutoPull() bool {
return s.autoPull
}

// AutoImport returns the value of auto import
func (s *Store) AutoImport() bool {
return s.autoImport
// AutoSync returns the value of auto sync
func (s *Store) AutoSync() bool {
return s.autoSync
}

// SafeContent returns the value of safe content
Expand All @@ -129,7 +102,7 @@ func (s *Store) NoPager() bool {
return s.noPager
}

// GitRecurse returns true if we should recurse git operations to substores
func (s *Store) GitRecurse() bool {
return s.gitRecurse
// NoConfirm returns true if no recipients should be confirmed on encryption
func (s *Store) NoConfirm() bool {
return s.noConfirm
}
8 changes: 0 additions & 8 deletions store/root/recipients.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ func (r *Store) addRecipient(prefix string, root tree.Tree, recp string, pretty

// ImportMissingPublicKeys import missing public keys in any substore
func (r *Store) ImportMissingPublicKeys() error {
if !r.loadKeys {
return nil
}

for alias, sub := range r.mounts {
if err := sub.ImportMissingPublicKeys(); err != nil {
fmt.Println(color.RedString("[%s] Failed to import missing public keys: %s", alias, err))
Expand All @@ -58,10 +54,6 @@ func (r *Store) ImportMissingPublicKeys() error {
// SaveRecipients persists the recipients to disk. Only useful if persist keys is
// enabled
func (r *Store) SaveRecipients() error {
if !r.persistKeys {
return nil
}

for alias, sub := range r.mounts {
if err := sub.SaveRecipients(); err != nil {
fmt.Println(color.RedString("[%s] Failed to save recipients: %s", alias, err))
Expand Down
58 changes: 23 additions & 35 deletions store/root/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,22 @@ type gpger interface {

// Store is the public facing password store
type Store struct {
alwaysTrust bool // always trust public keys when encrypting
askForMore bool
autoImport bool // import missing public keys w/o asking
autoPull bool // pull from git before push
autoPush bool // push to git remote after commit
checkRecipients bool
clipTimeout int // clear clipboard after seconds
debug bool
fsckFunc store.FsckCallback
gpg gpger
gitRecurse bool
importFunc store.ImportCallback
loadKeys bool // load missing keys from store
mounts map[string]*sub.Store
noColor bool // disable colors in output
noConfirm bool // do not confirm recipients when encrypting
noPager bool
path string // path to the root store
persistKeys bool // store recipient keys in store
safeContent bool // avoid showing passwords in terminal
store *sub.Store
version string
askForMore bool
autoImport bool
autoSync bool // push to git remote after commit
clipTimeout int // clear clipboard after seconds
debug bool
fsckFunc store.FsckCallback
gpg gpger
importFunc store.ImportCallback
mounts map[string]*sub.Store
noColor bool // disable colors in output
noConfirm bool
noPager bool
path string // path to the root store
safeContent bool // avoid showing passwords in terminal
store *sub.Store
version string
}

// New creates a new store
Expand All @@ -54,28 +48,22 @@ func New(cfg *config.Config) (*Store, error) {
return nil, fmt.Errorf("need path")
}
r := &Store{
alwaysTrust: cfg.AlwaysTrust,
askForMore: cfg.AskForMore,
autoImport: cfg.AutoImport,
autoPull: cfg.AutoPull,
autoPush: cfg.AutoPush,
checkRecipients: cfg.CheckRecipients,
clipTimeout: cfg.ClipTimeout,
debug: cfg.Debug,
fsckFunc: cfg.FsckFunc,
gitRecurse: cfg.GitRecurse,
askForMore: cfg.AskForMore,
autoImport: cfg.AutoImport,
autoSync: cfg.AutoSync,
clipTimeout: cfg.ClipTimeout,
debug: cfg.Debug,
fsckFunc: cfg.FsckFunc,
gpg: gpgcli.New(gpgcli.Config{
Debug: cfg.Debug,
AlwaysTrust: cfg.AlwaysTrust,
AlwaysTrust: true,
}),
importFunc: cfg.ImportFunc,
loadKeys: cfg.LoadKeys,
mounts: make(map[string]*sub.Store, len(cfg.Mounts)),
noColor: cfg.NoColor,
noConfirm: cfg.NoConfirm,
noPager: cfg.NoPager,
path: cfg.Path,
persistKeys: cfg.PersistKeys,
safeContent: cfg.SafeContent,
}

Expand Down
26 changes: 7 additions & 19 deletions store/sub/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,12 @@ import (
// Config returns this sub stores config as a config struct
func (s *Store) Config() *config.Config {
c := &config.Config{
AlwaysTrust: s.alwaysTrust,
AutoImport: s.autoImport,
AutoPull: s.autoPull,
AutoPush: s.autoPush,
CheckRecipients: s.checkRecipients,
Debug: s.debug,
FsckFunc: s.fsckFunc,
ImportFunc: s.importFunc,
LoadKeys: s.loadKeys,
Mounts: make(map[string]string),
Path: s.path,
PersistKeys: s.persistKeys,
AutoSync: s.autoSync,
AutoImport: s.autoImport,
FsckFunc: s.fsckFunc,
ImportFunc: s.importFunc,
Mounts: make(map[string]string),
Path: s.path,
}
return c
}
Expand All @@ -30,17 +24,11 @@ func (s *Store) UpdateConfig(cfg *config.Config) error {
if cfg == nil {
return fmt.Errorf("invalid config")
}
s.alwaysTrust = cfg.AlwaysTrust
s.autoImport = cfg.AutoImport
s.autoPull = cfg.AutoPull
s.autoPush = cfg.AutoPush
s.checkRecipients = cfg.CheckRecipients
s.debug = cfg.Debug
s.autoSync = cfg.AutoSync
s.fsckFunc = cfg.FsckFunc
s.importFunc = cfg.ImportFunc
s.loadKeys = cfg.LoadKeys
s.path = cfg.Path
s.persistKeys = cfg.PersistKeys

// substores have no mounts

Expand Down
11 changes: 3 additions & 8 deletions store/sub/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ func (s *Store) gitCmd(name string, args ...string) error {
return err
}
// load keys only after git pull
if s.debug {
fmt.Printf("[DEBUG] loadKeys: %t - cmd.Args: %+v\n", s.loadKeys, cmd.Args)
}
if s.loadKeys && len(cmd.Args) > 1 && cmd.Args[1] == "pull" {
if len(cmd.Args) > 1 && cmd.Args[1] == "pull" {
if s.debug {
fmt.Printf("[DEBUG] importing possilby missing keys ...\n")
}
Expand Down Expand Up @@ -218,10 +215,8 @@ func (s *Store) gitPush(remote, branch string) error {
return store.ErrGitNoRemote
}

if s.autoPull {
if err := s.Git("pull", remote, branch); err != nil {
fmt.Println(color.YellowString("Failed to pull before git push: %s", err))
}
if err := s.Git("pull", remote, branch); err != nil {
fmt.Println(color.YellowString("Failed to pull before git push: %s", err))
}

return s.Git("push", remote, branch)
Expand Down
Loading

0 comments on commit 9e0f323

Please sign in to comment.