repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
gopasspw/gopass
pkg/backend/crypto/plain/backend.go
Verify
func (m *Mocker) Verify(ctx context.Context, sigf string, in string) error { sigb, err := ioutil.ReadFile(sigf) if err != nil { return err } buf, err := ioutil.ReadFile(in) if err != nil { return err } sum := sha256.New() _, _ = sum.Write(buf) hexsum := fmt.Sprintf("%X", sum.Sum(nil)) if string(sigb) != hexsum { return fmt.Errorf("hashsum mismatch") } return nil }
go
func (m *Mocker) Verify(ctx context.Context, sigf string, in string) error { sigb, err := ioutil.ReadFile(sigf) if err != nil { return err } buf, err := ioutil.ReadFile(in) if err != nil { return err } sum := sha256.New() _, _ = sum.Write(buf) hexsum := fmt.Sprintf("%X", sum.Sum(nil)) if string(sigb) != hexsum { return fmt.Errorf("hashsum mismatch") } return nil }
[ "func", "(", "m", "*", "Mocker", ")", "Verify", "(", "ctx", "context", ".", "Context", ",", "sigf", "string", ",", "in", "string", ")", "error", "{", "sigb", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "sigf", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "buf", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "in", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "sum", ":=", "sha256", ".", "New", "(", ")", "\n", "_", ",", "_", "=", "sum", ".", "Write", "(", "buf", ")", "\n", "hexsum", ":=", "fmt", ".", "Sprintf", "(", "\"%X\"", ",", "sum", ".", "Sum", "(", "nil", ")", ")", "\n", "if", "string", "(", "sigb", ")", "!=", "hexsum", "{", "return", "fmt", ".", "Errorf", "(", "\"hashsum mismatch\"", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Verify does a pseudo-verification
[ "Verify", "does", "a", "pseudo", "-", "verification" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/plain/backend.go#L132-L151
train
gopasspw/gopass
pkg/backend/crypto/plain/backend.go
ReadNamesFromKey
func (m *Mocker) ReadNamesFromKey(ctx context.Context, buf []byte) ([]string, error) { return []string{"unsupported"}, nil }
go
func (m *Mocker) ReadNamesFromKey(ctx context.Context, buf []byte) ([]string, error) { return []string{"unsupported"}, nil }
[ "func", "(", "m", "*", "Mocker", ")", "ReadNamesFromKey", "(", "ctx", "context", ".", "Context", ",", "buf", "[", "]", "byte", ")", "(", "[", "]", "string", ",", "error", ")", "{", "return", "[", "]", "string", "{", "\"unsupported\"", "}", ",", "nil", "\n", "}" ]
// ReadNamesFromKey does nothing
[ "ReadNamesFromKey", "does", "nothing" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/plain/backend.go#L204-L206
train
gopasspw/gopass
pkg/backend/rcs/git/cli/loader.go
Clone
func (l loader) Clone(ctx context.Context, repo, path string) (backend.RCS, error) { return Clone(ctx, repo, path) }
go
func (l loader) Clone(ctx context.Context, repo, path string) (backend.RCS, error) { return Clone(ctx, repo, path) }
[ "func", "(", "l", "loader", ")", "Clone", "(", "ctx", "context", ".", "Context", ",", "repo", ",", "path", "string", ")", "(", "backend", ".", "RCS", ",", "error", ")", "{", "return", "Clone", "(", "ctx", ",", "repo", ",", "path", ")", "\n", "}" ]
// Clone implements backend.RCSLoader
[ "Clone", "implements", "backend", ".", "RCSLoader" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/cli/loader.go#L27-L29
train
gopasspw/gopass
pkg/backend/crypto/gpg/cli/import.go
ImportPublicKey
func (g *GPG) ImportPublicKey(ctx context.Context, buf []byte) error { if len(buf) < 1 { return errors.Errorf("empty input") } args := append(g.args, "--import") cmd := exec.CommandContext(ctx, g.binary, args...) cmd.Stdin = bytes.NewReader(buf) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr out.Debug(ctx, "gpg.ImportPublicKey: %s %+v", cmd.Path, cmd.Args) if err := cmd.Run(); err != nil { return errors.Wrapf(err, "failed to run command: '%s %+v'", cmd.Path, cmd.Args) } // clear key cache g.privKeys = nil g.pubKeys = nil return nil }
go
func (g *GPG) ImportPublicKey(ctx context.Context, buf []byte) error { if len(buf) < 1 { return errors.Errorf("empty input") } args := append(g.args, "--import") cmd := exec.CommandContext(ctx, g.binary, args...) cmd.Stdin = bytes.NewReader(buf) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr out.Debug(ctx, "gpg.ImportPublicKey: %s %+v", cmd.Path, cmd.Args) if err := cmd.Run(); err != nil { return errors.Wrapf(err, "failed to run command: '%s %+v'", cmd.Path, cmd.Args) } // clear key cache g.privKeys = nil g.pubKeys = nil return nil }
[ "func", "(", "g", "*", "GPG", ")", "ImportPublicKey", "(", "ctx", "context", ".", "Context", ",", "buf", "[", "]", "byte", ")", "error", "{", "if", "len", "(", "buf", ")", "<", "1", "{", "return", "errors", ".", "Errorf", "(", "\"empty input\"", ")", "\n", "}", "\n", "args", ":=", "append", "(", "g", ".", "args", ",", "\"--import\"", ")", "\n", "cmd", ":=", "exec", ".", "CommandContext", "(", "ctx", ",", "g", ".", "binary", ",", "args", "...", ")", "\n", "cmd", ".", "Stdin", "=", "bytes", ".", "NewReader", "(", "buf", ")", "\n", "cmd", ".", "Stdout", "=", "os", ".", "Stdout", "\n", "cmd", ".", "Stderr", "=", "os", ".", "Stderr", "\n", "out", ".", "Debug", "(", "ctx", ",", "\"gpg.ImportPublicKey: %s %+v\"", ",", "cmd", ".", "Path", ",", "cmd", ".", "Args", ")", "\n", "if", "err", ":=", "cmd", ".", "Run", "(", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to run command: '%s %+v'\"", ",", "cmd", ".", "Path", ",", "cmd", ".", "Args", ")", "\n", "}", "\n", "g", ".", "privKeys", "=", "nil", "\n", "g", ".", "pubKeys", "=", "nil", "\n", "return", "nil", "\n", "}" ]
// ImportPublicKey will import a key from the given location
[ "ImportPublicKey", "will", "import", "a", "key", "from", "the", "given", "location" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/cli/import.go#L15-L35
train
gopasspw/gopass
pkg/action/binary/copy.go
Copy
func Copy(ctx context.Context, c *cli.Context, store storer) error { from := c.Args().Get(0) to := c.Args().Get(1) // argument checking is in s.binaryCopy if err := binaryCopy(ctx, c, from, to, false, store); err != nil { return action.ExitError(ctx, action.ExitUnknown, err, "%s", err) } return nil }
go
func Copy(ctx context.Context, c *cli.Context, store storer) error { from := c.Args().Get(0) to := c.Args().Get(1) // argument checking is in s.binaryCopy if err := binaryCopy(ctx, c, from, to, false, store); err != nil { return action.ExitError(ctx, action.ExitUnknown, err, "%s", err) } return nil }
[ "func", "Copy", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ",", "store", "storer", ")", "error", "{", "from", ":=", "c", ".", "Args", "(", ")", ".", "Get", "(", "0", ")", "\n", "to", ":=", "c", ".", "Args", "(", ")", ".", "Get", "(", "1", ")", "\n", "if", "err", ":=", "binaryCopy", "(", "ctx", ",", "c", ",", "from", ",", "to", ",", "false", ",", "store", ")", ";", "err", "!=", "nil", "{", "return", "action", ".", "ExitError", "(", "ctx", ",", "action", ".", "ExitUnknown", ",", "err", ",", "\"%s\"", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Copy copies either from the filesystem to the store or from the store // to the filesystem
[ "Copy", "copies", "either", "from", "the", "filesystem", "to", "the", "store", "or", "from", "the", "store", "to", "the", "filesystem" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/binary/copy.go#L22-L31
train
gopasspw/gopass
pkg/action/fsck.go
Fsck
func (s *Action) Fsck(ctx context.Context, c *cli.Context) error { out.Print(ctx, "Checking store integrity ...") // make sure config is in the right place // we may have loaded it from one of the fallback locations if err := s.cfg.Save(); err != nil { return ExitError(ctx, ExitConfig, err, "failed to save config: %s", err) } // clean up any previous config locations oldCfg := filepath.Join(config.Homedir(), ".gopass.yml") if fsutil.IsFile(oldCfg) { if err := os.Remove(oldCfg); err != nil { out.Error(ctx, "Failed to remove old gopass config %s: %s", oldCfg, err) } } // display progress bar t, err := s.Store.Tree(ctx) if err != nil { return ExitError(ctx, ExitUnknown, err, "failed to list stores: %s", err) } pwList := t.List(0) bar := &goprogressbar.ProgressBar{ Total: int64(len(pwList) * 2), Width: 120, } if out.IsHidden(ctx) { old := goprogressbar.Stdout goprogressbar.Stdout = ioutil.Discard defer func() { goprogressbar.Stdout = old }() } ctx = ctxutil.WithProgressCallback(ctx, func() { bar.Current++ bar.Text = fmt.Sprintf("%d of %d objects checked", bar.Current, bar.Total) bar.LazyPrint() }) ctx = out.AddPrefix(ctx, "\n") // the main work in done by the sub stores if err := s.Store.Fsck(ctx, c.Args().Get(0)); err != nil { return ExitError(ctx, ExitFsck, err, "fsck found errors: %s", err) } return nil }
go
func (s *Action) Fsck(ctx context.Context, c *cli.Context) error { out.Print(ctx, "Checking store integrity ...") // make sure config is in the right place // we may have loaded it from one of the fallback locations if err := s.cfg.Save(); err != nil { return ExitError(ctx, ExitConfig, err, "failed to save config: %s", err) } // clean up any previous config locations oldCfg := filepath.Join(config.Homedir(), ".gopass.yml") if fsutil.IsFile(oldCfg) { if err := os.Remove(oldCfg); err != nil { out.Error(ctx, "Failed to remove old gopass config %s: %s", oldCfg, err) } } // display progress bar t, err := s.Store.Tree(ctx) if err != nil { return ExitError(ctx, ExitUnknown, err, "failed to list stores: %s", err) } pwList := t.List(0) bar := &goprogressbar.ProgressBar{ Total: int64(len(pwList) * 2), Width: 120, } if out.IsHidden(ctx) { old := goprogressbar.Stdout goprogressbar.Stdout = ioutil.Discard defer func() { goprogressbar.Stdout = old }() } ctx = ctxutil.WithProgressCallback(ctx, func() { bar.Current++ bar.Text = fmt.Sprintf("%d of %d objects checked", bar.Current, bar.Total) bar.LazyPrint() }) ctx = out.AddPrefix(ctx, "\n") // the main work in done by the sub stores if err := s.Store.Fsck(ctx, c.Args().Get(0)); err != nil { return ExitError(ctx, ExitFsck, err, "fsck found errors: %s", err) } return nil }
[ "func", "(", "s", "*", "Action", ")", "Fsck", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "out", ".", "Print", "(", "ctx", ",", "\"Checking store integrity ...\"", ")", "\n", "if", "err", ":=", "s", ".", "cfg", ".", "Save", "(", ")", ";", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitConfig", ",", "err", ",", "\"failed to save config: %s\"", ",", "err", ")", "\n", "}", "\n", "oldCfg", ":=", "filepath", ".", "Join", "(", "config", ".", "Homedir", "(", ")", ",", "\".gopass.yml\"", ")", "\n", "if", "fsutil", ".", "IsFile", "(", "oldCfg", ")", "{", "if", "err", ":=", "os", ".", "Remove", "(", "oldCfg", ")", ";", "err", "!=", "nil", "{", "out", ".", "Error", "(", "ctx", ",", "\"Failed to remove old gopass config %s: %s\"", ",", "oldCfg", ",", "err", ")", "\n", "}", "\n", "}", "\n", "t", ",", "err", ":=", "s", ".", "Store", ".", "Tree", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitUnknown", ",", "err", ",", "\"failed to list stores: %s\"", ",", "err", ")", "\n", "}", "\n", "pwList", ":=", "t", ".", "List", "(", "0", ")", "\n", "bar", ":=", "&", "goprogressbar", ".", "ProgressBar", "{", "Total", ":", "int64", "(", "len", "(", "pwList", ")", "*", "2", ")", ",", "Width", ":", "120", ",", "}", "\n", "if", "out", ".", "IsHidden", "(", "ctx", ")", "{", "old", ":=", "goprogressbar", ".", "Stdout", "\n", "goprogressbar", ".", "Stdout", "=", "ioutil", ".", "Discard", "\n", "defer", "func", "(", ")", "{", "goprogressbar", ".", "Stdout", "=", "old", "\n", "}", "(", ")", "\n", "}", "\n", "ctx", "=", "ctxutil", ".", "WithProgressCallback", "(", "ctx", ",", "func", "(", ")", "{", "bar", ".", "Current", "++", "\n", "bar", ".", "Text", "=", "fmt", ".", "Sprintf", "(", "\"%d of %d objects checked\"", ",", "bar", ".", "Current", ",", "bar", ".", "Total", ")", "\n", "bar", ".", "LazyPrint", "(", ")", "\n", "}", ")", "\n", "ctx", "=", "out", ".", "AddPrefix", "(", "ctx", ",", "\"\\n\"", ")", "\n", "\\n", "\n", "if", "err", ":=", "s", ".", "Store", ".", "Fsck", "(", "ctx", ",", "c", ".", "Args", "(", ")", ".", "Get", "(", "0", ")", ")", ";", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitFsck", ",", "err", ",", "\"fsck found errors: %s\"", ",", "err", ")", "\n", "}", "\n", "}" ]
// Fsck checks the store integrity
[ "Fsck", "checks", "the", "store", "integrity" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/fsck.go#L20-L68
train
gopasspw/gopass
pkg/notify/notify_others.go
Notify
func Notify(ctx context.Context, subj, msg string) error { return errors.Errorf("GOOS %s not yet supported", runtime.GOOS) }
go
func Notify(ctx context.Context, subj, msg string) error { return errors.Errorf("GOOS %s not yet supported", runtime.GOOS) }
[ "func", "Notify", "(", "ctx", "context", ".", "Context", ",", "subj", ",", "msg", "string", ")", "error", "{", "return", "errors", ".", "Errorf", "(", "\"GOOS %s not yet supported\"", ",", "runtime", ".", "GOOS", ")", "\n", "}" ]
// Notify is not yet implemented on this platform
[ "Notify", "is", "not", "yet", "implemented", "on", "this", "platform" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/notify/notify_others.go#L13-L15
train
gopasspw/gopass
pkg/backend/crypto/gpg/cli/export.go
ExportPublicKey
func (g *GPG) ExportPublicKey(ctx context.Context, id string) ([]byte, error) { if id == "" { return nil, errors.Errorf("id is empty") } args := append(g.args, "--armor", "--export", id) cmd := exec.CommandContext(ctx, g.binary, args...) out.Debug(ctx, "gpg.ExportPublicKey: %s %+v", cmd.Path, cmd.Args) out, err := cmd.Output() if err != nil { return nil, errors.Wrapf(err, "failed to run command '%s %+v'", cmd.Path, cmd.Args) } if len(out) < 1 { return nil, errors.Errorf("Key not found") } return out, nil }
go
func (g *GPG) ExportPublicKey(ctx context.Context, id string) ([]byte, error) { if id == "" { return nil, errors.Errorf("id is empty") } args := append(g.args, "--armor", "--export", id) cmd := exec.CommandContext(ctx, g.binary, args...) out.Debug(ctx, "gpg.ExportPublicKey: %s %+v", cmd.Path, cmd.Args) out, err := cmd.Output() if err != nil { return nil, errors.Wrapf(err, "failed to run command '%s %+v'", cmd.Path, cmd.Args) } if len(out) < 1 { return nil, errors.Errorf("Key not found") } return out, nil }
[ "func", "(", "g", "*", "GPG", ")", "ExportPublicKey", "(", "ctx", "context", ".", "Context", ",", "id", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "if", "id", "==", "\"\"", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"id is empty\"", ")", "\n", "}", "\n", "args", ":=", "append", "(", "g", ".", "args", ",", "\"--armor\"", ",", "\"--export\"", ",", "id", ")", "\n", "cmd", ":=", "exec", ".", "CommandContext", "(", "ctx", ",", "g", ".", "binary", ",", "args", "...", ")", "\n", "out", ".", "Debug", "(", "ctx", ",", "\"gpg.ExportPublicKey: %s %+v\"", ",", "cmd", ".", "Path", ",", "cmd", ".", "Args", ")", "\n", "out", ",", "err", ":=", "cmd", ".", "Output", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to run command '%s %+v'\"", ",", "cmd", ".", "Path", ",", "cmd", ".", "Args", ")", "\n", "}", "\n", "if", "len", "(", "out", ")", "<", "1", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"Key not found\"", ")", "\n", "}", "\n", "return", "out", ",", "nil", "\n", "}" ]
// ExportPublicKey will export the named public key to the location given
[ "ExportPublicKey", "will", "export", "the", "named", "public", "key", "to", "the", "location", "given" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/cli/export.go#L13-L32
train
gopasspw/gopass
pkg/backend/crypto/gpg/cli/utils.go
parseTS
func parseTS(str string) time.Time { t := time.Time{} if sec, err := strconv.ParseInt(str, 10, 64); err == nil { t = time.Unix(sec, 0) } return t }
go
func parseTS(str string) time.Time { t := time.Time{} if sec, err := strconv.ParseInt(str, 10, 64); err == nil { t = time.Unix(sec, 0) } return t }
[ "func", "parseTS", "(", "str", "string", ")", "time", ".", "Time", "{", "t", ":=", "time", ".", "Time", "{", "}", "\n", "if", "sec", ",", "err", ":=", "strconv", ".", "ParseInt", "(", "str", ",", "10", ",", "64", ")", ";", "err", "==", "nil", "{", "t", "=", "time", ".", "Unix", "(", "sec", ",", "0", ")", "\n", "}", "\n", "return", "t", "\n", "}" ]
// parseTS parses the passed string as an Epoch int and returns // the time struct or the zero time struct
[ "parseTS", "parses", "the", "passed", "string", "as", "an", "Epoch", "int", "and", "returns", "the", "time", "struct", "or", "the", "zero", "time", "struct" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/cli/utils.go#L12-L20
train
gopasspw/gopass
pkg/backend/crypto/gpg/cli/utils.go
parseInt
func parseInt(str string) int { i := 0 if iv, err := strconv.ParseInt(str, 10, 32); err == nil { i = int(iv) } return i }
go
func parseInt(str string) int { i := 0 if iv, err := strconv.ParseInt(str, 10, 32); err == nil { i = int(iv) } return i }
[ "func", "parseInt", "(", "str", "string", ")", "int", "{", "i", ":=", "0", "\n", "if", "iv", ",", "err", ":=", "strconv", ".", "ParseInt", "(", "str", ",", "10", ",", "32", ")", ";", "err", "==", "nil", "{", "i", "=", "int", "(", "iv", ")", "\n", "}", "\n", "return", "i", "\n", "}" ]
// parseInt parses the passed string as an int and returns it // or 0 on errors
[ "parseInt", "parses", "the", "passed", "string", "as", "an", "int", "and", "returns", "it", "or", "0", "on", "errors" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/cli/utils.go#L24-L32
train
gopasspw/gopass
pkg/backend/crypto/gpg/cli/utils.go
GPGOpts
func GPGOpts() []string { for _, en := range []string{"GOPASS_GPG_OPTS", "PASSWORD_STORE_GPG_OPTS"} { if opts := os.Getenv(en); opts != "" { return strings.Fields(opts) } } return nil }
go
func GPGOpts() []string { for _, en := range []string{"GOPASS_GPG_OPTS", "PASSWORD_STORE_GPG_OPTS"} { if opts := os.Getenv(en); opts != "" { return strings.Fields(opts) } } return nil }
[ "func", "GPGOpts", "(", ")", "[", "]", "string", "{", "for", "_", ",", "en", ":=", "range", "[", "]", "string", "{", "\"GOPASS_GPG_OPTS\"", ",", "\"PASSWORD_STORE_GPG_OPTS\"", "}", "{", "if", "opts", ":=", "os", ".", "Getenv", "(", "en", ")", ";", "opts", "!=", "\"\"", "{", "return", "strings", ".", "Fields", "(", "opts", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// GPGOpts parses extra GPG options from the environment
[ "GPGOpts", "parses", "extra", "GPG", "options", "from", "the", "environment" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/cli/utils.go#L48-L55
train
gopasspw/gopass
pkg/store/vault/store.go
Exists
func (s *Store) Exists(ctx context.Context, name string) bool { _, err := s.Get(ctx, name) return err == nil }
go
func (s *Store) Exists(ctx context.Context, name string) bool { _, err := s.Get(ctx, name) return err == nil }
[ "func", "(", "s", "*", "Store", ")", "Exists", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "bool", "{", "_", ",", "err", ":=", "s", ".", "Get", "(", "ctx", ",", "name", ")", "\n", "return", "err", "==", "nil", "\n", "}" ]
// Exists checks if a given secret exists
[ "Exists", "checks", "if", "a", "given", "secret", "exists" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/vault/store.go#L195-L198
train
gopasspw/gopass
pkg/store/vault/store.go
Get
func (s *Store) Get(ctx context.Context, name string) (store.Secret, error) { key := path.Join(s.path, name) out.Debug(ctx, "Get(%s) %s", name, key) sec, err := s.api.Logical().Read(key) if err != nil { return nil, err } if sec == nil || sec.Data == nil { return nil, fmt.Errorf("not found") } return &Secret{d: sec.Data}, nil }
go
func (s *Store) Get(ctx context.Context, name string) (store.Secret, error) { key := path.Join(s.path, name) out.Debug(ctx, "Get(%s) %s", name, key) sec, err := s.api.Logical().Read(key) if err != nil { return nil, err } if sec == nil || sec.Data == nil { return nil, fmt.Errorf("not found") } return &Secret{d: sec.Data}, nil }
[ "func", "(", "s", "*", "Store", ")", "Get", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "(", "store", ".", "Secret", ",", "error", ")", "{", "key", ":=", "path", ".", "Join", "(", "s", ".", "path", ",", "name", ")", "\n", "out", ".", "Debug", "(", "ctx", ",", "\"Get(%s) %s\"", ",", "name", ",", "key", ")", "\n", "sec", ",", "err", ":=", "s", ".", "api", ".", "Logical", "(", ")", ".", "Read", "(", "key", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "sec", "==", "nil", "||", "sec", ".", "Data", "==", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"not found\"", ")", "\n", "}", "\n", "return", "&", "Secret", "{", "d", ":", "sec", ".", "Data", "}", ",", "nil", "\n", "}" ]
// Get returns a secret
[ "Get", "returns", "a", "secret" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/vault/store.go#L201-L212
train
gopasspw/gopass
pkg/store/vault/store.go
Initialized
func (s *Store) Initialized(ctx context.Context) bool { _, err := s.List(ctx, "") return err == nil }
go
func (s *Store) Initialized(ctx context.Context) bool { _, err := s.List(ctx, "") return err == nil }
[ "func", "(", "s", "*", "Store", ")", "Initialized", "(", "ctx", "context", ".", "Context", ")", "bool", "{", "_", ",", "err", ":=", "s", ".", "List", "(", "ctx", ",", "\"\"", ")", "\n", "return", "err", "==", "nil", "\n", "}" ]
// Initialized returns true if the backend can communicate with Vault
[ "Initialized", "returns", "true", "if", "the", "backend", "can", "communicate", "with", "Vault" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/vault/store.go#L220-L223
train
gopasspw/gopass
pkg/store/vault/store.go
IsDir
func (s *Store) IsDir(ctx context.Context, name string) bool { ls, err := s.List(ctx, name) if err != nil { return false } return len(ls) > 1 }
go
func (s *Store) IsDir(ctx context.Context, name string) bool { ls, err := s.List(ctx, name) if err != nil { return false } return len(ls) > 1 }
[ "func", "(", "s", "*", "Store", ")", "IsDir", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "bool", "{", "ls", ",", "err", ":=", "s", ".", "List", "(", "ctx", ",", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", "\n", "}", "\n", "return", "len", "(", "ls", ")", ">", "1", "\n", "}" ]
// IsDir returns true if the given name is a dir
[ "IsDir", "returns", "true", "if", "the", "given", "name", "is", "a", "dir" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/vault/store.go#L226-L232
train
gopasspw/gopass
pkg/store/vault/store.go
List
func (s *Store) List(ctx context.Context, prefix string) ([]string, error) { keys, err := s.list(ctx, prefix) if err != nil { return nil, err } for i, e := range keys { keys[i] = path.Join(s.alias, e) } return keys, nil }
go
func (s *Store) List(ctx context.Context, prefix string) ([]string, error) { keys, err := s.list(ctx, prefix) if err != nil { return nil, err } for i, e := range keys { keys[i] = path.Join(s.alias, e) } return keys, nil }
[ "func", "(", "s", "*", "Store", ")", "List", "(", "ctx", "context", ".", "Context", ",", "prefix", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "keys", ",", "err", ":=", "s", ".", "list", "(", "ctx", ",", "prefix", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "for", "i", ",", "e", ":=", "range", "keys", "{", "keys", "[", "i", "]", "=", "path", ".", "Join", "(", "s", ".", "alias", ",", "e", ")", "\n", "}", "\n", "return", "keys", ",", "nil", "\n", "}" ]
// List returns a list of entries with the given prefix
[ "List", "returns", "a", "list", "of", "entries", "with", "the", "given", "prefix" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/vault/store.go#L253-L262
train
gopasspw/gopass
pkg/store/vault/store.go
Move
func (s *Store) Move(ctx context.Context, from string, to string) error { // recursive move? if s.IsDir(ctx, from) { if s.Exists(ctx, to) { return errors.Errorf("Can not move dir to file") } sf, err := s.List(ctx, "") if err != nil { return errors.Wrapf(err, "failed to list store") } destPrefix := to if s.IsDir(ctx, to) { destPrefix = filepath.Join(to, filepath.Base(from)) } for _, e := range sf { if !strings.HasPrefix(e, strings.TrimSuffix(from, "/")+"/") { continue } et := filepath.Join(destPrefix, strings.TrimPrefix(e, from)) if err := s.Move(ctx, e, et); err != nil { out.Error(ctx, "Failed to move '%s' to '%s': %s", e, et, err) } } return nil } content, err := s.Get(ctx, from) if err != nil { return errors.Wrapf(err, "failed to decrypt '%s'", from) } if err := s.Set(ctx, to, content); err != nil { return errors.Wrapf(err, "failed to write '%s'", to) } if err := s.Delete(ctx, from); err != nil { return errors.Wrapf(err, "failed to delete '%s'", from) } return nil }
go
func (s *Store) Move(ctx context.Context, from string, to string) error { // recursive move? if s.IsDir(ctx, from) { if s.Exists(ctx, to) { return errors.Errorf("Can not move dir to file") } sf, err := s.List(ctx, "") if err != nil { return errors.Wrapf(err, "failed to list store") } destPrefix := to if s.IsDir(ctx, to) { destPrefix = filepath.Join(to, filepath.Base(from)) } for _, e := range sf { if !strings.HasPrefix(e, strings.TrimSuffix(from, "/")+"/") { continue } et := filepath.Join(destPrefix, strings.TrimPrefix(e, from)) if err := s.Move(ctx, e, et); err != nil { out.Error(ctx, "Failed to move '%s' to '%s': %s", e, et, err) } } return nil } content, err := s.Get(ctx, from) if err != nil { return errors.Wrapf(err, "failed to decrypt '%s'", from) } if err := s.Set(ctx, to, content); err != nil { return errors.Wrapf(err, "failed to write '%s'", to) } if err := s.Delete(ctx, from); err != nil { return errors.Wrapf(err, "failed to delete '%s'", from) } return nil }
[ "func", "(", "s", "*", "Store", ")", "Move", "(", "ctx", "context", ".", "Context", ",", "from", "string", ",", "to", "string", ")", "error", "{", "if", "s", ".", "IsDir", "(", "ctx", ",", "from", ")", "{", "if", "s", ".", "Exists", "(", "ctx", ",", "to", ")", "{", "return", "errors", ".", "Errorf", "(", "\"Can not move dir to file\"", ")", "\n", "}", "\n", "sf", ",", "err", ":=", "s", ".", "List", "(", "ctx", ",", "\"\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to list store\"", ")", "\n", "}", "\n", "destPrefix", ":=", "to", "\n", "if", "s", ".", "IsDir", "(", "ctx", ",", "to", ")", "{", "destPrefix", "=", "filepath", ".", "Join", "(", "to", ",", "filepath", ".", "Base", "(", "from", ")", ")", "\n", "}", "\n", "for", "_", ",", "e", ":=", "range", "sf", "{", "if", "!", "strings", ".", "HasPrefix", "(", "e", ",", "strings", ".", "TrimSuffix", "(", "from", ",", "\"/\"", ")", "+", "\"/\"", ")", "{", "continue", "\n", "}", "\n", "et", ":=", "filepath", ".", "Join", "(", "destPrefix", ",", "strings", ".", "TrimPrefix", "(", "e", ",", "from", ")", ")", "\n", "if", "err", ":=", "s", ".", "Move", "(", "ctx", ",", "e", ",", "et", ")", ";", "err", "!=", "nil", "{", "out", ".", "Error", "(", "ctx", ",", "\"Failed to move '%s' to '%s': %s\"", ",", "e", ",", "et", ",", "err", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}", "\n", "content", ",", "err", ":=", "s", ".", "Get", "(", "ctx", ",", "from", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to decrypt '%s'\"", ",", "from", ")", "\n", "}", "\n", "if", "err", ":=", "s", ".", "Set", "(", "ctx", ",", "to", ",", "content", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to write '%s'\"", ",", "to", ")", "\n", "}", "\n", "if", "err", ":=", "s", ".", "Delete", "(", "ctx", ",", "from", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to delete '%s'\"", ",", "from", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Move moves one or many secrets
[ "Move", "moves", "one", "or", "many", "secrets" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/vault/store.go#L290-L327
train
gopasspw/gopass
pkg/store/vault/store.go
Set
func (s *Store) Set(ctx context.Context, name string, sec store.Secret) error { d := sec.Data() if d == nil { d = make(map[string]interface{}, 1) } d[passwordKey] = sec.Password() _, err := s.api.Logical().Write(path.Join(s.path, name), d) return err }
go
func (s *Store) Set(ctx context.Context, name string, sec store.Secret) error { d := sec.Data() if d == nil { d = make(map[string]interface{}, 1) } d[passwordKey] = sec.Password() _, err := s.api.Logical().Write(path.Join(s.path, name), d) return err }
[ "func", "(", "s", "*", "Store", ")", "Set", "(", "ctx", "context", ".", "Context", ",", "name", "string", ",", "sec", "store", ".", "Secret", ")", "error", "{", "d", ":=", "sec", ".", "Data", "(", ")", "\n", "if", "d", "==", "nil", "{", "d", "=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ",", "1", ")", "\n", "}", "\n", "d", "[", "passwordKey", "]", "=", "sec", ".", "Password", "(", ")", "\n", "_", ",", "err", ":=", "s", ".", "api", ".", "Logical", "(", ")", ".", "Write", "(", "path", ".", "Join", "(", "s", ".", "path", ",", "name", ")", ",", "d", ")", "\n", "return", "err", "\n", "}" ]
// Set writes a secret
[ "Set", "writes", "a", "secret" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/vault/store.go#L330-L338
train
gopasspw/gopass
pkg/store/vault/store.go
Prune
func (s *Store) Prune(ctx context.Context, name string) error { ls, err := s.List(ctx, name) if err != nil { return err } for _, e := range ls { if err := s.Delete(ctx, e); err != nil { return err } } return nil }
go
func (s *Store) Prune(ctx context.Context, name string) error { ls, err := s.List(ctx, name) if err != nil { return err } for _, e := range ls { if err := s.Delete(ctx, e); err != nil { return err } } return nil }
[ "func", "(", "s", "*", "Store", ")", "Prune", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "error", "{", "ls", ",", "err", ":=", "s", ".", "List", "(", "ctx", ",", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "for", "_", ",", "e", ":=", "range", "ls", "{", "if", "err", ":=", "s", ".", "Delete", "(", "ctx", ",", "e", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Prune removes a directory tree
[ "Prune", "removes", "a", "directory", "tree" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/vault/store.go#L341-L352
train
gopasspw/gopass
pkg/termio/ask.go
AskForInt
func AskForInt(ctx context.Context, text string, def int) (int, error) { if ctxutil.IsAlwaysYes(ctx) { return def, nil } str, err := AskForString(ctx, text, strconv.Itoa(def)) if err != nil { return 0, err } if str == "q" { return 0, ErrAborted } intVal, err := strconv.Atoi(str) if err != nil { return 0, errors.Wrapf(err, "failed to convert to number") } return intVal, nil }
go
func AskForInt(ctx context.Context, text string, def int) (int, error) { if ctxutil.IsAlwaysYes(ctx) { return def, nil } str, err := AskForString(ctx, text, strconv.Itoa(def)) if err != nil { return 0, err } if str == "q" { return 0, ErrAborted } intVal, err := strconv.Atoi(str) if err != nil { return 0, errors.Wrapf(err, "failed to convert to number") } return intVal, nil }
[ "func", "AskForInt", "(", "ctx", "context", ".", "Context", ",", "text", "string", ",", "def", "int", ")", "(", "int", ",", "error", ")", "{", "if", "ctxutil", ".", "IsAlwaysYes", "(", "ctx", ")", "{", "return", "def", ",", "nil", "\n", "}", "\n", "str", ",", "err", ":=", "AskForString", "(", "ctx", ",", "text", ",", "strconv", ".", "Itoa", "(", "def", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "if", "str", "==", "\"q\"", "{", "return", "0", ",", "ErrAborted", "\n", "}", "\n", "intVal", ",", "err", ":=", "strconv", ".", "Atoi", "(", "str", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to convert to number\"", ")", "\n", "}", "\n", "return", "intVal", ",", "nil", "\n", "}" ]
// AskForInt asks for an valid interger once. If the input // can not be converted to an int it returns an error
[ "AskForInt", "asks", "for", "an", "valid", "interger", "once", ".", "If", "the", "input", "can", "not", "be", "converted", "to", "an", "int", "it", "returns", "an", "error" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/termio/ask.go#L95-L112
train
gopasspw/gopass
pkg/termio/ask.go
AskForKeyImport
func AskForKeyImport(ctx context.Context, key string, names []string) bool { if ctxutil.IsAlwaysYes(ctx) { return true } if !ctxutil.IsInteractive(ctx) { return false } ok, err := AskForBool(ctx, fmt.Sprintf("Do you want to import the public key '%s' (Names: %+v) into your keyring?", key, names), false) if err != nil { return false } return ok }
go
func AskForKeyImport(ctx context.Context, key string, names []string) bool { if ctxutil.IsAlwaysYes(ctx) { return true } if !ctxutil.IsInteractive(ctx) { return false } ok, err := AskForBool(ctx, fmt.Sprintf("Do you want to import the public key '%s' (Names: %+v) into your keyring?", key, names), false) if err != nil { return false } return ok }
[ "func", "AskForKeyImport", "(", "ctx", "context", ".", "Context", ",", "key", "string", ",", "names", "[", "]", "string", ")", "bool", "{", "if", "ctxutil", ".", "IsAlwaysYes", "(", "ctx", ")", "{", "return", "true", "\n", "}", "\n", "if", "!", "ctxutil", ".", "IsInteractive", "(", "ctx", ")", "{", "return", "false", "\n", "}", "\n", "ok", ",", "err", ":=", "AskForBool", "(", "ctx", ",", "fmt", ".", "Sprintf", "(", "\"Do you want to import the public key '%s' (Names: %+v) into your keyring?\"", ",", "key", ",", "names", ")", ",", "false", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", "\n", "}", "\n", "return", "ok", "\n", "}" ]
// AskForKeyImport asks for permissions to import the named key
[ "AskForKeyImport", "asks", "for", "permissions", "to", "import", "the", "named", "key" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/termio/ask.go#L134-L148
train
gopasspw/gopass
pkg/termio/ask.go
AskForPassword
func AskForPassword(ctx context.Context, name string) (string, error) { if ctxutil.IsAlwaysYes(ctx) { return "", nil } askFn := GetPassPromptFunc(ctx) for i := 0; i < maxTries; i++ { // check for context cancelation select { case <-ctx.Done(): return "", ErrAborted default: } pass, err := askFn(ctx, fmt.Sprintf("Enter password for %s", name)) if err != nil { return "", err } passAgain, err := askFn(ctx, fmt.Sprintf("Retype password for %s", name)) if err != nil { return "", err } if pass == passAgain || pass == "" { return pass, nil } out.Error(ctx, "Error: the entered password do not match") } return "", errors.New("no valid user input") }
go
func AskForPassword(ctx context.Context, name string) (string, error) { if ctxutil.IsAlwaysYes(ctx) { return "", nil } askFn := GetPassPromptFunc(ctx) for i := 0; i < maxTries; i++ { // check for context cancelation select { case <-ctx.Done(): return "", ErrAborted default: } pass, err := askFn(ctx, fmt.Sprintf("Enter password for %s", name)) if err != nil { return "", err } passAgain, err := askFn(ctx, fmt.Sprintf("Retype password for %s", name)) if err != nil { return "", err } if pass == passAgain || pass == "" { return pass, nil } out.Error(ctx, "Error: the entered password do not match") } return "", errors.New("no valid user input") }
[ "func", "AskForPassword", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "(", "string", ",", "error", ")", "{", "if", "ctxutil", ".", "IsAlwaysYes", "(", "ctx", ")", "{", "return", "\"\"", ",", "nil", "\n", "}", "\n", "askFn", ":=", "GetPassPromptFunc", "(", "ctx", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "maxTries", ";", "i", "++", "{", "select", "{", "case", "<-", "ctx", ".", "Done", "(", ")", ":", "return", "\"\"", ",", "ErrAborted", "\n", "default", ":", "}", "\n", "pass", ",", "err", ":=", "askFn", "(", "ctx", ",", "fmt", ".", "Sprintf", "(", "\"Enter password for %s\"", ",", "name", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "err", "\n", "}", "\n", "passAgain", ",", "err", ":=", "askFn", "(", "ctx", ",", "fmt", ".", "Sprintf", "(", "\"Retype password for %s\"", ",", "name", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "err", "\n", "}", "\n", "if", "pass", "==", "passAgain", "||", "pass", "==", "\"\"", "{", "return", "pass", ",", "nil", "\n", "}", "\n", "out", ".", "Error", "(", "ctx", ",", "\"Error: the entered password do not match\"", ")", "\n", "}", "\n", "return", "\"\"", ",", "errors", ".", "New", "(", "\"no valid user input\"", ")", "\n", "}" ]
// AskForPassword prompts for a password twice until both match
[ "AskForPassword", "prompts", "for", "a", "password", "twice", "until", "both", "match" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/termio/ask.go#L151-L182
train
gopasspw/gopass
pkg/action/edit.go
Edit
func (s *Action) Edit(ctx context.Context, c *cli.Context) error { name := c.Args().First() if name == "" { return ExitError(ctx, ExitUsage, nil, "Usage: %s edit secret", s.Name) } return s.edit(ctx, c, name) }
go
func (s *Action) Edit(ctx context.Context, c *cli.Context) error { name := c.Args().First() if name == "" { return ExitError(ctx, ExitUsage, nil, "Usage: %s edit secret", s.Name) } return s.edit(ctx, c, name) }
[ "func", "(", "s", "*", "Action", ")", "Edit", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "name", ":=", "c", ".", "Args", "(", ")", ".", "First", "(", ")", "\n", "if", "name", "==", "\"\"", "{", "return", "ExitError", "(", "ctx", ",", "ExitUsage", ",", "nil", ",", "\"Usage: %s edit secret\"", ",", "s", ".", "Name", ")", "\n", "}", "\n", "return", "s", ".", "edit", "(", "ctx", ",", "c", ",", "name", ")", "\n", "}" ]
// Edit the content of a password file
[ "Edit", "the", "content", "of", "a", "password", "file" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/edit.go#L20-L27
train
gopasspw/gopass
pkg/backend/crypto/xc/encrypt.go
Encrypt
func (x *XC) Encrypt(ctx context.Context, plaintext []byte, recipients []string) ([]byte, error) { privKeyIDs := x.secring.KeyIDs() if len(privKeyIDs) < 1 { return nil, fmt.Errorf("no signing keys available on our keyring") } privKey := x.secring.Get(privKeyIDs[0]) var compressed bool plaintext, compressed = compress(plaintext) // encrypt body (also generates a random session key) sk, chunks, err := encryptBody(plaintext) if err != nil { return nil, errors.Wrapf(err, "failed to encrypt body: %s", err) } // encrypt the session key per recipient header, err := x.encryptHeader(ctx, privKey, sk, recipients) if err != nil { return nil, errors.Wrapf(err, "failed to encrypt header: %s", err) } msg := &xcpb.Message{ Version: OnDiskVersion, Header: header, Chunks: chunks, Compressed: compressed, } return proto.Marshal(msg) }
go
func (x *XC) Encrypt(ctx context.Context, plaintext []byte, recipients []string) ([]byte, error) { privKeyIDs := x.secring.KeyIDs() if len(privKeyIDs) < 1 { return nil, fmt.Errorf("no signing keys available on our keyring") } privKey := x.secring.Get(privKeyIDs[0]) var compressed bool plaintext, compressed = compress(plaintext) // encrypt body (also generates a random session key) sk, chunks, err := encryptBody(plaintext) if err != nil { return nil, errors.Wrapf(err, "failed to encrypt body: %s", err) } // encrypt the session key per recipient header, err := x.encryptHeader(ctx, privKey, sk, recipients) if err != nil { return nil, errors.Wrapf(err, "failed to encrypt header: %s", err) } msg := &xcpb.Message{ Version: OnDiskVersion, Header: header, Chunks: chunks, Compressed: compressed, } return proto.Marshal(msg) }
[ "func", "(", "x", "*", "XC", ")", "Encrypt", "(", "ctx", "context", ".", "Context", ",", "plaintext", "[", "]", "byte", ",", "recipients", "[", "]", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "privKeyIDs", ":=", "x", ".", "secring", ".", "KeyIDs", "(", ")", "\n", "if", "len", "(", "privKeyIDs", ")", "<", "1", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"no signing keys available on our keyring\"", ")", "\n", "}", "\n", "privKey", ":=", "x", ".", "secring", ".", "Get", "(", "privKeyIDs", "[", "0", "]", ")", "\n", "var", "compressed", "bool", "\n", "plaintext", ",", "compressed", "=", "compress", "(", "plaintext", ")", "\n", "sk", ",", "chunks", ",", "err", ":=", "encryptBody", "(", "plaintext", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to encrypt body: %s\"", ",", "err", ")", "\n", "}", "\n", "header", ",", "err", ":=", "x", ".", "encryptHeader", "(", "ctx", ",", "privKey", ",", "sk", ",", "recipients", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to encrypt header: %s\"", ",", "err", ")", "\n", "}", "\n", "msg", ":=", "&", "xcpb", ".", "Message", "{", "Version", ":", "OnDiskVersion", ",", "Header", ":", "header", ",", "Chunks", ":", "chunks", ",", "Compressed", ":", "compressed", ",", "}", "\n", "return", "proto", ".", "Marshal", "(", "msg", ")", "\n", "}" ]
// Encrypt encrypts the given plaintext for all the given recipients and returns the // ciphertext
[ "Encrypt", "encrypts", "the", "given", "plaintext", "for", "all", "the", "given", "recipients", "and", "returns", "the", "ciphertext" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/encrypt.go#L32-L62
train
gopasspw/gopass
pkg/backend/crypto/xc/encrypt.go
encryptForRecipient
func (x *XC) encryptForRecipient(ctx context.Context, sender *keyring.PrivateKey, sk []byte, recipient string) ([]byte, error) { recp := x.pubring.Get(recipient) if recp == nil { return nil, fmt.Errorf("recipient public key not available for %s", recipient) } var recipientPublicKey [32]byte copy(recipientPublicKey[:], recp.PublicKey[:]) // unlock sender key if err := x.decryptPrivateKey(ctx, sender); err != nil { return nil, err } // we need to copy the byte silces to byte arrays for box var senderPrivateKey [32]byte pk := sender.PrivateKey() copy(senderPrivateKey[:], pk[:]) var nonce [24]byte if _, err := io.ReadFull(crypto_rand.Reader, nonce[:]); err != nil { return nil, err } return box.Seal(nonce[:], sk, &nonce, &recipientPublicKey, &senderPrivateKey), nil }
go
func (x *XC) encryptForRecipient(ctx context.Context, sender *keyring.PrivateKey, sk []byte, recipient string) ([]byte, error) { recp := x.pubring.Get(recipient) if recp == nil { return nil, fmt.Errorf("recipient public key not available for %s", recipient) } var recipientPublicKey [32]byte copy(recipientPublicKey[:], recp.PublicKey[:]) // unlock sender key if err := x.decryptPrivateKey(ctx, sender); err != nil { return nil, err } // we need to copy the byte silces to byte arrays for box var senderPrivateKey [32]byte pk := sender.PrivateKey() copy(senderPrivateKey[:], pk[:]) var nonce [24]byte if _, err := io.ReadFull(crypto_rand.Reader, nonce[:]); err != nil { return nil, err } return box.Seal(nonce[:], sk, &nonce, &recipientPublicKey, &senderPrivateKey), nil }
[ "func", "(", "x", "*", "XC", ")", "encryptForRecipient", "(", "ctx", "context", ".", "Context", ",", "sender", "*", "keyring", ".", "PrivateKey", ",", "sk", "[", "]", "byte", ",", "recipient", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "recp", ":=", "x", ".", "pubring", ".", "Get", "(", "recipient", ")", "\n", "if", "recp", "==", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"recipient public key not available for %s\"", ",", "recipient", ")", "\n", "}", "\n", "var", "recipientPublicKey", "[", "32", "]", "byte", "\n", "copy", "(", "recipientPublicKey", "[", ":", "]", ",", "recp", ".", "PublicKey", "[", ":", "]", ")", "\n", "if", "err", ":=", "x", ".", "decryptPrivateKey", "(", "ctx", ",", "sender", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "var", "senderPrivateKey", "[", "32", "]", "byte", "\n", "pk", ":=", "sender", ".", "PrivateKey", "(", ")", "\n", "copy", "(", "senderPrivateKey", "[", ":", "]", ",", "pk", "[", ":", "]", ")", "\n", "var", "nonce", "[", "24", "]", "byte", "\n", "if", "_", ",", "err", ":=", "io", ".", "ReadFull", "(", "crypto_rand", ".", "Reader", ",", "nonce", "[", ":", "]", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "box", ".", "Seal", "(", "nonce", "[", ":", "]", ",", "sk", ",", "&", "nonce", ",", "&", "recipientPublicKey", ",", "&", "senderPrivateKey", ")", ",", "nil", "\n", "}" ]
// encryptForRecipients encrypts the given session key for the given recipient
[ "encryptForRecipients", "encrypts", "the", "given", "session", "key", "for", "the", "given", "recipient" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/encrypt.go#L93-L118
train
gopasspw/gopass
pkg/backend/crypto/xc/encrypt.go
encryptBody
func encryptBody(plaintext []byte) ([]byte, []*xcpb.Chunk, error) { // generate session / encryption key var sessionKey [32]byte if _, err := crypto_rand.Read(sessionKey[:]); err != nil { return nil, nil, err } chunks := make([]*xcpb.Chunk, 0, (len(plaintext)/chunkSizeMax)+1) offset := 0 for offset < len(plaintext) { // use a sequential nonce to prevent chunk reordering. // since the pair of key and nonce has to be unique and we're // generating a new random key for each message, this is OK var nonce [24]byte binary.BigEndian.PutUint64(nonce[:], uint64(len(chunks))) // encrypt the plaintext using the random nonce chunks = append(chunks, &xcpb.Chunk{ Body: secretbox.Seal(nil, plaintext[offset:min(len(plaintext), offset+chunkSizeMax)], &nonce, &sessionKey), }) offset += chunkSizeMax } return sessionKey[:], chunks, nil }
go
func encryptBody(plaintext []byte) ([]byte, []*xcpb.Chunk, error) { // generate session / encryption key var sessionKey [32]byte if _, err := crypto_rand.Read(sessionKey[:]); err != nil { return nil, nil, err } chunks := make([]*xcpb.Chunk, 0, (len(plaintext)/chunkSizeMax)+1) offset := 0 for offset < len(plaintext) { // use a sequential nonce to prevent chunk reordering. // since the pair of key and nonce has to be unique and we're // generating a new random key for each message, this is OK var nonce [24]byte binary.BigEndian.PutUint64(nonce[:], uint64(len(chunks))) // encrypt the plaintext using the random nonce chunks = append(chunks, &xcpb.Chunk{ Body: secretbox.Seal(nil, plaintext[offset:min(len(plaintext), offset+chunkSizeMax)], &nonce, &sessionKey), }) offset += chunkSizeMax } return sessionKey[:], chunks, nil }
[ "func", "encryptBody", "(", "plaintext", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "[", "]", "*", "xcpb", ".", "Chunk", ",", "error", ")", "{", "var", "sessionKey", "[", "32", "]", "byte", "\n", "if", "_", ",", "err", ":=", "crypto_rand", ".", "Read", "(", "sessionKey", "[", ":", "]", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n", "chunks", ":=", "make", "(", "[", "]", "*", "xcpb", ".", "Chunk", ",", "0", ",", "(", "len", "(", "plaintext", ")", "/", "chunkSizeMax", ")", "+", "1", ")", "\n", "offset", ":=", "0", "\n", "for", "offset", "<", "len", "(", "plaintext", ")", "{", "var", "nonce", "[", "24", "]", "byte", "\n", "binary", ".", "BigEndian", ".", "PutUint64", "(", "nonce", "[", ":", "]", ",", "uint64", "(", "len", "(", "chunks", ")", ")", ")", "\n", "chunks", "=", "append", "(", "chunks", ",", "&", "xcpb", ".", "Chunk", "{", "Body", ":", "secretbox", ".", "Seal", "(", "nil", ",", "plaintext", "[", "offset", ":", "min", "(", "len", "(", "plaintext", ")", ",", "offset", "+", "chunkSizeMax", ")", "]", ",", "&", "nonce", ",", "&", "sessionKey", ")", ",", "}", ")", "\n", "offset", "+=", "chunkSizeMax", "\n", "}", "\n", "return", "sessionKey", "[", ":", "]", ",", "chunks", ",", "nil", "\n", "}" ]
// encryptBody generates a random session key and a nonce and encrypts the given // plaintext with those. it returns all three
[ "encryptBody", "generates", "a", "random", "session", "key", "and", "a", "nonce", "and", "encrypts", "the", "given", "plaintext", "with", "those", ".", "it", "returns", "all", "three" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/encrypt.go#L122-L147
train
gopasspw/gopass
pkg/backend/crypto/gpg/cli/keyring.go
listKeys
func (g *GPG) listKeys(ctx context.Context, typ string, search ...string) (gpg.KeyList, error) { args := []string{"--with-colons", "--with-fingerprint", "--fixed-list-mode", "--list-" + typ + "-keys"} args = append(args, search...) if e, found := g.listCache.Get(strings.Join(args, ",")); found { if ev, ok := e.(gpg.KeyList); ok { return ev, nil } } cmd := exec.CommandContext(ctx, g.binary, args...) cmd.Stderr = nil out.Debug(ctx, "gpg.listKeys: %s %+v\n", cmd.Path, cmd.Args) cmdout, err := cmd.Output() if err != nil { if bytes.Contains(cmdout, []byte("secret key not available")) { return gpg.KeyList{}, nil } return gpg.KeyList{}, err } kl := parseColons(bytes.NewBuffer(cmdout)) g.listCache.Add(strings.Join(args, ","), kl) return kl, nil }
go
func (g *GPG) listKeys(ctx context.Context, typ string, search ...string) (gpg.KeyList, error) { args := []string{"--with-colons", "--with-fingerprint", "--fixed-list-mode", "--list-" + typ + "-keys"} args = append(args, search...) if e, found := g.listCache.Get(strings.Join(args, ",")); found { if ev, ok := e.(gpg.KeyList); ok { return ev, nil } } cmd := exec.CommandContext(ctx, g.binary, args...) cmd.Stderr = nil out.Debug(ctx, "gpg.listKeys: %s %+v\n", cmd.Path, cmd.Args) cmdout, err := cmd.Output() if err != nil { if bytes.Contains(cmdout, []byte("secret key not available")) { return gpg.KeyList{}, nil } return gpg.KeyList{}, err } kl := parseColons(bytes.NewBuffer(cmdout)) g.listCache.Add(strings.Join(args, ","), kl) return kl, nil }
[ "func", "(", "g", "*", "GPG", ")", "listKeys", "(", "ctx", "context", ".", "Context", ",", "typ", "string", ",", "search", "...", "string", ")", "(", "gpg", ".", "KeyList", ",", "error", ")", "{", "args", ":=", "[", "]", "string", "{", "\"--with-colons\"", ",", "\"--with-fingerprint\"", ",", "\"--fixed-list-mode\"", ",", "\"--list-\"", "+", "typ", "+", "\"-keys\"", "}", "\n", "args", "=", "append", "(", "args", ",", "search", "...", ")", "\n", "if", "e", ",", "found", ":=", "g", ".", "listCache", ".", "Get", "(", "strings", ".", "Join", "(", "args", ",", "\",\"", ")", ")", ";", "found", "{", "if", "ev", ",", "ok", ":=", "e", ".", "(", "gpg", ".", "KeyList", ")", ";", "ok", "{", "return", "ev", ",", "nil", "\n", "}", "\n", "}", "\n", "cmd", ":=", "exec", ".", "CommandContext", "(", "ctx", ",", "g", ".", "binary", ",", "args", "...", ")", "\n", "cmd", ".", "Stderr", "=", "nil", "\n", "out", ".", "Debug", "(", "ctx", ",", "\"gpg.listKeys: %s %+v\\n\"", ",", "\\n", ",", "cmd", ".", "Path", ")", "\n", "cmd", ".", "Args", "\n", "cmdout", ",", "err", ":=", "cmd", ".", "Output", "(", ")", "\n", "if", "err", "!=", "nil", "{", "if", "bytes", ".", "Contains", "(", "cmdout", ",", "[", "]", "byte", "(", "\"secret key not available\"", ")", ")", "{", "return", "gpg", ".", "KeyList", "{", "}", ",", "nil", "\n", "}", "\n", "return", "gpg", ".", "KeyList", "{", "}", ",", "err", "\n", "}", "\n", "kl", ":=", "parseColons", "(", "bytes", ".", "NewBuffer", "(", "cmdout", ")", ")", "\n", "g", ".", "listCache", ".", "Add", "(", "strings", ".", "Join", "(", "args", ",", "\",\"", ")", ",", "kl", ")", "\n", "}" ]
// listKey lists all keys of the given type and matching the search strings
[ "listKey", "lists", "all", "keys", "of", "the", "given", "type", "and", "matching", "the", "search", "strings" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/cli/keyring.go#L14-L37
train
gopasspw/gopass
pkg/backend/crypto/gpg/cli/keyring.go
ListPublicKeyIDs
func (g *GPG) ListPublicKeyIDs(ctx context.Context) ([]string, error) { if g.pubKeys == nil { kl, err := g.listKeys(ctx, "public") if err != nil { return nil, err } g.pubKeys = kl } if gpg.IsAlwaysTrust(ctx) { return g.pubKeys.Recipients(), nil } return g.pubKeys.UseableKeys().Recipients(), nil }
go
func (g *GPG) ListPublicKeyIDs(ctx context.Context) ([]string, error) { if g.pubKeys == nil { kl, err := g.listKeys(ctx, "public") if err != nil { return nil, err } g.pubKeys = kl } if gpg.IsAlwaysTrust(ctx) { return g.pubKeys.Recipients(), nil } return g.pubKeys.UseableKeys().Recipients(), nil }
[ "func", "(", "g", "*", "GPG", ")", "ListPublicKeyIDs", "(", "ctx", "context", ".", "Context", ")", "(", "[", "]", "string", ",", "error", ")", "{", "if", "g", ".", "pubKeys", "==", "nil", "{", "kl", ",", "err", ":=", "g", ".", "listKeys", "(", "ctx", ",", "\"public\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "g", ".", "pubKeys", "=", "kl", "\n", "}", "\n", "if", "gpg", ".", "IsAlwaysTrust", "(", "ctx", ")", "{", "return", "g", ".", "pubKeys", ".", "Recipients", "(", ")", ",", "nil", "\n", "}", "\n", "return", "g", ".", "pubKeys", ".", "UseableKeys", "(", ")", ".", "Recipients", "(", ")", ",", "nil", "\n", "}" ]
// ListPublicKeyIDs returns a parsed list of GPG public keys
[ "ListPublicKeyIDs", "returns", "a", "parsed", "list", "of", "GPG", "public", "keys" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/cli/keyring.go#L40-L52
train
gopasspw/gopass
pkg/backend/crypto/gpg/cli/keyring.go
FindPublicKeys
func (g *GPG) FindPublicKeys(ctx context.Context, search ...string) ([]string, error) { kl, err := g.listKeys(ctx, "public", search...) if err != nil || kl == nil { return nil, err } if gpg.IsAlwaysTrust(ctx) { return kl.Recipients(), nil } return kl.UseableKeys().Recipients(), nil }
go
func (g *GPG) FindPublicKeys(ctx context.Context, search ...string) ([]string, error) { kl, err := g.listKeys(ctx, "public", search...) if err != nil || kl == nil { return nil, err } if gpg.IsAlwaysTrust(ctx) { return kl.Recipients(), nil } return kl.UseableKeys().Recipients(), nil }
[ "func", "(", "g", "*", "GPG", ")", "FindPublicKeys", "(", "ctx", "context", ".", "Context", ",", "search", "...", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "kl", ",", "err", ":=", "g", ".", "listKeys", "(", "ctx", ",", "\"public\"", ",", "search", "...", ")", "\n", "if", "err", "!=", "nil", "||", "kl", "==", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "gpg", ".", "IsAlwaysTrust", "(", "ctx", ")", "{", "return", "kl", ".", "Recipients", "(", ")", ",", "nil", "\n", "}", "\n", "return", "kl", ".", "UseableKeys", "(", ")", ".", "Recipients", "(", ")", ",", "nil", "\n", "}" ]
// FindPublicKeys searches for the given public keys
[ "FindPublicKeys", "searches", "for", "the", "given", "public", "keys" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/cli/keyring.go#L55-L64
train
gopasspw/gopass
pkg/backend/crypto/gpg/cli/keyring.go
ListPrivateKeyIDs
func (g *GPG) ListPrivateKeyIDs(ctx context.Context) ([]string, error) { if g.privKeys == nil { kl, err := g.listKeys(ctx, "secret") if err != nil { return nil, err } g.privKeys = kl } if gpg.IsAlwaysTrust(ctx) { return g.privKeys.Recipients(), nil } return g.privKeys.UseableKeys().Recipients(), nil }
go
func (g *GPG) ListPrivateKeyIDs(ctx context.Context) ([]string, error) { if g.privKeys == nil { kl, err := g.listKeys(ctx, "secret") if err != nil { return nil, err } g.privKeys = kl } if gpg.IsAlwaysTrust(ctx) { return g.privKeys.Recipients(), nil } return g.privKeys.UseableKeys().Recipients(), nil }
[ "func", "(", "g", "*", "GPG", ")", "ListPrivateKeyIDs", "(", "ctx", "context", ".", "Context", ")", "(", "[", "]", "string", ",", "error", ")", "{", "if", "g", ".", "privKeys", "==", "nil", "{", "kl", ",", "err", ":=", "g", ".", "listKeys", "(", "ctx", ",", "\"secret\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "g", ".", "privKeys", "=", "kl", "\n", "}", "\n", "if", "gpg", ".", "IsAlwaysTrust", "(", "ctx", ")", "{", "return", "g", ".", "privKeys", ".", "Recipients", "(", ")", ",", "nil", "\n", "}", "\n", "return", "g", ".", "privKeys", ".", "UseableKeys", "(", ")", ".", "Recipients", "(", ")", ",", "nil", "\n", "}" ]
// ListPrivateKeyIDs returns a parsed list of GPG secret keys
[ "ListPrivateKeyIDs", "returns", "a", "parsed", "list", "of", "GPG", "secret", "keys" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/cli/keyring.go#L67-L79
train
gopasspw/gopass
pkg/backend/crypto/gpg/cli/keyring.go
EmailFromKey
func (g *GPG) EmailFromKey(ctx context.Context, id string) string { return g.findKey(ctx, id).Identity().Email }
go
func (g *GPG) EmailFromKey(ctx context.Context, id string) string { return g.findKey(ctx, id).Identity().Email }
[ "func", "(", "g", "*", "GPG", ")", "EmailFromKey", "(", "ctx", "context", ".", "Context", ",", "id", "string", ")", "string", "{", "return", "g", ".", "findKey", "(", "ctx", ",", "id", ")", ".", "Identity", "(", ")", ".", "Email", "\n", "}" ]
// EmailFromKey extracts the email from a key id
[ "EmailFromKey", "extracts", "the", "email", "from", "a", "key", "id" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/cli/keyring.go#L108-L110
train
gopasspw/gopass
pkg/backend/crypto/gpg/cli/keyring.go
NameFromKey
func (g *GPG) NameFromKey(ctx context.Context, id string) string { return g.findKey(ctx, id).Identity().Name }
go
func (g *GPG) NameFromKey(ctx context.Context, id string) string { return g.findKey(ctx, id).Identity().Name }
[ "func", "(", "g", "*", "GPG", ")", "NameFromKey", "(", "ctx", "context", ".", "Context", ",", "id", "string", ")", "string", "{", "return", "g", ".", "findKey", "(", "ctx", ",", "id", ")", ".", "Identity", "(", ")", ".", "Name", "\n", "}" ]
// NameFromKey extracts the name from a key id
[ "NameFromKey", "extracts", "the", "name", "from", "a", "key", "id" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/cli/keyring.go#L113-L115
train
gopasspw/gopass
pkg/backend/crypto/gpg/cli/keyring.go
FormatKey
func (g *GPG) FormatKey(ctx context.Context, id string) string { return g.findKey(ctx, id).OneLine() }
go
func (g *GPG) FormatKey(ctx context.Context, id string) string { return g.findKey(ctx, id).OneLine() }
[ "func", "(", "g", "*", "GPG", ")", "FormatKey", "(", "ctx", "context", ".", "Context", ",", "id", "string", ")", "string", "{", "return", "g", ".", "findKey", "(", "ctx", ",", "id", ")", ".", "OneLine", "(", ")", "\n", "}" ]
// FormatKey formats the details of a key id
[ "FormatKey", "formats", "the", "details", "of", "a", "key", "id" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/cli/keyring.go#L118-L120
train
gopasspw/gopass
pkg/action/grep.go
Grep
func (s *Action) Grep(ctx context.Context, c *cli.Context) error { if !c.Args().Present() { return ExitError(ctx, ExitUsage, nil, "Usage: %s grep arg", s.Name) } // get the search term needle := c.Args().First() haystack, err := s.Store.List(ctx, 0) if err != nil { return ExitError(ctx, ExitList, err, "failed to list store: %s", err) } var matches int var errors int for _, v := range haystack { sec, err := s.Store.Get(ctx, v) if err != nil { out.Error(ctx, "failed to decrypt %s: %v", v, err) continue } if strings.Contains(sec.Password(), needle) { out.Print(ctx, "%s:\n%s", color.BlueString(v), sec.Password()) } if strings.Contains(sec.Body(), needle) { out.Print(ctx, "%s:\n%s", color.BlueString(v), sec.Body()) } } if errors > 0 { return ExitError(ctx, ExitDecrypt, nil, "some secrets failed to decrypt") } if matches < 1 { return ExitError(ctx, ExitNotFound, nil, "no matches found") } out.Print(ctx, "\nScanned %d secrets. %d matches, %d errors", len(haystack), matches, errors) return nil }
go
func (s *Action) Grep(ctx context.Context, c *cli.Context) error { if !c.Args().Present() { return ExitError(ctx, ExitUsage, nil, "Usage: %s grep arg", s.Name) } // get the search term needle := c.Args().First() haystack, err := s.Store.List(ctx, 0) if err != nil { return ExitError(ctx, ExitList, err, "failed to list store: %s", err) } var matches int var errors int for _, v := range haystack { sec, err := s.Store.Get(ctx, v) if err != nil { out.Error(ctx, "failed to decrypt %s: %v", v, err) continue } if strings.Contains(sec.Password(), needle) { out.Print(ctx, "%s:\n%s", color.BlueString(v), sec.Password()) } if strings.Contains(sec.Body(), needle) { out.Print(ctx, "%s:\n%s", color.BlueString(v), sec.Body()) } } if errors > 0 { return ExitError(ctx, ExitDecrypt, nil, "some secrets failed to decrypt") } if matches < 1 { return ExitError(ctx, ExitNotFound, nil, "no matches found") } out.Print(ctx, "\nScanned %d secrets. %d matches, %d errors", len(haystack), matches, errors) return nil }
[ "func", "(", "s", "*", "Action", ")", "Grep", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "if", "!", "c", ".", "Args", "(", ")", ".", "Present", "(", ")", "{", "return", "ExitError", "(", "ctx", ",", "ExitUsage", ",", "nil", ",", "\"Usage: %s grep arg\"", ",", "s", ".", "Name", ")", "\n", "}", "\n", "needle", ":=", "c", ".", "Args", "(", ")", ".", "First", "(", ")", "\n", "haystack", ",", "err", ":=", "s", ".", "Store", ".", "List", "(", "ctx", ",", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitList", ",", "err", ",", "\"failed to list store: %s\"", ",", "err", ")", "\n", "}", "\n", "var", "matches", "int", "\n", "var", "errors", "int", "\n", "for", "_", ",", "v", ":=", "range", "haystack", "{", "sec", ",", "err", ":=", "s", ".", "Store", ".", "Get", "(", "ctx", ",", "v", ")", "\n", "if", "err", "!=", "nil", "{", "out", ".", "Error", "(", "ctx", ",", "\"failed to decrypt %s: %v\"", ",", "v", ",", "err", ")", "\n", "continue", "\n", "}", "\n", "if", "strings", ".", "Contains", "(", "sec", ".", "Password", "(", ")", ",", "needle", ")", "{", "out", ".", "Print", "(", "ctx", ",", "\"%s:\\n%s\"", ",", "\\n", ",", "color", ".", "BlueString", "(", "v", ")", ")", "\n", "}", "\n", "sec", ".", "Password", "(", ")", "\n", "}", "\n", "if", "strings", ".", "Contains", "(", "sec", ".", "Body", "(", ")", ",", "needle", ")", "{", "out", ".", "Print", "(", "ctx", ",", "\"%s:\\n%s\"", ",", "\\n", ",", "color", ".", "BlueString", "(", "v", ")", ")", "\n", "}", "\n", "sec", ".", "Body", "(", ")", "\n", "if", "errors", ">", "0", "{", "return", "ExitError", "(", "ctx", ",", "ExitDecrypt", ",", "nil", ",", "\"some secrets failed to decrypt\"", ")", "\n", "}", "\n", "if", "matches", "<", "1", "{", "return", "ExitError", "(", "ctx", ",", "ExitNotFound", ",", "nil", ",", "\"no matches found\"", ")", "\n", "}", "\n", "}" ]
// Grep searches a string inside the content of all files
[ "Grep", "searches", "a", "string", "inside", "the", "content", "of", "all", "files" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/grep.go#L14-L53
train
gopasspw/gopass
pkg/backend/crypto/gpg/openpgp/gpg.go
New
func New(ctx context.Context) (*GPG, error) { pubfn := filepath.Join(gpgHome(ctx), "pubring.gpg") pubring, err := readKeyring(pubfn) if err != nil { return nil, err } secfn := filepath.Join(gpgHome(ctx), "secring.gpg") secring, err := readKeyring(secfn) if err != nil { return nil, err } g := &GPG{ pubring: pubring, secring: secring, pubfn: pubfn, secfn: secfn, } return g, nil }
go
func New(ctx context.Context) (*GPG, error) { pubfn := filepath.Join(gpgHome(ctx), "pubring.gpg") pubring, err := readKeyring(pubfn) if err != nil { return nil, err } secfn := filepath.Join(gpgHome(ctx), "secring.gpg") secring, err := readKeyring(secfn) if err != nil { return nil, err } g := &GPG{ pubring: pubring, secring: secring, pubfn: pubfn, secfn: secfn, } return g, nil }
[ "func", "New", "(", "ctx", "context", ".", "Context", ")", "(", "*", "GPG", ",", "error", ")", "{", "pubfn", ":=", "filepath", ".", "Join", "(", "gpgHome", "(", "ctx", ")", ",", "\"pubring.gpg\"", ")", "\n", "pubring", ",", "err", ":=", "readKeyring", "(", "pubfn", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "secfn", ":=", "filepath", ".", "Join", "(", "gpgHome", "(", "ctx", ")", ",", "\"secring.gpg\"", ")", "\n", "secring", ",", "err", ":=", "readKeyring", "(", "secfn", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "g", ":=", "&", "GPG", "{", "pubring", ":", "pubring", ",", "secring", ":", "secring", ",", "pubfn", ":", "pubfn", ",", "secfn", ":", "secfn", ",", "}", "\n", "return", "g", ",", "nil", "\n", "}" ]
// New creates a new pure-Go GPG backend
[ "New", "creates", "a", "new", "pure", "-", "Go", "GPG", "backend" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/openpgp/gpg.go#L30-L48
train
gopasspw/gopass
pkg/backend/crypto/gpg/openpgp/gpg.go
RecipientIDs
func (g *GPG) RecipientIDs(ctx context.Context, ciphertext []byte) ([]string, error) { recps := make([]string, 0, 1) packets := packet.NewReader(bytes.NewReader(ciphertext)) for { p, err := packets.Next() if err != nil { if err == io.EOF { break } return nil, err } switch p := p.(type) { case *packet.EncryptedKey: for _, key := range g.pubring { if key.PrimaryKey == nil { continue } if key.PrimaryKey.KeyId == p.KeyId { recps = append(recps, key.PrimaryKey.KeyIdString()) } } } } return recps, nil }
go
func (g *GPG) RecipientIDs(ctx context.Context, ciphertext []byte) ([]string, error) { recps := make([]string, 0, 1) packets := packet.NewReader(bytes.NewReader(ciphertext)) for { p, err := packets.Next() if err != nil { if err == io.EOF { break } return nil, err } switch p := p.(type) { case *packet.EncryptedKey: for _, key := range g.pubring { if key.PrimaryKey == nil { continue } if key.PrimaryKey.KeyId == p.KeyId { recps = append(recps, key.PrimaryKey.KeyIdString()) } } } } return recps, nil }
[ "func", "(", "g", "*", "GPG", ")", "RecipientIDs", "(", "ctx", "context", ".", "Context", ",", "ciphertext", "[", "]", "byte", ")", "(", "[", "]", "string", ",", "error", ")", "{", "recps", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "1", ")", "\n", "packets", ":=", "packet", ".", "NewReader", "(", "bytes", ".", "NewReader", "(", "ciphertext", ")", ")", "\n", "for", "{", "p", ",", "err", ":=", "packets", ".", "Next", "(", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "==", "io", ".", "EOF", "{", "break", "\n", "}", "\n", "return", "nil", ",", "err", "\n", "}", "\n", "switch", "p", ":=", "p", ".", "(", "type", ")", "{", "case", "*", "packet", ".", "EncryptedKey", ":", "for", "_", ",", "key", ":=", "range", "g", ".", "pubring", "{", "if", "key", ".", "PrimaryKey", "==", "nil", "{", "continue", "\n", "}", "\n", "if", "key", ".", "PrimaryKey", ".", "KeyId", "==", "p", ".", "KeyId", "{", "recps", "=", "append", "(", "recps", ",", "key", ".", "PrimaryKey", ".", "KeyIdString", "(", ")", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "recps", ",", "nil", "\n", "}" ]
// RecipientIDs returns the recipients of the encrypted message
[ "RecipientIDs", "returns", "the", "recipients", "of", "the", "encrypted", "message" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/openpgp/gpg.go#L51-L75
train
gopasspw/gopass
pkg/backend/crypto/gpg/openpgp/gpg.go
Encrypt
func (g *GPG) Encrypt(ctx context.Context, plaintext []byte, recipients []string) ([]byte, error) { ciphertext := &bytes.Buffer{} ents := g.recipientsToEntities(recipients) wc, err := openpgp.Encrypt(ciphertext, ents, nil, nil, nil) if err != nil { return nil, errors.Wrapf(err, "failed to encrypt") } if _, err := io.Copy(wc, bytes.NewReader(plaintext)); err != nil { return nil, errors.Wrapf(err, "failed to write plaintext to encoder") } if err := wc.Close(); err != nil { return nil, errors.Wrapf(err, "failed to finalize encryption") } return ciphertext.Bytes(), nil }
go
func (g *GPG) Encrypt(ctx context.Context, plaintext []byte, recipients []string) ([]byte, error) { ciphertext := &bytes.Buffer{} ents := g.recipientsToEntities(recipients) wc, err := openpgp.Encrypt(ciphertext, ents, nil, nil, nil) if err != nil { return nil, errors.Wrapf(err, "failed to encrypt") } if _, err := io.Copy(wc, bytes.NewReader(plaintext)); err != nil { return nil, errors.Wrapf(err, "failed to write plaintext to encoder") } if err := wc.Close(); err != nil { return nil, errors.Wrapf(err, "failed to finalize encryption") } return ciphertext.Bytes(), nil }
[ "func", "(", "g", "*", "GPG", ")", "Encrypt", "(", "ctx", "context", ".", "Context", ",", "plaintext", "[", "]", "byte", ",", "recipients", "[", "]", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "ciphertext", ":=", "&", "bytes", ".", "Buffer", "{", "}", "\n", "ents", ":=", "g", ".", "recipientsToEntities", "(", "recipients", ")", "\n", "wc", ",", "err", ":=", "openpgp", ".", "Encrypt", "(", "ciphertext", ",", "ents", ",", "nil", ",", "nil", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to encrypt\"", ")", "\n", "}", "\n", "if", "_", ",", "err", ":=", "io", ".", "Copy", "(", "wc", ",", "bytes", ".", "NewReader", "(", "plaintext", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to write plaintext to encoder\"", ")", "\n", "}", "\n", "if", "err", ":=", "wc", ".", "Close", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to finalize encryption\"", ")", "\n", "}", "\n", "return", "ciphertext", ".", "Bytes", "(", ")", ",", "nil", "\n", "}" ]
// Encrypt encrypts the plaintext for the given recipients
[ "Encrypt", "encrypts", "the", "plaintext", "for", "the", "given", "recipients" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/openpgp/gpg.go#L78-L92
train
gopasspw/gopass
pkg/backend/crypto/gpg/openpgp/gpg.go
ImportPublicKey
func (g *GPG) ImportPublicKey(ctx context.Context, buf []byte) error { el, err := openpgp.ReadArmoredKeyRing(bytes.NewReader(buf)) if err != nil { return err } g.pubring = append(g.pubring, el...) return nil }
go
func (g *GPG) ImportPublicKey(ctx context.Context, buf []byte) error { el, err := openpgp.ReadArmoredKeyRing(bytes.NewReader(buf)) if err != nil { return err } g.pubring = append(g.pubring, el...) return nil }
[ "func", "(", "g", "*", "GPG", ")", "ImportPublicKey", "(", "ctx", "context", ".", "Context", ",", "buf", "[", "]", "byte", ")", "error", "{", "el", ",", "err", ":=", "openpgp", ".", "ReadArmoredKeyRing", "(", "bytes", ".", "NewReader", "(", "buf", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "g", ".", "pubring", "=", "append", "(", "g", ".", "pubring", ",", "el", "...", ")", "\n", "return", "nil", "\n", "}" ]
// ImportPublicKey does nothing
[ "ImportPublicKey", "does", "nothing" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/openpgp/gpg.go#L121-L128
train
gopasspw/gopass
pkg/backend/crypto/gpg/openpgp/gpg.go
Version
func (g *GPG) Version(context.Context) semver.Version { return semver.Version{Major: 1} }
go
func (g *GPG) Version(context.Context) semver.Version { return semver.Version{Major: 1} }
[ "func", "(", "g", "*", "GPG", ")", "Version", "(", "context", ".", "Context", ")", "semver", ".", "Version", "{", "return", "semver", ".", "Version", "{", "Major", ":", "1", "}", "\n", "}" ]
// Version returns dummy version info
[ "Version", "returns", "dummy", "version", "info" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/openpgp/gpg.go#L131-L133
train
gopasspw/gopass
pkg/backend/crypto/gpg/openpgp/gpg.go
Sign
func (g *GPG) Sign(ctx context.Context, in string, sigf string) error { signKeys := g.SigningKeys() if len(signKeys) < 1 { return fmt.Errorf("no signing keys available") } sigfh, err := os.OpenFile(sigf, os.O_WRONLY|os.O_CREATE, 0644) if err != nil { return err } defer sigfh.Close() wc, err := clearsign.Encode(sigfh, signKeys[0].PrivateKey, nil) if err != nil { return err } infh, err := os.Open(in) if err != nil { return err } defer infh.Close() if _, err := io.Copy(wc, infh); err != nil { return err } return wc.Close() }
go
func (g *GPG) Sign(ctx context.Context, in string, sigf string) error { signKeys := g.SigningKeys() if len(signKeys) < 1 { return fmt.Errorf("no signing keys available") } sigfh, err := os.OpenFile(sigf, os.O_WRONLY|os.O_CREATE, 0644) if err != nil { return err } defer sigfh.Close() wc, err := clearsign.Encode(sigfh, signKeys[0].PrivateKey, nil) if err != nil { return err } infh, err := os.Open(in) if err != nil { return err } defer infh.Close() if _, err := io.Copy(wc, infh); err != nil { return err } return wc.Close() }
[ "func", "(", "g", "*", "GPG", ")", "Sign", "(", "ctx", "context", ".", "Context", ",", "in", "string", ",", "sigf", "string", ")", "error", "{", "signKeys", ":=", "g", ".", "SigningKeys", "(", ")", "\n", "if", "len", "(", "signKeys", ")", "<", "1", "{", "return", "fmt", ".", "Errorf", "(", "\"no signing keys available\"", ")", "\n", "}", "\n", "sigfh", ",", "err", ":=", "os", ".", "OpenFile", "(", "sigf", ",", "os", ".", "O_WRONLY", "|", "os", ".", "O_CREATE", ",", "0644", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "sigfh", ".", "Close", "(", ")", "\n", "wc", ",", "err", ":=", "clearsign", ".", "Encode", "(", "sigfh", ",", "signKeys", "[", "0", "]", ".", "PrivateKey", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "infh", ",", "err", ":=", "os", ".", "Open", "(", "in", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "infh", ".", "Close", "(", ")", "\n", "if", "_", ",", "err", ":=", "io", ".", "Copy", "(", "wc", ",", "infh", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "wc", ".", "Close", "(", ")", "\n", "}" ]
// Sign is not implemented
[ "Sign", "is", "not", "implemented" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/openpgp/gpg.go#L141-L167
train
gopasspw/gopass
pkg/backend/crypto/gpg/openpgp/gpg.go
Verify
func (g *GPG) Verify(ctx context.Context, sigf string, in string) error { sig, err := ioutil.ReadFile(sigf) if err != nil { return err } b, _ := clearsign.Decode(sig) infh, err := os.Open(in) if err != nil { return err } defer infh.Close() _, err = openpgp.CheckDetachedSignature(g.pubring, infh, bytes.NewReader(b.Bytes)) if err != nil { return err } return nil }
go
func (g *GPG) Verify(ctx context.Context, sigf string, in string) error { sig, err := ioutil.ReadFile(sigf) if err != nil { return err } b, _ := clearsign.Decode(sig) infh, err := os.Open(in) if err != nil { return err } defer infh.Close() _, err = openpgp.CheckDetachedSignature(g.pubring, infh, bytes.NewReader(b.Bytes)) if err != nil { return err } return nil }
[ "func", "(", "g", "*", "GPG", ")", "Verify", "(", "ctx", "context", ".", "Context", ",", "sigf", "string", ",", "in", "string", ")", "error", "{", "sig", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "sigf", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "b", ",", "_", ":=", "clearsign", ".", "Decode", "(", "sig", ")", "\n", "infh", ",", "err", ":=", "os", ".", "Open", "(", "in", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "infh", ".", "Close", "(", ")", "\n", "_", ",", "err", "=", "openpgp", ".", "CheckDetachedSignature", "(", "g", ".", "pubring", ",", "infh", ",", "bytes", ".", "NewReader", "(", "b", ".", "Bytes", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Verify is not implemented
[ "Verify", "is", "not", "implemented" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/openpgp/gpg.go#L170-L186
train
gopasspw/gopass
pkg/backend/crypto/gpg/openpgp/gpg.go
EmailFromKey
func (g *GPG) EmailFromKey(ctx context.Context, id string) string { ent := g.findEntity(id) if ent == nil || ent.Identities == nil { return "" } for name, id := range ent.Identities { if id.UserId == nil { return name } return id.UserId.Email } return "" }
go
func (g *GPG) EmailFromKey(ctx context.Context, id string) string { ent := g.findEntity(id) if ent == nil || ent.Identities == nil { return "" } for name, id := range ent.Identities { if id.UserId == nil { return name } return id.UserId.Email } return "" }
[ "func", "(", "g", "*", "GPG", ")", "EmailFromKey", "(", "ctx", "context", ".", "Context", ",", "id", "string", ")", "string", "{", "ent", ":=", "g", ".", "findEntity", "(", "id", ")", "\n", "if", "ent", "==", "nil", "||", "ent", ".", "Identities", "==", "nil", "{", "return", "\"\"", "\n", "}", "\n", "for", "name", ",", "id", ":=", "range", "ent", ".", "Identities", "{", "if", "id", ".", "UserId", "==", "nil", "{", "return", "name", "\n", "}", "\n", "return", "id", ".", "UserId", ".", "Email", "\n", "}", "\n", "return", "\"\"", "\n", "}" ]
// EmailFromKey returns the email for this key
[ "EmailFromKey", "returns", "the", "email", "for", "this", "key" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/openpgp/gpg.go#L206-L218
train
gopasspw/gopass
pkg/backend/crypto/gpg/openpgp/gpg.go
NameFromKey
func (g *GPG) NameFromKey(ctx context.Context, id string) string { ent := g.findEntity(id) if ent == nil || ent.Identities == nil { return "" } for name, id := range ent.Identities { if id.UserId == nil { return name } return id.UserId.Name } return "" }
go
func (g *GPG) NameFromKey(ctx context.Context, id string) string { ent := g.findEntity(id) if ent == nil || ent.Identities == nil { return "" } for name, id := range ent.Identities { if id.UserId == nil { return name } return id.UserId.Name } return "" }
[ "func", "(", "g", "*", "GPG", ")", "NameFromKey", "(", "ctx", "context", ".", "Context", ",", "id", "string", ")", "string", "{", "ent", ":=", "g", ".", "findEntity", "(", "id", ")", "\n", "if", "ent", "==", "nil", "||", "ent", ".", "Identities", "==", "nil", "{", "return", "\"\"", "\n", "}", "\n", "for", "name", ",", "id", ":=", "range", "ent", ".", "Identities", "{", "if", "id", ".", "UserId", "==", "nil", "{", "return", "name", "\n", "}", "\n", "return", "id", ".", "UserId", ".", "Name", "\n", "}", "\n", "return", "\"\"", "\n", "}" ]
// NameFromKey is returns the name for this key
[ "NameFromKey", "is", "returns", "the", "name", "for", "this", "key" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/openpgp/gpg.go#L221-L233
train
gopasspw/gopass
pkg/backend/crypto/gpg/openpgp/gpg.go
ReadNamesFromKey
func (g *GPG) ReadNamesFromKey(ctx context.Context, buf []byte) ([]string, error) { el, err := openpgp.ReadArmoredKeyRing(bytes.NewReader(buf)) if err != nil { return nil, errors.Wrapf(err, "failed to read key ring") } if len(el) != 1 { return nil, errors.Errorf("Public Key must contain exactly one Entity") } names := make([]string, 0, len(el[0].Identities)) for _, v := range el[0].Identities { names = append(names, v.Name) } return names, nil }
go
func (g *GPG) ReadNamesFromKey(ctx context.Context, buf []byte) ([]string, error) { el, err := openpgp.ReadArmoredKeyRing(bytes.NewReader(buf)) if err != nil { return nil, errors.Wrapf(err, "failed to read key ring") } if len(el) != 1 { return nil, errors.Errorf("Public Key must contain exactly one Entity") } names := make([]string, 0, len(el[0].Identities)) for _, v := range el[0].Identities { names = append(names, v.Name) } return names, nil }
[ "func", "(", "g", "*", "GPG", ")", "ReadNamesFromKey", "(", "ctx", "context", ".", "Context", ",", "buf", "[", "]", "byte", ")", "(", "[", "]", "string", ",", "error", ")", "{", "el", ",", "err", ":=", "openpgp", ".", "ReadArmoredKeyRing", "(", "bytes", ".", "NewReader", "(", "buf", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to read key ring\"", ")", "\n", "}", "\n", "if", "len", "(", "el", ")", "!=", "1", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"Public Key must contain exactly one Entity\"", ")", "\n", "}", "\n", "names", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "el", "[", "0", "]", ".", "Identities", ")", ")", "\n", "for", "_", ",", "v", ":=", "range", "el", "[", "0", "]", ".", "Identities", "{", "names", "=", "append", "(", "names", ",", "v", ".", "Name", ")", "\n", "}", "\n", "return", "names", ",", "nil", "\n", "}" ]
// ReadNamesFromKey unmarshals and returns the names associated with the given public key
[ "ReadNamesFromKey", "unmarshals", "and", "returns", "the", "names", "associated", "with", "the", "given", "public", "key" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/openpgp/gpg.go#L277-L290
train
gopasspw/gopass
pkg/action/unclip.go
Unclip
func (s *Action) Unclip(ctx context.Context, c *cli.Context) error { force := c.Bool("force") timeout := c.Int("timeout") checksum := os.Getenv("GOPASS_UNCLIP_CHECKSUM") time.Sleep(time.Second * time.Duration(timeout)) if err := clipboard.Clear(ctx, checksum, force); err != nil { return ExitError(ctx, ExitIO, err, "Failed to clear clipboard: %s", err) } return nil }
go
func (s *Action) Unclip(ctx context.Context, c *cli.Context) error { force := c.Bool("force") timeout := c.Int("timeout") checksum := os.Getenv("GOPASS_UNCLIP_CHECKSUM") time.Sleep(time.Second * time.Duration(timeout)) if err := clipboard.Clear(ctx, checksum, force); err != nil { return ExitError(ctx, ExitIO, err, "Failed to clear clipboard: %s", err) } return nil }
[ "func", "(", "s", "*", "Action", ")", "Unclip", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "force", ":=", "c", ".", "Bool", "(", "\"force\"", ")", "\n", "timeout", ":=", "c", ".", "Int", "(", "\"timeout\"", ")", "\n", "checksum", ":=", "os", ".", "Getenv", "(", "\"GOPASS_UNCLIP_CHECKSUM\"", ")", "\n", "time", ".", "Sleep", "(", "time", ".", "Second", "*", "time", ".", "Duration", "(", "timeout", ")", ")", "\n", "if", "err", ":=", "clipboard", ".", "Clear", "(", "ctx", ",", "checksum", ",", "force", ")", ";", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitIO", ",", "err", ",", "\"Failed to clear clipboard: %s\"", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Unclip tries to erase the content of the clipboard
[ "Unclip", "tries", "to", "erase", "the", "content", "of", "the", "clipboard" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/unclip.go#L14-L24
train
gopasspw/gopass
pkg/action/find.go
Find
func (s *Action) Find(ctx context.Context, c *cli.Context) error { 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) } return s.find(ctx, c, c.Args().First(), s.show) }
go
func (s *Action) Find(ctx context.Context, c *cli.Context) error { 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) } return s.find(ctx, c, c.Args().First(), s.show) }
[ "func", "(", "s", "*", "Action", ")", "Find", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "if", "c", ".", "IsSet", "(", "\"clip\"", ")", "{", "ctx", "=", "WithClip", "(", "ctx", ",", "c", ".", "Bool", "(", "\"clip\"", ")", ")", "\n", "}", "\n", "if", "!", "c", ".", "Args", "(", ")", ".", "Present", "(", ")", "{", "return", "ExitError", "(", "ctx", ",", "ExitUsage", ",", "nil", ",", "\"Usage: %s find <NEEDLE>\"", ",", "s", ".", "Name", ")", "\n", "}", "\n", "return", "s", ".", "find", "(", "ctx", ",", "c", ",", "c", ".", "Args", "(", ")", ".", "First", "(", ")", ",", "s", ".", "show", ")", "\n", "}" ]
// Find a string in the secret file's name
[ "Find", "a", "string", "in", "the", "secret", "file", "s", "name" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/find.go#L18-L28
train
gopasspw/gopass
pkg/action/find.go
findSelection
func (s *Action) findSelection(ctx context.Context, c *cli.Context, choices []string, needle string, cb showFunc) error { sort.Strings(choices) act, sel := cui.GetSelection(ctx, "Found secrets - Please select an entry", "<↑/↓> to change the selection, <→> to show, <←> to copy, <s> to sync, <e> to edit, <ESC> to quit", choices) out.Debug(ctx, "Action: %s - Selection: %d", act, sel) switch act { case "default": // display or copy selected entry fmt.Fprintln(stdout, choices[sel]) return cb(ctx, c, choices[sel], "", false) case "copy": // display selected entry fmt.Fprintln(stdout, choices[sel]) return cb(WithClip(ctx, true), c, choices[sel], "", false) case "show": // display selected entry fmt.Fprintln(stdout, choices[sel]) return cb(WithClip(ctx, false), c, choices[sel], "", false) case "sync": // run sync and re-run show/find workflow if err := s.Sync(ctx, c); err != nil { return err } return cb(ctx, c, needle, "", true) case "edit": // edit selected entry fmt.Fprintln(stdout, choices[sel]) return s.edit(ctx, c, choices[sel]) default: return ExitError(ctx, ExitAborted, nil, "user aborted") } }
go
func (s *Action) findSelection(ctx context.Context, c *cli.Context, choices []string, needle string, cb showFunc) error { sort.Strings(choices) act, sel := cui.GetSelection(ctx, "Found secrets - Please select an entry", "<↑/↓> to change the selection, <→> to show, <←> to copy, <s> to sync, <e> to edit, <ESC> to quit", choices) out.Debug(ctx, "Action: %s - Selection: %d", act, sel) switch act { case "default": // display or copy selected entry fmt.Fprintln(stdout, choices[sel]) return cb(ctx, c, choices[sel], "", false) case "copy": // display selected entry fmt.Fprintln(stdout, choices[sel]) return cb(WithClip(ctx, true), c, choices[sel], "", false) case "show": // display selected entry fmt.Fprintln(stdout, choices[sel]) return cb(WithClip(ctx, false), c, choices[sel], "", false) case "sync": // run sync and re-run show/find workflow if err := s.Sync(ctx, c); err != nil { return err } return cb(ctx, c, needle, "", true) case "edit": // edit selected entry fmt.Fprintln(stdout, choices[sel]) return s.edit(ctx, c, choices[sel]) default: return ExitError(ctx, ExitAborted, nil, "user aborted") } }
[ "func", "(", "s", "*", "Action", ")", "findSelection", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ",", "choices", "[", "]", "string", ",", "needle", "string", ",", "cb", "showFunc", ")", "error", "{", "sort", ".", "Strings", "(", "choices", ")", "\n", "act", ",", "sel", ":=", "cui", ".", "GetSelection", "(", "ctx", ",", "\"Found secrets - Please select an entry\"", ",", "\"<↑/↓> to change the selection, <→> to show, <←> to copy, <s> to sync, <e> to edit, <ESC> to quit\", choice", "e", "identifier", ")", "\n", "s", "\n", "out", ".", "Debug", "(", "ctx", ",", "\"Action: %s - Selection: %d\"", ",", "act", ",", "sel", ")", "\n", "}" ]
// findSelection runs a wizard that lets the user select an entry
[ "findSelection", "runs", "a", "wizard", "that", "lets", "the", "user", "select", "an", "entry" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/find.go#L75-L105
train
gopasspw/gopass
pkg/qrcon/qrcon.go
QRCode
func QRCode(content string) (string, error) { q, err := qrcode.New(content, qrcode.Medium) if err != nil { return "", err } buf := bytes.Buffer{} i := q.Image(0) b := i.Bounds() for x := b.Min.X; x < b.Max.X; x++ { for y := b.Min.Y; y < b.Max.Y; y++ { col := i.At(x, y) if sameColor(col, q.ForegroundColor) { _, _ = buf.WriteString(black) } else if sameColor(col, q.BackgroundColor) { _, _ = buf.WriteString(white) } else { return "", errors.Errorf("Unexpected color at (%d,%d): %+v", x, y, col) } } _, _ = buf.WriteString("\n") } return buf.String(), nil }
go
func QRCode(content string) (string, error) { q, err := qrcode.New(content, qrcode.Medium) if err != nil { return "", err } buf := bytes.Buffer{} i := q.Image(0) b := i.Bounds() for x := b.Min.X; x < b.Max.X; x++ { for y := b.Min.Y; y < b.Max.Y; y++ { col := i.At(x, y) if sameColor(col, q.ForegroundColor) { _, _ = buf.WriteString(black) } else if sameColor(col, q.BackgroundColor) { _, _ = buf.WriteString(white) } else { return "", errors.Errorf("Unexpected color at (%d,%d): %+v", x, y, col) } } _, _ = buf.WriteString("\n") } return buf.String(), nil }
[ "func", "QRCode", "(", "content", "string", ")", "(", "string", ",", "error", ")", "{", "q", ",", "err", ":=", "qrcode", ".", "New", "(", "content", ",", "qrcode", ".", "Medium", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "err", "\n", "}", "\n", "buf", ":=", "bytes", ".", "Buffer", "{", "}", "\n", "i", ":=", "q", ".", "Image", "(", "0", ")", "\n", "b", ":=", "i", ".", "Bounds", "(", ")", "\n", "for", "x", ":=", "b", ".", "Min", ".", "X", ";", "x", "<", "b", ".", "Max", ".", "X", ";", "x", "++", "{", "for", "y", ":=", "b", ".", "Min", ".", "Y", ";", "y", "<", "b", ".", "Max", ".", "Y", ";", "y", "++", "{", "col", ":=", "i", ".", "At", "(", "x", ",", "y", ")", "\n", "if", "sameColor", "(", "col", ",", "q", ".", "ForegroundColor", ")", "{", "_", ",", "_", "=", "buf", ".", "WriteString", "(", "black", ")", "\n", "}", "else", "if", "sameColor", "(", "col", ",", "q", ".", "BackgroundColor", ")", "{", "_", ",", "_", "=", "buf", ".", "WriteString", "(", "white", ")", "\n", "}", "else", "{", "return", "\"\"", ",", "errors", ".", "Errorf", "(", "\"Unexpected color at (%d,%d): %+v\"", ",", "x", ",", "y", ",", "col", ")", "\n", "}", "\n", "}", "\n", "_", ",", "_", "=", "buf", ".", "WriteString", "(", "\"\\n\"", ")", "\n", "}", "\n", "\\n", "\n", "}" ]
// QRCode returns a string containing an ANSI encoded // QR Code
[ "QRCode", "returns", "a", "string", "containing", "an", "ANSI", "encoded", "QR", "Code" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/qrcon/qrcon.go#L18-L40
train
gopasspw/gopass
pkg/store/root/read.go
GetContext
func (r *Store) GetContext(ctx context.Context, name string) (store.Secret, context.Context, error) { // forward to substore ctx, store, name := r.getStore(ctx, name) sec, err := store.Get(ctx, name) return sec, ctx, err }
go
func (r *Store) GetContext(ctx context.Context, name string) (store.Secret, context.Context, error) { // forward to substore ctx, store, name := r.getStore(ctx, name) sec, err := store.Get(ctx, name) return sec, ctx, err }
[ "func", "(", "r", "*", "Store", ")", "GetContext", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "(", "store", ".", "Secret", ",", "context", ".", "Context", ",", "error", ")", "{", "ctx", ",", "store", ",", "name", ":=", "r", ".", "getStore", "(", "ctx", ",", "name", ")", "\n", "sec", ",", "err", ":=", "store", ".", "Get", "(", "ctx", ",", "name", ")", "\n", "return", "sec", ",", "ctx", ",", "err", "\n", "}" ]
// GetContext returns the plaintext and the context of a single key
[ "GetContext", "returns", "the", "plaintext", "and", "the", "context", "of", "a", "single", "key" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/read.go#L17-L22
train
gopasspw/gopass
pkg/tree/simple/tree.go
New
func New(name string) *Folder { f := newFolder(name) f.Root = true return f }
go
func New(name string) *Folder { f := newFolder(name) f.Root = true return f }
[ "func", "New", "(", "name", "string", ")", "*", "Folder", "{", "f", ":=", "newFolder", "(", "name", ")", "\n", "f", ".", "Root", "=", "true", "\n", "return", "f", "\n", "}" ]
// New create a new root folder
[ "New", "create", "a", "new", "root", "folder" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/tree/simple/tree.go#L27-L31
train
gopasspw/gopass
pkg/updater/update_others.go
IsUpdateable
func IsUpdateable(ctx context.Context) error { fn, err := executable(ctx) if err != nil { return err } out.Debug(ctx, "isUpdateable - File: %s", fn) // check if this is a test binary if strings.HasSuffix(filepath.Base(fn), ".test") { return nil } // check if we want to force updateability if uf := os.Getenv("GOPASS_FORCE_UPDATE"); uf != "" { out.Debug(ctx, "updateable due to force flag") return nil } // check if file is in GOPATH if gp := os.Getenv("GOPATH"); strings.HasPrefix(fn, gp) { return fmt.Errorf("use go get -u to update binary in GOPATH") } // check file fi, err := os.Stat(fn) if err != nil { return err } if !fi.Mode().IsRegular() { return fmt.Errorf("not a regular file") } if err := unix.Access(fn, unix.W_OK); err != nil { return err } // check dir fdir := filepath.Dir(fn) return unix.Access(fdir, unix.W_OK) }
go
func IsUpdateable(ctx context.Context) error { fn, err := executable(ctx) if err != nil { return err } out.Debug(ctx, "isUpdateable - File: %s", fn) // check if this is a test binary if strings.HasSuffix(filepath.Base(fn), ".test") { return nil } // check if we want to force updateability if uf := os.Getenv("GOPASS_FORCE_UPDATE"); uf != "" { out.Debug(ctx, "updateable due to force flag") return nil } // check if file is in GOPATH if gp := os.Getenv("GOPATH"); strings.HasPrefix(fn, gp) { return fmt.Errorf("use go get -u to update binary in GOPATH") } // check file fi, err := os.Stat(fn) if err != nil { return err } if !fi.Mode().IsRegular() { return fmt.Errorf("not a regular file") } if err := unix.Access(fn, unix.W_OK); err != nil { return err } // check dir fdir := filepath.Dir(fn) return unix.Access(fdir, unix.W_OK) }
[ "func", "IsUpdateable", "(", "ctx", "context", ".", "Context", ")", "error", "{", "fn", ",", "err", ":=", "executable", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "out", ".", "Debug", "(", "ctx", ",", "\"isUpdateable - File: %s\"", ",", "fn", ")", "\n", "if", "strings", ".", "HasSuffix", "(", "filepath", ".", "Base", "(", "fn", ")", ",", "\".test\"", ")", "{", "return", "nil", "\n", "}", "\n", "if", "uf", ":=", "os", ".", "Getenv", "(", "\"GOPASS_FORCE_UPDATE\"", ")", ";", "uf", "!=", "\"\"", "{", "out", ".", "Debug", "(", "ctx", ",", "\"updateable due to force flag\"", ")", "\n", "return", "nil", "\n", "}", "\n", "if", "gp", ":=", "os", ".", "Getenv", "(", "\"GOPATH\"", ")", ";", "strings", ".", "HasPrefix", "(", "fn", ",", "gp", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"use go get -u to update binary in GOPATH\"", ")", "\n", "}", "\n", "fi", ",", "err", ":=", "os", ".", "Stat", "(", "fn", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "!", "fi", ".", "Mode", "(", ")", ".", "IsRegular", "(", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"not a regular file\"", ")", "\n", "}", "\n", "if", "err", ":=", "unix", ".", "Access", "(", "fn", ",", "unix", ".", "W_OK", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "fdir", ":=", "filepath", ".", "Dir", "(", "fn", ")", "\n", "return", "unix", ".", "Access", "(", "fdir", ",", "unix", ".", "W_OK", ")", "\n", "}" ]
// IsUpdateable returns an error if this binary is not updateable
[ "IsUpdateable", "returns", "an", "error", "if", "this", "binary", "is", "not", "updateable" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/updater/update_others.go#L77-L114
train
gopasspw/gopass
pkg/config/location.go
Homedir
func Homedir() string { if hd := os.Getenv("GOPASS_HOMEDIR"); hd != "" { return hd } hd, err := homedir.Dir() if err != nil { if debug { fmt.Printf("[DEBUG] Failed to get homedir: %s\n", err) } return "" } return hd }
go
func Homedir() string { if hd := os.Getenv("GOPASS_HOMEDIR"); hd != "" { return hd } hd, err := homedir.Dir() if err != nil { if debug { fmt.Printf("[DEBUG] Failed to get homedir: %s\n", err) } return "" } return hd }
[ "func", "Homedir", "(", ")", "string", "{", "if", "hd", ":=", "os", ".", "Getenv", "(", "\"GOPASS_HOMEDIR\"", ")", ";", "hd", "!=", "\"\"", "{", "return", "hd", "\n", "}", "\n", "hd", ",", "err", ":=", "homedir", ".", "Dir", "(", ")", "\n", "if", "err", "!=", "nil", "{", "if", "debug", "{", "fmt", ".", "Printf", "(", "\"[DEBUG] Failed to get homedir: %s\\n\"", ",", "\\n", ")", "\n", "}", "\n", "err", "\n", "}", "\n", "return", "\"\"", "\n", "}" ]
// Homedir returns the users home dir or an empty string if the lookup fails
[ "Homedir", "returns", "the", "users", "home", "dir", "or", "an", "empty", "string", "if", "the", "lookup", "fails" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/config/location.go#L15-L27
train
gopasspw/gopass
pkg/config/location.go
configLocations
func configLocations() []string { l := []string{} if cf := os.Getenv("GOPASS_CONFIG"); cf != "" { l = append(l, cf) } if xch := os.Getenv("XDG_CONFIG_HOME"); xch != "" { l = append(l, filepath.Join(xch, "gopass", "config.yml")) } l = append(l, filepath.Join(Homedir(), ".config", "gopass", "config.yml")) l = append(l, filepath.Join(Homedir(), ".gopass.yml")) return l }
go
func configLocations() []string { l := []string{} if cf := os.Getenv("GOPASS_CONFIG"); cf != "" { l = append(l, cf) } if xch := os.Getenv("XDG_CONFIG_HOME"); xch != "" { l = append(l, filepath.Join(xch, "gopass", "config.yml")) } l = append(l, filepath.Join(Homedir(), ".config", "gopass", "config.yml")) l = append(l, filepath.Join(Homedir(), ".gopass.yml")) return l }
[ "func", "configLocations", "(", ")", "[", "]", "string", "{", "l", ":=", "[", "]", "string", "{", "}", "\n", "if", "cf", ":=", "os", ".", "Getenv", "(", "\"GOPASS_CONFIG\"", ")", ";", "cf", "!=", "\"\"", "{", "l", "=", "append", "(", "l", ",", "cf", ")", "\n", "}", "\n", "if", "xch", ":=", "os", ".", "Getenv", "(", "\"XDG_CONFIG_HOME\"", ")", ";", "xch", "!=", "\"\"", "{", "l", "=", "append", "(", "l", ",", "filepath", ".", "Join", "(", "xch", ",", "\"gopass\"", ",", "\"config.yml\"", ")", ")", "\n", "}", "\n", "l", "=", "append", "(", "l", ",", "filepath", ".", "Join", "(", "Homedir", "(", ")", ",", "\".config\"", ",", "\"gopass\"", ",", "\"config.yml\"", ")", ")", "\n", "l", "=", "append", "(", "l", ",", "filepath", ".", "Join", "(", "Homedir", "(", ")", ",", "\".gopass.yml\"", ")", ")", "\n", "return", "l", "\n", "}" ]
// configLocations returns the possible locations of gopass config files, // in decreasing priority
[ "configLocations", "returns", "the", "possible", "locations", "of", "gopass", "config", "files", "in", "decreasing", "priority" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/config/location.go#L49-L60
train
gopasspw/gopass
pkg/jsonapi/manifest/wrapper.go
Render
func Render(browser, wrapperPath, binPath string, global bool) ([]byte, []byte, error) { mf, err := getManifestContent(browser, wrapperPath) if err != nil { return nil, nil, err } if binPath == "" { binPath = gopassPath(global) } wrap, err := getWrapperContent(binPath) if err != nil { return nil, nil, err } return wrap, mf, nil }
go
func Render(browser, wrapperPath, binPath string, global bool) ([]byte, []byte, error) { mf, err := getManifestContent(browser, wrapperPath) if err != nil { return nil, nil, err } if binPath == "" { binPath = gopassPath(global) } wrap, err := getWrapperContent(binPath) if err != nil { return nil, nil, err } return wrap, mf, nil }
[ "func", "Render", "(", "browser", ",", "wrapperPath", ",", "binPath", "string", ",", "global", "bool", ")", "(", "[", "]", "byte", ",", "[", "]", "byte", ",", "error", ")", "{", "mf", ",", "err", ":=", "getManifestContent", "(", "browser", ",", "wrapperPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n", "if", "binPath", "==", "\"\"", "{", "binPath", "=", "gopassPath", "(", "global", ")", "\n", "}", "\n", "wrap", ",", "err", ":=", "getWrapperContent", "(", "binPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n", "return", "wrap", ",", "mf", ",", "nil", "\n", "}" ]
// Render returns the rendered wrapper and manifest
[ "Render", "returns", "the", "rendered", "wrapper", "and", "manifest" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/jsonapi/manifest/wrapper.go#L31-L46
train
gopasspw/gopass
pkg/store/root/git.go
GitInit
func (r *Store) GitInit(ctx context.Context, name, userName, userEmail string) error { ctx, store, _ := r.getStore(ctx, name) return store.GitInit(ctx, userName, userEmail) }
go
func (r *Store) GitInit(ctx context.Context, name, userName, userEmail string) error { ctx, store, _ := r.getStore(ctx, name) return store.GitInit(ctx, userName, userEmail) }
[ "func", "(", "r", "*", "Store", ")", "GitInit", "(", "ctx", "context", ".", "Context", ",", "name", ",", "userName", ",", "userEmail", "string", ")", "error", "{", "ctx", ",", "store", ",", "_", ":=", "r", ".", "getStore", "(", "ctx", ",", "name", ")", "\n", "return", "store", ".", "GitInit", "(", "ctx", ",", "userName", ",", "userEmail", ")", "\n", "}" ]
// GitInit initializes the git repo
[ "GitInit", "initializes", "the", "git", "repo" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/git.go#L22-L25
train
gopasspw/gopass
pkg/store/root/git.go
GitInitConfig
func (r *Store) GitInitConfig(ctx context.Context, name, userName, userEmail string) error { ctx, store, _ := r.getStore(ctx, name) return store.RCS().InitConfig(ctx, userName, userEmail) }
go
func (r *Store) GitInitConfig(ctx context.Context, name, userName, userEmail string) error { ctx, store, _ := r.getStore(ctx, name) return store.RCS().InitConfig(ctx, userName, userEmail) }
[ "func", "(", "r", "*", "Store", ")", "GitInitConfig", "(", "ctx", "context", ".", "Context", ",", "name", ",", "userName", ",", "userEmail", "string", ")", "error", "{", "ctx", ",", "store", ",", "_", ":=", "r", ".", "getStore", "(", "ctx", ",", "name", ")", "\n", "return", "store", ".", "RCS", "(", ")", ".", "InitConfig", "(", "ctx", ",", "userName", ",", "userEmail", ")", "\n", "}" ]
// GitInitConfig initializes the git repos local config
[ "GitInitConfig", "initializes", "the", "git", "repos", "local", "config" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/git.go#L28-L31
train
gopasspw/gopass
pkg/store/root/git.go
GitVersion
func (r *Store) GitVersion(ctx context.Context) semver.Version { return r.store.RCS().Version(ctx) }
go
func (r *Store) GitVersion(ctx context.Context) semver.Version { return r.store.RCS().Version(ctx) }
[ "func", "(", "r", "*", "Store", ")", "GitVersion", "(", "ctx", "context", ".", "Context", ")", "semver", ".", "Version", "{", "return", "r", ".", "store", ".", "RCS", "(", ")", ".", "Version", "(", "ctx", ")", "\n", "}" ]
// GitVersion returns git version information
[ "GitVersion", "returns", "git", "version", "information" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/git.go#L34-L36
train
gopasspw/gopass
pkg/store/root/git.go
GitAddRemote
func (r *Store) GitAddRemote(ctx context.Context, name, remote, url string) error { ctx, store, _ := r.getStore(ctx, name) return store.RCS().AddRemote(ctx, remote, url) }
go
func (r *Store) GitAddRemote(ctx context.Context, name, remote, url string) error { ctx, store, _ := r.getStore(ctx, name) return store.RCS().AddRemote(ctx, remote, url) }
[ "func", "(", "r", "*", "Store", ")", "GitAddRemote", "(", "ctx", "context", ".", "Context", ",", "name", ",", "remote", ",", "url", "string", ")", "error", "{", "ctx", ",", "store", ",", "_", ":=", "r", ".", "getStore", "(", "ctx", ",", "name", ")", "\n", "return", "store", ".", "RCS", "(", ")", ".", "AddRemote", "(", "ctx", ",", "remote", ",", "url", ")", "\n", "}" ]
// GitAddRemote adds a git remote
[ "GitAddRemote", "adds", "a", "git", "remote" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/git.go#L39-L42
train
gopasspw/gopass
pkg/store/root/git.go
GitRemoveRemote
func (r *Store) GitRemoveRemote(ctx context.Context, name, remote string) error { ctx, store, _ := r.getStore(ctx, name) return store.RCS().RemoveRemote(ctx, remote) }
go
func (r *Store) GitRemoveRemote(ctx context.Context, name, remote string) error { ctx, store, _ := r.getStore(ctx, name) return store.RCS().RemoveRemote(ctx, remote) }
[ "func", "(", "r", "*", "Store", ")", "GitRemoveRemote", "(", "ctx", "context", ".", "Context", ",", "name", ",", "remote", "string", ")", "error", "{", "ctx", ",", "store", ",", "_", ":=", "r", ".", "getStore", "(", "ctx", ",", "name", ")", "\n", "return", "store", ".", "RCS", "(", ")", ".", "RemoveRemote", "(", "ctx", ",", "remote", ")", "\n", "}" ]
// GitRemoveRemote removes a git remote
[ "GitRemoveRemote", "removes", "a", "git", "remote" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/git.go#L45-L48
train
gopasspw/gopass
pkg/store/root/git.go
GitPull
func (r *Store) GitPull(ctx context.Context, name, origin, remote string) error { ctx, store, _ := r.getStore(ctx, name) return store.RCS().Pull(ctx, origin, remote) }
go
func (r *Store) GitPull(ctx context.Context, name, origin, remote string) error { ctx, store, _ := r.getStore(ctx, name) return store.RCS().Pull(ctx, origin, remote) }
[ "func", "(", "r", "*", "Store", ")", "GitPull", "(", "ctx", "context", ".", "Context", ",", "name", ",", "origin", ",", "remote", "string", ")", "error", "{", "ctx", ",", "store", ",", "_", ":=", "r", ".", "getStore", "(", "ctx", ",", "name", ")", "\n", "return", "store", ".", "RCS", "(", ")", ".", "Pull", "(", "ctx", ",", "origin", ",", "remote", ")", "\n", "}" ]
// GitPull performs a git pull
[ "GitPull", "performs", "a", "git", "pull" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/git.go#L51-L54
train
gopasspw/gopass
pkg/store/root/git.go
GitPush
func (r *Store) GitPush(ctx context.Context, name, origin, remote string) error { ctx, store, _ := r.getStore(ctx, name) return store.RCS().Push(ctx, origin, remote) }
go
func (r *Store) GitPush(ctx context.Context, name, origin, remote string) error { ctx, store, _ := r.getStore(ctx, name) return store.RCS().Push(ctx, origin, remote) }
[ "func", "(", "r", "*", "Store", ")", "GitPush", "(", "ctx", "context", ".", "Context", ",", "name", ",", "origin", ",", "remote", "string", ")", "error", "{", "ctx", ",", "store", ",", "_", ":=", "r", ".", "getStore", "(", "ctx", ",", "name", ")", "\n", "return", "store", ".", "RCS", "(", ")", ".", "Push", "(", "ctx", ",", "origin", ",", "remote", ")", "\n", "}" ]
// GitPush performs a git push
[ "GitPush", "performs", "a", "git", "push" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/git.go#L57-L60
train
gopasspw/gopass
pkg/store/root/git.go
ListRevisions
func (r *Store) ListRevisions(ctx context.Context, name string) ([]backend.Revision, error) { ctx, store, name := r.getStore(ctx, name) return store.ListRevisions(ctx, name) }
go
func (r *Store) ListRevisions(ctx context.Context, name string) ([]backend.Revision, error) { ctx, store, name := r.getStore(ctx, name) return store.ListRevisions(ctx, name) }
[ "func", "(", "r", "*", "Store", ")", "ListRevisions", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "(", "[", "]", "backend", ".", "Revision", ",", "error", ")", "{", "ctx", ",", "store", ",", "name", ":=", "r", ".", "getStore", "(", "ctx", ",", "name", ")", "\n", "return", "store", ".", "ListRevisions", "(", "ctx", ",", "name", ")", "\n", "}" ]
// ListRevisions will list all revisions for the named entity
[ "ListRevisions", "will", "list", "all", "revisions", "for", "the", "named", "entity" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/git.go#L63-L66
train
gopasspw/gopass
pkg/store/root/git.go
GetRevision
func (r *Store) GetRevision(ctx context.Context, name, revision string) (store.Secret, error) { ctx, store, name := r.getStore(ctx, name) return store.GetRevision(ctx, name, revision) }
go
func (r *Store) GetRevision(ctx context.Context, name, revision string) (store.Secret, error) { ctx, store, name := r.getStore(ctx, name) return store.GetRevision(ctx, name, revision) }
[ "func", "(", "r", "*", "Store", ")", "GetRevision", "(", "ctx", "context", ".", "Context", ",", "name", ",", "revision", "string", ")", "(", "store", ".", "Secret", ",", "error", ")", "{", "ctx", ",", "store", ",", "name", ":=", "r", ".", "getStore", "(", "ctx", ",", "name", ")", "\n", "return", "store", ".", "GetRevision", "(", "ctx", ",", "name", ",", "revision", ")", "\n", "}" ]
// GetRevision will try to retrieve the given revision from the sync backend
[ "GetRevision", "will", "try", "to", "retrieve", "the", "given", "revision", "from", "the", "sync", "backend" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/git.go#L69-L72
train
gopasspw/gopass
pkg/backend/rcs/git/gogit/loader.go
Init
func (l loader) Init(ctx context.Context, path, username, email string) (backend.RCS, error) { return Init(ctx, path) }
go
func (l loader) Init(ctx context.Context, path, username, email string) (backend.RCS, error) { return Init(ctx, path) }
[ "func", "(", "l", "loader", ")", "Init", "(", "ctx", "context", ".", "Context", ",", "path", ",", "username", ",", "email", "string", ")", "(", "backend", ".", "RCS", ",", "error", ")", "{", "return", "Init", "(", "ctx", ",", "path", ")", "\n", "}" ]
// Init implements backend.RCSLoader
[ "Init", "implements", "backend", ".", "RCSLoader" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/gogit/loader.go#L32-L34
train
gopasspw/gopass
pkg/action/insert.go
Insert
func (s *Action) Insert(ctx context.Context, c *cli.Context) error { echo := c.Bool("echo") multiline := c.Bool("multiline") force := c.Bool("force") append := c.Bool("append") args, kvps := parseArgs(c) name := args.Get(0) key := args.Get(1) if name == "" { return ExitError(ctx, ExitNoName, nil, "Usage: %s insert name", s.Name) } return s.insert(ctx, c, name, key, echo, multiline, force, append, kvps) }
go
func (s *Action) Insert(ctx context.Context, c *cli.Context) error { echo := c.Bool("echo") multiline := c.Bool("multiline") force := c.Bool("force") append := c.Bool("append") args, kvps := parseArgs(c) name := args.Get(0) key := args.Get(1) if name == "" { return ExitError(ctx, ExitNoName, nil, "Usage: %s insert name", s.Name) } return s.insert(ctx, c, name, key, echo, multiline, force, append, kvps) }
[ "func", "(", "s", "*", "Action", ")", "Insert", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "echo", ":=", "c", ".", "Bool", "(", "\"echo\"", ")", "\n", "multiline", ":=", "c", ".", "Bool", "(", "\"multiline\"", ")", "\n", "force", ":=", "c", ".", "Bool", "(", "\"force\"", ")", "\n", "append", ":=", "c", ".", "Bool", "(", "\"append\"", ")", "\n", "args", ",", "kvps", ":=", "parseArgs", "(", "c", ")", "\n", "name", ":=", "args", ".", "Get", "(", "0", ")", "\n", "key", ":=", "args", ".", "Get", "(", "1", ")", "\n", "if", "name", "==", "\"\"", "{", "return", "ExitError", "(", "ctx", ",", "ExitNoName", ",", "nil", ",", "\"Usage: %s insert name\"", ",", "s", ".", "Name", ")", "\n", "}", "\n", "return", "s", ".", "insert", "(", "ctx", ",", "c", ",", "name", ",", "key", ",", "echo", ",", "multiline", ",", "force", ",", "append", ",", "kvps", ")", "\n", "}" ]
// Insert a string as content to a secret file
[ "Insert", "a", "string", "as", "content", "to", "a", "secret", "file" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/insert.go#L23-L38
train
gopasspw/gopass
pkg/config/io.go
Load
func Load() *Config { for _, l := range configLocations() { if debug { fmt.Printf("[DEBUG] Trying to load config from %s\n", l) } cfg, err := load(l) if err == ErrConfigNotFound { continue } if err != nil { panic(err) } _ = cfg.checkDefaults() if debug { fmt.Printf("[DEBUG] Loaded config from %s: %+v\n", l, cfg) } return cfg } cfg := New() cfg.Root.Path = backend.FromPath(PwStoreDir("")) _ = cfg.checkDefaults() if debug { fmt.Printf("[DEBUG] config.Load(): %+v\n", cfg) } return cfg }
go
func Load() *Config { for _, l := range configLocations() { if debug { fmt.Printf("[DEBUG] Trying to load config from %s\n", l) } cfg, err := load(l) if err == ErrConfigNotFound { continue } if err != nil { panic(err) } _ = cfg.checkDefaults() if debug { fmt.Printf("[DEBUG] Loaded config from %s: %+v\n", l, cfg) } return cfg } cfg := New() cfg.Root.Path = backend.FromPath(PwStoreDir("")) _ = cfg.checkDefaults() if debug { fmt.Printf("[DEBUG] config.Load(): %+v\n", cfg) } return cfg }
[ "func", "Load", "(", ")", "*", "Config", "{", "for", "_", ",", "l", ":=", "range", "configLocations", "(", ")", "{", "if", "debug", "{", "fmt", ".", "Printf", "(", "\"[DEBUG] Trying to load config from %s\\n\"", ",", "\\n", ")", "\n", "}", "\n", "l", "\n", "cfg", ",", "err", ":=", "load", "(", "l", ")", "\n", "if", "err", "==", "ErrConfigNotFound", "{", "continue", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "_", "=", "cfg", ".", "checkDefaults", "(", ")", "\n", "if", "debug", "{", "fmt", ".", "Printf", "(", "\"[DEBUG] Loaded config from %s: %+v\\n\"", ",", "\\n", ",", "l", ")", "\n", "}", "\n", "}", "\n", "cfg", "\n", "return", "cfg", "\n", "cfg", ":=", "New", "(", ")", "\n", "cfg", ".", "Root", ".", "Path", "=", "backend", ".", "FromPath", "(", "PwStoreDir", "(", "\"\"", ")", ")", "\n", "_", "=", "cfg", ".", "checkDefaults", "(", ")", "\n", "}" ]
// Load will try to load the config from one of the default locations
[ "Load", "will", "try", "to", "load", "the", "config", "from", "one", "of", "the", "default", "locations" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/config/io.go#L17-L42
train
gopasspw/gopass
pkg/config/io.go
Save
func (c *Config) Save() error { if err := c.checkDefaults(); err != nil { return err } buf, err := yaml.Marshal(c) if err != nil { return errors.Wrapf(err, "failed to marshal YAML") } cfgLoc := configLocation() cfgDir := filepath.Dir(cfgLoc) if !fsutil.IsDir(cfgDir) { if err := os.MkdirAll(cfgDir, 0700); err != nil { return errors.Wrapf(err, "failed to create dir '%s'", cfgDir) } } if err := ioutil.WriteFile(cfgLoc, buf, 0600); err != nil { return errors.Wrapf(err, "failed to write config file to '%s'", cfgLoc) } if debug { fmt.Printf("[DEBUG] Saved config to %s: %+v\n", cfgLoc, c) } return nil }
go
func (c *Config) Save() error { if err := c.checkDefaults(); err != nil { return err } buf, err := yaml.Marshal(c) if err != nil { return errors.Wrapf(err, "failed to marshal YAML") } cfgLoc := configLocation() cfgDir := filepath.Dir(cfgLoc) if !fsutil.IsDir(cfgDir) { if err := os.MkdirAll(cfgDir, 0700); err != nil { return errors.Wrapf(err, "failed to create dir '%s'", cfgDir) } } if err := ioutil.WriteFile(cfgLoc, buf, 0600); err != nil { return errors.Wrapf(err, "failed to write config file to '%s'", cfgLoc) } if debug { fmt.Printf("[DEBUG] Saved config to %s: %+v\n", cfgLoc, c) } return nil }
[ "func", "(", "c", "*", "Config", ")", "Save", "(", ")", "error", "{", "if", "err", ":=", "c", ".", "checkDefaults", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "buf", ",", "err", ":=", "yaml", ".", "Marshal", "(", "c", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to marshal YAML\"", ")", "\n", "}", "\n", "cfgLoc", ":=", "configLocation", "(", ")", "\n", "cfgDir", ":=", "filepath", ".", "Dir", "(", "cfgLoc", ")", "\n", "if", "!", "fsutil", ".", "IsDir", "(", "cfgDir", ")", "{", "if", "err", ":=", "os", ".", "MkdirAll", "(", "cfgDir", ",", "0700", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to create dir '%s'\"", ",", "cfgDir", ")", "\n", "}", "\n", "}", "\n", "if", "err", ":=", "ioutil", ".", "WriteFile", "(", "cfgLoc", ",", "buf", ",", "0600", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to write config file to '%s'\"", ",", "cfgLoc", ")", "\n", "}", "\n", "if", "debug", "{", "fmt", ".", "Printf", "(", "\"[DEBUG] Saved config to %s: %+v\\n\"", ",", "\\n", ",", "cfgLoc", ")", "\n", "}", "\n", "c", "\n", "}" ]
// Save saves the config
[ "Save", "saves", "the", "config" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/config/io.go#L119-L143
train
gopasspw/gopass
pkg/action/delete.go
Delete
func (s *Action) Delete(ctx context.Context, c *cli.Context) error { force := c.Bool("force") recursive := c.Bool("recursive") name := c.Args().First() if name == "" { return ExitError(ctx, ExitUsage, nil, "Usage: %s rm name", s.Name) } if !recursive && s.Store.IsDir(ctx, name) { return ExitError(ctx, ExitUsage, nil, "Cannot remove '%s': Is a directory. Use 'gopass rm -r %s' to delete", name, name) } // specifying a key is optional key := c.Args().Get(1) if !force { // don't check if it's force anyway recStr := "" if recursive { recStr = "recursively " } if (s.Store.Exists(ctx, name) || s.Store.IsDir(ctx, name)) && key == "" && !termio.AskForConfirmation(ctx, fmt.Sprintf("Are you sure you would like to %sdelete %s?", recStr, name)) { return nil } } if recursive { if err := s.Store.Prune(ctx, name); err != nil { return ExitError(ctx, ExitUnknown, err, "failed to prune '%s': %s", name, err) } return nil } // deletes a single key from a YAML doc if key != "" { return s.deleteKeyFromYAML(ctx, name, key) } if err := s.Store.Delete(ctx, name); err != nil { return ExitError(ctx, ExitIO, err, "Can not delete '%s': %s", name, err) } return nil }
go
func (s *Action) Delete(ctx context.Context, c *cli.Context) error { force := c.Bool("force") recursive := c.Bool("recursive") name := c.Args().First() if name == "" { return ExitError(ctx, ExitUsage, nil, "Usage: %s rm name", s.Name) } if !recursive && s.Store.IsDir(ctx, name) { return ExitError(ctx, ExitUsage, nil, "Cannot remove '%s': Is a directory. Use 'gopass rm -r %s' to delete", name, name) } // specifying a key is optional key := c.Args().Get(1) if !force { // don't check if it's force anyway recStr := "" if recursive { recStr = "recursively " } if (s.Store.Exists(ctx, name) || s.Store.IsDir(ctx, name)) && key == "" && !termio.AskForConfirmation(ctx, fmt.Sprintf("Are you sure you would like to %sdelete %s?", recStr, name)) { return nil } } if recursive { if err := s.Store.Prune(ctx, name); err != nil { return ExitError(ctx, ExitUnknown, err, "failed to prune '%s': %s", name, err) } return nil } // deletes a single key from a YAML doc if key != "" { return s.deleteKeyFromYAML(ctx, name, key) } if err := s.Store.Delete(ctx, name); err != nil { return ExitError(ctx, ExitIO, err, "Can not delete '%s': %s", name, err) } return nil }
[ "func", "(", "s", "*", "Action", ")", "Delete", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "force", ":=", "c", ".", "Bool", "(", "\"force\"", ")", "\n", "recursive", ":=", "c", ".", "Bool", "(", "\"recursive\"", ")", "\n", "name", ":=", "c", ".", "Args", "(", ")", ".", "First", "(", ")", "\n", "if", "name", "==", "\"\"", "{", "return", "ExitError", "(", "ctx", ",", "ExitUsage", ",", "nil", ",", "\"Usage: %s rm name\"", ",", "s", ".", "Name", ")", "\n", "}", "\n", "if", "!", "recursive", "&&", "s", ".", "Store", ".", "IsDir", "(", "ctx", ",", "name", ")", "{", "return", "ExitError", "(", "ctx", ",", "ExitUsage", ",", "nil", ",", "\"Cannot remove '%s': Is a directory. Use 'gopass rm -r %s' to delete\"", ",", "name", ",", "name", ")", "\n", "}", "\n", "key", ":=", "c", ".", "Args", "(", ")", ".", "Get", "(", "1", ")", "\n", "if", "!", "force", "{", "recStr", ":=", "\"\"", "\n", "if", "recursive", "{", "recStr", "=", "\"recursively \"", "\n", "}", "\n", "if", "(", "s", ".", "Store", ".", "Exists", "(", "ctx", ",", "name", ")", "||", "s", ".", "Store", ".", "IsDir", "(", "ctx", ",", "name", ")", ")", "&&", "key", "==", "\"\"", "&&", "!", "termio", ".", "AskForConfirmation", "(", "ctx", ",", "fmt", ".", "Sprintf", "(", "\"Are you sure you would like to %sdelete %s?\"", ",", "recStr", ",", "name", ")", ")", "{", "return", "nil", "\n", "}", "\n", "}", "\n", "if", "recursive", "{", "if", "err", ":=", "s", ".", "Store", ".", "Prune", "(", "ctx", ",", "name", ")", ";", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitUnknown", ",", "err", ",", "\"failed to prune '%s': %s\"", ",", "name", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}", "\n", "if", "key", "!=", "\"\"", "{", "return", "s", ".", "deleteKeyFromYAML", "(", "ctx", ",", "name", ",", "key", ")", "\n", "}", "\n", "if", "err", ":=", "s", ".", "Store", ".", "Delete", "(", "ctx", ",", "name", ")", ";", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitIO", ",", "err", ",", "\"Can not delete '%s': %s\"", ",", "name", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Delete a secret file with its content
[ "Delete", "a", "secret", "file", "with", "its", "content" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/delete.go#L14-L56
train
gopasspw/gopass
pkg/action/delete.go
deleteKeyFromYAML
func (s *Action) deleteKeyFromYAML(ctx context.Context, name, key string) error { sec, err := s.Store.Get(ctx, name) if err != nil { return ExitError(ctx, ExitIO, err, "Can not delete key '%s' from '%s': %s", key, name, err) } if err := sec.DeleteKey(key); err != nil { return ExitError(ctx, ExitIO, err, "Can not delete key '%s' from '%s': %s", key, name, err) } if err := s.Store.Set(sub.WithReason(ctx, "Updated Key in YAML"), name, sec); err != nil { return ExitError(ctx, ExitIO, err, "Can not delete key '%s' from '%s': %s", key, name, err) } return nil }
go
func (s *Action) deleteKeyFromYAML(ctx context.Context, name, key string) error { sec, err := s.Store.Get(ctx, name) if err != nil { return ExitError(ctx, ExitIO, err, "Can not delete key '%s' from '%s': %s", key, name, err) } if err := sec.DeleteKey(key); err != nil { return ExitError(ctx, ExitIO, err, "Can not delete key '%s' from '%s': %s", key, name, err) } if err := s.Store.Set(sub.WithReason(ctx, "Updated Key in YAML"), name, sec); err != nil { return ExitError(ctx, ExitIO, err, "Can not delete key '%s' from '%s': %s", key, name, err) } return nil }
[ "func", "(", "s", "*", "Action", ")", "deleteKeyFromYAML", "(", "ctx", "context", ".", "Context", ",", "name", ",", "key", "string", ")", "error", "{", "sec", ",", "err", ":=", "s", ".", "Store", ".", "Get", "(", "ctx", ",", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitIO", ",", "err", ",", "\"Can not delete key '%s' from '%s': %s\"", ",", "key", ",", "name", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "sec", ".", "DeleteKey", "(", "key", ")", ";", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitIO", ",", "err", ",", "\"Can not delete key '%s' from '%s': %s\"", ",", "key", ",", "name", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "s", ".", "Store", ".", "Set", "(", "sub", ".", "WithReason", "(", "ctx", ",", "\"Updated Key in YAML\"", ")", ",", "name", ",", "sec", ")", ";", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitIO", ",", "err", ",", "\"Can not delete key '%s' from '%s': %s\"", ",", "key", ",", "name", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// deleteKeyFromYAML deletes a single key from YAML
[ "deleteKeyFromYAML", "deletes", "a", "single", "key", "from", "YAML" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/delete.go#L59-L71
train
gopasspw/gopass
pkg/backend/rcs/git/gogit/git.go
Open
func Open(path string) (*Git, error) { r, err := git.PlainOpen(path) if err != nil { return nil, err } w, err := r.Worktree() if err != nil { return nil, err } return &Git{ path: path, repo: r, wt: w, }, nil }
go
func Open(path string) (*Git, error) { r, err := git.PlainOpen(path) if err != nil { return nil, err } w, err := r.Worktree() if err != nil { return nil, err } return &Git{ path: path, repo: r, wt: w, }, nil }
[ "func", "Open", "(", "path", "string", ")", "(", "*", "Git", ",", "error", ")", "{", "r", ",", "err", ":=", "git", ".", "PlainOpen", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "w", ",", "err", ":=", "r", ".", "Worktree", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "Git", "{", "path", ":", "path", ",", "repo", ":", "r", ",", "wt", ":", "w", ",", "}", ",", "nil", "\n", "}" ]
// Open tries to open an existing git repo on disk
[ "Open", "tries", "to", "open", "an", "existing", "git", "repo", "on", "disk" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/gogit/git.go#L38-L54
train
gopasspw/gopass
pkg/backend/rcs/git/gogit/git.go
Clone
func Clone(ctx context.Context, repo, path string) (*Git, error) { r, err := git.PlainCloneContext(ctx, path, false, &git.CloneOptions{ URL: repo, Progress: Stdout, }) if err != nil { return nil, err } w, err := r.Worktree() if err != nil { return nil, err } return &Git{ path: path, repo: r, wt: w, }, nil }
go
func Clone(ctx context.Context, repo, path string) (*Git, error) { r, err := git.PlainCloneContext(ctx, path, false, &git.CloneOptions{ URL: repo, Progress: Stdout, }) if err != nil { return nil, err } w, err := r.Worktree() if err != nil { return nil, err } return &Git{ path: path, repo: r, wt: w, }, nil }
[ "func", "Clone", "(", "ctx", "context", ".", "Context", ",", "repo", ",", "path", "string", ")", "(", "*", "Git", ",", "error", ")", "{", "r", ",", "err", ":=", "git", ".", "PlainCloneContext", "(", "ctx", ",", "path", ",", "false", ",", "&", "git", ".", "CloneOptions", "{", "URL", ":", "repo", ",", "Progress", ":", "Stdout", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "w", ",", "err", ":=", "r", ".", "Worktree", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "Git", "{", "path", ":", "path", ",", "repo", ":", "r", ",", "wt", ":", "w", ",", "}", ",", "nil", "\n", "}" ]
// Clone tries to clone an git repo from a remote
[ "Clone", "tries", "to", "clone", "an", "git", "repo", "from", "a", "remote" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/gogit/git.go#L57-L76
train
gopasspw/gopass
pkg/backend/rcs/git/gogit/git.go
Init
func Init(ctx context.Context, path string) (*Git, error) { g := &Git{ path: path, } if !g.IsInitialized() { r, err := git.PlainInit(path, false) if err != nil { return nil, errors.Wrapf(err, "Failed to initialize git: %s", err) } g.repo = r wt, err := g.repo.Worktree() if err != nil { return nil, errors.Wrapf(err, "Failed to get worktree: %s", err) } g.wt = wt } if !ctxutil.IsGitInit(ctx) { return g, nil } // add current content of the store if err := g.Add(ctx, g.path); err != nil { return g, errors.Wrapf(err, "failed to add '%s' to git", g.path) } // commit if there is something to commit if !g.HasStagedChanges(ctx) { out.Debug(ctx, "No staged changes") return g, nil } if err := g.Commit(ctx, "Add current content of password store"); err != nil { return nil, errors.Wrapf(err, "failed to commit changes to git") } return g, nil }
go
func Init(ctx context.Context, path string) (*Git, error) { g := &Git{ path: path, } if !g.IsInitialized() { r, err := git.PlainInit(path, false) if err != nil { return nil, errors.Wrapf(err, "Failed to initialize git: %s", err) } g.repo = r wt, err := g.repo.Worktree() if err != nil { return nil, errors.Wrapf(err, "Failed to get worktree: %s", err) } g.wt = wt } if !ctxutil.IsGitInit(ctx) { return g, nil } // add current content of the store if err := g.Add(ctx, g.path); err != nil { return g, errors.Wrapf(err, "failed to add '%s' to git", g.path) } // commit if there is something to commit if !g.HasStagedChanges(ctx) { out.Debug(ctx, "No staged changes") return g, nil } if err := g.Commit(ctx, "Add current content of password store"); err != nil { return nil, errors.Wrapf(err, "failed to commit changes to git") } return g, nil }
[ "func", "Init", "(", "ctx", "context", ".", "Context", ",", "path", "string", ")", "(", "*", "Git", ",", "error", ")", "{", "g", ":=", "&", "Git", "{", "path", ":", "path", ",", "}", "\n", "if", "!", "g", ".", "IsInitialized", "(", ")", "{", "r", ",", "err", ":=", "git", ".", "PlainInit", "(", "path", ",", "false", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"Failed to initialize git: %s\"", ",", "err", ")", "\n", "}", "\n", "g", ".", "repo", "=", "r", "\n", "wt", ",", "err", ":=", "g", ".", "repo", ".", "Worktree", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"Failed to get worktree: %s\"", ",", "err", ")", "\n", "}", "\n", "g", ".", "wt", "=", "wt", "\n", "}", "\n", "if", "!", "ctxutil", ".", "IsGitInit", "(", "ctx", ")", "{", "return", "g", ",", "nil", "\n", "}", "\n", "if", "err", ":=", "g", ".", "Add", "(", "ctx", ",", "g", ".", "path", ")", ";", "err", "!=", "nil", "{", "return", "g", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to add '%s' to git\"", ",", "g", ".", "path", ")", "\n", "}", "\n", "if", "!", "g", ".", "HasStagedChanges", "(", "ctx", ")", "{", "out", ".", "Debug", "(", "ctx", ",", "\"No staged changes\"", ")", "\n", "return", "g", ",", "nil", "\n", "}", "\n", "if", "err", ":=", "g", ".", "Commit", "(", "ctx", ",", "\"Add current content of password store\"", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to commit changes to git\"", ")", "\n", "}", "\n", "return", "g", ",", "nil", "\n", "}" ]
// Init creates a new git repo on disk
[ "Init", "creates", "a", "new", "git", "repo", "on", "disk" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/gogit/git.go#L79-L117
train
gopasspw/gopass
pkg/backend/rcs/git/gogit/git.go
IsInitialized
func (g *Git) IsInitialized() bool { _, err := git.PlainOpen(g.path) return err == nil }
go
func (g *Git) IsInitialized() bool { _, err := git.PlainOpen(g.path) return err == nil }
[ "func", "(", "g", "*", "Git", ")", "IsInitialized", "(", ")", "bool", "{", "_", ",", "err", ":=", "git", ".", "PlainOpen", "(", "g", ".", "path", ")", "\n", "return", "err", "==", "nil", "\n", "}" ]
// IsInitialized returns true if this is a valid repo
[ "IsInitialized", "returns", "true", "if", "this", "is", "a", "valid", "repo" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/gogit/git.go#L128-L131
train
gopasspw/gopass
pkg/backend/rcs/git/gogit/git.go
Add
func (g *Git) Add(ctx context.Context, files ...string) error { if len(files) < 1 || (len(files) == 1 && files[0] == g.path) { return g.addAll() } for _, file := range files { if strings.HasPrefix(file, g.path) { file = strings.TrimPrefix(file, g.path+string(filepath.Separator)) } _, err := g.wt.Add(file) if err != nil { return errors.Wrapf(err, "failed to add file '%s': %s", file, err) } } return nil }
go
func (g *Git) Add(ctx context.Context, files ...string) error { if len(files) < 1 || (len(files) == 1 && files[0] == g.path) { return g.addAll() } for _, file := range files { if strings.HasPrefix(file, g.path) { file = strings.TrimPrefix(file, g.path+string(filepath.Separator)) } _, err := g.wt.Add(file) if err != nil { return errors.Wrapf(err, "failed to add file '%s': %s", file, err) } } return nil }
[ "func", "(", "g", "*", "Git", ")", "Add", "(", "ctx", "context", ".", "Context", ",", "files", "...", "string", ")", "error", "{", "if", "len", "(", "files", ")", "<", "1", "||", "(", "len", "(", "files", ")", "==", "1", "&&", "files", "[", "0", "]", "==", "g", ".", "path", ")", "{", "return", "g", ".", "addAll", "(", ")", "\n", "}", "\n", "for", "_", ",", "file", ":=", "range", "files", "{", "if", "strings", ".", "HasPrefix", "(", "file", ",", "g", ".", "path", ")", "{", "file", "=", "strings", ".", "TrimPrefix", "(", "file", ",", "g", ".", "path", "+", "string", "(", "filepath", ".", "Separator", ")", ")", "\n", "}", "\n", "_", ",", "err", ":=", "g", ".", "wt", ".", "Add", "(", "file", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to add file '%s': %s\"", ",", "file", ",", "err", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Add adds any number of files to git
[ "Add", "adds", "any", "number", "of", "files", "to", "git" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/gogit/git.go#L134-L148
train
gopasspw/gopass
pkg/backend/rcs/git/gogit/git.go
HasStagedChanges
func (g *Git) HasStagedChanges(ctx context.Context) bool { st, err := g.wt.Status() if err != nil { out.Error(ctx, "Error: Unable to get status: %s", err) return false } return !st.IsClean() }
go
func (g *Git) HasStagedChanges(ctx context.Context) bool { st, err := g.wt.Status() if err != nil { out.Error(ctx, "Error: Unable to get status: %s", err) return false } return !st.IsClean() }
[ "func", "(", "g", "*", "Git", ")", "HasStagedChanges", "(", "ctx", "context", ".", "Context", ")", "bool", "{", "st", ",", "err", ":=", "g", ".", "wt", ".", "Status", "(", ")", "\n", "if", "err", "!=", "nil", "{", "out", ".", "Error", "(", "ctx", ",", "\"Error: Unable to get status: %s\"", ",", "err", ")", "\n", "return", "false", "\n", "}", "\n", "return", "!", "st", ".", "IsClean", "(", ")", "\n", "}" ]
// HasStagedChanges retures true if there are changes which can be committed
[ "HasStagedChanges", "retures", "true", "if", "there", "are", "changes", "which", "can", "be", "committed" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/gogit/git.go#L182-L189
train
gopasspw/gopass
pkg/backend/rcs/git/gogit/git.go
Commit
func (g *Git) Commit(ctx context.Context, msg string) error { if !g.HasStagedChanges(ctx) { return store.ErrGitNothingToCommit } _, err := g.wt.Commit(msg, &git.CommitOptions{ All: true, Author: &object.Signature{ Name: os.Getenv("GIT_AUTHOR_NAME"), Email: os.Getenv("GIT_AUTHOR_EMAIL"), When: time.Now(), }, }) return err }
go
func (g *Git) Commit(ctx context.Context, msg string) error { if !g.HasStagedChanges(ctx) { return store.ErrGitNothingToCommit } _, err := g.wt.Commit(msg, &git.CommitOptions{ All: true, Author: &object.Signature{ Name: os.Getenv("GIT_AUTHOR_NAME"), Email: os.Getenv("GIT_AUTHOR_EMAIL"), When: time.Now(), }, }) return err }
[ "func", "(", "g", "*", "Git", ")", "Commit", "(", "ctx", "context", ".", "Context", ",", "msg", "string", ")", "error", "{", "if", "!", "g", ".", "HasStagedChanges", "(", "ctx", ")", "{", "return", "store", ".", "ErrGitNothingToCommit", "\n", "}", "\n", "_", ",", "err", ":=", "g", ".", "wt", ".", "Commit", "(", "msg", ",", "&", "git", ".", "CommitOptions", "{", "All", ":", "true", ",", "Author", ":", "&", "object", ".", "Signature", "{", "Name", ":", "os", ".", "Getenv", "(", "\"GIT_AUTHOR_NAME\"", ")", ",", "Email", ":", "os", ".", "Getenv", "(", "\"GIT_AUTHOR_EMAIL\"", ")", ",", "When", ":", "time", ".", "Now", "(", ")", ",", "}", ",", "}", ")", "\n", "return", "err", "\n", "}" ]
// Commit creates a new commit
[ "Commit", "creates", "a", "new", "commit" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/gogit/git.go#L192-L206
train
gopasspw/gopass
pkg/backend/rcs/git/gogit/git.go
PushPull
func (g *Git) PushPull(ctx context.Context, op, remote, branch string) error { if err := g.Pull(ctx, remote, branch); err != nil { if op == "pull" { return err } out.Yellow(ctx, "Failed to pull before git push: %s", err) } if op == "pull" { return nil } return g.Push(ctx, remote, branch) }
go
func (g *Git) PushPull(ctx context.Context, op, remote, branch string) error { if err := g.Pull(ctx, remote, branch); err != nil { if op == "pull" { return err } out.Yellow(ctx, "Failed to pull before git push: %s", err) } if op == "pull" { return nil } return g.Push(ctx, remote, branch) }
[ "func", "(", "g", "*", "Git", ")", "PushPull", "(", "ctx", "context", ".", "Context", ",", "op", ",", "remote", ",", "branch", "string", ")", "error", "{", "if", "err", ":=", "g", ".", "Pull", "(", "ctx", ",", "remote", ",", "branch", ")", ";", "err", "!=", "nil", "{", "if", "op", "==", "\"pull\"", "{", "return", "err", "\n", "}", "\n", "out", ".", "Yellow", "(", "ctx", ",", "\"Failed to pull before git push: %s\"", ",", "err", ")", "\n", "}", "\n", "if", "op", "==", "\"pull\"", "{", "return", "nil", "\n", "}", "\n", "return", "g", ".", "Push", "(", "ctx", ",", "remote", ",", "branch", ")", "\n", "}" ]
// PushPull will first pull from the remote and then push any changes
[ "PushPull", "will", "first", "pull", "from", "the", "remote", "and", "then", "push", "any", "changes" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/gogit/git.go#L209-L221
train
gopasspw/gopass
pkg/backend/rcs/git/gogit/git.go
Pull
func (g *Git) Pull(ctx context.Context, remote, branch string) error { if !g.IsInitialized() { return store.ErrGitNotInit } if remote == "" { remote = "origin" } if branch == "" { branch = "master" } cfg, err := g.repo.Config() if err != nil { return errors.Wrapf(err, "Failed to get git config: %s", err) } if _, found := cfg.Remotes[remote]; !found { return store.ErrGitNoRemote } return g.wt.PullContext(ctx, &git.PullOptions{ RemoteName: remote, ReferenceName: plumbing.ReferenceName(branch), Progress: Stdout, }) }
go
func (g *Git) Pull(ctx context.Context, remote, branch string) error { if !g.IsInitialized() { return store.ErrGitNotInit } if remote == "" { remote = "origin" } if branch == "" { branch = "master" } cfg, err := g.repo.Config() if err != nil { return errors.Wrapf(err, "Failed to get git config: %s", err) } if _, found := cfg.Remotes[remote]; !found { return store.ErrGitNoRemote } return g.wt.PullContext(ctx, &git.PullOptions{ RemoteName: remote, ReferenceName: plumbing.ReferenceName(branch), Progress: Stdout, }) }
[ "func", "(", "g", "*", "Git", ")", "Pull", "(", "ctx", "context", ".", "Context", ",", "remote", ",", "branch", "string", ")", "error", "{", "if", "!", "g", ".", "IsInitialized", "(", ")", "{", "return", "store", ".", "ErrGitNotInit", "\n", "}", "\n", "if", "remote", "==", "\"\"", "{", "remote", "=", "\"origin\"", "\n", "}", "\n", "if", "branch", "==", "\"\"", "{", "branch", "=", "\"master\"", "\n", "}", "\n", "cfg", ",", "err", ":=", "g", ".", "repo", ".", "Config", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"Failed to get git config: %s\"", ",", "err", ")", "\n", "}", "\n", "if", "_", ",", "found", ":=", "cfg", ".", "Remotes", "[", "remote", "]", ";", "!", "found", "{", "return", "store", ".", "ErrGitNoRemote", "\n", "}", "\n", "return", "g", ".", "wt", ".", "PullContext", "(", "ctx", ",", "&", "git", ".", "PullOptions", "{", "RemoteName", ":", "remote", ",", "ReferenceName", ":", "plumbing", ".", "ReferenceName", "(", "branch", ")", ",", "Progress", ":", "Stdout", ",", "}", ")", "\n", "}" ]
// Pull will pull any changes
[ "Pull", "will", "pull", "any", "changes" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/gogit/git.go#L224-L249
train
gopasspw/gopass
pkg/backend/rcs/git/gogit/git.go
Push
func (g *Git) Push(ctx context.Context, remote, branch string) error { if !g.IsInitialized() { return store.ErrGitNotInit } if remote == "" { remote = "origin" } cfg, err := g.repo.Config() if err != nil { return errors.Wrapf(err, "Failed to get git config: %s", err) } if _, found := cfg.Remotes[remote]; !found { return store.ErrGitNoRemote } return g.repo.PushContext(ctx, &git.PushOptions{ RemoteName: remote, Progress: Stdout, }) }
go
func (g *Git) Push(ctx context.Context, remote, branch string) error { if !g.IsInitialized() { return store.ErrGitNotInit } if remote == "" { remote = "origin" } cfg, err := g.repo.Config() if err != nil { return errors.Wrapf(err, "Failed to get git config: %s", err) } if _, found := cfg.Remotes[remote]; !found { return store.ErrGitNoRemote } return g.repo.PushContext(ctx, &git.PushOptions{ RemoteName: remote, Progress: Stdout, }) }
[ "func", "(", "g", "*", "Git", ")", "Push", "(", "ctx", "context", ".", "Context", ",", "remote", ",", "branch", "string", ")", "error", "{", "if", "!", "g", ".", "IsInitialized", "(", ")", "{", "return", "store", ".", "ErrGitNotInit", "\n", "}", "\n", "if", "remote", "==", "\"\"", "{", "remote", "=", "\"origin\"", "\n", "}", "\n", "cfg", ",", "err", ":=", "g", ".", "repo", ".", "Config", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"Failed to get git config: %s\"", ",", "err", ")", "\n", "}", "\n", "if", "_", ",", "found", ":=", "cfg", ".", "Remotes", "[", "remote", "]", ";", "!", "found", "{", "return", "store", ".", "ErrGitNoRemote", "\n", "}", "\n", "return", "g", ".", "repo", ".", "PushContext", "(", "ctx", ",", "&", "git", ".", "PushOptions", "{", "RemoteName", ":", "remote", ",", "Progress", ":", "Stdout", ",", "}", ")", "\n", "}" ]
// Push will push any changes to the remote
[ "Push", "will", "push", "any", "changes", "to", "the", "remote" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/gogit/git.go#L252-L272
train
gopasspw/gopass
pkg/backend/rcs/git/gogit/git.go
Cmd
func (g *Git) Cmd(context.Context, string, ...string) error { return fmt.Errorf("not supported") }
go
func (g *Git) Cmd(context.Context, string, ...string) error { return fmt.Errorf("not supported") }
[ "func", "(", "g", "*", "Git", ")", "Cmd", "(", "context", ".", "Context", ",", "string", ",", "...", "string", ")", "error", "{", "return", "fmt", ".", "Errorf", "(", "\"not supported\"", ")", "\n", "}" ]
// Cmd is not supported and will go away eventually
[ "Cmd", "is", "not", "supported", "and", "will", "go", "away", "eventually" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/gogit/git.go#L275-L277
train
gopasspw/gopass
pkg/store/root/gpg.go
Crypto
func (r *Store) Crypto(ctx context.Context, name string) backend.Crypto { _, sub, _ := r.getStore(ctx, name) if !sub.Valid() { out.Debug(ctx, "Sub-Store not found for %s. Returning nil crypto backend", name) return nil } return sub.Crypto() }
go
func (r *Store) Crypto(ctx context.Context, name string) backend.Crypto { _, sub, _ := r.getStore(ctx, name) if !sub.Valid() { out.Debug(ctx, "Sub-Store not found for %s. Returning nil crypto backend", name) return nil } return sub.Crypto() }
[ "func", "(", "r", "*", "Store", ")", "Crypto", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "backend", ".", "Crypto", "{", "_", ",", "sub", ",", "_", ":=", "r", ".", "getStore", "(", "ctx", ",", "name", ")", "\n", "if", "!", "sub", ".", "Valid", "(", ")", "{", "out", ".", "Debug", "(", "ctx", ",", "\"Sub-Store not found for %s. Returning nil crypto backend\"", ",", "name", ")", "\n", "return", "nil", "\n", "}", "\n", "return", "sub", ".", "Crypto", "(", ")", "\n", "}" ]
// Crypto returns the crypto backend
[ "Crypto", "returns", "the", "crypto", "backend" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/gpg.go#L11-L18
train
gopasspw/gopass
pkg/action/audit.go
Audit
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 ...") t, err := s.Store.Tree(ctx) if err != nil { return ExitError(ctx, ExitList, err, "failed to get store tree: %s", err) } if filter != "" { subtree, err := t.FindFolder(filter) if err != nil { return ExitError(ctx, ExitUnknown, err, "failed to find subtree: %s", err) } t = subtree } list := t.List(0) if len(list) < 1 { out.Yellow(ctx, "No secrets found") return nil } return audit.Batch(ctx, list, s.Store) }
go
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 ...") t, err := s.Store.Tree(ctx) if err != nil { return ExitError(ctx, ExitList, err, "failed to get store tree: %s", err) } if filter != "" { subtree, err := t.FindFolder(filter) if err != nil { return ExitError(ctx, ExitUnknown, err, "failed to find subtree: %s", err) } t = subtree } list := t.List(0) if len(list) < 1 { out.Yellow(ctx, "No secrets found") return nil } return audit.Batch(ctx, list, s.Store) }
[ "func", "(", "s", "*", "Action", ")", "Audit", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "filter", ":=", "c", ".", "Args", "(", ")", ".", "First", "(", ")", "\n", "ctx", "=", "s", ".", "Store", ".", "WithConfig", "(", "ctx", ",", "filter", ")", "\n", "out", ".", "Print", "(", "ctx", ",", "\"Auditing passwords for common flaws ...\"", ")", "\n", "t", ",", "err", ":=", "s", ".", "Store", ".", "Tree", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitList", ",", "err", ",", "\"failed to get store tree: %s\"", ",", "err", ")", "\n", "}", "\n", "if", "filter", "!=", "\"\"", "{", "subtree", ",", "err", ":=", "t", ".", "FindFolder", "(", "filter", ")", "\n", "if", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitUnknown", ",", "err", ",", "\"failed to find subtree: %s\"", ",", "err", ")", "\n", "}", "\n", "t", "=", "subtree", "\n", "}", "\n", "list", ":=", "t", ".", "List", "(", "0", ")", "\n", "if", "len", "(", "list", ")", "<", "1", "{", "out", ".", "Yellow", "(", "ctx", ",", "\"No secrets found\"", ")", "\n", "return", "nil", "\n", "}", "\n", "return", "audit", ".", "Batch", "(", "ctx", ",", "list", ",", "s", ".", "Store", ")", "\n", "}" ]
// Audit validates passwords against common flaws
[ "Audit", "validates", "passwords", "against", "common", "flaws" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/audit.go#L13-L38
train
gopasspw/gopass
pkg/backend/crypto/gpg/cli/gpg.go
New
func New(ctx context.Context, cfg Config) (*GPG, error) { // ensure created files don't have group or world perms set // this setting should be inherited by sub-processes umask(cfg.Umask) // make sure GPG_TTY is set (if possible) if gt := os.Getenv("GPG_TTY"); gt == "" { if t := tty(); t != "" { _ = os.Setenv("GPG_TTY", t) } } g := &GPG{ binary: "gpg", args: append(defaultArgs, cfg.Args...), } cache, err := lru.New2Q(1024) if err != nil { return nil, err } g.listCache = cache bin, err := Binary(ctx, cfg.Binary) if err != nil { return nil, err } g.binary = bin return g, nil }
go
func New(ctx context.Context, cfg Config) (*GPG, error) { // ensure created files don't have group or world perms set // this setting should be inherited by sub-processes umask(cfg.Umask) // make sure GPG_TTY is set (if possible) if gt := os.Getenv("GPG_TTY"); gt == "" { if t := tty(); t != "" { _ = os.Setenv("GPG_TTY", t) } } g := &GPG{ binary: "gpg", args: append(defaultArgs, cfg.Args...), } cache, err := lru.New2Q(1024) if err != nil { return nil, err } g.listCache = cache bin, err := Binary(ctx, cfg.Binary) if err != nil { return nil, err } g.binary = bin return g, nil }
[ "func", "New", "(", "ctx", "context", ".", "Context", ",", "cfg", "Config", ")", "(", "*", "GPG", ",", "error", ")", "{", "umask", "(", "cfg", ".", "Umask", ")", "\n", "if", "gt", ":=", "os", ".", "Getenv", "(", "\"GPG_TTY\"", ")", ";", "gt", "==", "\"\"", "{", "if", "t", ":=", "tty", "(", ")", ";", "t", "!=", "\"\"", "{", "_", "=", "os", ".", "Setenv", "(", "\"GPG_TTY\"", ",", "t", ")", "\n", "}", "\n", "}", "\n", "g", ":=", "&", "GPG", "{", "binary", ":", "\"gpg\"", ",", "args", ":", "append", "(", "defaultArgs", ",", "cfg", ".", "Args", "...", ")", ",", "}", "\n", "cache", ",", "err", ":=", "lru", ".", "New2Q", "(", "1024", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "g", ".", "listCache", "=", "cache", "\n", "bin", ",", "err", ":=", "Binary", "(", "ctx", ",", "cfg", ".", "Binary", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "g", ".", "binary", "=", "bin", "\n", "return", "g", ",", "nil", "\n", "}" ]
// New creates a new GPG wrapper
[ "New", "creates", "a", "new", "GPG", "wrapper" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/cli/gpg.go#L43-L73
train
gopasspw/gopass
pkg/backend/crypto/gpg/cli/gpg.go
RecipientIDs
func (g *GPG) RecipientIDs(ctx context.Context, buf []byte) ([]string, error) { _ = os.Setenv("LANGUAGE", "C") recp := make([]string, 0, 5) args := []string{"--batch", "--list-only", "--list-packets", "--no-default-keyring", "--secret-keyring", "/dev/null"} cmd := exec.CommandContext(ctx, g.binary, args...) cmd.Stdin = bytes.NewReader(buf) out.Debug(ctx, "gpg.GetRecipients: %s %+v", cmd.Path, cmd.Args) cmdout, err := cmd.CombinedOutput() if err != nil { return []string{}, err } scanner := bufio.NewScanner(bytes.NewBuffer(cmdout)) for scanner.Scan() { line := strings.TrimSpace(scanner.Text()) out.Debug(ctx, "gpg Output: %s", line) if !strings.HasPrefix(line, ":pubkey enc packet:") { continue } m := splitPacket(line) if keyid, found := m["keyid"]; found { kl, err := g.listKeys(ctx, "public", keyid) if err != nil || len(kl) < 1 { continue } recp = append(recp, kl[0].Fingerprint) } } return recp, nil }
go
func (g *GPG) RecipientIDs(ctx context.Context, buf []byte) ([]string, error) { _ = os.Setenv("LANGUAGE", "C") recp := make([]string, 0, 5) args := []string{"--batch", "--list-only", "--list-packets", "--no-default-keyring", "--secret-keyring", "/dev/null"} cmd := exec.CommandContext(ctx, g.binary, args...) cmd.Stdin = bytes.NewReader(buf) out.Debug(ctx, "gpg.GetRecipients: %s %+v", cmd.Path, cmd.Args) cmdout, err := cmd.CombinedOutput() if err != nil { return []string{}, err } scanner := bufio.NewScanner(bytes.NewBuffer(cmdout)) for scanner.Scan() { line := strings.TrimSpace(scanner.Text()) out.Debug(ctx, "gpg Output: %s", line) if !strings.HasPrefix(line, ":pubkey enc packet:") { continue } m := splitPacket(line) if keyid, found := m["keyid"]; found { kl, err := g.listKeys(ctx, "public", keyid) if err != nil || len(kl) < 1 { continue } recp = append(recp, kl[0].Fingerprint) } } return recp, nil }
[ "func", "(", "g", "*", "GPG", ")", "RecipientIDs", "(", "ctx", "context", ".", "Context", ",", "buf", "[", "]", "byte", ")", "(", "[", "]", "string", ",", "error", ")", "{", "_", "=", "os", ".", "Setenv", "(", "\"LANGUAGE\"", ",", "\"C\"", ")", "\n", "recp", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "5", ")", "\n", "args", ":=", "[", "]", "string", "{", "\"--batch\"", ",", "\"--list-only\"", ",", "\"--list-packets\"", ",", "\"--no-default-keyring\"", ",", "\"--secret-keyring\"", ",", "\"/dev/null\"", "}", "\n", "cmd", ":=", "exec", ".", "CommandContext", "(", "ctx", ",", "g", ".", "binary", ",", "args", "...", ")", "\n", "cmd", ".", "Stdin", "=", "bytes", ".", "NewReader", "(", "buf", ")", "\n", "out", ".", "Debug", "(", "ctx", ",", "\"gpg.GetRecipients: %s %+v\"", ",", "cmd", ".", "Path", ",", "cmd", ".", "Args", ")", "\n", "cmdout", ",", "err", ":=", "cmd", ".", "CombinedOutput", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "]", "string", "{", "}", ",", "err", "\n", "}", "\n", "scanner", ":=", "bufio", ".", "NewScanner", "(", "bytes", ".", "NewBuffer", "(", "cmdout", ")", ")", "\n", "for", "scanner", ".", "Scan", "(", ")", "{", "line", ":=", "strings", ".", "TrimSpace", "(", "scanner", ".", "Text", "(", ")", ")", "\n", "out", ".", "Debug", "(", "ctx", ",", "\"gpg Output: %s\"", ",", "line", ")", "\n", "if", "!", "strings", ".", "HasPrefix", "(", "line", ",", "\":pubkey enc packet:\"", ")", "{", "continue", "\n", "}", "\n", "m", ":=", "splitPacket", "(", "line", ")", "\n", "if", "keyid", ",", "found", ":=", "m", "[", "\"keyid\"", "]", ";", "found", "{", "kl", ",", "err", ":=", "g", ".", "listKeys", "(", "ctx", ",", "\"public\"", ",", "keyid", ")", "\n", "if", "err", "!=", "nil", "||", "len", "(", "kl", ")", "<", "1", "{", "continue", "\n", "}", "\n", "recp", "=", "append", "(", "recp", ",", "kl", "[", "0", "]", ".", "Fingerprint", ")", "\n", "}", "\n", "}", "\n", "return", "recp", ",", "nil", "\n", "}" ]
// RecipientIDs returns a list of recipient IDs for a given file
[ "RecipientIDs", "returns", "a", "list", "of", "recipient", "IDs", "for", "a", "given", "file" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/cli/gpg.go#L76-L108
train
gopasspw/gopass
pkg/backend/crypto/gpg/cli/gpg.go
Decrypt
func (g *GPG) Decrypt(ctx context.Context, ciphertext []byte) ([]byte, error) { args := append(g.args, "--decrypt") cmd := exec.CommandContext(ctx, g.binary, args...) cmd.Stdin = bytes.NewReader(ciphertext) cmd.Stderr = os.Stderr out.Debug(ctx, "gpg.Decrypt: %s %+v", cmd.Path, cmd.Args) return cmd.Output() }
go
func (g *GPG) Decrypt(ctx context.Context, ciphertext []byte) ([]byte, error) { args := append(g.args, "--decrypt") cmd := exec.CommandContext(ctx, g.binary, args...) cmd.Stdin = bytes.NewReader(ciphertext) cmd.Stderr = os.Stderr out.Debug(ctx, "gpg.Decrypt: %s %+v", cmd.Path, cmd.Args) return cmd.Output() }
[ "func", "(", "g", "*", "GPG", ")", "Decrypt", "(", "ctx", "context", ".", "Context", ",", "ciphertext", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "args", ":=", "append", "(", "g", ".", "args", ",", "\"--decrypt\"", ")", "\n", "cmd", ":=", "exec", ".", "CommandContext", "(", "ctx", ",", "g", ".", "binary", ",", "args", "...", ")", "\n", "cmd", ".", "Stdin", "=", "bytes", ".", "NewReader", "(", "ciphertext", ")", "\n", "cmd", ".", "Stderr", "=", "os", ".", "Stderr", "\n", "out", ".", "Debug", "(", "ctx", ",", "\"gpg.Decrypt: %s %+v\"", ",", "cmd", ".", "Path", ",", "cmd", ".", "Args", ")", "\n", "return", "cmd", ".", "Output", "(", ")", "\n", "}" ]
// Decrypt will try to decrypt the given file
[ "Decrypt", "will", "try", "to", "decrypt", "the", "given", "file" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/cli/gpg.go#L137-L145
train
gopasspw/gopass
pkg/otp/otp.go
Calculate
func Calculate(ctx context.Context, name string, sec store.Secret) (twofactor.OTP, string, error) { otpURL := "" // check body for _, line := range strings.Split(sec.Body(), "\n") { if strings.HasPrefix(line, "otpauth://") { otpURL = line break } } if otpURL != "" { return twofactor.FromURL(otpURL) } // check yaml entry and fall back to password if we don't have one label := name secKey, err := sec.Value("totp") if err != nil { secKey = sec.Password() } if strings.HasPrefix(secKey, "otpauth://") { return twofactor.FromURL(secKey) } otp, err := twofactor.NewGoogleTOTP(secKey) return otp, label, err }
go
func Calculate(ctx context.Context, name string, sec store.Secret) (twofactor.OTP, string, error) { otpURL := "" // check body for _, line := range strings.Split(sec.Body(), "\n") { if strings.HasPrefix(line, "otpauth://") { otpURL = line break } } if otpURL != "" { return twofactor.FromURL(otpURL) } // check yaml entry and fall back to password if we don't have one label := name secKey, err := sec.Value("totp") if err != nil { secKey = sec.Password() } if strings.HasPrefix(secKey, "otpauth://") { return twofactor.FromURL(secKey) } otp, err := twofactor.NewGoogleTOTP(secKey) return otp, label, err }
[ "func", "Calculate", "(", "ctx", "context", ".", "Context", ",", "name", "string", ",", "sec", "store", ".", "Secret", ")", "(", "twofactor", ".", "OTP", ",", "string", ",", "error", ")", "{", "otpURL", ":=", "\"\"", "\n", "for", "_", ",", "line", ":=", "range", "strings", ".", "Split", "(", "sec", ".", "Body", "(", ")", ",", "\"\\n\"", ")", "\\n", "\n", "{", "if", "strings", ".", "HasPrefix", "(", "line", ",", "\"otpauth://\"", ")", "{", "otpURL", "=", "line", "\n", "break", "\n", "}", "\n", "}", "\n", "if", "otpURL", "!=", "\"\"", "{", "return", "twofactor", ".", "FromURL", "(", "otpURL", ")", "\n", "}", "\n", "label", ":=", "name", "\n", "secKey", ",", "err", ":=", "sec", ".", "Value", "(", "\"totp\"", ")", "\n", "if", "err", "!=", "nil", "{", "secKey", "=", "sec", ".", "Password", "(", ")", "\n", "}", "\n", "if", "strings", ".", "HasPrefix", "(", "secKey", ",", "\"otpauth://\"", ")", "{", "return", "twofactor", ".", "FromURL", "(", "secKey", ")", "\n", "}", "\n", "otp", ",", "err", ":=", "twofactor", ".", "NewGoogleTOTP", "(", "secKey", ")", "\n", "}" ]
// Calculate will compute a OTP code from a given secret
[ "Calculate", "will", "compute", "a", "OTP", "code", "from", "a", "given", "secret" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/otp/otp.go#L15-L42
train
gopasspw/gopass
pkg/otp/otp.go
WriteQRFile
func WriteQRFile(ctx context.Context, otp twofactor.OTP, label, file string) error { var qr []byte var err error switch otp.Type() { case twofactor.OATH_HOTP: hotp := otp.(*twofactor.HOTP) qr, err = hotp.QR(label) case twofactor.OATH_TOTP: totp := otp.(*twofactor.TOTP) qr, err = totp.QR(label) default: err = errors.New("QR codes can only be generated for OATH OTPs") } if err != nil { return errors.Wrapf(err, "%s", err) } if err := ioutil.WriteFile(file, qr, 0600); err != nil { return errors.Wrapf(err, "failed to write QR code: %s", err) } return nil }
go
func WriteQRFile(ctx context.Context, otp twofactor.OTP, label, file string) error { var qr []byte var err error switch otp.Type() { case twofactor.OATH_HOTP: hotp := otp.(*twofactor.HOTP) qr, err = hotp.QR(label) case twofactor.OATH_TOTP: totp := otp.(*twofactor.TOTP) qr, err = totp.QR(label) default: err = errors.New("QR codes can only be generated for OATH OTPs") } if err != nil { return errors.Wrapf(err, "%s", err) } if err := ioutil.WriteFile(file, qr, 0600); err != nil { return errors.Wrapf(err, "failed to write QR code: %s", err) } return nil }
[ "func", "WriteQRFile", "(", "ctx", "context", ".", "Context", ",", "otp", "twofactor", ".", "OTP", ",", "label", ",", "file", "string", ")", "error", "{", "var", "qr", "[", "]", "byte", "\n", "var", "err", "error", "\n", "switch", "otp", ".", "Type", "(", ")", "{", "case", "twofactor", ".", "OATH_HOTP", ":", "hotp", ":=", "otp", ".", "(", "*", "twofactor", ".", "HOTP", ")", "\n", "qr", ",", "err", "=", "hotp", ".", "QR", "(", "label", ")", "\n", "case", "twofactor", ".", "OATH_TOTP", ":", "totp", ":=", "otp", ".", "(", "*", "twofactor", ".", "TOTP", ")", "\n", "qr", ",", "err", "=", "totp", ".", "QR", "(", "label", ")", "\n", "default", ":", "err", "=", "errors", ".", "New", "(", "\"QR codes can only be generated for OATH OTPs\"", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"%s\"", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "ioutil", ".", "WriteFile", "(", "file", ",", "qr", ",", "0600", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to write QR code: %s\"", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// WriteQRFile writes the given OTP code as a QR image to disk
[ "WriteQRFile", "writes", "the", "given", "OTP", "code", "as", "a", "QR", "image", "to", "disk" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/otp/otp.go#L45-L66
train
gopasspw/gopass
pkg/store/root/recipients.go
ListRecipients
func (r *Store) ListRecipients(ctx context.Context, store string) []string { ctx, sub, _ := r.getStore(ctx, store) return sub.Recipients(ctx) }
go
func (r *Store) ListRecipients(ctx context.Context, store string) []string { ctx, sub, _ := r.getStore(ctx, store) return sub.Recipients(ctx) }
[ "func", "(", "r", "*", "Store", ")", "ListRecipients", "(", "ctx", "context", ".", "Context", ",", "store", "string", ")", "[", "]", "string", "{", "ctx", ",", "sub", ",", "_", ":=", "r", ".", "getStore", "(", "ctx", ",", "store", ")", "\n", "return", "sub", ".", "Recipients", "(", "ctx", ")", "\n", "}" ]
// ListRecipients lists all recipients for the given store
[ "ListRecipients", "lists", "all", "recipients", "for", "the", "given", "store" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/recipients.go#L18-L21
train
gopasspw/gopass
pkg/store/root/recipients.go
RemoveRecipient
func (r *Store) RemoveRecipient(ctx context.Context, store, rec string) error { ctx, sub, _ := r.getStore(ctx, store) return sub.RemoveRecipient(ctx, rec) }
go
func (r *Store) RemoveRecipient(ctx context.Context, store, rec string) error { ctx, sub, _ := r.getStore(ctx, store) return sub.RemoveRecipient(ctx, rec) }
[ "func", "(", "r", "*", "Store", ")", "RemoveRecipient", "(", "ctx", "context", ".", "Context", ",", "store", ",", "rec", "string", ")", "error", "{", "ctx", ",", "sub", ",", "_", ":=", "r", ".", "getStore", "(", "ctx", ",", "store", ")", "\n", "return", "sub", ".", "RemoveRecipient", "(", "ctx", ",", "rec", ")", "\n", "}" ]
// RemoveRecipient removes a single recipient from the given store
[ "RemoveRecipient", "removes", "a", "single", "recipient", "from", "the", "given", "store" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/recipients.go#L30-L33
train
gopasspw/gopass
pkg/store/root/recipients.go
ImportMissingPublicKeys
func (r *Store) ImportMissingPublicKeys(ctx context.Context) error { for alias, sub := range r.mounts { ctx := r.cfg.Mounts[alias].WithContext(ctx) if err := sub.ImportMissingPublicKeys(ctx); err != nil { out.Error(ctx, "[%s] Failed to import missing public keys: %s", alias, err) } } return r.store.ImportMissingPublicKeys(ctx) }
go
func (r *Store) ImportMissingPublicKeys(ctx context.Context) error { for alias, sub := range r.mounts { ctx := r.cfg.Mounts[alias].WithContext(ctx) if err := sub.ImportMissingPublicKeys(ctx); err != nil { out.Error(ctx, "[%s] Failed to import missing public keys: %s", alias, err) } } return r.store.ImportMissingPublicKeys(ctx) }
[ "func", "(", "r", "*", "Store", ")", "ImportMissingPublicKeys", "(", "ctx", "context", ".", "Context", ")", "error", "{", "for", "alias", ",", "sub", ":=", "range", "r", ".", "mounts", "{", "ctx", ":=", "r", ".", "cfg", ".", "Mounts", "[", "alias", "]", ".", "WithContext", "(", "ctx", ")", "\n", "if", "err", ":=", "sub", ".", "ImportMissingPublicKeys", "(", "ctx", ")", ";", "err", "!=", "nil", "{", "out", ".", "Error", "(", "ctx", ",", "\"[%s] Failed to import missing public keys: %s\"", ",", "alias", ",", "err", ")", "\n", "}", "\n", "}", "\n", "return", "r", ".", "store", ".", "ImportMissingPublicKeys", "(", "ctx", ")", "\n", "}" ]
// ImportMissingPublicKeys import missing public keys in any substore
[ "ImportMissingPublicKeys", "import", "missing", "public", "keys", "in", "any", "substore" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/recipients.go#L53-L62
train
gopasspw/gopass
pkg/store/root/recipients.go
RecipientsTree
func (r *Store) RecipientsTree(ctx context.Context, pretty bool) (tree.Tree, error) { root := simple.New("gopass") for _, recp := range r.store.Recipients(ctx) { if err := r.addRecipient(ctx, "", root, recp, pretty); err != nil { color.Yellow("Failed to add recipient to tree %s: %s", recp, err) } } mps := r.MountPoints() sort.Sort(store.ByPathLen(mps)) for _, alias := range mps { substore := r.mounts[alias] if substore == nil { continue } if err := root.AddMount(alias, substore.Path()); err != nil { return nil, errors.Errorf("failed to add mount: %s", err) } for _, recp := range substore.Recipients(ctx) { if err := r.addRecipient(ctx, alias+"/", root, recp, pretty); err != nil { out.Debug(ctx, "Failed to add recipient to tree %s: %s", recp, err) } } } return root, nil }
go
func (r *Store) RecipientsTree(ctx context.Context, pretty bool) (tree.Tree, error) { root := simple.New("gopass") for _, recp := range r.store.Recipients(ctx) { if err := r.addRecipient(ctx, "", root, recp, pretty); err != nil { color.Yellow("Failed to add recipient to tree %s: %s", recp, err) } } mps := r.MountPoints() sort.Sort(store.ByPathLen(mps)) for _, alias := range mps { substore := r.mounts[alias] if substore == nil { continue } if err := root.AddMount(alias, substore.Path()); err != nil { return nil, errors.Errorf("failed to add mount: %s", err) } for _, recp := range substore.Recipients(ctx) { if err := r.addRecipient(ctx, alias+"/", root, recp, pretty); err != nil { out.Debug(ctx, "Failed to add recipient to tree %s: %s", recp, err) } } } return root, nil }
[ "func", "(", "r", "*", "Store", ")", "RecipientsTree", "(", "ctx", "context", ".", "Context", ",", "pretty", "bool", ")", "(", "tree", ".", "Tree", ",", "error", ")", "{", "root", ":=", "simple", ".", "New", "(", "\"gopass\"", ")", "\n", "for", "_", ",", "recp", ":=", "range", "r", ".", "store", ".", "Recipients", "(", "ctx", ")", "{", "if", "err", ":=", "r", ".", "addRecipient", "(", "ctx", ",", "\"\"", ",", "root", ",", "recp", ",", "pretty", ")", ";", "err", "!=", "nil", "{", "color", ".", "Yellow", "(", "\"Failed to add recipient to tree %s: %s\"", ",", "recp", ",", "err", ")", "\n", "}", "\n", "}", "\n", "mps", ":=", "r", ".", "MountPoints", "(", ")", "\n", "sort", ".", "Sort", "(", "store", ".", "ByPathLen", "(", "mps", ")", ")", "\n", "for", "_", ",", "alias", ":=", "range", "mps", "{", "substore", ":=", "r", ".", "mounts", "[", "alias", "]", "\n", "if", "substore", "==", "nil", "{", "continue", "\n", "}", "\n", "if", "err", ":=", "root", ".", "AddMount", "(", "alias", ",", "substore", ".", "Path", "(", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"failed to add mount: %s\"", ",", "err", ")", "\n", "}", "\n", "for", "_", ",", "recp", ":=", "range", "substore", ".", "Recipients", "(", "ctx", ")", "{", "if", "err", ":=", "r", ".", "addRecipient", "(", "ctx", ",", "alias", "+", "\"/\"", ",", "root", ",", "recp", ",", "pretty", ")", ";", "err", "!=", "nil", "{", "out", ".", "Debug", "(", "ctx", ",", "\"Failed to add recipient to tree %s: %s\"", ",", "recp", ",", "err", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "root", ",", "nil", "\n", "}" ]
// RecipientsTree returns a tree view of all stores' recipients
[ "RecipientsTree", "returns", "a", "tree", "view", "of", "all", "stores", "recipients" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/recipients.go#L78-L105
train
gopasspw/gopass
pkg/backend/crypto/gpg/openpgp/utils.go
gpgHome
func gpgHome(ctx context.Context) string { if gh := os.Getenv("GNUPGHOME"); gh != "" { return gh } hd, err := homedir.Dir() if err != nil { out.Debug(ctx, "Failed to get homedir: %s", err) return "" } return filepath.Join(hd, ".gnupg") }
go
func gpgHome(ctx context.Context) string { if gh := os.Getenv("GNUPGHOME"); gh != "" { return gh } hd, err := homedir.Dir() if err != nil { out.Debug(ctx, "Failed to get homedir: %s", err) return "" } return filepath.Join(hd, ".gnupg") }
[ "func", "gpgHome", "(", "ctx", "context", ".", "Context", ")", "string", "{", "if", "gh", ":=", "os", ".", "Getenv", "(", "\"GNUPGHOME\"", ")", ";", "gh", "!=", "\"\"", "{", "return", "gh", "\n", "}", "\n", "hd", ",", "err", ":=", "homedir", ".", "Dir", "(", ")", "\n", "if", "err", "!=", "nil", "{", "out", ".", "Debug", "(", "ctx", ",", "\"Failed to get homedir: %s\"", ",", "err", ")", "\n", "return", "\"\"", "\n", "}", "\n", "return", "filepath", ".", "Join", "(", "hd", ",", "\".gnupg\"", ")", "\n", "}" ]
// gpgHome returns the gnupg homedir
[ "gpgHome", "returns", "the", "gnupg", "homedir" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/openpgp/utils.go#L115-L125
train
gopasspw/gopass
pkg/store/sub/context.go
WithFsckCheck
func WithFsckCheck(ctx context.Context, check bool) context.Context { return context.WithValue(ctx, ctxKeyFsckCheck, check) }
go
func WithFsckCheck(ctx context.Context, check bool) context.Context { return context.WithValue(ctx, ctxKeyFsckCheck, check) }
[ "func", "WithFsckCheck", "(", "ctx", "context", ".", "Context", ",", "check", "bool", ")", "context", ".", "Context", "{", "return", "context", ".", "WithValue", "(", "ctx", ",", "ctxKeyFsckCheck", ",", "check", ")", "\n", "}" ]
// WithFsckCheck returns a context with the flag for fscks check set
[ "WithFsckCheck", "returns", "a", "context", "with", "the", "flag", "for", "fscks", "check", "set" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/context.go#L23-L25
train
gopasspw/gopass
pkg/store/sub/context.go
HasFsckCheck
func HasFsckCheck(ctx context.Context) bool { _, ok := ctx.Value(ctxKeyFsckCheck).(bool) return ok }
go
func HasFsckCheck(ctx context.Context) bool { _, ok := ctx.Value(ctxKeyFsckCheck).(bool) return ok }
[ "func", "HasFsckCheck", "(", "ctx", "context", ".", "Context", ")", "bool", "{", "_", ",", "ok", ":=", "ctx", ".", "Value", "(", "ctxKeyFsckCheck", ")", ".", "(", "bool", ")", "\n", "return", "ok", "\n", "}" ]
// HasFsckCheck returns true if a value for fsck check has been set in this // context
[ "HasFsckCheck", "returns", "true", "if", "a", "value", "for", "fsck", "check", "has", "been", "set", "in", "this", "context" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/context.go#L29-L32
train
gopasspw/gopass
pkg/store/sub/context.go
IsFsckCheck
func IsFsckCheck(ctx context.Context) bool { bv, ok := ctx.Value(ctxKeyFsckCheck).(bool) if !ok { return false } return bv }
go
func IsFsckCheck(ctx context.Context) bool { bv, ok := ctx.Value(ctxKeyFsckCheck).(bool) if !ok { return false } return bv }
[ "func", "IsFsckCheck", "(", "ctx", "context", ".", "Context", ")", "bool", "{", "bv", ",", "ok", ":=", "ctx", ".", "Value", "(", "ctxKeyFsckCheck", ")", ".", "(", "bool", ")", "\n", "if", "!", "ok", "{", "return", "false", "\n", "}", "\n", "return", "bv", "\n", "}" ]
// IsFsckCheck returns the value of fsck check
[ "IsFsckCheck", "returns", "the", "value", "of", "fsck", "check" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/context.go#L35-L41
train
gopasspw/gopass
pkg/store/sub/context.go
WithFsckForce
func WithFsckForce(ctx context.Context, force bool) context.Context { return context.WithValue(ctx, ctxKeyFsckForce, force) }
go
func WithFsckForce(ctx context.Context, force bool) context.Context { return context.WithValue(ctx, ctxKeyFsckForce, force) }
[ "func", "WithFsckForce", "(", "ctx", "context", ".", "Context", ",", "force", "bool", ")", "context", ".", "Context", "{", "return", "context", ".", "WithValue", "(", "ctx", ",", "ctxKeyFsckForce", ",", "force", ")", "\n", "}" ]
// WithFsckForce returns a context with the flag for fsck force set
[ "WithFsckForce", "returns", "a", "context", "with", "the", "flag", "for", "fsck", "force", "set" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/context.go#L44-L46
train
gopasspw/gopass
pkg/store/sub/context.go
HasFsckForce
func HasFsckForce(ctx context.Context) bool { _, ok := ctx.Value(ctxKeyFsckForce).(bool) return ok }
go
func HasFsckForce(ctx context.Context) bool { _, ok := ctx.Value(ctxKeyFsckForce).(bool) return ok }
[ "func", "HasFsckForce", "(", "ctx", "context", ".", "Context", ")", "bool", "{", "_", ",", "ok", ":=", "ctx", ".", "Value", "(", "ctxKeyFsckForce", ")", ".", "(", "bool", ")", "\n", "return", "ok", "\n", "}" ]
// HasFsckForce returns true if a value for fsck force has been set in this // context
[ "HasFsckForce", "returns", "true", "if", "a", "value", "for", "fsck", "force", "has", "been", "set", "in", "this", "context" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/context.go#L50-L53
train
gopasspw/gopass
pkg/store/sub/context.go
IsFsckForce
func IsFsckForce(ctx context.Context) bool { bv, ok := ctx.Value(ctxKeyFsckForce).(bool) if !ok { return false } return bv }
go
func IsFsckForce(ctx context.Context) bool { bv, ok := ctx.Value(ctxKeyFsckForce).(bool) if !ok { return false } return bv }
[ "func", "IsFsckForce", "(", "ctx", "context", ".", "Context", ")", "bool", "{", "bv", ",", "ok", ":=", "ctx", ".", "Value", "(", "ctxKeyFsckForce", ")", ".", "(", "bool", ")", "\n", "if", "!", "ok", "{", "return", "false", "\n", "}", "\n", "return", "bv", "\n", "}" ]
// IsFsckForce returns the value of fsck force
[ "IsFsckForce", "returns", "the", "value", "of", "fsck", "force" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/context.go#L56-L62
train
gopasspw/gopass
pkg/store/sub/context.go
WithAutoSync
func WithAutoSync(ctx context.Context, sync bool) context.Context { return context.WithValue(ctx, ctxKeyAutoSync, sync) }
go
func WithAutoSync(ctx context.Context, sync bool) context.Context { return context.WithValue(ctx, ctxKeyAutoSync, sync) }
[ "func", "WithAutoSync", "(", "ctx", "context", ".", "Context", ",", "sync", "bool", ")", "context", ".", "Context", "{", "return", "context", ".", "WithValue", "(", "ctx", ",", "ctxKeyAutoSync", ",", "sync", ")", "\n", "}" ]
// WithAutoSync returns a context with the flag for autosync set
[ "WithAutoSync", "returns", "a", "context", "with", "the", "flag", "for", "autosync", "set" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/context.go#L65-L67
train
gopasspw/gopass
pkg/store/sub/context.go
HasAutoSync
func HasAutoSync(ctx context.Context) bool { _, ok := ctx.Value(ctxKeyAutoSync).(bool) return ok }
go
func HasAutoSync(ctx context.Context) bool { _, ok := ctx.Value(ctxKeyAutoSync).(bool) return ok }
[ "func", "HasAutoSync", "(", "ctx", "context", ".", "Context", ")", "bool", "{", "_", ",", "ok", ":=", "ctx", ".", "Value", "(", "ctxKeyAutoSync", ")", ".", "(", "bool", ")", "\n", "return", "ok", "\n", "}" ]
// HasAutoSync has been set if a value for auto sync has been set in this // context
[ "HasAutoSync", "has", "been", "set", "if", "a", "value", "for", "auto", "sync", "has", "been", "set", "in", "this", "context" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/context.go#L71-L74
train