repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequence
docstring
stringlengths
6
2.61k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
gopasspw/gopass
pkg/action/generate.go
generateSetPassword
func (s *Action) generateSetPassword(ctx context.Context, name, key, password string, kvps map[string]string) (context.Context, error) { // set a single key in a yaml doc if key != "" { sec, ctx, err := s.Store.GetContext(ctx, name) if err != nil { return ctx, ExitError(ctx, ExitEncrypt, err, "failed to set key '%s' of '%s': %s", key, name, err) } setMetadata(sec, kvps) if err := sec.SetValue(key, password); err != nil { return ctx, ExitError(ctx, ExitEncrypt, err, "failed to set key '%s' of '%s': %s", key, name, err) } if err := s.Store.Set(sub.WithReason(ctx, "Generated password for YAML key"), name, sec); err != nil { return ctx, ExitError(ctx, ExitEncrypt, err, "failed to set key '%s' of '%s': %s", key, name, err) } return ctx, nil } // replace password in existing secret if s.Store.Exists(ctx, name) { sec, ctx, err := s.Store.GetContext(ctx, name) if err != nil { return ctx, ExitError(ctx, ExitEncrypt, err, "failed to set key '%s' of '%s': %s", key, name, err) } setMetadata(sec, kvps) sec.SetPassword(password) if err := s.Store.Set(sub.WithReason(ctx, "Generated password for YAML key"), name, sec); err != nil { return ctx, ExitError(ctx, ExitEncrypt, err, "failed to set key '%s' of '%s': %s", key, name, err) } return ctx, nil } // generate a completely new secret var err error sec := secret.New(password, "") if content, found := s.renderTemplate(ctx, name, []byte(password)); found { nSec, err := secret.Parse(content) if err == nil { sec = nSec } } ctx, err = s.Store.SetContext(sub.WithReason(ctx, "Generated Password"), name, sec) if err != nil { return ctx, ExitError(ctx, ExitEncrypt, err, "failed to create '%s': %s", name, err) } return ctx, nil }
go
func (s *Action) generateSetPassword(ctx context.Context, name, key, password string, kvps map[string]string) (context.Context, error) { // set a single key in a yaml doc if key != "" { sec, ctx, err := s.Store.GetContext(ctx, name) if err != nil { return ctx, ExitError(ctx, ExitEncrypt, err, "failed to set key '%s' of '%s': %s", key, name, err) } setMetadata(sec, kvps) if err := sec.SetValue(key, password); err != nil { return ctx, ExitError(ctx, ExitEncrypt, err, "failed to set key '%s' of '%s': %s", key, name, err) } if err := s.Store.Set(sub.WithReason(ctx, "Generated password for YAML key"), name, sec); err != nil { return ctx, ExitError(ctx, ExitEncrypt, err, "failed to set key '%s' of '%s': %s", key, name, err) } return ctx, nil } // replace password in existing secret if s.Store.Exists(ctx, name) { sec, ctx, err := s.Store.GetContext(ctx, name) if err != nil { return ctx, ExitError(ctx, ExitEncrypt, err, "failed to set key '%s' of '%s': %s", key, name, err) } setMetadata(sec, kvps) sec.SetPassword(password) if err := s.Store.Set(sub.WithReason(ctx, "Generated password for YAML key"), name, sec); err != nil { return ctx, ExitError(ctx, ExitEncrypt, err, "failed to set key '%s' of '%s': %s", key, name, err) } return ctx, nil } // generate a completely new secret var err error sec := secret.New(password, "") if content, found := s.renderTemplate(ctx, name, []byte(password)); found { nSec, err := secret.Parse(content) if err == nil { sec = nSec } } ctx, err = s.Store.SetContext(sub.WithReason(ctx, "Generated Password"), name, sec) if err != nil { return ctx, ExitError(ctx, ExitEncrypt, err, "failed to create '%s': %s", name, err) } return ctx, nil }
[ "func", "(", "s", "*", "Action", ")", "generateSetPassword", "(", "ctx", "context", ".", "Context", ",", "name", ",", "key", ",", "password", "string", ",", "kvps", "map", "[", "string", "]", "string", ")", "(", "context", ".", "Context", ",", "error", ")", "{", "// set a single key in a yaml doc", "if", "key", "!=", "\"", "\"", "{", "sec", ",", "ctx", ",", "err", ":=", "s", ".", "Store", ".", "GetContext", "(", "ctx", ",", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "ctx", ",", "ExitError", "(", "ctx", ",", "ExitEncrypt", ",", "err", ",", "\"", "\"", ",", "key", ",", "name", ",", "err", ")", "\n", "}", "\n", "setMetadata", "(", "sec", ",", "kvps", ")", "\n", "if", "err", ":=", "sec", ".", "SetValue", "(", "key", ",", "password", ")", ";", "err", "!=", "nil", "{", "return", "ctx", ",", "ExitError", "(", "ctx", ",", "ExitEncrypt", ",", "err", ",", "\"", "\"", ",", "key", ",", "name", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "s", ".", "Store", ".", "Set", "(", "sub", ".", "WithReason", "(", "ctx", ",", "\"", "\"", ")", ",", "name", ",", "sec", ")", ";", "err", "!=", "nil", "{", "return", "ctx", ",", "ExitError", "(", "ctx", ",", "ExitEncrypt", ",", "err", ",", "\"", "\"", ",", "key", ",", "name", ",", "err", ")", "\n", "}", "\n", "return", "ctx", ",", "nil", "\n", "}", "\n\n", "// replace password in existing secret", "if", "s", ".", "Store", ".", "Exists", "(", "ctx", ",", "name", ")", "{", "sec", ",", "ctx", ",", "err", ":=", "s", ".", "Store", ".", "GetContext", "(", "ctx", ",", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "ctx", ",", "ExitError", "(", "ctx", ",", "ExitEncrypt", ",", "err", ",", "\"", "\"", ",", "key", ",", "name", ",", "err", ")", "\n", "}", "\n", "setMetadata", "(", "sec", ",", "kvps", ")", "\n", "sec", ".", "SetPassword", "(", "password", ")", "\n", "if", "err", ":=", "s", ".", "Store", ".", "Set", "(", "sub", ".", "WithReason", "(", "ctx", ",", "\"", "\"", ")", ",", "name", ",", "sec", ")", ";", "err", "!=", "nil", "{", "return", "ctx", ",", "ExitError", "(", "ctx", ",", "ExitEncrypt", ",", "err", ",", "\"", "\"", ",", "key", ",", "name", ",", "err", ")", "\n", "}", "\n", "return", "ctx", ",", "nil", "\n", "}", "\n\n", "// generate a completely new secret", "var", "err", "error", "\n", "sec", ":=", "secret", ".", "New", "(", "password", ",", "\"", "\"", ")", "\n\n", "if", "content", ",", "found", ":=", "s", ".", "renderTemplate", "(", "ctx", ",", "name", ",", "[", "]", "byte", "(", "password", ")", ")", ";", "found", "{", "nSec", ",", "err", ":=", "secret", ".", "Parse", "(", "content", ")", "\n", "if", "err", "==", "nil", "{", "sec", "=", "nSec", "\n", "}", "\n", "}", "\n\n", "ctx", ",", "err", "=", "s", ".", "Store", ".", "SetContext", "(", "sub", ".", "WithReason", "(", "ctx", ",", "\"", "\"", ")", ",", "name", ",", "sec", ")", "\n", "if", "err", "!=", "nil", "{", "return", "ctx", ",", "ExitError", "(", "ctx", ",", "ExitEncrypt", ",", "err", ",", "\"", "\"", ",", "name", ",", "err", ")", "\n", "}", "\n", "return", "ctx", ",", "nil", "\n", "}" ]
// generateSetPassword will update or create a secret
[ "generateSetPassword", "will", "update", "or", "create", "a", "secret" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/generate.go#L209-L256
train
gopasspw/gopass
pkg/action/generate.go
CompleteGenerate
func (s *Action) CompleteGenerate(ctx context.Context, c *cli.Context) { args := c.Args() if len(args) < 1 { return } needle := args[0] _, err := s.Store.Initialized(ctx) // important to make sure the structs are not nil if err != nil { out.Error(ctx, "Store not initialized: %s", err) return } list, err := s.Store.List(ctx, 0) if err != nil { return } if strings.Contains(needle, "/") { list = filterPrefix(uniq(extractEmails(list)), path.Base(needle)) } else { list = filterPrefix(uniq(extractDomains(list)), needle) } for _, v := range list { fmt.Fprintln(stdout, bashEscape(v)) } }
go
func (s *Action) CompleteGenerate(ctx context.Context, c *cli.Context) { args := c.Args() if len(args) < 1 { return } needle := args[0] _, err := s.Store.Initialized(ctx) // important to make sure the structs are not nil if err != nil { out.Error(ctx, "Store not initialized: %s", err) return } list, err := s.Store.List(ctx, 0) if err != nil { return } if strings.Contains(needle, "/") { list = filterPrefix(uniq(extractEmails(list)), path.Base(needle)) } else { list = filterPrefix(uniq(extractDomains(list)), needle) } for _, v := range list { fmt.Fprintln(stdout, bashEscape(v)) } }
[ "func", "(", "s", "*", "Action", ")", "CompleteGenerate", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "{", "args", ":=", "c", ".", "Args", "(", ")", "\n", "if", "len", "(", "args", ")", "<", "1", "{", "return", "\n", "}", "\n", "needle", ":=", "args", "[", "0", "]", "\n\n", "_", ",", "err", ":=", "s", ".", "Store", ".", "Initialized", "(", "ctx", ")", "// important to make sure the structs are not nil", "\n", "if", "err", "!=", "nil", "{", "out", ".", "Error", "(", "ctx", ",", "\"", "\"", ",", "err", ")", "\n", "return", "\n", "}", "\n", "list", ",", "err", ":=", "s", ".", "Store", ".", "List", "(", "ctx", ",", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n\n", "if", "strings", ".", "Contains", "(", "needle", ",", "\"", "\"", ")", "{", "list", "=", "filterPrefix", "(", "uniq", "(", "extractEmails", "(", "list", ")", ")", ",", "path", ".", "Base", "(", "needle", ")", ")", "\n", "}", "else", "{", "list", "=", "filterPrefix", "(", "uniq", "(", "extractDomains", "(", "list", ")", ")", ",", "needle", ")", "\n", "}", "\n\n", "for", "_", ",", "v", ":=", "range", "list", "{", "fmt", ".", "Fprintln", "(", "stdout", ",", "bashEscape", "(", "v", ")", ")", "\n", "}", "\n", "}" ]
// CompleteGenerate implements the completion heuristic for the generate command
[ "CompleteGenerate", "implements", "the", "completion", "heuristic", "for", "the", "generate", "command" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/generate.go#L265-L291
train
gopasspw/gopass
pkg/editor/editor.go
Invoke
func Invoke(ctx context.Context, editor string, content []byte) ([]byte, error) { if !ctxutil.IsTerminal(ctx) { return nil, errors.New("need terminal") } tmpfile, err := tempfile.New(ctx, "gopass-edit") if err != nil { return []byte{}, errors.Errorf("failed to create tmpfile %s: %s", editor, err) } defer func() { if err := tmpfile.Remove(ctx); err != nil { color.Red("Failed to remove tempfile at %s: %s", tmpfile.Name(), err) } }() if _, err := tmpfile.Write(content); err != nil { return []byte{}, errors.Errorf("failed to write tmpfile to start with %s %v: %s", editor, tmpfile.Name(), err) } if err := tmpfile.Close(); err != nil { return []byte{}, errors.Errorf("failed to close tmpfile to start with %s %v: %s", editor, tmpfile.Name(), err) } cmdArgs, err := shellquote.Split(editor) if err != nil { return []byte{}, errors.Errorf("failed to parse EDITOR command `%s`", editor) } editor = cmdArgs[0] args := append(cmdArgs[1:], tmpfile.Name()) cmd := exec.Command(editor, args...) cmd.Stdin = Stdin cmd.Stdout = Stdout cmd.Stderr = Stderr if err := cmd.Run(); err != nil { out.Debug(ctx, "editor - cmd: %s %+v - error: %+v", cmd.Path, cmd.Args, err) return []byte{}, errors.Errorf("failed to run %s with %s file: %s", editor, tmpfile.Name(), err) } nContent, err := ioutil.ReadFile(tmpfile.Name()) if err != nil { return []byte{}, errors.Errorf("failed to read from tmpfile: %v", err) } // enforce unix line endings in the password store nContent = bytes.Replace(nContent, []byte("\r\n"), []byte("\n"), -1) nContent = bytes.Replace(nContent, []byte("\r"), []byte("\n"), -1) return nContent, nil }
go
func Invoke(ctx context.Context, editor string, content []byte) ([]byte, error) { if !ctxutil.IsTerminal(ctx) { return nil, errors.New("need terminal") } tmpfile, err := tempfile.New(ctx, "gopass-edit") if err != nil { return []byte{}, errors.Errorf("failed to create tmpfile %s: %s", editor, err) } defer func() { if err := tmpfile.Remove(ctx); err != nil { color.Red("Failed to remove tempfile at %s: %s", tmpfile.Name(), err) } }() if _, err := tmpfile.Write(content); err != nil { return []byte{}, errors.Errorf("failed to write tmpfile to start with %s %v: %s", editor, tmpfile.Name(), err) } if err := tmpfile.Close(); err != nil { return []byte{}, errors.Errorf("failed to close tmpfile to start with %s %v: %s", editor, tmpfile.Name(), err) } cmdArgs, err := shellquote.Split(editor) if err != nil { return []byte{}, errors.Errorf("failed to parse EDITOR command `%s`", editor) } editor = cmdArgs[0] args := append(cmdArgs[1:], tmpfile.Name()) cmd := exec.Command(editor, args...) cmd.Stdin = Stdin cmd.Stdout = Stdout cmd.Stderr = Stderr if err := cmd.Run(); err != nil { out.Debug(ctx, "editor - cmd: %s %+v - error: %+v", cmd.Path, cmd.Args, err) return []byte{}, errors.Errorf("failed to run %s with %s file: %s", editor, tmpfile.Name(), err) } nContent, err := ioutil.ReadFile(tmpfile.Name()) if err != nil { return []byte{}, errors.Errorf("failed to read from tmpfile: %v", err) } // enforce unix line endings in the password store nContent = bytes.Replace(nContent, []byte("\r\n"), []byte("\n"), -1) nContent = bytes.Replace(nContent, []byte("\r"), []byte("\n"), -1) return nContent, nil }
[ "func", "Invoke", "(", "ctx", "context", ".", "Context", ",", "editor", "string", ",", "content", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "if", "!", "ctxutil", ".", "IsTerminal", "(", "ctx", ")", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "tmpfile", ",", "err", ":=", "tempfile", ".", "New", "(", "ctx", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "]", "byte", "{", "}", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "editor", ",", "err", ")", "\n", "}", "\n", "defer", "func", "(", ")", "{", "if", "err", ":=", "tmpfile", ".", "Remove", "(", "ctx", ")", ";", "err", "!=", "nil", "{", "color", ".", "Red", "(", "\"", "\"", ",", "tmpfile", ".", "Name", "(", ")", ",", "err", ")", "\n", "}", "\n", "}", "(", ")", "\n\n", "if", "_", ",", "err", ":=", "tmpfile", ".", "Write", "(", "content", ")", ";", "err", "!=", "nil", "{", "return", "[", "]", "byte", "{", "}", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "editor", ",", "tmpfile", ".", "Name", "(", ")", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "tmpfile", ".", "Close", "(", ")", ";", "err", "!=", "nil", "{", "return", "[", "]", "byte", "{", "}", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "editor", ",", "tmpfile", ".", "Name", "(", ")", ",", "err", ")", "\n", "}", "\n\n", "cmdArgs", ",", "err", ":=", "shellquote", ".", "Split", "(", "editor", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "]", "byte", "{", "}", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "editor", ")", "\n", "}", "\n\n", "editor", "=", "cmdArgs", "[", "0", "]", "\n", "args", ":=", "append", "(", "cmdArgs", "[", "1", ":", "]", ",", "tmpfile", ".", "Name", "(", ")", ")", "\n\n", "cmd", ":=", "exec", ".", "Command", "(", "editor", ",", "args", "...", ")", "\n", "cmd", ".", "Stdin", "=", "Stdin", "\n", "cmd", ".", "Stdout", "=", "Stdout", "\n", "cmd", ".", "Stderr", "=", "Stderr", "\n\n", "if", "err", ":=", "cmd", ".", "Run", "(", ")", ";", "err", "!=", "nil", "{", "out", ".", "Debug", "(", "ctx", ",", "\"", "\"", ",", "cmd", ".", "Path", ",", "cmd", ".", "Args", ",", "err", ")", "\n", "return", "[", "]", "byte", "{", "}", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "editor", ",", "tmpfile", ".", "Name", "(", ")", ",", "err", ")", "\n", "}", "\n\n", "nContent", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "tmpfile", ".", "Name", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "]", "byte", "{", "}", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// enforce unix line endings in the password store", "nContent", "=", "bytes", ".", "Replace", "(", "nContent", ",", "[", "]", "byte", "(", "\"", "\\r", "\\n", "\"", ")", ",", "[", "]", "byte", "(", "\"", "\\n", "\"", ")", ",", "-", "1", ")", "\n", "nContent", "=", "bytes", ".", "Replace", "(", "nContent", ",", "[", "]", "byte", "(", "\"", "\\r", "\"", ")", ",", "[", "]", "byte", "(", "\"", "\\n", "\"", ")", ",", "-", "1", ")", "\n\n", "return", "nContent", ",", "nil", "\n", "}" ]
// Invoke will start the given editor and return the content
[ "Invoke", "will", "start", "the", "given", "editor", "and", "return", "the", "content" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/editor/editor.go#L30-L80
train
gopasspw/gopass
pkg/audit/audit.go
Batch
func Batch(ctx context.Context, secrets []string, secStore secretGetter) error { out.Print(ctx, "Checking %d secrets. This may take some time ...\n", len(secrets)) // Secrets that still need auditing. pending := make(chan string, 100) // Secrets that have been audited. checked := make(chan auditedSecret, 100) // Spawn workers that run the auditing of all secrets concurrently. validator := crunchy.NewValidator() maxJobs := runtime.NumCPU() done := make(chan struct{}, maxJobs) for jobs := 0; jobs < maxJobs; jobs++ { go audit(ctx, secStore, validator, pending, checked, done) } go func() { for _, secret := range secrets { pending <- secret } close(pending) }() go func() { for i := 0; i < maxJobs; i++ { <-done } close(checked) }() duplicates := make(map[string][]string) messages := make(map[string][]string) errors := make(map[string][]string) bar := &goprogressbar.ProgressBar{ Total: int64(len(secrets)), Width: 120, } if out.IsHidden(ctx) { old := goprogressbar.Stdout goprogressbar.Stdout = ioutil.Discard defer func() { goprogressbar.Stdout = old }() } i := 0 for secret := range checked { if secret.err != nil { errors[secret.err.Error()] = append(errors[secret.err.Error()], secret.name) } else { duplicates[secret.content] = append(duplicates[secret.content], secret.name) } if secret.message != "" { messages[secret.message] = append(messages[secret.message], secret.name) } i++ bar.Current = int64(i) bar.Text = fmt.Sprintf("%d of %d secrets checked", bar.Current, bar.Total) bar.LazyPrint() if i == len(secrets) { break } } fmt.Fprintln(goprogressbar.Stdout) // Print empty line after the progressbar. return auditPrintResults(ctx, duplicates, messages, errors) }
go
func Batch(ctx context.Context, secrets []string, secStore secretGetter) error { out.Print(ctx, "Checking %d secrets. This may take some time ...\n", len(secrets)) // Secrets that still need auditing. pending := make(chan string, 100) // Secrets that have been audited. checked := make(chan auditedSecret, 100) // Spawn workers that run the auditing of all secrets concurrently. validator := crunchy.NewValidator() maxJobs := runtime.NumCPU() done := make(chan struct{}, maxJobs) for jobs := 0; jobs < maxJobs; jobs++ { go audit(ctx, secStore, validator, pending, checked, done) } go func() { for _, secret := range secrets { pending <- secret } close(pending) }() go func() { for i := 0; i < maxJobs; i++ { <-done } close(checked) }() duplicates := make(map[string][]string) messages := make(map[string][]string) errors := make(map[string][]string) bar := &goprogressbar.ProgressBar{ Total: int64(len(secrets)), Width: 120, } if out.IsHidden(ctx) { old := goprogressbar.Stdout goprogressbar.Stdout = ioutil.Discard defer func() { goprogressbar.Stdout = old }() } i := 0 for secret := range checked { if secret.err != nil { errors[secret.err.Error()] = append(errors[secret.err.Error()], secret.name) } else { duplicates[secret.content] = append(duplicates[secret.content], secret.name) } if secret.message != "" { messages[secret.message] = append(messages[secret.message], secret.name) } i++ bar.Current = int64(i) bar.Text = fmt.Sprintf("%d of %d secrets checked", bar.Current, bar.Total) bar.LazyPrint() if i == len(secrets) { break } } fmt.Fprintln(goprogressbar.Stdout) // Print empty line after the progressbar. return auditPrintResults(ctx, duplicates, messages, errors) }
[ "func", "Batch", "(", "ctx", "context", ".", "Context", ",", "secrets", "[", "]", "string", ",", "secStore", "secretGetter", ")", "error", "{", "out", ".", "Print", "(", "ctx", ",", "\"", "\\n", "\"", ",", "len", "(", "secrets", ")", ")", "\n\n", "// Secrets that still need auditing.", "pending", ":=", "make", "(", "chan", "string", ",", "100", ")", "\n\n", "// Secrets that have been audited.", "checked", ":=", "make", "(", "chan", "auditedSecret", ",", "100", ")", "\n\n", "// Spawn workers that run the auditing of all secrets concurrently.", "validator", ":=", "crunchy", ".", "NewValidator", "(", ")", "\n", "maxJobs", ":=", "runtime", ".", "NumCPU", "(", ")", "\n", "done", ":=", "make", "(", "chan", "struct", "{", "}", ",", "maxJobs", ")", "\n", "for", "jobs", ":=", "0", ";", "jobs", "<", "maxJobs", ";", "jobs", "++", "{", "go", "audit", "(", "ctx", ",", "secStore", ",", "validator", ",", "pending", ",", "checked", ",", "done", ")", "\n", "}", "\n\n", "go", "func", "(", ")", "{", "for", "_", ",", "secret", ":=", "range", "secrets", "{", "pending", "<-", "secret", "\n", "}", "\n", "close", "(", "pending", ")", "\n", "}", "(", ")", "\n", "go", "func", "(", ")", "{", "for", "i", ":=", "0", ";", "i", "<", "maxJobs", ";", "i", "++", "{", "<-", "done", "\n", "}", "\n", "close", "(", "checked", ")", "\n", "}", "(", ")", "\n\n", "duplicates", ":=", "make", "(", "map", "[", "string", "]", "[", "]", "string", ")", "\n", "messages", ":=", "make", "(", "map", "[", "string", "]", "[", "]", "string", ")", "\n", "errors", ":=", "make", "(", "map", "[", "string", "]", "[", "]", "string", ")", "\n\n", "bar", ":=", "&", "goprogressbar", ".", "ProgressBar", "{", "Total", ":", "int64", "(", "len", "(", "secrets", ")", ")", ",", "Width", ":", "120", ",", "}", "\n", "if", "out", ".", "IsHidden", "(", "ctx", ")", "{", "old", ":=", "goprogressbar", ".", "Stdout", "\n", "goprogressbar", ".", "Stdout", "=", "ioutil", ".", "Discard", "\n", "defer", "func", "(", ")", "{", "goprogressbar", ".", "Stdout", "=", "old", "\n", "}", "(", ")", "\n", "}", "\n\n", "i", ":=", "0", "\n", "for", "secret", ":=", "range", "checked", "{", "if", "secret", ".", "err", "!=", "nil", "{", "errors", "[", "secret", ".", "err", ".", "Error", "(", ")", "]", "=", "append", "(", "errors", "[", "secret", ".", "err", ".", "Error", "(", ")", "]", ",", "secret", ".", "name", ")", "\n", "}", "else", "{", "duplicates", "[", "secret", ".", "content", "]", "=", "append", "(", "duplicates", "[", "secret", ".", "content", "]", ",", "secret", ".", "name", ")", "\n", "}", "\n", "if", "secret", ".", "message", "!=", "\"", "\"", "{", "messages", "[", "secret", ".", "message", "]", "=", "append", "(", "messages", "[", "secret", ".", "message", "]", ",", "secret", ".", "name", ")", "\n", "}", "\n\n", "i", "++", "\n", "bar", ".", "Current", "=", "int64", "(", "i", ")", "\n", "bar", ".", "Text", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "bar", ".", "Current", ",", "bar", ".", "Total", ")", "\n", "bar", ".", "LazyPrint", "(", ")", "\n\n", "if", "i", "==", "len", "(", "secrets", ")", "{", "break", "\n", "}", "\n", "}", "\n", "fmt", ".", "Fprintln", "(", "goprogressbar", ".", "Stdout", ")", "// Print empty line after the progressbar.", "\n\n", "return", "auditPrintResults", "(", "ctx", ",", "duplicates", ",", "messages", ",", "errors", ")", "\n", "}" ]
// Batch runs a password strength audit on multiple secrets
[ "Batch", "runs", "a", "password", "strength", "audit", "on", "multiple", "secrets" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/audit/audit.go#L39-L108
train
gopasspw/gopass
pkg/audit/audit.go
Single
func Single(ctx context.Context, password string) { validator := crunchy.NewValidator() if err := validator.Check(password); err != nil { out.Cyan(ctx, fmt.Sprintf("Warning: %s", err)) } }
go
func Single(ctx context.Context, password string) { validator := crunchy.NewValidator() if err := validator.Check(password); err != nil { out.Cyan(ctx, fmt.Sprintf("Warning: %s", err)) } }
[ "func", "Single", "(", "ctx", "context", ".", "Context", ",", "password", "string", ")", "{", "validator", ":=", "crunchy", ".", "NewValidator", "(", ")", "\n", "if", "err", ":=", "validator", ".", "Check", "(", "password", ")", ";", "err", "!=", "nil", "{", "out", ".", "Cyan", "(", "ctx", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "err", ")", ")", "\n", "}", "\n", "}" ]
// Single runs a password strength audit on a single password
[ "Single", "runs", "a", "password", "strength", "audit", "on", "a", "single", "password" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/audit/audit.go#L155-L160
train
gopasspw/gopass
pkg/store/vault/secret.go
Bytes
func (s *Secret) Bytes() ([]byte, error) { if s.d == nil { return []byte{}, nil } buf := &bytes.Buffer{} if pw, found := s.d[passwordKey]; found { if sv, ok := pw.(string); ok { _, _ = buf.WriteString(sv) } } _, _ = buf.WriteString("\n") keys := make([]string, 0, len(s.d)) for k := range s.d { keys = append(keys, k) } sort.Strings(keys) for _, k := range keys { v := s.d[k] if k == passwordKey { continue } _, _ = buf.WriteString(k) _, _ = buf.WriteString(": ") if sv, ok := v.(string); ok { _, _ = buf.WriteString(sv) } _, _ = buf.WriteString("\n") } return buf.Bytes(), nil }
go
func (s *Secret) Bytes() ([]byte, error) { if s.d == nil { return []byte{}, nil } buf := &bytes.Buffer{} if pw, found := s.d[passwordKey]; found { if sv, ok := pw.(string); ok { _, _ = buf.WriteString(sv) } } _, _ = buf.WriteString("\n") keys := make([]string, 0, len(s.d)) for k := range s.d { keys = append(keys, k) } sort.Strings(keys) for _, k := range keys { v := s.d[k] if k == passwordKey { continue } _, _ = buf.WriteString(k) _, _ = buf.WriteString(": ") if sv, ok := v.(string); ok { _, _ = buf.WriteString(sv) } _, _ = buf.WriteString("\n") } return buf.Bytes(), nil }
[ "func", "(", "s", "*", "Secret", ")", "Bytes", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "if", "s", ".", "d", "==", "nil", "{", "return", "[", "]", "byte", "{", "}", ",", "nil", "\n", "}", "\n\n", "buf", ":=", "&", "bytes", ".", "Buffer", "{", "}", "\n", "if", "pw", ",", "found", ":=", "s", ".", "d", "[", "passwordKey", "]", ";", "found", "{", "if", "sv", ",", "ok", ":=", "pw", ".", "(", "string", ")", ";", "ok", "{", "_", ",", "_", "=", "buf", ".", "WriteString", "(", "sv", ")", "\n", "}", "\n", "}", "\n", "_", ",", "_", "=", "buf", ".", "WriteString", "(", "\"", "\\n", "\"", ")", "\n", "keys", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "s", ".", "d", ")", ")", "\n", "for", "k", ":=", "range", "s", ".", "d", "{", "keys", "=", "append", "(", "keys", ",", "k", ")", "\n", "}", "\n", "sort", ".", "Strings", "(", "keys", ")", "\n", "for", "_", ",", "k", ":=", "range", "keys", "{", "v", ":=", "s", ".", "d", "[", "k", "]", "\n", "if", "k", "==", "passwordKey", "{", "continue", "\n", "}", "\n", "_", ",", "_", "=", "buf", ".", "WriteString", "(", "k", ")", "\n", "_", ",", "_", "=", "buf", ".", "WriteString", "(", "\"", "\"", ")", "\n", "if", "sv", ",", "ok", ":=", "v", ".", "(", "string", ")", ";", "ok", "{", "_", ",", "_", "=", "buf", ".", "WriteString", "(", "sv", ")", "\n", "}", "\n", "_", ",", "_", "=", "buf", ".", "WriteString", "(", "\"", "\\n", "\"", ")", "\n", "}", "\n", "return", "buf", ".", "Bytes", "(", ")", ",", "nil", "\n", "}" ]
// Bytes returns a list serialized copy of this secret
[ "Bytes", "returns", "a", "list", "serialized", "copy", "of", "this", "secret" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/vault/secret.go#L23-L53
train
gopasspw/gopass
pkg/store/vault/secret.go
Data
func (s *Secret) Data() map[string]interface{} { if s.d == nil { s.d = make(map[string]interface{}) } return s.d }
go
func (s *Secret) Data() map[string]interface{} { if s.d == nil { s.d = make(map[string]interface{}) } return s.d }
[ "func", "(", "s", "*", "Secret", ")", "Data", "(", ")", "map", "[", "string", "]", "interface", "{", "}", "{", "if", "s", ".", "d", "==", "nil", "{", "s", ".", "d", "=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "}", "\n", "return", "s", ".", "d", "\n", "}" ]
// Data returns the data map. Will never be nil
[ "Data", "returns", "the", "data", "map", ".", "Will", "never", "be", "nil" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/vault/secret.go#L56-L61
train
gopasspw/gopass
pkg/store/vault/secret.go
DeleteKey
func (s *Secret) DeleteKey(key string) error { if s.d == nil { return nil } delete(s.d, key) return nil }
go
func (s *Secret) DeleteKey(key string) error { if s.d == nil { return nil } delete(s.d, key) return nil }
[ "func", "(", "s", "*", "Secret", ")", "DeleteKey", "(", "key", "string", ")", "error", "{", "if", "s", ".", "d", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "delete", "(", "s", ".", "d", ",", "key", ")", "\n", "return", "nil", "\n", "}" ]
// DeleteKey removes a single key
[ "DeleteKey", "removes", "a", "single", "key" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/vault/secret.go#L64-L70
train
gopasspw/gopass
pkg/store/vault/secret.go
Equal
func (s *Secret) Equal(other store.Secret) bool { b1, err := s.Bytes() if err != nil { return false } b2, err := other.Bytes() if err != nil { return false } return string(b1) == string(b2) }
go
func (s *Secret) Equal(other store.Secret) bool { b1, err := s.Bytes() if err != nil { return false } b2, err := other.Bytes() if err != nil { return false } return string(b1) == string(b2) }
[ "func", "(", "s", "*", "Secret", ")", "Equal", "(", "other", "store", ".", "Secret", ")", "bool", "{", "b1", ",", "err", ":=", "s", ".", "Bytes", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", "\n", "}", "\n", "b2", ",", "err", ":=", "other", ".", "Bytes", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", "\n", "}", "\n", "return", "string", "(", "b1", ")", "==", "string", "(", "b2", ")", "\n", "}" ]
// Equal returns true if two secrets match
[ "Equal", "returns", "true", "if", "two", "secrets", "match" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/vault/secret.go#L73-L83
train
gopasspw/gopass
pkg/store/vault/secret.go
Password
func (s *Secret) Password() string { v := s.d[passwordKey] if sv, ok := v.(string); ok { return sv } return "" }
go
func (s *Secret) Password() string { v := s.d[passwordKey] if sv, ok := v.(string); ok { return sv } return "" }
[ "func", "(", "s", "*", "Secret", ")", "Password", "(", ")", "string", "{", "v", ":=", "s", ".", "d", "[", "passwordKey", "]", "\n", "if", "sv", ",", "ok", ":=", "v", ".", "(", "string", ")", ";", "ok", "{", "return", "sv", "\n", "}", "\n", "return", "\"", "\"", "\n", "}" ]
// Password returns the password
[ "Password", "returns", "the", "password" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/vault/secret.go#L86-L92
train
gopasspw/gopass
pkg/store/vault/secret.go
SetValue
func (s *Secret) SetValue(key string, value string) error { s.d[key] = value return nil }
go
func (s *Secret) SetValue(key string, value string) error { s.d[key] = value return nil }
[ "func", "(", "s", "*", "Secret", ")", "SetValue", "(", "key", "string", ",", "value", "string", ")", "error", "{", "s", ".", "d", "[", "key", "]", "=", "value", "\n", "return", "nil", "\n", "}" ]
// SetValue sets a single key
[ "SetValue", "sets", "a", "single", "key" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/vault/secret.go#L105-L108
train
gopasspw/gopass
pkg/store/vault/secret.go
Value
func (s *Secret) Value(key string) (string, error) { v := s.d[key] if sv, ok := v.(string); ok { return sv, nil } return "", nil }
go
func (s *Secret) Value(key string) (string, error) { v := s.d[key] if sv, ok := v.(string); ok { return sv, nil } return "", nil }
[ "func", "(", "s", "*", "Secret", ")", "Value", "(", "key", "string", ")", "(", "string", ",", "error", ")", "{", "v", ":=", "s", ".", "d", "[", "key", "]", "\n", "if", "sv", ",", "ok", ":=", "v", ".", "(", "string", ")", ";", "ok", "{", "return", "sv", ",", "nil", "\n", "}", "\n", "return", "\"", "\"", ",", "nil", "\n", "}" ]
// Value returns a single value
[ "Value", "returns", "a", "single", "value" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/vault/secret.go#L137-L143
train
gopasspw/gopass
pkg/store/sub/init.go
Initialized
func (s *Store) Initialized(ctx context.Context) bool { if s == nil || s.storage == nil { return false } return s.storage.Exists(ctx, s.idFile(ctx, "")) }
go
func (s *Store) Initialized(ctx context.Context) bool { if s == nil || s.storage == nil { return false } return s.storage.Exists(ctx, s.idFile(ctx, "")) }
[ "func", "(", "s", "*", "Store", ")", "Initialized", "(", "ctx", "context", ".", "Context", ")", "bool", "{", "if", "s", "==", "nil", "||", "s", ".", "storage", "==", "nil", "{", "return", "false", "\n", "}", "\n", "return", "s", ".", "storage", ".", "Exists", "(", "ctx", ",", "s", ".", "idFile", "(", "ctx", ",", "\"", "\"", ")", ")", "\n", "}" ]
// Initialized returns true if the store is properly initialized
[ "Initialized", "returns", "true", "if", "the", "store", "is", "properly", "initialized" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/init.go#L13-L18
train
gopasspw/gopass
pkg/store/root/list.go
List
func (r *Store) List(ctx context.Context, maxDepth int) ([]string, error) { t, err := r.Tree(ctx) if err != nil { return []string{}, err } return t.List(maxDepth), nil }
go
func (r *Store) List(ctx context.Context, maxDepth int) ([]string, error) { t, err := r.Tree(ctx) if err != nil { return []string{}, err } return t.List(maxDepth), nil }
[ "func", "(", "r", "*", "Store", ")", "List", "(", "ctx", "context", ".", "Context", ",", "maxDepth", "int", ")", "(", "[", "]", "string", ",", "error", ")", "{", "t", ",", "err", ":=", "r", ".", "Tree", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "]", "string", "{", "}", ",", "err", "\n", "}", "\n", "return", "t", ".", "List", "(", "maxDepth", ")", ",", "nil", "\n", "}" ]
// List will return a flattened list of all tree entries
[ "List", "will", "return", "a", "flattened", "list", "of", "all", "tree", "entries" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/list.go#L17-L23
train
gopasspw/gopass
pkg/store/root/list.go
Tree
func (r *Store) Tree(ctx context.Context) (tree.Tree, error) { root := simple.New("gopass") addFileFunc := func(in ...string) { for _, f := range in { var ct string switch { case strings.HasSuffix(f, ".b64"): ct = "application/octet-stream" case strings.HasSuffix(f, ".yml"): ct = "text/yaml" case strings.HasSuffix(f, ".yaml"): ct = "text/yaml" default: ct = "text/plain" } if err := root.AddFile(f, ct); err != nil { out.Error(ctx, "Failed to add file %s to tree: %s", f, err) continue } } } addTplFunc := func(in ...string) { for _, f := range in { if err := root.AddTemplate(f); err != nil { out.Error(ctx, "Failed to add template %s to tree: %s", f, err) continue } } } sf, err := r.store.List(ctx, "") if err != nil { return nil, err } addFileFunc(sf...) addTplFunc(r.store.ListTemplates(ctx, "")...) 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) } sf, err := substore.List(ctx, "") if err != nil { return nil, errors.Errorf("failed to add file: %s", err) } addFileFunc(sf...) addTplFunc(substore.ListTemplates(ctx, alias)...) } return root, nil }
go
func (r *Store) Tree(ctx context.Context) (tree.Tree, error) { root := simple.New("gopass") addFileFunc := func(in ...string) { for _, f := range in { var ct string switch { case strings.HasSuffix(f, ".b64"): ct = "application/octet-stream" case strings.HasSuffix(f, ".yml"): ct = "text/yaml" case strings.HasSuffix(f, ".yaml"): ct = "text/yaml" default: ct = "text/plain" } if err := root.AddFile(f, ct); err != nil { out.Error(ctx, "Failed to add file %s to tree: %s", f, err) continue } } } addTplFunc := func(in ...string) { for _, f := range in { if err := root.AddTemplate(f); err != nil { out.Error(ctx, "Failed to add template %s to tree: %s", f, err) continue } } } sf, err := r.store.List(ctx, "") if err != nil { return nil, err } addFileFunc(sf...) addTplFunc(r.store.ListTemplates(ctx, "")...) 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) } sf, err := substore.List(ctx, "") if err != nil { return nil, errors.Errorf("failed to add file: %s", err) } addFileFunc(sf...) addTplFunc(substore.ListTemplates(ctx, alias)...) } return root, nil }
[ "func", "(", "r", "*", "Store", ")", "Tree", "(", "ctx", "context", ".", "Context", ")", "(", "tree", ".", "Tree", ",", "error", ")", "{", "root", ":=", "simple", ".", "New", "(", "\"", "\"", ")", "\n", "addFileFunc", ":=", "func", "(", "in", "...", "string", ")", "{", "for", "_", ",", "f", ":=", "range", "in", "{", "var", "ct", "string", "\n", "switch", "{", "case", "strings", ".", "HasSuffix", "(", "f", ",", "\"", "\"", ")", ":", "ct", "=", "\"", "\"", "\n", "case", "strings", ".", "HasSuffix", "(", "f", ",", "\"", "\"", ")", ":", "ct", "=", "\"", "\"", "\n", "case", "strings", ".", "HasSuffix", "(", "f", ",", "\"", "\"", ")", ":", "ct", "=", "\"", "\"", "\n", "default", ":", "ct", "=", "\"", "\"", "\n", "}", "\n", "if", "err", ":=", "root", ".", "AddFile", "(", "f", ",", "ct", ")", ";", "err", "!=", "nil", "{", "out", ".", "Error", "(", "ctx", ",", "\"", "\"", ",", "f", ",", "err", ")", "\n", "continue", "\n", "}", "\n", "}", "\n", "}", "\n", "addTplFunc", ":=", "func", "(", "in", "...", "string", ")", "{", "for", "_", ",", "f", ":=", "range", "in", "{", "if", "err", ":=", "root", ".", "AddTemplate", "(", "f", ")", ";", "err", "!=", "nil", "{", "out", ".", "Error", "(", "ctx", ",", "\"", "\"", ",", "f", ",", "err", ")", "\n", "continue", "\n", "}", "\n", "}", "\n", "}", "\n\n", "sf", ",", "err", ":=", "r", ".", "store", ".", "List", "(", "ctx", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "addFileFunc", "(", "sf", "...", ")", "\n", "addTplFunc", "(", "r", ".", "store", ".", "ListTemplates", "(", "ctx", ",", "\"", "\"", ")", "...", ")", "\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", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "sf", ",", "err", ":=", "substore", ".", "List", "(", "ctx", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "addFileFunc", "(", "sf", "...", ")", "\n", "addTplFunc", "(", "substore", ".", "ListTemplates", "(", "ctx", ",", "alias", ")", "...", ")", "\n", "}", "\n\n", "return", "root", ",", "nil", "\n", "}" ]
// Tree returns the tree representation of the entries
[ "Tree", "returns", "the", "tree", "representation", "of", "the", "entries" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/list.go#L26-L82
train
gopasspw/gopass
pkg/action/hibp.go
HIBP
func (s *Action) HIBP(ctx context.Context, c *cli.Context) error { force := c.Bool("force") api := c.Bool("api") if api { return s.hibpAPI(ctx, force) } out.Yellow(ctx, "WARNING: Using the HIBPv2 dumps is very expensive. If you can condone leaking a few bits of entropy per secret you should probably use the '--api' flag.") dumps := c.StringSlice("dumps") return s.hibpDump(ctx, force, dumps) }
go
func (s *Action) HIBP(ctx context.Context, c *cli.Context) error { force := c.Bool("force") api := c.Bool("api") if api { return s.hibpAPI(ctx, force) } out.Yellow(ctx, "WARNING: Using the HIBPv2 dumps is very expensive. If you can condone leaking a few bits of entropy per secret you should probably use the '--api' flag.") dumps := c.StringSlice("dumps") return s.hibpDump(ctx, force, dumps) }
[ "func", "(", "s", "*", "Action", ")", "HIBP", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "force", ":=", "c", ".", "Bool", "(", "\"", "\"", ")", "\n", "api", ":=", "c", ".", "Bool", "(", "\"", "\"", ")", "\n\n", "if", "api", "{", "return", "s", ".", "hibpAPI", "(", "ctx", ",", "force", ")", "\n", "}", "\n\n", "out", ".", "Yellow", "(", "ctx", ",", "\"", "\"", ")", "\n\n", "dumps", ":=", "c", ".", "StringSlice", "(", "\"", "\"", ")", "\n", "return", "s", ".", "hibpDump", "(", "ctx", ",", "force", ",", "dumps", ")", "\n", "}" ]
// HIBP compares all entries from the store against the provided SHA1 sum dumps
[ "HIBP", "compares", "all", "entries", "from", "the", "store", "against", "the", "provided", "SHA1", "sum", "dumps" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/hibp.go#L22-L34
train
gopasspw/gopass
pkg/backend/crypto/xc/utils.go
RecipientIDs
func (x *XC) RecipientIDs(ctx context.Context, ciphertext []byte) ([]string, error) { msg := &xcpb.Message{} if err := proto.Unmarshal(ciphertext, msg); err != nil { return nil, err } ids := make([]string, 0, len(msg.Header.Recipients)) for k := range msg.Header.Recipients { ids = append(ids, k) } sort.Strings(ids) return ids, nil }
go
func (x *XC) RecipientIDs(ctx context.Context, ciphertext []byte) ([]string, error) { msg := &xcpb.Message{} if err := proto.Unmarshal(ciphertext, msg); err != nil { return nil, err } ids := make([]string, 0, len(msg.Header.Recipients)) for k := range msg.Header.Recipients { ids = append(ids, k) } sort.Strings(ids) return ids, nil }
[ "func", "(", "x", "*", "XC", ")", "RecipientIDs", "(", "ctx", "context", ".", "Context", ",", "ciphertext", "[", "]", "byte", ")", "(", "[", "]", "string", ",", "error", ")", "{", "msg", ":=", "&", "xcpb", ".", "Message", "{", "}", "\n", "if", "err", ":=", "proto", ".", "Unmarshal", "(", "ciphertext", ",", "msg", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "ids", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "msg", ".", "Header", ".", "Recipients", ")", ")", "\n", "for", "k", ":=", "range", "msg", ".", "Header", ".", "Recipients", "{", "ids", "=", "append", "(", "ids", ",", "k", ")", "\n", "}", "\n", "sort", ".", "Strings", "(", "ids", ")", "\n", "return", "ids", ",", "nil", "\n", "}" ]
// RecipientIDs reads the header of the given file and extracts the // recipients IDs
[ "RecipientIDs", "reads", "the", "header", "of", "the", "given", "file", "and", "extracts", "the", "recipients", "IDs" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/utils.go#L18-L30
train
gopasspw/gopass
pkg/backend/crypto/xc/utils.go
ReadNamesFromKey
func (x *XC) ReadNamesFromKey(ctx context.Context, buf []byte) ([]string, error) { pk := &xcpb.PublicKey{} if err := proto.Unmarshal(buf, pk); err != nil { return nil, errors.Wrapf(err, "failed to unmarshal public key: %s", err) } return []string{pk.Identity.Name}, nil }
go
func (x *XC) ReadNamesFromKey(ctx context.Context, buf []byte) ([]string, error) { pk := &xcpb.PublicKey{} if err := proto.Unmarshal(buf, pk); err != nil { return nil, errors.Wrapf(err, "failed to unmarshal public key: %s", err) } return []string{pk.Identity.Name}, nil }
[ "func", "(", "x", "*", "XC", ")", "ReadNamesFromKey", "(", "ctx", "context", ".", "Context", ",", "buf", "[", "]", "byte", ")", "(", "[", "]", "string", ",", "error", ")", "{", "pk", ":=", "&", "xcpb", ".", "PublicKey", "{", "}", "\n", "if", "err", ":=", "proto", ".", "Unmarshal", "(", "buf", ",", "pk", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "return", "[", "]", "string", "{", "pk", ".", "Identity", ".", "Name", "}", ",", "nil", "\n", "}" ]
// ReadNamesFromKey unmarshals the given public key and returns the identities name
[ "ReadNamesFromKey", "unmarshals", "the", "given", "public", "key", "and", "returns", "the", "identities", "name" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/utils.go#L33-L40
train
gopasspw/gopass
pkg/backend/crypto/xc/utils.go
ListPublicKeyIDs
func (x *XC) ListPublicKeyIDs(ctx context.Context) ([]string, error) { return x.pubring.KeyIDs(), nil }
go
func (x *XC) ListPublicKeyIDs(ctx context.Context) ([]string, error) { return x.pubring.KeyIDs(), nil }
[ "func", "(", "x", "*", "XC", ")", "ListPublicKeyIDs", "(", "ctx", "context", ".", "Context", ")", "(", "[", "]", "string", ",", "error", ")", "{", "return", "x", ".", "pubring", ".", "KeyIDs", "(", ")", ",", "nil", "\n", "}" ]
// ListPublicKeyIDs lists all public key IDs
[ "ListPublicKeyIDs", "lists", "all", "public", "key", "IDs" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/utils.go#L43-L45
train
gopasspw/gopass
pkg/backend/crypto/xc/utils.go
ListPrivateKeyIDs
func (x *XC) ListPrivateKeyIDs(ctx context.Context) ([]string, error) { return x.secring.KeyIDs(), nil }
go
func (x *XC) ListPrivateKeyIDs(ctx context.Context) ([]string, error) { return x.secring.KeyIDs(), nil }
[ "func", "(", "x", "*", "XC", ")", "ListPrivateKeyIDs", "(", "ctx", "context", ".", "Context", ")", "(", "[", "]", "string", ",", "error", ")", "{", "return", "x", ".", "secring", ".", "KeyIDs", "(", ")", ",", "nil", "\n", "}" ]
// ListPrivateKeyIDs lists all private key IDs
[ "ListPrivateKeyIDs", "lists", "all", "private", "key", "IDs" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/utils.go#L48-L50
train
gopasspw/gopass
pkg/backend/crypto/xc/utils.go
FindPublicKeys
func (x *XC) FindPublicKeys(ctx context.Context, search ...string) ([]string, error) { ids := make([]string, 0, 1) candidates, _ := x.ListPublicKeyIDs(ctx) for _, needle := range search { for _, fp := range candidates { if strings.HasSuffix(fp, needle) { ids = append(ids, fp) } } } sort.Strings(ids) return ids, nil }
go
func (x *XC) FindPublicKeys(ctx context.Context, search ...string) ([]string, error) { ids := make([]string, 0, 1) candidates, _ := x.ListPublicKeyIDs(ctx) for _, needle := range search { for _, fp := range candidates { if strings.HasSuffix(fp, needle) { ids = append(ids, fp) } } } sort.Strings(ids) return ids, nil }
[ "func", "(", "x", "*", "XC", ")", "FindPublicKeys", "(", "ctx", "context", ".", "Context", ",", "search", "...", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "ids", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "1", ")", "\n", "candidates", ",", "_", ":=", "x", ".", "ListPublicKeyIDs", "(", "ctx", ")", "\n", "for", "_", ",", "needle", ":=", "range", "search", "{", "for", "_", ",", "fp", ":=", "range", "candidates", "{", "if", "strings", ".", "HasSuffix", "(", "fp", ",", "needle", ")", "{", "ids", "=", "append", "(", "ids", ",", "fp", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "sort", ".", "Strings", "(", "ids", ")", "\n", "return", "ids", ",", "nil", "\n", "}" ]
// FindPublicKeys finds all matching public keys
[ "FindPublicKeys", "finds", "all", "matching", "public", "keys" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/utils.go#L53-L65
train
gopasspw/gopass
pkg/backend/crypto/xc/utils.go
FormatKey
func (x *XC) FormatKey(ctx context.Context, id string) string { if key := x.pubring.Get(id); key != nil { return id + " - " + key.Identity.ID() } if key := x.secring.Get(id); key != nil { return id + " - " + key.PublicKey.Identity.ID() } return id }
go
func (x *XC) FormatKey(ctx context.Context, id string) string { if key := x.pubring.Get(id); key != nil { return id + " - " + key.Identity.ID() } if key := x.secring.Get(id); key != nil { return id + " - " + key.PublicKey.Identity.ID() } return id }
[ "func", "(", "x", "*", "XC", ")", "FormatKey", "(", "ctx", "context", ".", "Context", ",", "id", "string", ")", "string", "{", "if", "key", ":=", "x", ".", "pubring", ".", "Get", "(", "id", ")", ";", "key", "!=", "nil", "{", "return", "id", "+", "\"", "\"", "+", "key", ".", "Identity", ".", "ID", "(", ")", "\n", "}", "\n", "if", "key", ":=", "x", ".", "secring", ".", "Get", "(", "id", ")", ";", "key", "!=", "nil", "{", "return", "id", "+", "\"", "\"", "+", "key", ".", "PublicKey", ".", "Identity", ".", "ID", "(", ")", "\n", "}", "\n", "return", "id", "\n", "}" ]
// FormatKey formats a key
[ "FormatKey", "formats", "a", "key" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/utils.go#L83-L91
train
gopasspw/gopass
pkg/backend/crypto/xc/utils.go
NameFromKey
func (x *XC) NameFromKey(ctx context.Context, id string) string { if key := x.pubring.Get(id); key != nil { return key.Identity.Name } if key := x.secring.Get(id); key != nil { return key.PublicKey.Identity.Name } return id }
go
func (x *XC) NameFromKey(ctx context.Context, id string) string { if key := x.pubring.Get(id); key != nil { return key.Identity.Name } if key := x.secring.Get(id); key != nil { return key.PublicKey.Identity.Name } return id }
[ "func", "(", "x", "*", "XC", ")", "NameFromKey", "(", "ctx", "context", ".", "Context", ",", "id", "string", ")", "string", "{", "if", "key", ":=", "x", ".", "pubring", ".", "Get", "(", "id", ")", ";", "key", "!=", "nil", "{", "return", "key", ".", "Identity", ".", "Name", "\n", "}", "\n", "if", "key", ":=", "x", ".", "secring", ".", "Get", "(", "id", ")", ";", "key", "!=", "nil", "{", "return", "key", ".", "PublicKey", ".", "Identity", ".", "Name", "\n", "}", "\n", "return", "id", "\n", "}" ]
// NameFromKey extracts the name from a key
[ "NameFromKey", "extracts", "the", "name", "from", "a", "key" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/utils.go#L94-L102
train
gopasspw/gopass
pkg/backend/crypto/xc/utils.go
EmailFromKey
func (x *XC) EmailFromKey(ctx context.Context, id string) string { if key := x.pubring.Get(id); key != nil { return key.Identity.Email } if key := x.secring.Get(id); key != nil { return key.PublicKey.Identity.Email } return id }
go
func (x *XC) EmailFromKey(ctx context.Context, id string) string { if key := x.pubring.Get(id); key != nil { return key.Identity.Email } if key := x.secring.Get(id); key != nil { return key.PublicKey.Identity.Email } return id }
[ "func", "(", "x", "*", "XC", ")", "EmailFromKey", "(", "ctx", "context", ".", "Context", ",", "id", "string", ")", "string", "{", "if", "key", ":=", "x", ".", "pubring", ".", "Get", "(", "id", ")", ";", "key", "!=", "nil", "{", "return", "key", ".", "Identity", ".", "Email", "\n", "}", "\n", "if", "key", ":=", "x", ".", "secring", ".", "Get", "(", "id", ")", ";", "key", "!=", "nil", "{", "return", "key", ".", "PublicKey", ".", "Identity", ".", "Email", "\n", "}", "\n", "return", "id", "\n", "}" ]
// EmailFromKey extracts the email from a key
[ "EmailFromKey", "extracts", "the", "email", "from", "a", "key" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/utils.go#L105-L113
train
gopasspw/gopass
pkg/backend/crypto/xc/utils.go
CreatePrivateKeyBatch
func (x *XC) CreatePrivateKeyBatch(ctx context.Context, name, email, passphrase string) error { k, err := keyring.GenerateKeypair(passphrase) if err != nil { return errors.Wrapf(err, "failed to generate keypair: %s", err) } k.Identity.Name = name k.Identity.Email = email if err := x.secring.Set(k); err != nil { return errors.Wrapf(err, "failed to set %v to secring: %s", k, err) } return x.secring.Save() }
go
func (x *XC) CreatePrivateKeyBatch(ctx context.Context, name, email, passphrase string) error { k, err := keyring.GenerateKeypair(passphrase) if err != nil { return errors.Wrapf(err, "failed to generate keypair: %s", err) } k.Identity.Name = name k.Identity.Email = email if err := x.secring.Set(k); err != nil { return errors.Wrapf(err, "failed to set %v to secring: %s", k, err) } return x.secring.Save() }
[ "func", "(", "x", "*", "XC", ")", "CreatePrivateKeyBatch", "(", "ctx", "context", ".", "Context", ",", "name", ",", "email", ",", "passphrase", "string", ")", "error", "{", "k", ",", "err", ":=", "keyring", ".", "GenerateKeypair", "(", "passphrase", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "k", ".", "Identity", ".", "Name", "=", "name", "\n", "k", ".", "Identity", ".", "Email", "=", "email", "\n", "if", "err", ":=", "x", ".", "secring", ".", "Set", "(", "k", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "k", ",", "err", ")", "\n", "}", "\n", "return", "x", ".", "secring", ".", "Save", "(", ")", "\n", "}" ]
// CreatePrivateKeyBatch creates a new keypair
[ "CreatePrivateKeyBatch", "creates", "a", "new", "keypair" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/utils.go#L121-L132
train
gopasspw/gopass
pkg/backend/crypto/gpg/context.go
WithAlwaysTrust
func WithAlwaysTrust(ctx context.Context, at bool) context.Context { return context.WithValue(ctx, ctxKeyAlwaysTrust, at) }
go
func WithAlwaysTrust(ctx context.Context, at bool) context.Context { return context.WithValue(ctx, ctxKeyAlwaysTrust, at) }
[ "func", "WithAlwaysTrust", "(", "ctx", "context", ".", "Context", ",", "at", "bool", ")", "context", ".", "Context", "{", "return", "context", ".", "WithValue", "(", "ctx", ",", "ctxKeyAlwaysTrust", ",", "at", ")", "\n", "}" ]
// WithAlwaysTrust will return a context with the flag for always trust set
[ "WithAlwaysTrust", "will", "return", "a", "context", "with", "the", "flag", "for", "always", "trust", "set" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/context.go#L12-L14
train
gopasspw/gopass
pkg/backend/crypto/xc/keyring/pubring.go
NewPubring
func NewPubring(sec *Secring) *Pubring { return &Pubring{ data: &xcpb.Pubring{ PublicKeys: make([]*xcpb.PublicKey, 0, 10), }, secring: sec, } }
go
func NewPubring(sec *Secring) *Pubring { return &Pubring{ data: &xcpb.Pubring{ PublicKeys: make([]*xcpb.PublicKey, 0, 10), }, secring: sec, } }
[ "func", "NewPubring", "(", "sec", "*", "Secring", ")", "*", "Pubring", "{", "return", "&", "Pubring", "{", "data", ":", "&", "xcpb", ".", "Pubring", "{", "PublicKeys", ":", "make", "(", "[", "]", "*", "xcpb", ".", "PublicKey", ",", "0", ",", "10", ")", ",", "}", ",", "secring", ":", "sec", ",", "}", "\n", "}" ]
// NewPubring initializes a new public key ring
[ "NewPubring", "initializes", "a", "new", "public", "key", "ring" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/keyring/pubring.go#L27-L34
train
gopasspw/gopass
pkg/backend/crypto/xc/keyring/pubring.go
LoadPubring
func LoadPubring(file string, sec *Secring) (*Pubring, error) { pr := NewPubring(sec) pr.File = file buf, err := ioutil.ReadFile(file) if os.IsNotExist(err) { return pr, nil } if err != nil { return nil, err } if err := proto.Unmarshal(buf, pr.data); err != nil { return nil, err } return pr, nil }
go
func LoadPubring(file string, sec *Secring) (*Pubring, error) { pr := NewPubring(sec) pr.File = file buf, err := ioutil.ReadFile(file) if os.IsNotExist(err) { return pr, nil } if err != nil { return nil, err } if err := proto.Unmarshal(buf, pr.data); err != nil { return nil, err } return pr, nil }
[ "func", "LoadPubring", "(", "file", "string", ",", "sec", "*", "Secring", ")", "(", "*", "Pubring", ",", "error", ")", "{", "pr", ":=", "NewPubring", "(", "sec", ")", "\n", "pr", ".", "File", "=", "file", "\n\n", "buf", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "file", ")", "\n", "if", "os", ".", "IsNotExist", "(", "err", ")", "{", "return", "pr", ",", "nil", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "err", ":=", "proto", ".", "Unmarshal", "(", "buf", ",", "pr", ".", "data", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "pr", ",", "nil", "\n", "}" ]
// LoadPubring loads an existing keyring from disk. If the file is not // found an empty keyring is returned.
[ "LoadPubring", "loads", "an", "existing", "keyring", "from", "disk", ".", "If", "the", "file", "is", "not", "found", "an", "empty", "keyring", "is", "returned", "." ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/keyring/pubring.go#L38-L55
train
gopasspw/gopass
pkg/backend/crypto/xc/keyring/pubring.go
Contains
func (p *Pubring) Contains(fp string) bool { p.Lock() defer p.Unlock() for _, pk := range p.data.PublicKeys { if pk.Fingerprint == fp { return true } } if p.secring == nil { return false } return p.secring.Contains(fp) }
go
func (p *Pubring) Contains(fp string) bool { p.Lock() defer p.Unlock() for _, pk := range p.data.PublicKeys { if pk.Fingerprint == fp { return true } } if p.secring == nil { return false } return p.secring.Contains(fp) }
[ "func", "(", "p", "*", "Pubring", ")", "Contains", "(", "fp", "string", ")", "bool", "{", "p", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "Unlock", "(", ")", "\n\n", "for", "_", ",", "pk", ":=", "range", "p", ".", "data", ".", "PublicKeys", "{", "if", "pk", ".", "Fingerprint", "==", "fp", "{", "return", "true", "\n", "}", "\n", "}", "\n\n", "if", "p", ".", "secring", "==", "nil", "{", "return", "false", "\n", "}", "\n\n", "return", "p", ".", "secring", ".", "Contains", "(", "fp", ")", "\n", "}" ]
// Contains checks if a given key is in the keyring
[ "Contains", "checks", "if", "a", "given", "key", "is", "in", "the", "keyring" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/keyring/pubring.go#L67-L82
train
gopasspw/gopass
pkg/backend/crypto/xc/keyring/pubring.go
KeyIDs
func (p *Pubring) KeyIDs() []string { p.Lock() defer p.Unlock() ids := make([]string, 0, len(p.data.PublicKeys)) for _, pk := range p.data.PublicKeys { ids = append(ids, pk.Fingerprint) } if p.secring != nil { ids = append(ids, p.secring.KeyIDs()...) } sort.Strings(ids) return ids }
go
func (p *Pubring) KeyIDs() []string { p.Lock() defer p.Unlock() ids := make([]string, 0, len(p.data.PublicKeys)) for _, pk := range p.data.PublicKeys { ids = append(ids, pk.Fingerprint) } if p.secring != nil { ids = append(ids, p.secring.KeyIDs()...) } sort.Strings(ids) return ids }
[ "func", "(", "p", "*", "Pubring", ")", "KeyIDs", "(", ")", "[", "]", "string", "{", "p", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "Unlock", "(", ")", "\n\n", "ids", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "p", ".", "data", ".", "PublicKeys", ")", ")", "\n", "for", "_", ",", "pk", ":=", "range", "p", ".", "data", ".", "PublicKeys", "{", "ids", "=", "append", "(", "ids", ",", "pk", ".", "Fingerprint", ")", "\n", "}", "\n", "if", "p", ".", "secring", "!=", "nil", "{", "ids", "=", "append", "(", "ids", ",", "p", ".", "secring", ".", "KeyIDs", "(", ")", "...", ")", "\n", "}", "\n", "sort", ".", "Strings", "(", "ids", ")", "\n", "return", "ids", "\n", "}" ]
// KeyIDs returns a list of all key IDs
[ "KeyIDs", "returns", "a", "list", "of", "all", "key", "IDs" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/keyring/pubring.go#L85-L98
train
gopasspw/gopass
pkg/backend/crypto/xc/keyring/pubring.go
Export
func (p *Pubring) Export(id string) ([]byte, error) { p.Lock() defer p.Unlock() xpk := p.fetch(id) if xpk == nil { if p.secring != nil { return p.secring.Export(id, false) } return nil, fmt.Errorf("key not found") } return proto.Marshal(xpk) }
go
func (p *Pubring) Export(id string) ([]byte, error) { p.Lock() defer p.Unlock() xpk := p.fetch(id) if xpk == nil { if p.secring != nil { return p.secring.Export(id, false) } return nil, fmt.Errorf("key not found") } return proto.Marshal(xpk) }
[ "func", "(", "p", "*", "Pubring", ")", "Export", "(", "id", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "p", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "Unlock", "(", ")", "\n\n", "xpk", ":=", "p", ".", "fetch", "(", "id", ")", "\n", "if", "xpk", "==", "nil", "{", "if", "p", ".", "secring", "!=", "nil", "{", "return", "p", ".", "secring", ".", "Export", "(", "id", ",", "false", ")", "\n", "}", "\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "proto", ".", "Marshal", "(", "xpk", ")", "\n", "}" ]
// Export marshals a single key
[ "Export", "marshals", "a", "single", "key" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/keyring/pubring.go#L101-L114
train
gopasspw/gopass
pkg/backend/crypto/xc/keyring/pubring.go
Import
func (p *Pubring) Import(buf []byte) error { pk := &xcpb.PublicKey{} if err := proto.Unmarshal(buf, pk); err != nil { return err } p.insert(pk) return nil }
go
func (p *Pubring) Import(buf []byte) error { pk := &xcpb.PublicKey{} if err := proto.Unmarshal(buf, pk); err != nil { return err } p.insert(pk) return nil }
[ "func", "(", "p", "*", "Pubring", ")", "Import", "(", "buf", "[", "]", "byte", ")", "error", "{", "pk", ":=", "&", "xcpb", ".", "PublicKey", "{", "}", "\n", "if", "err", ":=", "proto", ".", "Unmarshal", "(", "buf", ",", "pk", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "p", ".", "insert", "(", "pk", ")", "\n", "return", "nil", "\n", "}" ]
// Import unmarshals and inserts and previously exported key
[ "Import", "unmarshals", "and", "inserts", "and", "previously", "exported", "key" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/keyring/pubring.go#L144-L152
train
gopasspw/gopass
pkg/backend/crypto/xc/keyring/pubring.go
Set
func (p *Pubring) Set(pk *PublicKey) error { p.Lock() defer p.Unlock() p.insert(pubKRToPB(pk)) return nil }
go
func (p *Pubring) Set(pk *PublicKey) error { p.Lock() defer p.Unlock() p.insert(pubKRToPB(pk)) return nil }
[ "func", "(", "p", "*", "Pubring", ")", "Set", "(", "pk", "*", "PublicKey", ")", "error", "{", "p", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "Unlock", "(", ")", "\n\n", "p", ".", "insert", "(", "pubKRToPB", "(", "pk", ")", ")", "\n", "return", "nil", "\n", "}" ]
// Set inserts a key, possibly overwriting and existing entry
[ "Set", "inserts", "a", "key", "possibly", "overwriting", "and", "existing", "entry" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/keyring/pubring.go#L155-L161
train
gopasspw/gopass
pkg/backend/crypto/xc/keyring/pubring.go
Remove
func (p *Pubring) Remove(id string) error { p.Lock() defer p.Unlock() match := -1 for i, pk := range p.data.PublicKeys { if pk.Fingerprint == id { match = i break } } if match < 0 || match > len(p.data.PublicKeys) { return fmt.Errorf("not found") } p.data.PublicKeys = append(p.data.PublicKeys[:match], p.data.PublicKeys[match+1:]...) return nil }
go
func (p *Pubring) Remove(id string) error { p.Lock() defer p.Unlock() match := -1 for i, pk := range p.data.PublicKeys { if pk.Fingerprint == id { match = i break } } if match < 0 || match > len(p.data.PublicKeys) { return fmt.Errorf("not found") } p.data.PublicKeys = append(p.data.PublicKeys[:match], p.data.PublicKeys[match+1:]...) return nil }
[ "func", "(", "p", "*", "Pubring", ")", "Remove", "(", "id", "string", ")", "error", "{", "p", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "Unlock", "(", ")", "\n\n", "match", ":=", "-", "1", "\n", "for", "i", ",", "pk", ":=", "range", "p", ".", "data", ".", "PublicKeys", "{", "if", "pk", ".", "Fingerprint", "==", "id", "{", "match", "=", "i", "\n", "break", "\n", "}", "\n", "}", "\n", "if", "match", "<", "0", "||", "match", ">", "len", "(", "p", ".", "data", ".", "PublicKeys", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "p", ".", "data", ".", "PublicKeys", "=", "append", "(", "p", ".", "data", ".", "PublicKeys", "[", ":", "match", "]", ",", "p", ".", "data", ".", "PublicKeys", "[", "match", "+", "1", ":", "]", "...", ")", "\n", "return", "nil", "\n", "}" ]
// Remove deletes a single key
[ "Remove", "deletes", "a", "single", "key" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/keyring/pubring.go#L175-L191
train
gopasspw/gopass
pkg/config/store_config.go
ConfigMap
func (c *StoreConfig) ConfigMap() map[string]string { m := make(map[string]string, 20) o := reflect.ValueOf(c).Elem() for i := 0; i < o.NumField(); i++ { jsonArg := o.Type().Field(i).Tag.Get("yaml") if jsonArg == "" || jsonArg == "-" { continue } f := o.Field(i) var strVal string switch f.Kind() { case reflect.String: strVal = f.String() case reflect.Bool: strVal = fmt.Sprintf("%t", f.Bool()) case reflect.Int: strVal = fmt.Sprintf("%d", f.Int()) case reflect.Ptr: switch bup := f.Interface().(type) { case *backend.URL: if bup == nil { continue } strVal = bup.String() } default: continue } m[jsonArg] = strVal } return m }
go
func (c *StoreConfig) ConfigMap() map[string]string { m := make(map[string]string, 20) o := reflect.ValueOf(c).Elem() for i := 0; i < o.NumField(); i++ { jsonArg := o.Type().Field(i).Tag.Get("yaml") if jsonArg == "" || jsonArg == "-" { continue } f := o.Field(i) var strVal string switch f.Kind() { case reflect.String: strVal = f.String() case reflect.Bool: strVal = fmt.Sprintf("%t", f.Bool()) case reflect.Int: strVal = fmt.Sprintf("%d", f.Int()) case reflect.Ptr: switch bup := f.Interface().(type) { case *backend.URL: if bup == nil { continue } strVal = bup.String() } default: continue } m[jsonArg] = strVal } return m }
[ "func", "(", "c", "*", "StoreConfig", ")", "ConfigMap", "(", ")", "map", "[", "string", "]", "string", "{", "m", ":=", "make", "(", "map", "[", "string", "]", "string", ",", "20", ")", "\n", "o", ":=", "reflect", ".", "ValueOf", "(", "c", ")", ".", "Elem", "(", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "o", ".", "NumField", "(", ")", ";", "i", "++", "{", "jsonArg", ":=", "o", ".", "Type", "(", ")", ".", "Field", "(", "i", ")", ".", "Tag", ".", "Get", "(", "\"", "\"", ")", "\n", "if", "jsonArg", "==", "\"", "\"", "||", "jsonArg", "==", "\"", "\"", "{", "continue", "\n", "}", "\n", "f", ":=", "o", ".", "Field", "(", "i", ")", "\n", "var", "strVal", "string", "\n", "switch", "f", ".", "Kind", "(", ")", "{", "case", "reflect", ".", "String", ":", "strVal", "=", "f", ".", "String", "(", ")", "\n", "case", "reflect", ".", "Bool", ":", "strVal", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "f", ".", "Bool", "(", ")", ")", "\n", "case", "reflect", ".", "Int", ":", "strVal", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "f", ".", "Int", "(", ")", ")", "\n", "case", "reflect", ".", "Ptr", ":", "switch", "bup", ":=", "f", ".", "Interface", "(", ")", ".", "(", "type", ")", "{", "case", "*", "backend", ".", "URL", ":", "if", "bup", "==", "nil", "{", "continue", "\n", "}", "\n", "strVal", "=", "bup", ".", "String", "(", ")", "\n", "}", "\n", "default", ":", "continue", "\n", "}", "\n", "m", "[", "jsonArg", "]", "=", "strVal", "\n", "}", "\n", "return", "m", "\n", "}" ]
// ConfigMap returns a map of stringified config values for easy printing
[ "ConfigMap", "returns", "a", "map", "of", "stringified", "config", "values", "for", "easy", "printing" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/config/store_config.go#L52-L83
train
gopasspw/gopass
pkg/store/root/mount.go
RemoveMount
func (r *Store) RemoveMount(ctx context.Context, alias string) error { if _, found := r.mounts[alias]; !found { return errors.Errorf("%s is not mounted", alias) } if _, found := r.mounts[alias]; !found { out.Yellow(ctx, "%s is not initialized", alias) } delete(r.mounts, alias) delete(r.cfg.Mounts, alias) return nil }
go
func (r *Store) RemoveMount(ctx context.Context, alias string) error { if _, found := r.mounts[alias]; !found { return errors.Errorf("%s is not mounted", alias) } if _, found := r.mounts[alias]; !found { out.Yellow(ctx, "%s is not initialized", alias) } delete(r.mounts, alias) delete(r.cfg.Mounts, alias) return nil }
[ "func", "(", "r", "*", "Store", ")", "RemoveMount", "(", "ctx", "context", ".", "Context", ",", "alias", "string", ")", "error", "{", "if", "_", ",", "found", ":=", "r", ".", "mounts", "[", "alias", "]", ";", "!", "found", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "alias", ")", "\n", "}", "\n", "if", "_", ",", "found", ":=", "r", ".", "mounts", "[", "alias", "]", ";", "!", "found", "{", "out", ".", "Yellow", "(", "ctx", ",", "\"", "\"", ",", "alias", ")", "\n", "}", "\n", "delete", "(", "r", ".", "mounts", ",", "alias", ")", "\n", "delete", "(", "r", ".", "cfg", ".", "Mounts", ",", "alias", ")", "\n", "return", "nil", "\n", "}" ]
// RemoveMount removes and existing mount
[ "RemoveMount", "removes", "and", "existing", "mount" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/mount.go#L128-L138
train
gopasspw/gopass
pkg/store/root/mount.go
Mounts
func (r *Store) Mounts() map[string]string { m := make(map[string]string, len(r.mounts)) for alias, sub := range r.mounts { m[alias] = sub.Path() } return m }
go
func (r *Store) Mounts() map[string]string { m := make(map[string]string, len(r.mounts)) for alias, sub := range r.mounts { m[alias] = sub.Path() } return m }
[ "func", "(", "r", "*", "Store", ")", "Mounts", "(", ")", "map", "[", "string", "]", "string", "{", "m", ":=", "make", "(", "map", "[", "string", "]", "string", ",", "len", "(", "r", ".", "mounts", ")", ")", "\n", "for", "alias", ",", "sub", ":=", "range", "r", ".", "mounts", "{", "m", "[", "alias", "]", "=", "sub", ".", "Path", "(", ")", "\n", "}", "\n", "return", "m", "\n", "}" ]
// Mounts returns a map of mounts with their paths
[ "Mounts", "returns", "a", "map", "of", "mounts", "with", "their", "paths" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/mount.go#L141-L147
train
gopasspw/gopass
pkg/store/root/mount.go
MountPoints
func (r *Store) MountPoints() []string { mps := make([]string, 0, len(r.mounts)) for k := range r.mounts { mps = append(mps, k) } sort.Sort(sort.Reverse(store.ByPathLen(mps))) return mps }
go
func (r *Store) MountPoints() []string { mps := make([]string, 0, len(r.mounts)) for k := range r.mounts { mps = append(mps, k) } sort.Sort(sort.Reverse(store.ByPathLen(mps))) return mps }
[ "func", "(", "r", "*", "Store", ")", "MountPoints", "(", ")", "[", "]", "string", "{", "mps", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "r", ".", "mounts", ")", ")", "\n", "for", "k", ":=", "range", "r", ".", "mounts", "{", "mps", "=", "append", "(", "mps", ",", "k", ")", "\n", "}", "\n", "sort", ".", "Sort", "(", "sort", ".", "Reverse", "(", "store", ".", "ByPathLen", "(", "mps", ")", ")", ")", "\n", "return", "mps", "\n", "}" ]
// MountPoints returns a sorted list of mount points. It encodes the logic that // the longer a mount point the more specific it is. This allows to "shadow" a // shorter mount point by a longer one.
[ "MountPoints", "returns", "a", "sorted", "list", "of", "mount", "points", ".", "It", "encodes", "the", "logic", "that", "the", "longer", "a", "mount", "point", "the", "more", "specific", "it", "is", ".", "This", "allows", "to", "shadow", "a", "shorter", "mount", "point", "by", "a", "longer", "one", "." ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/mount.go#L152-L159
train
gopasspw/gopass
pkg/store/root/mount.go
MountPoint
func (r *Store) MountPoint(name string) string { for _, mp := range r.MountPoints() { if strings.HasPrefix(name+"/", mp+"/") { return mp } } return "" }
go
func (r *Store) MountPoint(name string) string { for _, mp := range r.MountPoints() { if strings.HasPrefix(name+"/", mp+"/") { return mp } } return "" }
[ "func", "(", "r", "*", "Store", ")", "MountPoint", "(", "name", "string", ")", "string", "{", "for", "_", ",", "mp", ":=", "range", "r", ".", "MountPoints", "(", ")", "{", "if", "strings", ".", "HasPrefix", "(", "name", "+", "\"", "\"", ",", "mp", "+", "\"", "\"", ")", "{", "return", "mp", "\n", "}", "\n", "}", "\n", "return", "\"", "\"", "\n", "}" ]
// MountPoint returns the most-specific mount point for the given key
[ "MountPoint", "returns", "the", "most", "-", "specific", "mount", "point", "for", "the", "given", "key" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/mount.go#L162-L169
train
gopasspw/gopass
pkg/store/root/mount.go
getStore
func (r *Store) getStore(ctx context.Context, name string) (context.Context, store.Store, string) { name = strings.TrimSuffix(name, "/") mp := r.MountPoint(name) if sub, found := r.mounts[mp]; found { return r.cfg.Mounts[mp].WithContext(ctx), sub, strings.TrimPrefix(name, sub.Alias()) } return r.cfg.Root.WithContext(ctx), r.store, name }
go
func (r *Store) getStore(ctx context.Context, name string) (context.Context, store.Store, string) { name = strings.TrimSuffix(name, "/") mp := r.MountPoint(name) if sub, found := r.mounts[mp]; found { return r.cfg.Mounts[mp].WithContext(ctx), sub, strings.TrimPrefix(name, sub.Alias()) } return r.cfg.Root.WithContext(ctx), r.store, name }
[ "func", "(", "r", "*", "Store", ")", "getStore", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "(", "context", ".", "Context", ",", "store", ".", "Store", ",", "string", ")", "{", "name", "=", "strings", ".", "TrimSuffix", "(", "name", ",", "\"", "\"", ")", "\n", "mp", ":=", "r", ".", "MountPoint", "(", "name", ")", "\n", "if", "sub", ",", "found", ":=", "r", ".", "mounts", "[", "mp", "]", ";", "found", "{", "return", "r", ".", "cfg", ".", "Mounts", "[", "mp", "]", ".", "WithContext", "(", "ctx", ")", ",", "sub", ",", "strings", ".", "TrimPrefix", "(", "name", ",", "sub", ".", "Alias", "(", ")", ")", "\n", "}", "\n", "return", "r", ".", "cfg", ".", "Root", ".", "WithContext", "(", "ctx", ")", ",", "r", ".", "store", ",", "name", "\n", "}" ]
// getStore returns the Store object at the most-specific mount point for the // given key // context with sub store options set, sub store reference, truncated path to secret
[ "getStore", "returns", "the", "Store", "object", "at", "the", "most", "-", "specific", "mount", "point", "for", "the", "given", "key", "context", "with", "sub", "store", "options", "set", "sub", "store", "reference", "truncated", "path", "to", "secret" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/mount.go#L174-L181
train
gopasspw/gopass
pkg/store/root/mount.go
WithConfig
func (r *Store) WithConfig(ctx context.Context, name string) context.Context { name = strings.TrimSuffix(name, "/") mp := r.MountPoint(name) if _, found := r.mounts[mp]; found { return r.cfg.Mounts[mp].WithContext(ctx) } return r.cfg.Root.WithContext(ctx) }
go
func (r *Store) WithConfig(ctx context.Context, name string) context.Context { name = strings.TrimSuffix(name, "/") mp := r.MountPoint(name) if _, found := r.mounts[mp]; found { return r.cfg.Mounts[mp].WithContext(ctx) } return r.cfg.Root.WithContext(ctx) }
[ "func", "(", "r", "*", "Store", ")", "WithConfig", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "context", ".", "Context", "{", "name", "=", "strings", ".", "TrimSuffix", "(", "name", ",", "\"", "\"", ")", "\n", "mp", ":=", "r", ".", "MountPoint", "(", "name", ")", "\n", "if", "_", ",", "found", ":=", "r", ".", "mounts", "[", "mp", "]", ";", "found", "{", "return", "r", ".", "cfg", ".", "Mounts", "[", "mp", "]", ".", "WithContext", "(", "ctx", ")", "\n", "}", "\n", "return", "r", ".", "cfg", ".", "Root", ".", "WithContext", "(", "ctx", ")", "\n", "}" ]
// WithConfig populates the context with the substore config
[ "WithConfig", "populates", "the", "context", "with", "the", "substore", "config" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/mount.go#L184-L191
train
gopasspw/gopass
pkg/store/root/mount.go
GetSubStore
func (r *Store) GetSubStore(name string) (store.Store, error) { if name == "" { return r.store, nil } if sub, found := r.mounts[name]; found { return sub, nil } return nil, errors.Errorf("no such mount point '%s'", name) }
go
func (r *Store) GetSubStore(name string) (store.Store, error) { if name == "" { return r.store, nil } if sub, found := r.mounts[name]; found { return sub, nil } return nil, errors.Errorf("no such mount point '%s'", name) }
[ "func", "(", "r", "*", "Store", ")", "GetSubStore", "(", "name", "string", ")", "(", "store", ".", "Store", ",", "error", ")", "{", "if", "name", "==", "\"", "\"", "{", "return", "r", ".", "store", ",", "nil", "\n", "}", "\n", "if", "sub", ",", "found", ":=", "r", ".", "mounts", "[", "name", "]", ";", "found", "{", "return", "sub", ",", "nil", "\n", "}", "\n", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "name", ")", "\n", "}" ]
// GetSubStore returns an exact match for a mount point or an error if this // mount point does not exist
[ "GetSubStore", "returns", "an", "exact", "match", "for", "a", "mount", "point", "or", "an", "error", "if", "this", "mount", "point", "does", "not", "exist" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/mount.go#L195-L203
train
gopasspw/gopass
pkg/store/root/mount.go
checkMounts
func (r *Store) checkMounts() error { paths := make(map[string]string, len(r.mounts)) for k, v := range r.mounts { if _, found := paths[v.Path()]; found { return errors.Errorf("Doubly mounted path at %s: %s", v.Path(), k) } paths[v.Path()] = k } return nil }
go
func (r *Store) checkMounts() error { paths := make(map[string]string, len(r.mounts)) for k, v := range r.mounts { if _, found := paths[v.Path()]; found { return errors.Errorf("Doubly mounted path at %s: %s", v.Path(), k) } paths[v.Path()] = k } return nil }
[ "func", "(", "r", "*", "Store", ")", "checkMounts", "(", ")", "error", "{", "paths", ":=", "make", "(", "map", "[", "string", "]", "string", ",", "len", "(", "r", ".", "mounts", ")", ")", "\n", "for", "k", ",", "v", ":=", "range", "r", ".", "mounts", "{", "if", "_", ",", "found", ":=", "paths", "[", "v", ".", "Path", "(", ")", "]", ";", "found", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "v", ".", "Path", "(", ")", ",", "k", ")", "\n", "}", "\n", "paths", "[", "v", ".", "Path", "(", ")", "]", "=", "k", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// checkMounts performs some sanity checks on our mounts. At the moment it // only checks if some path is mounted twice.
[ "checkMounts", "performs", "some", "sanity", "checks", "on", "our", "mounts", ".", "At", "the", "moment", "it", "only", "checks", "if", "some", "path", "is", "mounted", "twice", "." ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/mount.go#L207-L216
train
gopasspw/gopass
pkg/action/version.go
Version
func (s *Action) Version(ctx context.Context, c *cli.Context) error { version := make(chan string, 1) go s.checkVersion(ctx, version) _ = s.Initialized(ctx, c) cli.VersionPrinter(c) cryptoVer := versionInfo(ctx, s.Store.Crypto(ctx, "")) rcsVer := versionInfo(ctx, s.Store.RCS(ctx, "")) storageVer := versionInfo(ctx, s.Store.Storage(ctx, "")) tpl := "%-10s - %10s - %10s - %10s\n" fmt.Fprintf(stdout, tpl, "<root>", cryptoVer, rcsVer, storageVer) // report all used crypto, sync and fs backends for _, mp := range s.Store.MountPoints() { cv := versionInfo(ctx, s.Store.Crypto(ctx, mp)) rv := versionInfo(ctx, s.Store.RCS(ctx, mp)) sv := versionInfo(ctx, s.Store.Storage(ctx, mp)) if cv != cryptoVer || rv != rcsVer || sv != storageVer { fmt.Fprintf(stdout, tpl, mp, cv, rv, sv) } } fmt.Fprintf(stdout, "Available Crypto Backends: %s\n", strings.Join(backend.CryptoBackends(), ", ")) fmt.Fprintf(stdout, "Available RCS Backends: %s\n", strings.Join(backend.RCSBackends(), ", ")) fmt.Fprintf(stdout, "Available Storage Backends: %s\n", strings.Join(backend.StorageBackends(), ", ")) select { case vi := <-version: if vi != "" { fmt.Fprintln(stdout, vi) } case <-time.After(2 * time.Second): out.Error(ctx, "Version check timed out") case <-ctx.Done(): return ExitError(ctx, ExitAborted, nil, "user aborted") } return nil }
go
func (s *Action) Version(ctx context.Context, c *cli.Context) error { version := make(chan string, 1) go s.checkVersion(ctx, version) _ = s.Initialized(ctx, c) cli.VersionPrinter(c) cryptoVer := versionInfo(ctx, s.Store.Crypto(ctx, "")) rcsVer := versionInfo(ctx, s.Store.RCS(ctx, "")) storageVer := versionInfo(ctx, s.Store.Storage(ctx, "")) tpl := "%-10s - %10s - %10s - %10s\n" fmt.Fprintf(stdout, tpl, "<root>", cryptoVer, rcsVer, storageVer) // report all used crypto, sync and fs backends for _, mp := range s.Store.MountPoints() { cv := versionInfo(ctx, s.Store.Crypto(ctx, mp)) rv := versionInfo(ctx, s.Store.RCS(ctx, mp)) sv := versionInfo(ctx, s.Store.Storage(ctx, mp)) if cv != cryptoVer || rv != rcsVer || sv != storageVer { fmt.Fprintf(stdout, tpl, mp, cv, rv, sv) } } fmt.Fprintf(stdout, "Available Crypto Backends: %s\n", strings.Join(backend.CryptoBackends(), ", ")) fmt.Fprintf(stdout, "Available RCS Backends: %s\n", strings.Join(backend.RCSBackends(), ", ")) fmt.Fprintf(stdout, "Available Storage Backends: %s\n", strings.Join(backend.StorageBackends(), ", ")) select { case vi := <-version: if vi != "" { fmt.Fprintln(stdout, vi) } case <-time.After(2 * time.Second): out.Error(ctx, "Version check timed out") case <-ctx.Done(): return ExitError(ctx, ExitAborted, nil, "user aborted") } return nil }
[ "func", "(", "s", "*", "Action", ")", "Version", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "version", ":=", "make", "(", "chan", "string", ",", "1", ")", "\n", "go", "s", ".", "checkVersion", "(", "ctx", ",", "version", ")", "\n\n", "_", "=", "s", ".", "Initialized", "(", "ctx", ",", "c", ")", "\n\n", "cli", ".", "VersionPrinter", "(", "c", ")", "\n\n", "cryptoVer", ":=", "versionInfo", "(", "ctx", ",", "s", ".", "Store", ".", "Crypto", "(", "ctx", ",", "\"", "\"", ")", ")", "\n", "rcsVer", ":=", "versionInfo", "(", "ctx", ",", "s", ".", "Store", ".", "RCS", "(", "ctx", ",", "\"", "\"", ")", ")", "\n", "storageVer", ":=", "versionInfo", "(", "ctx", ",", "s", ".", "Store", ".", "Storage", "(", "ctx", ",", "\"", "\"", ")", ")", "\n\n", "tpl", ":=", "\"", "\\n", "\"", "\n", "fmt", ".", "Fprintf", "(", "stdout", ",", "tpl", ",", "\"", "\"", ",", "cryptoVer", ",", "rcsVer", ",", "storageVer", ")", "\n\n", "// report all used crypto, sync and fs backends", "for", "_", ",", "mp", ":=", "range", "s", ".", "Store", ".", "MountPoints", "(", ")", "{", "cv", ":=", "versionInfo", "(", "ctx", ",", "s", ".", "Store", ".", "Crypto", "(", "ctx", ",", "mp", ")", ")", "\n", "rv", ":=", "versionInfo", "(", "ctx", ",", "s", ".", "Store", ".", "RCS", "(", "ctx", ",", "mp", ")", ")", "\n", "sv", ":=", "versionInfo", "(", "ctx", ",", "s", ".", "Store", ".", "Storage", "(", "ctx", ",", "mp", ")", ")", "\n\n", "if", "cv", "!=", "cryptoVer", "||", "rv", "!=", "rcsVer", "||", "sv", "!=", "storageVer", "{", "fmt", ".", "Fprintf", "(", "stdout", ",", "tpl", ",", "mp", ",", "cv", ",", "rv", ",", "sv", ")", "\n", "}", "\n", "}", "\n\n", "fmt", ".", "Fprintf", "(", "stdout", ",", "\"", "\\n", "\"", ",", "strings", ".", "Join", "(", "backend", ".", "CryptoBackends", "(", ")", ",", "\"", "\"", ")", ")", "\n", "fmt", ".", "Fprintf", "(", "stdout", ",", "\"", "\\n", "\"", ",", "strings", ".", "Join", "(", "backend", ".", "RCSBackends", "(", ")", ",", "\"", "\"", ")", ")", "\n", "fmt", ".", "Fprintf", "(", "stdout", ",", "\"", "\\n", "\"", ",", "strings", ".", "Join", "(", "backend", ".", "StorageBackends", "(", ")", ",", "\"", "\"", ")", ")", "\n\n", "select", "{", "case", "vi", ":=", "<-", "version", ":", "if", "vi", "!=", "\"", "\"", "{", "fmt", ".", "Fprintln", "(", "stdout", ",", "vi", ")", "\n", "}", "\n", "case", "<-", "time", ".", "After", "(", "2", "*", "time", ".", "Second", ")", ":", "out", ".", "Error", "(", "ctx", ",", "\"", "\"", ")", "\n", "case", "<-", "ctx", ".", "Done", "(", ")", ":", "return", "ExitError", "(", "ctx", ",", "ExitAborted", ",", "nil", ",", "\"", "\"", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Version prints the gopass version
[ "Version", "prints", "the", "gopass", "version" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/version.go#L21-L63
train
gopasspw/gopass
pkg/clipboard/kill_ps.go
killPrecedessors
func killPrecedessors() error { procs, err := ps.Processes() if err != nil { return err } for _, proc := range procs { walkFn(proc.Pid(), killProc) } return nil }
go
func killPrecedessors() error { procs, err := ps.Processes() if err != nil { return err } for _, proc := range procs { walkFn(proc.Pid(), killProc) } return nil }
[ "func", "killPrecedessors", "(", ")", "error", "{", "procs", ",", "err", ":=", "ps", ".", "Processes", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "for", "_", ",", "proc", ":=", "range", "procs", "{", "walkFn", "(", "proc", ".", "Pid", "(", ")", ",", "killProc", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// killPrecedessors will kill any previous "gopass unclip" invokations to avoid // erasing the clipboard prematurely in case the the same content is copied to // the clipboard repeatedly
[ "killPrecedessors", "will", "kill", "any", "previous", "gopass", "unclip", "invokations", "to", "avoid", "erasing", "the", "clipboard", "prematurely", "in", "case", "the", "the", "same", "content", "is", "copied", "to", "the", "clipboard", "repeatedly" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/clipboard/kill_ps.go#L12-L21
train
gopasspw/gopass
pkg/tpl/template.go
Execute
func Execute(ctx context.Context, tpl, name string, content []byte, s kvstore) ([]byte, error) { funcs := funcMap(ctx, s) pl := payload{ Dir: filepath.Dir(name), Path: name, Name: filepath.Base(name), Content: string(content), } tmpl, err := template.New(tpl).Funcs(funcs).Parse(tpl) if err != nil { return []byte{}, err } buff := &bytes.Buffer{} if err := tmpl.Execute(buff, pl); err != nil { return []byte{}, err } return buff.Bytes(), nil }
go
func Execute(ctx context.Context, tpl, name string, content []byte, s kvstore) ([]byte, error) { funcs := funcMap(ctx, s) pl := payload{ Dir: filepath.Dir(name), Path: name, Name: filepath.Base(name), Content: string(content), } tmpl, err := template.New(tpl).Funcs(funcs).Parse(tpl) if err != nil { return []byte{}, err } buff := &bytes.Buffer{} if err := tmpl.Execute(buff, pl); err != nil { return []byte{}, err } return buff.Bytes(), nil }
[ "func", "Execute", "(", "ctx", "context", ".", "Context", ",", "tpl", ",", "name", "string", ",", "content", "[", "]", "byte", ",", "s", "kvstore", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "funcs", ":=", "funcMap", "(", "ctx", ",", "s", ")", "\n", "pl", ":=", "payload", "{", "Dir", ":", "filepath", ".", "Dir", "(", "name", ")", ",", "Path", ":", "name", ",", "Name", ":", "filepath", ".", "Base", "(", "name", ")", ",", "Content", ":", "string", "(", "content", ")", ",", "}", "\n\n", "tmpl", ",", "err", ":=", "template", ".", "New", "(", "tpl", ")", ".", "Funcs", "(", "funcs", ")", ".", "Parse", "(", "tpl", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "]", "byte", "{", "}", ",", "err", "\n", "}", "\n\n", "buff", ":=", "&", "bytes", ".", "Buffer", "{", "}", "\n", "if", "err", ":=", "tmpl", ".", "Execute", "(", "buff", ",", "pl", ")", ";", "err", "!=", "nil", "{", "return", "[", "]", "byte", "{", "}", ",", "err", "\n", "}", "\n\n", "return", "buff", ".", "Bytes", "(", ")", ",", "nil", "\n", "}" ]
// Execute executes the given template
[ "Execute", "executes", "the", "given", "template" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/tpl/template.go#L24-L44
train
gopasspw/gopass
pkg/store/secret/yaml.go
Value
func (s *Secret) Value(key string) (string, error) { s.Lock() defer s.Unlock() if s.data == nil { if !strings.HasPrefix(s.body, "---\n") { return "", store.ErrYAMLNoMark } if err := s.decode(); err != nil { return "", err } } if v, found := s.data[key]; found { return fmt.Sprintf("%v", v), nil } return "", store.ErrYAMLNoKey }
go
func (s *Secret) Value(key string) (string, error) { s.Lock() defer s.Unlock() if s.data == nil { if !strings.HasPrefix(s.body, "---\n") { return "", store.ErrYAMLNoMark } if err := s.decode(); err != nil { return "", err } } if v, found := s.data[key]; found { return fmt.Sprintf("%v", v), nil } return "", store.ErrYAMLNoKey }
[ "func", "(", "s", "*", "Secret", ")", "Value", "(", "key", "string", ")", "(", "string", ",", "error", ")", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n\n", "if", "s", ".", "data", "==", "nil", "{", "if", "!", "strings", ".", "HasPrefix", "(", "s", ".", "body", ",", "\"", "\\n", "\"", ")", "{", "return", "\"", "\"", ",", "store", ".", "ErrYAMLNoMark", "\n", "}", "\n", "if", "err", ":=", "s", ".", "decode", "(", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "}", "\n", "if", "v", ",", "found", ":=", "s", ".", "data", "[", "key", "]", ";", "found", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "v", ")", ",", "nil", "\n", "}", "\n", "return", "\"", "\"", ",", "store", ".", "ErrYAMLNoKey", "\n", "}" ]
// Value returns the value of the given key if the body contained valid // YAML
[ "Value", "returns", "the", "value", "of", "the", "given", "key", "if", "the", "body", "contained", "valid", "YAML" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/secret/yaml.go#L14-L30
train
gopasspw/gopass
pkg/store/secret/yaml.go
SetValue
func (s *Secret) SetValue(key, value string) error { s.Lock() defer s.Unlock() if s.body == "" && s.data == nil { s.data = make(map[string]interface{}, 1) } if s.data == nil { return store.ErrYAMLNoMark } s.data[key] = value return s.encode() }
go
func (s *Secret) SetValue(key, value string) error { s.Lock() defer s.Unlock() if s.body == "" && s.data == nil { s.data = make(map[string]interface{}, 1) } if s.data == nil { return store.ErrYAMLNoMark } s.data[key] = value return s.encode() }
[ "func", "(", "s", "*", "Secret", ")", "SetValue", "(", "key", ",", "value", "string", ")", "error", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n\n", "if", "s", ".", "body", "==", "\"", "\"", "&&", "s", ".", "data", "==", "nil", "{", "s", ".", "data", "=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ",", "1", ")", "\n", "}", "\n", "if", "s", ".", "data", "==", "nil", "{", "return", "store", ".", "ErrYAMLNoMark", "\n", "}", "\n", "s", ".", "data", "[", "key", "]", "=", "value", "\n", "return", "s", ".", "encode", "(", ")", "\n", "}" ]
// SetValue sets a key to a given value. Will fail if an non-empty body exists
[ "SetValue", "sets", "a", "key", "to", "a", "given", "value", ".", "Will", "fail", "if", "an", "non", "-", "empty", "body", "exists" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/secret/yaml.go#L33-L45
train
gopasspw/gopass
pkg/store/secret/yaml.go
DeleteKey
func (s *Secret) DeleteKey(key string) error { s.Lock() defer s.Unlock() if s.data == nil { return store.ErrYAMLNoMark } delete(s.data, key) return s.encode() }
go
func (s *Secret) DeleteKey(key string) error { s.Lock() defer s.Unlock() if s.data == nil { return store.ErrYAMLNoMark } delete(s.data, key) return s.encode() }
[ "func", "(", "s", "*", "Secret", ")", "DeleteKey", "(", "key", "string", ")", "error", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n\n", "if", "s", ".", "data", "==", "nil", "{", "return", "store", ".", "ErrYAMLNoMark", "\n", "}", "\n", "delete", "(", "s", ".", "data", ",", "key", ")", "\n", "return", "s", ".", "encode", "(", ")", "\n", "}" ]
// DeleteKey key will delete a single key from an decoded map
[ "DeleteKey", "key", "will", "delete", "a", "single", "key", "from", "an", "decoded", "map" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/secret/yaml.go#L48-L57
train
gopasspw/gopass
pkg/store/secret/yaml.go
decodeYAML
func (s *Secret) decodeYAML() (bool, error) { if !strings.HasPrefix(s.body, "---\n") && s.password != "---" { return false, nil } d := make(map[string]interface{}) err := yaml.Unmarshal([]byte(s.body), &d) if err != nil { return true, err } s.data = d return true, nil }
go
func (s *Secret) decodeYAML() (bool, error) { if !strings.HasPrefix(s.body, "---\n") && s.password != "---" { return false, nil } d := make(map[string]interface{}) err := yaml.Unmarshal([]byte(s.body), &d) if err != nil { return true, err } s.data = d return true, nil }
[ "func", "(", "s", "*", "Secret", ")", "decodeYAML", "(", ")", "(", "bool", ",", "error", ")", "{", "if", "!", "strings", ".", "HasPrefix", "(", "s", ".", "body", ",", "\"", "\\n", "\"", ")", "&&", "s", ".", "password", "!=", "\"", "\"", "{", "return", "false", ",", "nil", "\n", "}", "\n", "d", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "err", ":=", "yaml", ".", "Unmarshal", "(", "[", "]", "byte", "(", "s", ".", "body", ")", ",", "&", "d", ")", "\n", "if", "err", "!=", "nil", "{", "return", "true", ",", "err", "\n", "}", "\n", "s", ".", "data", "=", "d", "\n", "return", "true", ",", "nil", "\n", "}" ]
// decodeYAML attempts to decode an optional YAML part of a secret
[ "decodeYAML", "attempts", "to", "decode", "an", "optional", "YAML", "part", "of", "a", "secret" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/secret/yaml.go#L60-L71
train
gopasspw/gopass
pkg/backend/crypto/gpg/openpgp/keyring.go
ListPublicKeyIDs
func (g *GPG) ListPublicKeyIDs(context.Context) ([]string, error) { if g.pubring == nil { return nil, fmt.Errorf("pubring is not initialized") } ids := listKeyIDs(g.pubring) if g.secring != nil { ids = append(ids, listKeyIDs(g.secring)...) } return ids, nil }
go
func (g *GPG) ListPublicKeyIDs(context.Context) ([]string, error) { if g.pubring == nil { return nil, fmt.Errorf("pubring is not initialized") } ids := listKeyIDs(g.pubring) if g.secring != nil { ids = append(ids, listKeyIDs(g.secring)...) } return ids, nil }
[ "func", "(", "g", "*", "GPG", ")", "ListPublicKeyIDs", "(", "context", ".", "Context", ")", "(", "[", "]", "string", ",", "error", ")", "{", "if", "g", ".", "pubring", "==", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "ids", ":=", "listKeyIDs", "(", "g", ".", "pubring", ")", "\n", "if", "g", ".", "secring", "!=", "nil", "{", "ids", "=", "append", "(", "ids", ",", "listKeyIDs", "(", "g", ".", "secring", ")", "...", ")", "\n", "}", "\n", "return", "ids", ",", "nil", "\n", "}" ]
// ListPublicKeyIDs does nothing
[ "ListPublicKeyIDs", "does", "nothing" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/openpgp/keyring.go#L15-L24
train
gopasspw/gopass
pkg/backend/crypto/gpg/openpgp/keyring.go
KeysByIdUsage
func (g *GPG) KeysByIdUsage(id uint64, requiredUsage byte) []openpgp.Key { return append(g.secring.KeysByIdUsage(id, requiredUsage), g.pubring.KeysByIdUsage(id, requiredUsage)...) }
go
func (g *GPG) KeysByIdUsage(id uint64, requiredUsage byte) []openpgp.Key { return append(g.secring.KeysByIdUsage(id, requiredUsage), g.pubring.KeysByIdUsage(id, requiredUsage)...) }
[ "func", "(", "g", "*", "GPG", ")", "KeysByIdUsage", "(", "id", "uint64", ",", "requiredUsage", "byte", ")", "[", "]", "openpgp", ".", "Key", "{", "return", "append", "(", "g", ".", "secring", ".", "KeysByIdUsage", "(", "id", ",", "requiredUsage", ")", ",", "g", ".", "pubring", ".", "KeysByIdUsage", "(", "id", ",", "requiredUsage", ")", "...", ")", "\n", "}" ]
// KeysByIdUsage implements openpgp.Keyring
[ "KeysByIdUsage", "implements", "openpgp", ".", "Keyring" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/openpgp/keyring.go#L137-L139
train
gopasspw/gopass
pkg/backend/crypto/gpg/openpgp/keyring.go
SigningKeys
func (g *GPG) SigningKeys() []openpgp.Key { keys := []openpgp.Key{} for _, e := range g.secring { for _, subKey := range e.Subkeys { if subKey.PrivateKey != nil && (!subKey.Sig.FlagsValid || subKey.Sig.FlagSign) { keys = append(keys, openpgp.Key{ Entity: e, PublicKey: subKey.PublicKey, PrivateKey: subKey.PrivateKey, SelfSignature: subKey.Sig, }) } } } return keys }
go
func (g *GPG) SigningKeys() []openpgp.Key { keys := []openpgp.Key{} for _, e := range g.secring { for _, subKey := range e.Subkeys { if subKey.PrivateKey != nil && (!subKey.Sig.FlagsValid || subKey.Sig.FlagSign) { keys = append(keys, openpgp.Key{ Entity: e, PublicKey: subKey.PublicKey, PrivateKey: subKey.PrivateKey, SelfSignature: subKey.Sig, }) } } } return keys }
[ "func", "(", "g", "*", "GPG", ")", "SigningKeys", "(", ")", "[", "]", "openpgp", ".", "Key", "{", "keys", ":=", "[", "]", "openpgp", ".", "Key", "{", "}", "\n", "for", "_", ",", "e", ":=", "range", "g", ".", "secring", "{", "for", "_", ",", "subKey", ":=", "range", "e", ".", "Subkeys", "{", "if", "subKey", ".", "PrivateKey", "!=", "nil", "&&", "(", "!", "subKey", ".", "Sig", ".", "FlagsValid", "||", "subKey", ".", "Sig", ".", "FlagSign", ")", "{", "keys", "=", "append", "(", "keys", ",", "openpgp", ".", "Key", "{", "Entity", ":", "e", ",", "PublicKey", ":", "subKey", ".", "PublicKey", ",", "PrivateKey", ":", "subKey", ".", "PrivateKey", ",", "SelfSignature", ":", "subKey", ".", "Sig", ",", "}", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "keys", "\n", "}" ]
// SigningKeys returns a list of signing keys
[ "SigningKeys", "returns", "a", "list", "of", "signing", "keys" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/openpgp/keyring.go#L149-L164
train
gopasspw/gopass
pkg/jsonapi/helpers.go
isPublicSuffix
func isPublicSuffix(host string) bool { suffix, _ := publicsuffix.PublicSuffix(host) return host == suffix }
go
func isPublicSuffix(host string) bool { suffix, _ := publicsuffix.PublicSuffix(host) return host == suffix }
[ "func", "isPublicSuffix", "(", "host", "string", ")", "bool", "{", "suffix", ",", "_", ":=", "publicsuffix", ".", "PublicSuffix", "(", "host", ")", "\n", "return", "host", "==", "suffix", "\n", "}" ]
// isPublicSuffix returns true if this host is one users can or could directly // register names
[ "isPublicSuffix", "returns", "true", "if", "this", "host", "is", "one", "users", "can", "or", "could", "directly", "register", "names" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/jsonapi/helpers.go#L12-L15
train
gopasspw/gopass
pkg/store/sub/recipients.go
Recipients
func (s *Store) Recipients(ctx context.Context) []string { rs, err := s.GetRecipients(ctx, "") if err != nil { out.Error(ctx, "failed to read recipient list: %s", err) } return rs }
go
func (s *Store) Recipients(ctx context.Context) []string { rs, err := s.GetRecipients(ctx, "") if err != nil { out.Error(ctx, "failed to read recipient list: %s", err) } return rs }
[ "func", "(", "s", "*", "Store", ")", "Recipients", "(", "ctx", "context", ".", "Context", ")", "[", "]", "string", "{", "rs", ",", "err", ":=", "s", ".", "GetRecipients", "(", "ctx", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "out", ".", "Error", "(", "ctx", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "rs", "\n", "}" ]
// Recipients returns the list of recipients of this store
[ "Recipients", "returns", "the", "list", "of", "recipients", "of", "this", "store" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/recipients.go#L30-L36
train
gopasspw/gopass
pkg/store/sub/recipients.go
AddRecipient
func (s *Store) AddRecipient(ctx context.Context, id string) error { rs, err := s.GetRecipients(ctx, "") if err != nil { return errors.Wrapf(err, "failed to read recipient list") } for _, k := range rs { if k == id { return errors.Errorf("Recipient already in store") } } rs = append(rs, id) if err := s.saveRecipients(ctx, rs, "Added Recipient "+id, true); err != nil { return errors.Wrapf(err, "failed to save recipients") } out.Cyan(ctx, "Reencrypting existing secrets. This may take some time ...") return s.reencrypt(WithReason(ctx, "Added Recipient "+id)) }
go
func (s *Store) AddRecipient(ctx context.Context, id string) error { rs, err := s.GetRecipients(ctx, "") if err != nil { return errors.Wrapf(err, "failed to read recipient list") } for _, k := range rs { if k == id { return errors.Errorf("Recipient already in store") } } rs = append(rs, id) if err := s.saveRecipients(ctx, rs, "Added Recipient "+id, true); err != nil { return errors.Wrapf(err, "failed to save recipients") } out.Cyan(ctx, "Reencrypting existing secrets. This may take some time ...") return s.reencrypt(WithReason(ctx, "Added Recipient "+id)) }
[ "func", "(", "s", "*", "Store", ")", "AddRecipient", "(", "ctx", "context", ".", "Context", ",", "id", "string", ")", "error", "{", "rs", ",", "err", ":=", "s", ".", "GetRecipients", "(", "ctx", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "for", "_", ",", "k", ":=", "range", "rs", "{", "if", "k", "==", "id", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "\n\n", "rs", "=", "append", "(", "rs", ",", "id", ")", "\n\n", "if", "err", ":=", "s", ".", "saveRecipients", "(", "ctx", ",", "rs", ",", "\"", "\"", "+", "id", ",", "true", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "out", ".", "Cyan", "(", "ctx", ",", "\"", "\"", ")", "\n", "return", "s", ".", "reencrypt", "(", "WithReason", "(", "ctx", ",", "\"", "\"", "+", "id", ")", ")", "\n", "}" ]
// AddRecipient adds a new recipient to the list
[ "AddRecipient", "adds", "a", "new", "recipient", "to", "the", "list" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/recipients.go#L39-L59
train
gopasspw/gopass
pkg/store/sub/recipients.go
SaveRecipients
func (s *Store) SaveRecipients(ctx context.Context) error { rs, err := s.GetRecipients(ctx, "") if err != nil { return errors.Wrapf(err, "failed to get recipients") } return s.saveRecipients(ctx, rs, "Save Recipients", true) }
go
func (s *Store) SaveRecipients(ctx context.Context) error { rs, err := s.GetRecipients(ctx, "") if err != nil { return errors.Wrapf(err, "failed to get recipients") } return s.saveRecipients(ctx, rs, "Save Recipients", true) }
[ "func", "(", "s", "*", "Store", ")", "SaveRecipients", "(", "ctx", "context", ".", "Context", ")", "error", "{", "rs", ",", "err", ":=", "s", ".", "GetRecipients", "(", "ctx", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "s", ".", "saveRecipients", "(", "ctx", ",", "rs", ",", "\"", "\"", ",", "true", ")", "\n", "}" ]
// SaveRecipients persists the current recipients on disk
[ "SaveRecipients", "persists", "the", "current", "recipients", "on", "disk" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/recipients.go#L62-L68
train
gopasspw/gopass
pkg/store/sub/recipients.go
SetRecipients
func (s *Store) SetRecipients(ctx context.Context, rs []string) error { return s.saveRecipients(ctx, rs, "Set Recipients", true) }
go
func (s *Store) SetRecipients(ctx context.Context, rs []string) error { return s.saveRecipients(ctx, rs, "Set Recipients", true) }
[ "func", "(", "s", "*", "Store", ")", "SetRecipients", "(", "ctx", "context", ".", "Context", ",", "rs", "[", "]", "string", ")", "error", "{", "return", "s", ".", "saveRecipients", "(", "ctx", ",", "rs", ",", "\"", "\"", ",", "true", ")", "\n", "}" ]
// SetRecipients will update the stored recipients and the associated checksum
[ "SetRecipients", "will", "update", "the", "stored", "recipients", "and", "the", "associated", "checksum" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/recipients.go#L71-L73
train
gopasspw/gopass
pkg/store/sub/recipients.go
RemoveRecipient
func (s *Store) RemoveRecipient(ctx context.Context, id string) error { keys, err := s.crypto.FindPublicKeys(ctx, id) if err != nil { out.Cyan(ctx, "Warning: Failed to get GPG Key Info for %s: %s", id, err) } rs, err := s.GetRecipients(ctx, "") if err != nil { return errors.Wrapf(err, "failed to read recipient list") } nk := make([]string, 0, len(rs)-1) RECIPIENTS: for _, k := range rs { if k == id { continue RECIPIENTS } // if the key is available locally we can also match the id against // the fingerprint for _, key := range keys { if strings.HasSuffix(key, k) { continue RECIPIENTS } } nk = append(nk, k) } if len(rs) == len(nk) { return errors.Errorf("recipient not in store") } if err := s.saveRecipients(ctx, nk, "Removed Recipient "+id, true); err != nil { return errors.Wrapf(err, "failed to save recipients") } return s.reencrypt(WithReason(ctx, "Removed Recipient "+id)) }
go
func (s *Store) RemoveRecipient(ctx context.Context, id string) error { keys, err := s.crypto.FindPublicKeys(ctx, id) if err != nil { out.Cyan(ctx, "Warning: Failed to get GPG Key Info for %s: %s", id, err) } rs, err := s.GetRecipients(ctx, "") if err != nil { return errors.Wrapf(err, "failed to read recipient list") } nk := make([]string, 0, len(rs)-1) RECIPIENTS: for _, k := range rs { if k == id { continue RECIPIENTS } // if the key is available locally we can also match the id against // the fingerprint for _, key := range keys { if strings.HasSuffix(key, k) { continue RECIPIENTS } } nk = append(nk, k) } if len(rs) == len(nk) { return errors.Errorf("recipient not in store") } if err := s.saveRecipients(ctx, nk, "Removed Recipient "+id, true); err != nil { return errors.Wrapf(err, "failed to save recipients") } return s.reencrypt(WithReason(ctx, "Removed Recipient "+id)) }
[ "func", "(", "s", "*", "Store", ")", "RemoveRecipient", "(", "ctx", "context", ".", "Context", ",", "id", "string", ")", "error", "{", "keys", ",", "err", ":=", "s", ".", "crypto", ".", "FindPublicKeys", "(", "ctx", ",", "id", ")", "\n", "if", "err", "!=", "nil", "{", "out", ".", "Cyan", "(", "ctx", ",", "\"", "\"", ",", "id", ",", "err", ")", "\n", "}", "\n\n", "rs", ",", "err", ":=", "s", ".", "GetRecipients", "(", "ctx", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "nk", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "rs", ")", "-", "1", ")", "\n", "RECIPIENTS", ":", "for", "_", ",", "k", ":=", "range", "rs", "{", "if", "k", "==", "id", "{", "continue", "RECIPIENTS", "\n", "}", "\n", "// if the key is available locally we can also match the id against", "// the fingerprint", "for", "_", ",", "key", ":=", "range", "keys", "{", "if", "strings", ".", "HasSuffix", "(", "key", ",", "k", ")", "{", "continue", "RECIPIENTS", "\n", "}", "\n", "}", "\n", "nk", "=", "append", "(", "nk", ",", "k", ")", "\n", "}", "\n\n", "if", "len", "(", "rs", ")", "==", "len", "(", "nk", ")", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "err", ":=", "s", ".", "saveRecipients", "(", "ctx", ",", "nk", ",", "\"", "\"", "+", "id", ",", "true", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "return", "s", ".", "reencrypt", "(", "WithReason", "(", "ctx", ",", "\"", "\"", "+", "id", ")", ")", "\n", "}" ]
// RemoveRecipient will remove the given recipient from the store // but if this key is not available on this machine we // just try to remove it literally
[ "RemoveRecipient", "will", "remove", "the", "given", "recipient", "from", "the", "store", "but", "if", "this", "key", "is", "not", "available", "on", "this", "machine", "we", "just", "try", "to", "remove", "it", "literally" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/recipients.go#L78-L114
train
gopasspw/gopass
pkg/store/sub/recipients.go
ExportMissingPublicKeys
func (s *Store) ExportMissingPublicKeys(ctx context.Context, rs []string) (bool, error) { ok := true exported := false for _, r := range rs { if r == "" { continue } path, err := s.exportPublicKey(ctx, r) if err != nil { ok = false out.Error(ctx, "failed to export public key for '%s': %s", r, err) continue } if path == "" { continue } // at least one key has been exported exported = true if err := s.rcs.Add(ctx, path); err != nil { if errors.Cause(err) == store.ErrGitNotInit { continue } ok = false out.Error(ctx, "failed to add public key for '%s' to git: %s", r, err) continue } if err := s.rcs.Commit(ctx, fmt.Sprintf("Exported Public Keys %s", r)); err != nil && err != store.ErrGitNothingToCommit { ok = false out.Error(ctx, "Failed to git commit: %s", err) continue } } if !ok { return exported, errors.New("some keys failed") } return exported, nil }
go
func (s *Store) ExportMissingPublicKeys(ctx context.Context, rs []string) (bool, error) { ok := true exported := false for _, r := range rs { if r == "" { continue } path, err := s.exportPublicKey(ctx, r) if err != nil { ok = false out.Error(ctx, "failed to export public key for '%s': %s", r, err) continue } if path == "" { continue } // at least one key has been exported exported = true if err := s.rcs.Add(ctx, path); err != nil { if errors.Cause(err) == store.ErrGitNotInit { continue } ok = false out.Error(ctx, "failed to add public key for '%s' to git: %s", r, err) continue } if err := s.rcs.Commit(ctx, fmt.Sprintf("Exported Public Keys %s", r)); err != nil && err != store.ErrGitNothingToCommit { ok = false out.Error(ctx, "Failed to git commit: %s", err) continue } } if !ok { return exported, errors.New("some keys failed") } return exported, nil }
[ "func", "(", "s", "*", "Store", ")", "ExportMissingPublicKeys", "(", "ctx", "context", ".", "Context", ",", "rs", "[", "]", "string", ")", "(", "bool", ",", "error", ")", "{", "ok", ":=", "true", "\n", "exported", ":=", "false", "\n", "for", "_", ",", "r", ":=", "range", "rs", "{", "if", "r", "==", "\"", "\"", "{", "continue", "\n", "}", "\n", "path", ",", "err", ":=", "s", ".", "exportPublicKey", "(", "ctx", ",", "r", ")", "\n", "if", "err", "!=", "nil", "{", "ok", "=", "false", "\n", "out", ".", "Error", "(", "ctx", ",", "\"", "\"", ",", "r", ",", "err", ")", "\n", "continue", "\n", "}", "\n", "if", "path", "==", "\"", "\"", "{", "continue", "\n", "}", "\n", "// at least one key has been exported", "exported", "=", "true", "\n", "if", "err", ":=", "s", ".", "rcs", ".", "Add", "(", "ctx", ",", "path", ")", ";", "err", "!=", "nil", "{", "if", "errors", ".", "Cause", "(", "err", ")", "==", "store", ".", "ErrGitNotInit", "{", "continue", "\n", "}", "\n", "ok", "=", "false", "\n", "out", ".", "Error", "(", "ctx", ",", "\"", "\"", ",", "r", ",", "err", ")", "\n", "continue", "\n", "}", "\n", "if", "err", ":=", "s", ".", "rcs", ".", "Commit", "(", "ctx", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "r", ")", ")", ";", "err", "!=", "nil", "&&", "err", "!=", "store", ".", "ErrGitNothingToCommit", "{", "ok", "=", "false", "\n", "out", ".", "Error", "(", "ctx", ",", "\"", "\"", ",", "err", ")", "\n", "continue", "\n", "}", "\n", "}", "\n", "if", "!", "ok", "{", "return", "exported", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "exported", ",", "nil", "\n", "}" ]
// ExportMissingPublicKeys will export any possibly missing public keys to the // stores .public-keys directory
[ "ExportMissingPublicKeys", "will", "export", "any", "possibly", "missing", "public", "keys", "to", "the", "stores", ".", "public", "-", "keys", "directory" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/recipients.go#L179-L215
train
gopasspw/gopass
pkg/store/sub/recipients.go
unmarshalRecipients
func unmarshalRecipients(buf []byte) []string { m := make(map[string]struct{}, 5) scanner := bufio.NewScanner(bytes.NewReader(buf)) for scanner.Scan() { line := strings.TrimSpace(scanner.Text()) if line != "" { // deduplicate m[line] = struct{}{} } } lst := make([]string, 0, len(m)) for k := range m { lst = append(lst, k) } // sort sort.Strings(lst) return lst }
go
func unmarshalRecipients(buf []byte) []string { m := make(map[string]struct{}, 5) scanner := bufio.NewScanner(bytes.NewReader(buf)) for scanner.Scan() { line := strings.TrimSpace(scanner.Text()) if line != "" { // deduplicate m[line] = struct{}{} } } lst := make([]string, 0, len(m)) for k := range m { lst = append(lst, k) } // sort sort.Strings(lst) return lst }
[ "func", "unmarshalRecipients", "(", "buf", "[", "]", "byte", ")", "[", "]", "string", "{", "m", ":=", "make", "(", "map", "[", "string", "]", "struct", "{", "}", ",", "5", ")", "\n", "scanner", ":=", "bufio", ".", "NewScanner", "(", "bytes", ".", "NewReader", "(", "buf", ")", ")", "\n\n", "for", "scanner", ".", "Scan", "(", ")", "{", "line", ":=", "strings", ".", "TrimSpace", "(", "scanner", ".", "Text", "(", ")", ")", "\n", "if", "line", "!=", "\"", "\"", "{", "// deduplicate", "m", "[", "line", "]", "=", "struct", "{", "}", "{", "}", "\n", "}", "\n", "}", "\n\n", "lst", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "m", ")", ")", "\n", "for", "k", ":=", "range", "m", "{", "lst", "=", "append", "(", "lst", ",", "k", ")", "\n", "}", "\n", "// sort", "sort", ".", "Strings", "(", "lst", ")", "\n\n", "return", "lst", "\n", "}" ]
// unmarshal Recipients line by line from a io.Reader.
[ "unmarshal", "Recipients", "line", "by", "line", "from", "a", "io", ".", "Reader", "." ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/recipients.go#L302-L322
train
gopasspw/gopass
pkg/out/print.go
Print
func Print(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprintf(Stdout, Prefix(ctx)+format+newline(ctx), args...) }
go
func Print(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprintf(Stdout, Prefix(ctx)+format+newline(ctx), args...) }
[ "func", "Print", "(", "ctx", "context", ".", "Context", ",", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "if", "IsHidden", "(", "ctx", ")", "&&", "!", "ctxutil", ".", "IsDebug", "(", "ctx", ")", "{", "return", "\n", "}", "\n", "fmt", ".", "Fprintf", "(", "Stdout", ",", "Prefix", "(", "ctx", ")", "+", "format", "+", "newline", "(", "ctx", ")", ",", "args", "...", ")", "\n", "}" ]
// Print formats and prints the given string
[ "Print", "formats", "and", "prints", "the", "given", "string" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/out/print.go#L31-L36
train
gopasspw/gopass
pkg/out/print.go
Debug
func Debug(ctx context.Context, format string, args ...interface{}) { if !ctxutil.IsDebug(ctx) { return } var loc string if _, file, line, ok := runtime.Caller(1); ok { file = file[strings.Index(file, "pkg/"):] file = strings.TrimPrefix(file, "pkg/") loc = fmt.Sprintf("%s:%d ", file, line) } fmt.Fprintf(Stdout, Prefix(ctx)+"[DEBUG] "+loc+format+newline(ctx), args...) }
go
func Debug(ctx context.Context, format string, args ...interface{}) { if !ctxutil.IsDebug(ctx) { return } var loc string if _, file, line, ok := runtime.Caller(1); ok { file = file[strings.Index(file, "pkg/"):] file = strings.TrimPrefix(file, "pkg/") loc = fmt.Sprintf("%s:%d ", file, line) } fmt.Fprintf(Stdout, Prefix(ctx)+"[DEBUG] "+loc+format+newline(ctx), args...) }
[ "func", "Debug", "(", "ctx", "context", ".", "Context", ",", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "if", "!", "ctxutil", ".", "IsDebug", "(", "ctx", ")", "{", "return", "\n", "}", "\n\n", "var", "loc", "string", "\n", "if", "_", ",", "file", ",", "line", ",", "ok", ":=", "runtime", ".", "Caller", "(", "1", ")", ";", "ok", "{", "file", "=", "file", "[", "strings", ".", "Index", "(", "file", ",", "\"", "\"", ")", ":", "]", "\n", "file", "=", "strings", ".", "TrimPrefix", "(", "file", ",", "\"", "\"", ")", "\n", "loc", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "file", ",", "line", ")", "\n", "}", "\n\n", "fmt", ".", "Fprintf", "(", "Stdout", ",", "Prefix", "(", "ctx", ")", "+", "\"", "\"", "+", "loc", "+", "format", "+", "newline", "(", "ctx", ")", ",", "args", "...", ")", "\n", "}" ]
// Debug prints the given string if the debug flag is set
[ "Debug", "prints", "the", "given", "string", "if", "the", "debug", "flag", "is", "set" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/out/print.go#L39-L52
train
gopasspw/gopass
pkg/out/print.go
Black
func Black(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprint(Stdout, color.BlackString(Prefix(ctx)+format+newline(ctx), args...)) }
go
func Black(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprint(Stdout, color.BlackString(Prefix(ctx)+format+newline(ctx), args...)) }
[ "func", "Black", "(", "ctx", "context", ".", "Context", ",", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "if", "IsHidden", "(", "ctx", ")", "&&", "!", "ctxutil", ".", "IsDebug", "(", "ctx", ")", "{", "return", "\n", "}", "\n", "fmt", ".", "Fprint", "(", "Stdout", ",", "color", ".", "BlackString", "(", "Prefix", "(", "ctx", ")", "+", "format", "+", "newline", "(", "ctx", ")", ",", "args", "...", ")", ")", "\n", "}" ]
// Black prints the string in black
[ "Black", "prints", "the", "string", "in", "black" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/out/print.go#L55-L60
train
gopasspw/gopass
pkg/out/print.go
Blue
func Blue(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprint(Stdout, color.BlueString(Prefix(ctx)+format+newline(ctx), args...)) }
go
func Blue(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprint(Stdout, color.BlueString(Prefix(ctx)+format+newline(ctx), args...)) }
[ "func", "Blue", "(", "ctx", "context", ".", "Context", ",", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "if", "IsHidden", "(", "ctx", ")", "&&", "!", "ctxutil", ".", "IsDebug", "(", "ctx", ")", "{", "return", "\n", "}", "\n", "fmt", ".", "Fprint", "(", "Stdout", ",", "color", ".", "BlueString", "(", "Prefix", "(", "ctx", ")", "+", "format", "+", "newline", "(", "ctx", ")", ",", "args", "...", ")", ")", "\n", "}" ]
// Blue prints the string in blue
[ "Blue", "prints", "the", "string", "in", "blue" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/out/print.go#L63-L68
train
gopasspw/gopass
pkg/out/print.go
Cyan
func Cyan(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprint(Stdout, color.CyanString(Prefix(ctx)+format+newline(ctx), args...)) }
go
func Cyan(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprint(Stdout, color.CyanString(Prefix(ctx)+format+newline(ctx), args...)) }
[ "func", "Cyan", "(", "ctx", "context", ".", "Context", ",", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "if", "IsHidden", "(", "ctx", ")", "&&", "!", "ctxutil", ".", "IsDebug", "(", "ctx", ")", "{", "return", "\n", "}", "\n", "fmt", ".", "Fprint", "(", "Stdout", ",", "color", ".", "CyanString", "(", "Prefix", "(", "ctx", ")", "+", "format", "+", "newline", "(", "ctx", ")", ",", "args", "...", ")", ")", "\n", "}" ]
// Cyan prints the string in cyan
[ "Cyan", "prints", "the", "string", "in", "cyan" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/out/print.go#L71-L76
train
gopasspw/gopass
pkg/out/print.go
Green
func Green(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprint(Stdout, color.GreenString(Prefix(ctx)+format+newline(ctx), args...)) }
go
func Green(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprint(Stdout, color.GreenString(Prefix(ctx)+format+newline(ctx), args...)) }
[ "func", "Green", "(", "ctx", "context", ".", "Context", ",", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "if", "IsHidden", "(", "ctx", ")", "&&", "!", "ctxutil", ".", "IsDebug", "(", "ctx", ")", "{", "return", "\n", "}", "\n", "fmt", ".", "Fprint", "(", "Stdout", ",", "color", ".", "GreenString", "(", "Prefix", "(", "ctx", ")", "+", "format", "+", "newline", "(", "ctx", ")", ",", "args", "...", ")", ")", "\n", "}" ]
// Green prints the string in green
[ "Green", "prints", "the", "string", "in", "green" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/out/print.go#L79-L84
train
gopasspw/gopass
pkg/out/print.go
Magenta
func Magenta(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprint(Stdout, color.MagentaString(Prefix(ctx)+format+newline(ctx), args...)) }
go
func Magenta(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprint(Stdout, color.MagentaString(Prefix(ctx)+format+newline(ctx), args...)) }
[ "func", "Magenta", "(", "ctx", "context", ".", "Context", ",", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "if", "IsHidden", "(", "ctx", ")", "&&", "!", "ctxutil", ".", "IsDebug", "(", "ctx", ")", "{", "return", "\n", "}", "\n", "fmt", ".", "Fprint", "(", "Stdout", ",", "color", ".", "MagentaString", "(", "Prefix", "(", "ctx", ")", "+", "format", "+", "newline", "(", "ctx", ")", ",", "args", "...", ")", ")", "\n", "}" ]
// Magenta prints the string in magenta
[ "Magenta", "prints", "the", "string", "in", "magenta" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/out/print.go#L87-L92
train
gopasspw/gopass
pkg/out/print.go
Red
func Red(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprint(Stdout, color.RedString(Prefix(ctx)+format+newline(ctx), args...)) }
go
func Red(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprint(Stdout, color.RedString(Prefix(ctx)+format+newline(ctx), args...)) }
[ "func", "Red", "(", "ctx", "context", ".", "Context", ",", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "if", "IsHidden", "(", "ctx", ")", "&&", "!", "ctxutil", ".", "IsDebug", "(", "ctx", ")", "{", "return", "\n", "}", "\n", "fmt", ".", "Fprint", "(", "Stdout", ",", "color", ".", "RedString", "(", "Prefix", "(", "ctx", ")", "+", "format", "+", "newline", "(", "ctx", ")", ",", "args", "...", ")", ")", "\n", "}" ]
// Red prints the string in red
[ "Red", "prints", "the", "string", "in", "red" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/out/print.go#L95-L100
train
gopasspw/gopass
pkg/out/print.go
Error
func Error(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprint(Stderr, color.RedString(Prefix(ctx)+format+newline(ctx), args...)) }
go
func Error(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprint(Stderr, color.RedString(Prefix(ctx)+format+newline(ctx), args...)) }
[ "func", "Error", "(", "ctx", "context", ".", "Context", ",", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "if", "IsHidden", "(", "ctx", ")", "&&", "!", "ctxutil", ".", "IsDebug", "(", "ctx", ")", "{", "return", "\n", "}", "\n", "fmt", ".", "Fprint", "(", "Stderr", ",", "color", ".", "RedString", "(", "Prefix", "(", "ctx", ")", "+", "format", "+", "newline", "(", "ctx", ")", ",", "args", "...", ")", ")", "\n", "}" ]
// Error prints the string in red to stderr
[ "Error", "prints", "the", "string", "in", "red", "to", "stderr" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/out/print.go#L103-L108
train
gopasspw/gopass
pkg/out/print.go
White
func White(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprint(Stdout, color.WhiteString(Prefix(ctx)+format+newline(ctx), args...)) }
go
func White(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprint(Stdout, color.WhiteString(Prefix(ctx)+format+newline(ctx), args...)) }
[ "func", "White", "(", "ctx", "context", ".", "Context", ",", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "if", "IsHidden", "(", "ctx", ")", "&&", "!", "ctxutil", ".", "IsDebug", "(", "ctx", ")", "{", "return", "\n", "}", "\n", "fmt", ".", "Fprint", "(", "Stdout", ",", "color", ".", "WhiteString", "(", "Prefix", "(", "ctx", ")", "+", "format", "+", "newline", "(", "ctx", ")", ",", "args", "...", ")", ")", "\n", "}" ]
// White prints the string in white
[ "White", "prints", "the", "string", "in", "white" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/out/print.go#L111-L116
train
gopasspw/gopass
pkg/out/print.go
Yellow
func Yellow(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprint(Stdout, color.YellowString(Prefix(ctx)+format+newline(ctx), args...)) }
go
func Yellow(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprint(Stdout, color.YellowString(Prefix(ctx)+format+newline(ctx), args...)) }
[ "func", "Yellow", "(", "ctx", "context", ".", "Context", ",", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "if", "IsHidden", "(", "ctx", ")", "&&", "!", "ctxutil", ".", "IsDebug", "(", "ctx", ")", "{", "return", "\n", "}", "\n", "fmt", ".", "Fprint", "(", "Stdout", ",", "color", ".", "YellowString", "(", "Prefix", "(", "ctx", ")", "+", "format", "+", "newline", "(", "ctx", ")", ",", "args", "...", ")", ")", "\n", "}" ]
// Yellow prints the string in yellow
[ "Yellow", "prints", "the", "string", "in", "yellow" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/out/print.go#L119-L124
train
gopasspw/gopass
pkg/tree/simple/folder.go
Len
func (f *Folder) Len() int { l := len(f.Files) for _, f := range f.Folders { l += f.Len() } return l }
go
func (f *Folder) Len() int { l := len(f.Files) for _, f := range f.Folders { l += f.Len() } return l }
[ "func", "(", "f", "*", "Folder", ")", "Len", "(", ")", "int", "{", "l", ":=", "len", "(", "f", ".", "Files", ")", "\n", "for", "_", ",", "f", ":=", "range", "f", ".", "Folders", "{", "l", "+=", "f", ".", "Len", "(", ")", "\n", "}", "\n", "return", "l", "\n", "}" ]
// Len returns the number of entries in this folder and all subfolder including // this folder itself
[ "Len", "returns", "the", "number", "of", "entries", "in", "this", "folder", "and", "all", "subfolder", "including", "this", "folder", "itself" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/tree/simple/folder.go#L26-L32
train
gopasspw/gopass
pkg/tree/simple/folder.go
Format
func (f *Folder) Format(maxDepth int) string { return f.format("", true, maxDepth, 0) }
go
func (f *Folder) Format(maxDepth int) string { return f.format("", true, maxDepth, 0) }
[ "func", "(", "f", "*", "Folder", ")", "Format", "(", "maxDepth", "int", ")", "string", "{", "return", "f", ".", "format", "(", "\"", "\"", ",", "true", ",", "maxDepth", ",", "0", ")", "\n", "}" ]
// Format returns a pretty printed tree
[ "Format", "returns", "a", "pretty", "printed", "tree" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/tree/simple/folder.go#L48-L50
train
gopasspw/gopass
pkg/tree/simple/folder.go
AddFile
func (f *Folder) AddFile(name string, contentType string) error { return f.addFile(strings.Split(name, sep), contentType) }
go
func (f *Folder) AddFile(name string, contentType string) error { return f.addFile(strings.Split(name, sep), contentType) }
[ "func", "(", "f", "*", "Folder", ")", "AddFile", "(", "name", "string", ",", "contentType", "string", ")", "error", "{", "return", "f", ".", "addFile", "(", "strings", ".", "Split", "(", "name", ",", "sep", ")", ",", "contentType", ")", "\n", "}" ]
// AddFile adds a new file
[ "AddFile", "adds", "a", "new", "file" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/tree/simple/folder.go#L58-L60
train
gopasspw/gopass
pkg/tree/simple/folder.go
AddTemplate
func (f *Folder) AddTemplate(name string) error { return f.addTemplate(strings.Split(name, sep)) }
go
func (f *Folder) AddTemplate(name string) error { return f.addTemplate(strings.Split(name, sep)) }
[ "func", "(", "f", "*", "Folder", ")", "AddTemplate", "(", "name", "string", ")", "error", "{", "return", "f", ".", "addTemplate", "(", "strings", ".", "Split", "(", "name", ",", "sep", ")", ")", "\n", "}" ]
// AddTemplate adds a new template
[ "AddTemplate", "adds", "a", "new", "template" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/tree/simple/folder.go#L68-L70
train
gopasspw/gopass
pkg/tree/simple/folder.go
newFolder
func newFolder(name string) *Folder { return &Folder{ Name: name, Path: "", Folders: make(map[string]*Folder, 10), Files: make(map[string]*File, 10), } }
go
func newFolder(name string) *Folder { return &Folder{ Name: name, Path: "", Folders: make(map[string]*Folder, 10), Files: make(map[string]*File, 10), } }
[ "func", "newFolder", "(", "name", "string", ")", "*", "Folder", "{", "return", "&", "Folder", "{", "Name", ":", "name", ",", "Path", ":", "\"", "\"", ",", "Folders", ":", "make", "(", "map", "[", "string", "]", "*", "Folder", ",", "10", ")", ",", "Files", ":", "make", "(", "map", "[", "string", "]", "*", "File", ",", "10", ")", ",", "}", "\n", "}" ]
// newFolder creates a new, initialized folder
[ "newFolder", "creates", "a", "new", "initialized", "folder" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/tree/simple/folder.go#L73-L80
train
gopasspw/gopass
pkg/tree/simple/folder.go
getFolder
func (f *Folder) getFolder(name string) *Folder { if next, found := f.Folders[name]; found { return next } next := newFolder(name) f.Folders[name] = next return next }
go
func (f *Folder) getFolder(name string) *Folder { if next, found := f.Folders[name]; found { return next } next := newFolder(name) f.Folders[name] = next return next }
[ "func", "(", "f", "*", "Folder", ")", "getFolder", "(", "name", "string", ")", "*", "Folder", "{", "if", "next", ",", "found", ":=", "f", ".", "Folders", "[", "name", "]", ";", "found", "{", "return", "next", "\n", "}", "\n", "next", ":=", "newFolder", "(", "name", ")", "\n", "f", ".", "Folders", "[", "name", "]", "=", "next", "\n", "return", "next", "\n", "}" ]
// getFolder returns a direct sub-folder within this folder. // name MUST NOT include filepath separators. If there is no // such folder a new one is created with that name.
[ "getFolder", "returns", "a", "direct", "sub", "-", "folder", "within", "this", "folder", ".", "name", "MUST", "NOT", "include", "filepath", "separators", ".", "If", "there", "is", "no", "such", "folder", "a", "new", "one", "is", "created", "with", "that", "name", "." ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/tree/simple/folder.go#L193-L200
train
gopasspw/gopass
pkg/tree/simple/folder.go
FindFolder
func (f *Folder) FindFolder(name string) (tree.Tree, error) { sub := f.findFolder(strings.Split(strings.TrimSuffix(name, sep), sep)) if sub == nil { return nil, errors.Errorf("Entry not found") } return sub, nil }
go
func (f *Folder) FindFolder(name string) (tree.Tree, error) { sub := f.findFolder(strings.Split(strings.TrimSuffix(name, sep), sep)) if sub == nil { return nil, errors.Errorf("Entry not found") } return sub, nil }
[ "func", "(", "f", "*", "Folder", ")", "FindFolder", "(", "name", "string", ")", "(", "tree", ".", "Tree", ",", "error", ")", "{", "sub", ":=", "f", ".", "findFolder", "(", "strings", ".", "Split", "(", "strings", ".", "TrimSuffix", "(", "name", ",", "sep", ")", ",", "sep", ")", ")", "\n", "if", "sub", "==", "nil", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "sub", ",", "nil", "\n", "}" ]
// FindFolder returns a sub-tree or nil, if the subtree does not exist
[ "FindFolder", "returns", "a", "sub", "-", "tree", "or", "nil", "if", "the", "subtree", "does", "not", "exist" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/tree/simple/folder.go#L203-L209
train
gopasspw/gopass
pkg/tree/simple/folder.go
findFolder
func (f *Folder) findFolder(path []string) *Folder { if len(path) < 1 { return f } name := path[0] if next, found := f.Folders[name]; found { return next.findFolder(path[1:]) } return nil }
go
func (f *Folder) findFolder(path []string) *Folder { if len(path) < 1 { return f } name := path[0] if next, found := f.Folders[name]; found { return next.findFolder(path[1:]) } return nil }
[ "func", "(", "f", "*", "Folder", ")", "findFolder", "(", "path", "[", "]", "string", ")", "*", "Folder", "{", "if", "len", "(", "path", ")", "<", "1", "{", "return", "f", "\n", "}", "\n", "name", ":=", "path", "[", "0", "]", "\n", "if", "next", ",", "found", ":=", "f", ".", "Folders", "[", "name", "]", ";", "found", "{", "return", "next", ".", "findFolder", "(", "path", "[", "1", ":", "]", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// findFolder recursively tries to find the named sub-folder
[ "findFolder", "recursively", "tries", "to", "find", "the", "named", "sub", "-", "folder" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/tree/simple/folder.go#L212-L221
train
gopasspw/gopass
pkg/tree/simple/folder.go
addFile
func (f *Folder) addFile(path []string, contentType string) error { if len(path) < 1 { return errors.Errorf("Path must not be empty") } name := path[0] if len(path) == 1 { if _, found := f.Files[name]; found { return errors.Errorf("File %s exists", name) } f.Files[name] = &File{ Name: name, Metadata: map[string]string{ "Content-Type": contentType, }, } return nil } next := f.getFolder(name) return next.addFile(path[1:], contentType) }
go
func (f *Folder) addFile(path []string, contentType string) error { if len(path) < 1 { return errors.Errorf("Path must not be empty") } name := path[0] if len(path) == 1 { if _, found := f.Files[name]; found { return errors.Errorf("File %s exists", name) } f.Files[name] = &File{ Name: name, Metadata: map[string]string{ "Content-Type": contentType, }, } return nil } next := f.getFolder(name) return next.addFile(path[1:], contentType) }
[ "func", "(", "f", "*", "Folder", ")", "addFile", "(", "path", "[", "]", "string", ",", "contentType", "string", ")", "error", "{", "if", "len", "(", "path", ")", "<", "1", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "name", ":=", "path", "[", "0", "]", "\n", "if", "len", "(", "path", ")", "==", "1", "{", "if", "_", ",", "found", ":=", "f", ".", "Files", "[", "name", "]", ";", "found", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "name", ")", "\n", "}", "\n", "f", ".", "Files", "[", "name", "]", "=", "&", "File", "{", "Name", ":", "name", ",", "Metadata", ":", "map", "[", "string", "]", "string", "{", "\"", "\"", ":", "contentType", ",", "}", ",", "}", "\n", "return", "nil", "\n", "}", "\n", "next", ":=", "f", ".", "getFolder", "(", "name", ")", "\n", "return", "next", ".", "addFile", "(", "path", "[", "1", ":", "]", ",", "contentType", ")", "\n", "}" ]
// addFile adds new file
[ "addFile", "adds", "new", "file" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/tree/simple/folder.go#L224-L243
train
gopasspw/gopass
pkg/jsonapi/api.go
ReadAndRespond
func (api *API) ReadAndRespond(ctx context.Context) error { silentCtx := out.WithHidden(ctx, true) message, err := readMessage(api.Reader) if message == nil || err != nil { return err } return api.respondMessage(silentCtx, message) }
go
func (api *API) ReadAndRespond(ctx context.Context) error { silentCtx := out.WithHidden(ctx, true) message, err := readMessage(api.Reader) if message == nil || err != nil { return err } return api.respondMessage(silentCtx, message) }
[ "func", "(", "api", "*", "API", ")", "ReadAndRespond", "(", "ctx", "context", ".", "Context", ")", "error", "{", "silentCtx", ":=", "out", ".", "WithHidden", "(", "ctx", ",", "true", ")", "\n", "message", ",", "err", ":=", "readMessage", "(", "api", ".", "Reader", ")", "\n", "if", "message", "==", "nil", "||", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "api", ".", "respondMessage", "(", "silentCtx", ",", "message", ")", "\n", "}" ]
// ReadAndRespond a single message
[ "ReadAndRespond", "a", "single", "message" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/jsonapi/api.go#L21-L29
train
gopasspw/gopass
pkg/jsonapi/api.go
RespondError
func (api *API) RespondError(err error) error { var response errorResponse response.Error = err.Error() return sendSerializedJSONMessage(response, api.Writer) }
go
func (api *API) RespondError(err error) error { var response errorResponse response.Error = err.Error() return sendSerializedJSONMessage(response, api.Writer) }
[ "func", "(", "api", "*", "API", ")", "RespondError", "(", "err", "error", ")", "error", "{", "var", "response", "errorResponse", "\n", "response", ".", "Error", "=", "err", ".", "Error", "(", ")", "\n\n", "return", "sendSerializedJSONMessage", "(", "response", ",", "api", ".", "Writer", ")", "\n", "}" ]
// RespondError sends err as JSON response
[ "RespondError", "sends", "err", "as", "JSON", "response" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/jsonapi/api.go#L32-L37
train
gopasspw/gopass
pkg/pinentry/pinentry.go
New
func New() (*Client, error) { cmd := exec.Command(GetBinary()) stdin, err := cmd.StdinPipe() if err != nil { return nil, err } stdout, err := cmd.StdoutPipe() if err != nil { return nil, err } br := bufio.NewReader(stdout) if err := cmd.Start(); err != nil { return nil, err } // check welcome message banner, _, err := br.ReadLine() if err != nil { return nil, err } if !bytes.HasPrefix(banner, []byte("OK")) { return nil, fmt.Errorf("wrong banner: %s", banner) } cl := &Client{ cmd: cmd, in: stdin, out: br, } return cl, nil }
go
func New() (*Client, error) { cmd := exec.Command(GetBinary()) stdin, err := cmd.StdinPipe() if err != nil { return nil, err } stdout, err := cmd.StdoutPipe() if err != nil { return nil, err } br := bufio.NewReader(stdout) if err := cmd.Start(); err != nil { return nil, err } // check welcome message banner, _, err := br.ReadLine() if err != nil { return nil, err } if !bytes.HasPrefix(banner, []byte("OK")) { return nil, fmt.Errorf("wrong banner: %s", banner) } cl := &Client{ cmd: cmd, in: stdin, out: br, } return cl, nil }
[ "func", "New", "(", ")", "(", "*", "Client", ",", "error", ")", "{", "cmd", ":=", "exec", ".", "Command", "(", "GetBinary", "(", ")", ")", "\n", "stdin", ",", "err", ":=", "cmd", ".", "StdinPipe", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "stdout", ",", "err", ":=", "cmd", ".", "StdoutPipe", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "br", ":=", "bufio", ".", "NewReader", "(", "stdout", ")", "\n", "if", "err", ":=", "cmd", ".", "Start", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// check welcome message", "banner", ",", "_", ",", "err", ":=", "br", ".", "ReadLine", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "!", "bytes", ".", "HasPrefix", "(", "banner", ",", "[", "]", "byte", "(", "\"", "\"", ")", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "banner", ")", "\n", "}", "\n\n", "cl", ":=", "&", "Client", "{", "cmd", ":", "cmd", ",", "in", ":", "stdin", ",", "out", ":", "br", ",", "}", "\n\n", "return", "cl", ",", "nil", "\n", "}" ]
// New creates a new pinentry client
[ "New", "creates", "a", "new", "pinentry", "client" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/pinentry/pinentry.go#L22-L55
train
gopasspw/gopass
pkg/pinentry/pinentry.go
Confirm
func (c *Client) Confirm() bool { if err := c.Set("confirm", ""); err == nil { return true } return false }
go
func (c *Client) Confirm() bool { if err := c.Set("confirm", ""); err == nil { return true } return false }
[ "func", "(", "c", "*", "Client", ")", "Confirm", "(", ")", "bool", "{", "if", "err", ":=", "c", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", ";", "err", "==", "nil", "{", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}" ]
// Confirm sends the confirm message
[ "Confirm", "sends", "the", "confirm", "message" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/pinentry/pinentry.go#L63-L68
train
gopasspw/gopass
pkg/pinentry/pinentry.go
Set
func (c *Client) Set(key, value string) error { key = strings.ToUpper(key) if value != "" { value = " " + value } val := "SET" + key + value + "\n" if _, err := c.in.Write([]byte(val)); err != nil { return err } line, _, _ := c.out.ReadLine() if string(line) != "OK" { return errors.Errorf("error: %s", line) } return nil }
go
func (c *Client) Set(key, value string) error { key = strings.ToUpper(key) if value != "" { value = " " + value } val := "SET" + key + value + "\n" if _, err := c.in.Write([]byte(val)); err != nil { return err } line, _, _ := c.out.ReadLine() if string(line) != "OK" { return errors.Errorf("error: %s", line) } return nil }
[ "func", "(", "c", "*", "Client", ")", "Set", "(", "key", ",", "value", "string", ")", "error", "{", "key", "=", "strings", ".", "ToUpper", "(", "key", ")", "\n", "if", "value", "!=", "\"", "\"", "{", "value", "=", "\"", "\"", "+", "value", "\n", "}", "\n", "val", ":=", "\"", "\"", "+", "key", "+", "value", "+", "\"", "\\n", "\"", "\n", "if", "_", ",", "err", ":=", "c", ".", "in", ".", "Write", "(", "[", "]", "byte", "(", "val", ")", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "line", ",", "_", ",", "_", ":=", "c", ".", "out", ".", "ReadLine", "(", ")", "\n", "if", "string", "(", "line", ")", "!=", "\"", "\"", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "line", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Set sets a key
[ "Set", "sets", "a", "key" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/pinentry/pinentry.go#L71-L85
train
gopasspw/gopass
pkg/pinentry/pinentry.go
GetPin
func (c *Client) GetPin() ([]byte, error) { if _, err := c.in.Write([]byte("GETPIN\n")); err != nil { return nil, err } pin, _, err := c.out.ReadLine() if err != nil { return nil, err } if bytes.HasPrefix(pin, []byte("OK")) { return nil, nil } if !bytes.HasPrefix(pin, []byte("D ")) { return nil, fmt.Errorf("unexpected response: %s", pin) } ok, _, err := c.out.ReadLine() if err != nil { return nil, err } if !bytes.HasPrefix(ok, []byte("OK")) { return nil, fmt.Errorf("unexpected response: %s", ok) } return pin[2:], nil }
go
func (c *Client) GetPin() ([]byte, error) { if _, err := c.in.Write([]byte("GETPIN\n")); err != nil { return nil, err } pin, _, err := c.out.ReadLine() if err != nil { return nil, err } if bytes.HasPrefix(pin, []byte("OK")) { return nil, nil } if !bytes.HasPrefix(pin, []byte("D ")) { return nil, fmt.Errorf("unexpected response: %s", pin) } ok, _, err := c.out.ReadLine() if err != nil { return nil, err } if !bytes.HasPrefix(ok, []byte("OK")) { return nil, fmt.Errorf("unexpected response: %s", ok) } return pin[2:], nil }
[ "func", "(", "c", "*", "Client", ")", "GetPin", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "if", "_", ",", "err", ":=", "c", ".", "in", ".", "Write", "(", "[", "]", "byte", "(", "\"", "\\n", "\"", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "pin", ",", "_", ",", "err", ":=", "c", ".", "out", ".", "ReadLine", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "bytes", ".", "HasPrefix", "(", "pin", ",", "[", "]", "byte", "(", "\"", "\"", ")", ")", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "if", "!", "bytes", ".", "HasPrefix", "(", "pin", ",", "[", "]", "byte", "(", "\"", "\"", ")", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "pin", ")", "\n", "}", "\n\n", "ok", ",", "_", ",", "err", ":=", "c", ".", "out", ".", "ReadLine", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "!", "bytes", ".", "HasPrefix", "(", "ok", ",", "[", "]", "byte", "(", "\"", "\"", ")", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "ok", ")", "\n", "}", "\n", "return", "pin", "[", "2", ":", "]", ",", "nil", "\n", "}" ]
// GetPin asks for the pin
[ "GetPin", "asks", "for", "the", "pin" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/pinentry/pinentry.go#L88-L111
train
gopasspw/gopass
pkg/action/config.go
Config
func (s *Action) Config(ctx context.Context, c *cli.Context) error { if len(c.Args()) < 1 { s.printConfigValues(ctx, "") return nil } if len(c.Args()) == 1 { s.printConfigValues(ctx, "", c.Args()[0]) return nil } if len(c.Args()) > 2 { return ExitError(ctx, ExitUsage, nil, "Usage: %s config key value", s.Name) } if err := s.setConfigValue(ctx, c.String("store"), c.Args()[0], c.Args()[1]); err != nil { return ExitError(ctx, ExitUnknown, err, "Error setting config value") } return nil }
go
func (s *Action) Config(ctx context.Context, c *cli.Context) error { if len(c.Args()) < 1 { s.printConfigValues(ctx, "") return nil } if len(c.Args()) == 1 { s.printConfigValues(ctx, "", c.Args()[0]) return nil } if len(c.Args()) > 2 { return ExitError(ctx, ExitUsage, nil, "Usage: %s config key value", s.Name) } if err := s.setConfigValue(ctx, c.String("store"), c.Args()[0], c.Args()[1]); err != nil { return ExitError(ctx, ExitUnknown, err, "Error setting config value") } return nil }
[ "func", "(", "s", "*", "Action", ")", "Config", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "if", "len", "(", "c", ".", "Args", "(", ")", ")", "<", "1", "{", "s", ".", "printConfigValues", "(", "ctx", ",", "\"", "\"", ")", "\n", "return", "nil", "\n", "}", "\n\n", "if", "len", "(", "c", ".", "Args", "(", ")", ")", "==", "1", "{", "s", ".", "printConfigValues", "(", "ctx", ",", "\"", "\"", ",", "c", ".", "Args", "(", ")", "[", "0", "]", ")", "\n", "return", "nil", "\n", "}", "\n\n", "if", "len", "(", "c", ".", "Args", "(", ")", ")", ">", "2", "{", "return", "ExitError", "(", "ctx", ",", "ExitUsage", ",", "nil", ",", "\"", "\"", ",", "s", ".", "Name", ")", "\n", "}", "\n\n", "if", "err", ":=", "s", ".", "setConfigValue", "(", "ctx", ",", "c", ".", "String", "(", "\"", "\"", ")", ",", "c", ".", "Args", "(", ")", "[", "0", "]", ",", "c", ".", "Args", "(", ")", "[", "1", "]", ")", ";", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitUnknown", ",", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Config handles changes to the gopass configuration
[ "Config", "handles", "changes", "to", "the", "gopass", "configuration" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/config.go#L15-L34
train
gopasspw/gopass
pkg/action/config.go
ConfigComplete
func (s *Action) ConfigComplete(c *cli.Context) { cm := s.cfg.Root.ConfigMap() keys := make([]string, 0, len(cm)) for k := range cm { keys = append(keys, k) } sort.Strings(keys) for _, k := range keys { fmt.Fprintln(stdout, k) } }
go
func (s *Action) ConfigComplete(c *cli.Context) { cm := s.cfg.Root.ConfigMap() keys := make([]string, 0, len(cm)) for k := range cm { keys = append(keys, k) } sort.Strings(keys) for _, k := range keys { fmt.Fprintln(stdout, k) } }
[ "func", "(", "s", "*", "Action", ")", "ConfigComplete", "(", "c", "*", "cli", ".", "Context", ")", "{", "cm", ":=", "s", ".", "cfg", ".", "Root", ".", "ConfigMap", "(", ")", "\n", "keys", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "cm", ")", ")", "\n", "for", "k", ":=", "range", "cm", "{", "keys", "=", "append", "(", "keys", ",", "k", ")", "\n", "}", "\n", "sort", ".", "Strings", "(", "keys", ")", "\n", "for", "_", ",", "k", ":=", "range", "keys", "{", "fmt", ".", "Fprintln", "(", "stdout", ",", "k", ")", "\n", "}", "\n", "}" ]
// ConfigComplete will print the list of valid config keys
[ "ConfigComplete", "will", "print", "the", "list", "of", "valid", "config", "keys" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/config.go#L101-L111
train
gopasspw/gopass
pkg/fsutil/umask.go
Umask
func Umask() int { for _, en := range []string{"GOPASS_UMASK", "PASSWORD_STORE_UMASK"} { if um := os.Getenv(en); um != "" { if iv, err := strconv.ParseInt(um, 8, 32); err == nil && iv >= 0 && iv <= 0777 { return int(iv) } } } return 077 }
go
func Umask() int { for _, en := range []string{"GOPASS_UMASK", "PASSWORD_STORE_UMASK"} { if um := os.Getenv(en); um != "" { if iv, err := strconv.ParseInt(um, 8, 32); err == nil && iv >= 0 && iv <= 0777 { return int(iv) } } } return 077 }
[ "func", "Umask", "(", ")", "int", "{", "for", "_", ",", "en", ":=", "range", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", "}", "{", "if", "um", ":=", "os", ".", "Getenv", "(", "en", ")", ";", "um", "!=", "\"", "\"", "{", "if", "iv", ",", "err", ":=", "strconv", ".", "ParseInt", "(", "um", ",", "8", ",", "32", ")", ";", "err", "==", "nil", "&&", "iv", ">=", "0", "&&", "iv", "<=", "0777", "{", "return", "int", "(", "iv", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "077", "\n", "}" ]
// Umask extracts the umask from env
[ "Umask", "extracts", "the", "umask", "from", "env" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/fsutil/umask.go#L9-L18
train
gopasspw/gopass
pkg/store/root/init.go
Initialized
func (r *Store) Initialized(ctx context.Context) (bool, error) { if r.store == nil { out.Debug(ctx, "initializing store and possible sub-stores") if err := r.initialize(ctx); err != nil { return false, errors.Wrapf(err, "failed to initialized stores: %s", err) } } return r.store.Initialized(ctx), nil }
go
func (r *Store) Initialized(ctx context.Context) (bool, error) { if r.store == nil { out.Debug(ctx, "initializing store and possible sub-stores") if err := r.initialize(ctx); err != nil { return false, errors.Wrapf(err, "failed to initialized stores: %s", err) } } return r.store.Initialized(ctx), nil }
[ "func", "(", "r", "*", "Store", ")", "Initialized", "(", "ctx", "context", ".", "Context", ")", "(", "bool", ",", "error", ")", "{", "if", "r", ".", "store", "==", "nil", "{", "out", ".", "Debug", "(", "ctx", ",", "\"", "\"", ")", "\n", "if", "err", ":=", "r", ".", "initialize", "(", "ctx", ")", ";", "err", "!=", "nil", "{", "return", "false", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "}", "\n", "return", "r", ".", "store", ".", "Initialized", "(", "ctx", ")", ",", "nil", "\n", "}" ]
// Initialized checks on disk if .gpg-id was generated and thus returns true.
[ "Initialized", "checks", "on", "disk", "if", ".", "gpg", "-", "id", "was", "generated", "and", "thus", "returns", "true", "." ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/init.go#L16-L24
train
gopasspw/gopass
pkg/hibp/api/client.go
Lookup
func Lookup(ctx context.Context, shaSum string) (uint64, error) { if len(shaSum) != 40 { return 0, errors.Errorf("invalid shasum") } shaSum = strings.ToUpper(shaSum) prefix := shaSum[:5] suffix := shaSum[5:] var count uint64 url := fmt.Sprintf("%s/range/%s", URL, prefix) op := func() error { out.Debug(ctx, "[%s] HTTP Request: %s", shaSum, url) resp, err := http.Get(url) if err != nil { return err } defer func() { _ = resp.Body.Close() }() if resp.StatusCode == http.StatusNotFound { return nil } body, err := ioutil.ReadAll(resp.Body) if err != nil { return err } if resp.StatusCode != http.StatusOK { return fmt.Errorf("HTTP request failed: %s %s", resp.Status, body) } for _, line := range strings.Split(string(body), "\n") { line = strings.TrimSpace(line) if len(line) < 37 { continue } if line[:35] != suffix { continue } if iv, err := strconv.ParseUint(line[36:], 10, 64); err == nil { count = iv return nil } } return nil } bo := backoff.NewExponentialBackOff() bo.MaxElapsedTime = 10 * time.Second err := backoff.Retry(op, bo) return count, err }
go
func Lookup(ctx context.Context, shaSum string) (uint64, error) { if len(shaSum) != 40 { return 0, errors.Errorf("invalid shasum") } shaSum = strings.ToUpper(shaSum) prefix := shaSum[:5] suffix := shaSum[5:] var count uint64 url := fmt.Sprintf("%s/range/%s", URL, prefix) op := func() error { out.Debug(ctx, "[%s] HTTP Request: %s", shaSum, url) resp, err := http.Get(url) if err != nil { return err } defer func() { _ = resp.Body.Close() }() if resp.StatusCode == http.StatusNotFound { return nil } body, err := ioutil.ReadAll(resp.Body) if err != nil { return err } if resp.StatusCode != http.StatusOK { return fmt.Errorf("HTTP request failed: %s %s", resp.Status, body) } for _, line := range strings.Split(string(body), "\n") { line = strings.TrimSpace(line) if len(line) < 37 { continue } if line[:35] != suffix { continue } if iv, err := strconv.ParseUint(line[36:], 10, 64); err == nil { count = iv return nil } } return nil } bo := backoff.NewExponentialBackOff() bo.MaxElapsedTime = 10 * time.Second err := backoff.Retry(op, bo) return count, err }
[ "func", "Lookup", "(", "ctx", "context", ".", "Context", ",", "shaSum", "string", ")", "(", "uint64", ",", "error", ")", "{", "if", "len", "(", "shaSum", ")", "!=", "40", "{", "return", "0", ",", "errors", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "shaSum", "=", "strings", ".", "ToUpper", "(", "shaSum", ")", "\n", "prefix", ":=", "shaSum", "[", ":", "5", "]", "\n", "suffix", ":=", "shaSum", "[", "5", ":", "]", "\n\n", "var", "count", "uint64", "\n", "url", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "URL", ",", "prefix", ")", "\n\n", "op", ":=", "func", "(", ")", "error", "{", "out", ".", "Debug", "(", "ctx", ",", "\"", "\"", ",", "shaSum", ",", "url", ")", "\n", "resp", ",", "err", ":=", "http", ".", "Get", "(", "url", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "func", "(", ")", "{", "_", "=", "resp", ".", "Body", ".", "Close", "(", ")", "\n", "}", "(", ")", "\n\n", "if", "resp", ".", "StatusCode", "==", "http", ".", "StatusNotFound", "{", "return", "nil", "\n", "}", "\n\n", "body", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "resp", ".", "Body", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "resp", ".", "StatusCode", "!=", "http", ".", "StatusOK", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "resp", ".", "Status", ",", "body", ")", "\n", "}", "\n\n", "for", "_", ",", "line", ":=", "range", "strings", ".", "Split", "(", "string", "(", "body", ")", ",", "\"", "\\n", "\"", ")", "{", "line", "=", "strings", ".", "TrimSpace", "(", "line", ")", "\n", "if", "len", "(", "line", ")", "<", "37", "{", "continue", "\n", "}", "\n", "if", "line", "[", ":", "35", "]", "!=", "suffix", "{", "continue", "\n", "}", "\n", "if", "iv", ",", "err", ":=", "strconv", ".", "ParseUint", "(", "line", "[", "36", ":", "]", ",", "10", ",", "64", ")", ";", "err", "==", "nil", "{", "count", "=", "iv", "\n", "return", "nil", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}", "\n\n", "bo", ":=", "backoff", ".", "NewExponentialBackOff", "(", ")", "\n", "bo", ".", "MaxElapsedTime", "=", "10", "*", "time", ".", "Second", "\n\n", "err", ":=", "backoff", ".", "Retry", "(", "op", ",", "bo", ")", "\n", "return", "count", ",", "err", "\n", "}" ]
// Lookup performs a lookup against the HIBP v2 API
[ "Lookup", "performs", "a", "lookup", "against", "the", "HIBP", "v2", "API" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/hibp/api/client.go#L22-L78
train
gopasspw/gopass
pkg/action/git.go
GitInit
func (s *Action) GitInit(ctx context.Context, c *cli.Context) error { store := c.String("store") un := c.String("username") ue := c.String("useremail") ctx = backend.WithRCSBackendString(ctx, c.String("rcs")) // default to git if !backend.HasRCSBackend(ctx) { ctx = backend.WithRCSBackend(ctx, backend.GitCLI) } if err := s.rcsInit(ctx, store, un, ue); err != nil { return ExitError(ctx, ExitGit, err, "failed to initialize git: %s", err) } return nil }
go
func (s *Action) GitInit(ctx context.Context, c *cli.Context) error { store := c.String("store") un := c.String("username") ue := c.String("useremail") ctx = backend.WithRCSBackendString(ctx, c.String("rcs")) // default to git if !backend.HasRCSBackend(ctx) { ctx = backend.WithRCSBackend(ctx, backend.GitCLI) } if err := s.rcsInit(ctx, store, un, ue); err != nil { return ExitError(ctx, ExitGit, err, "failed to initialize git: %s", err) } return nil }
[ "func", "(", "s", "*", "Action", ")", "GitInit", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "store", ":=", "c", ".", "String", "(", "\"", "\"", ")", "\n", "un", ":=", "c", ".", "String", "(", "\"", "\"", ")", "\n", "ue", ":=", "c", ".", "String", "(", "\"", "\"", ")", "\n", "ctx", "=", "backend", ".", "WithRCSBackendString", "(", "ctx", ",", "c", ".", "String", "(", "\"", "\"", ")", ")", "\n\n", "// default to git", "if", "!", "backend", ".", "HasRCSBackend", "(", "ctx", ")", "{", "ctx", "=", "backend", ".", "WithRCSBackend", "(", "ctx", ",", "backend", ".", "GitCLI", ")", "\n", "}", "\n\n", "if", "err", ":=", "s", ".", "rcsInit", "(", "ctx", ",", "store", ",", "un", ",", "ue", ")", ";", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitGit", ",", "err", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// GitInit initializes a git repo including basic configuration
[ "GitInit", "initializes", "a", "git", "repo", "including", "basic", "configuration" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/git.go#L18-L33
train
gopasspw/gopass
pkg/action/git.go
GitAddRemote
func (s *Action) GitAddRemote(ctx context.Context, c *cli.Context) error { store := c.String("store") remote := c.Args().Get(0) url := c.Args().Get(1) if remote == "" || url == "" { return ExitError(ctx, ExitUsage, nil, "Usage: %s git remote add <REMOTE> <URL>", s.Name) } return s.Store.GitAddRemote(ctx, store, remote, url) }
go
func (s *Action) GitAddRemote(ctx context.Context, c *cli.Context) error { store := c.String("store") remote := c.Args().Get(0) url := c.Args().Get(1) if remote == "" || url == "" { return ExitError(ctx, ExitUsage, nil, "Usage: %s git remote add <REMOTE> <URL>", s.Name) } return s.Store.GitAddRemote(ctx, store, remote, url) }
[ "func", "(", "s", "*", "Action", ")", "GitAddRemote", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "store", ":=", "c", ".", "String", "(", "\"", "\"", ")", "\n", "remote", ":=", "c", ".", "Args", "(", ")", ".", "Get", "(", "0", ")", "\n", "url", ":=", "c", ".", "Args", "(", ")", ".", "Get", "(", "1", ")", "\n\n", "if", "remote", "==", "\"", "\"", "||", "url", "==", "\"", "\"", "{", "return", "ExitError", "(", "ctx", ",", "ExitUsage", ",", "nil", ",", "\"", "\"", ",", "s", ".", "Name", ")", "\n", "}", "\n\n", "return", "s", ".", "Store", ".", "GitAddRemote", "(", "ctx", ",", "store", ",", "remote", ",", "url", ")", "\n", "}" ]
// GitAddRemote adds a new git remote
[ "GitAddRemote", "adds", "a", "new", "git", "remote" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/git.go#L79-L89
train
gopasspw/gopass
pkg/action/git.go
GitPull
func (s *Action) GitPull(ctx context.Context, c *cli.Context) error { store := c.String("store") origin := c.Args().Get(0) branch := c.Args().Get(1) if origin == "" { origin = "origin" } if branch == "" { branch = "master" } return s.Store.GitPull(ctx, store, origin, branch) }
go
func (s *Action) GitPull(ctx context.Context, c *cli.Context) error { store := c.String("store") origin := c.Args().Get(0) branch := c.Args().Get(1) if origin == "" { origin = "origin" } if branch == "" { branch = "master" } return s.Store.GitPull(ctx, store, origin, branch) }
[ "func", "(", "s", "*", "Action", ")", "GitPull", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "store", ":=", "c", ".", "String", "(", "\"", "\"", ")", "\n", "origin", ":=", "c", ".", "Args", "(", ")", ".", "Get", "(", "0", ")", "\n", "branch", ":=", "c", ".", "Args", "(", ")", ".", "Get", "(", "1", ")", "\n\n", "if", "origin", "==", "\"", "\"", "{", "origin", "=", "\"", "\"", "\n", "}", "\n", "if", "branch", "==", "\"", "\"", "{", "branch", "=", "\"", "\"", "\n", "}", "\n", "return", "s", ".", "Store", ".", "GitPull", "(", "ctx", ",", "store", ",", "origin", ",", "branch", ")", "\n", "}" ]
// GitPull pulls from a git remote
[ "GitPull", "pulls", "from", "a", "git", "remote" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/git.go#L104-L116
train
gopasspw/gopass
pkg/action/git.go
GitPush
func (s *Action) GitPush(ctx context.Context, c *cli.Context) error { store := c.String("store") origin := c.Args().Get(0) branch := c.Args().Get(1) if origin == "" || branch == "" { return ExitError(ctx, ExitUsage, nil, "Usage: %s git push <ORIGIN> <BRANCH>", s.Name) } return s.Store.GitPush(ctx, store, origin, branch) }
go
func (s *Action) GitPush(ctx context.Context, c *cli.Context) error { store := c.String("store") origin := c.Args().Get(0) branch := c.Args().Get(1) if origin == "" || branch == "" { return ExitError(ctx, ExitUsage, nil, "Usage: %s git push <ORIGIN> <BRANCH>", s.Name) } return s.Store.GitPush(ctx, store, origin, branch) }
[ "func", "(", "s", "*", "Action", ")", "GitPush", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "store", ":=", "c", ".", "String", "(", "\"", "\"", ")", "\n", "origin", ":=", "c", ".", "Args", "(", ")", ".", "Get", "(", "0", ")", "\n", "branch", ":=", "c", ".", "Args", "(", ")", ".", "Get", "(", "1", ")", "\n\n", "if", "origin", "==", "\"", "\"", "||", "branch", "==", "\"", "\"", "{", "return", "ExitError", "(", "ctx", ",", "ExitUsage", ",", "nil", ",", "\"", "\"", ",", "s", ".", "Name", ")", "\n", "}", "\n", "return", "s", ".", "Store", ".", "GitPush", "(", "ctx", ",", "store", ",", "origin", ",", "branch", ")", "\n", "}" ]
// GitPush pushes to a git remote
[ "GitPush", "pushes", "to", "a", "git", "remote" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/git.go#L119-L128
train
gopasspw/gopass
pkg/store/sub/store.go
New
func New(ctx context.Context, sc recipientHashStorer, alias string, u *backend.URL, cfgdir string, agent *client.Client) (*Store, error) { out.Debug(ctx, "sub.New - URL: %s", u.String()) s := &Store{ alias: alias, url: u, rcs: noop.New(), cfgdir: cfgdir, agent: agent, sc: sc, } // init store backend if backend.HasStorageBackend(ctx) { s.url.Storage = backend.GetStorageBackend(ctx) out.Debug(ctx, "sub.New - Using storage backend from ctx: %s", backend.StorageBackendName(s.url.Storage)) } if err := s.initStorageBackend(ctx); err != nil { return nil, errors.Wrapf(err, "failed to init storage backend: %s", err) } // init sync backend if backend.HasRCSBackend(ctx) { s.url.RCS = backend.GetRCSBackend(ctx) out.Debug(ctx, "sub.New - Using RCS backend from ctx: %s", backend.RCSBackendName(s.url.RCS)) } if err := s.initRCSBackend(ctx); err != nil { return nil, errors.Wrapf(err, "failed to init RCS backend: %s", err) } // init crypto backend if backend.HasCryptoBackend(ctx) { s.url.Crypto = backend.GetCryptoBackend(ctx) out.Debug(ctx, "sub.New - Using Crypto backend from ctx: %s", backend.CryptoBackendName(s.url.Crypto)) } if err := s.initCryptoBackend(ctx); err != nil { return nil, errors.Wrapf(err, "failed to init crypto backend: %s", err) } out.Debug(ctx, "sub.New - initialized - storage: %s (%p) - rcs: %s (%p) - crypto: %s (%p)", s.storage.Name(), s.storage, s.rcs.Name(), s.rcs, s.crypto.Name(), s.crypto) return s, nil }
go
func New(ctx context.Context, sc recipientHashStorer, alias string, u *backend.URL, cfgdir string, agent *client.Client) (*Store, error) { out.Debug(ctx, "sub.New - URL: %s", u.String()) s := &Store{ alias: alias, url: u, rcs: noop.New(), cfgdir: cfgdir, agent: agent, sc: sc, } // init store backend if backend.HasStorageBackend(ctx) { s.url.Storage = backend.GetStorageBackend(ctx) out.Debug(ctx, "sub.New - Using storage backend from ctx: %s", backend.StorageBackendName(s.url.Storage)) } if err := s.initStorageBackend(ctx); err != nil { return nil, errors.Wrapf(err, "failed to init storage backend: %s", err) } // init sync backend if backend.HasRCSBackend(ctx) { s.url.RCS = backend.GetRCSBackend(ctx) out.Debug(ctx, "sub.New - Using RCS backend from ctx: %s", backend.RCSBackendName(s.url.RCS)) } if err := s.initRCSBackend(ctx); err != nil { return nil, errors.Wrapf(err, "failed to init RCS backend: %s", err) } // init crypto backend if backend.HasCryptoBackend(ctx) { s.url.Crypto = backend.GetCryptoBackend(ctx) out.Debug(ctx, "sub.New - Using Crypto backend from ctx: %s", backend.CryptoBackendName(s.url.Crypto)) } if err := s.initCryptoBackend(ctx); err != nil { return nil, errors.Wrapf(err, "failed to init crypto backend: %s", err) } out.Debug(ctx, "sub.New - initialized - storage: %s (%p) - rcs: %s (%p) - crypto: %s (%p)", s.storage.Name(), s.storage, s.rcs.Name(), s.rcs, s.crypto.Name(), s.crypto) return s, nil }
[ "func", "New", "(", "ctx", "context", ".", "Context", ",", "sc", "recipientHashStorer", ",", "alias", "string", ",", "u", "*", "backend", ".", "URL", ",", "cfgdir", "string", ",", "agent", "*", "client", ".", "Client", ")", "(", "*", "Store", ",", "error", ")", "{", "out", ".", "Debug", "(", "ctx", ",", "\"", "\"", ",", "u", ".", "String", "(", ")", ")", "\n\n", "s", ":=", "&", "Store", "{", "alias", ":", "alias", ",", "url", ":", "u", ",", "rcs", ":", "noop", ".", "New", "(", ")", ",", "cfgdir", ":", "cfgdir", ",", "agent", ":", "agent", ",", "sc", ":", "sc", ",", "}", "\n\n", "// init store backend", "if", "backend", ".", "HasStorageBackend", "(", "ctx", ")", "{", "s", ".", "url", ".", "Storage", "=", "backend", ".", "GetStorageBackend", "(", "ctx", ")", "\n", "out", ".", "Debug", "(", "ctx", ",", "\"", "\"", ",", "backend", ".", "StorageBackendName", "(", "s", ".", "url", ".", "Storage", ")", ")", "\n", "}", "\n", "if", "err", ":=", "s", ".", "initStorageBackend", "(", "ctx", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// init sync backend", "if", "backend", ".", "HasRCSBackend", "(", "ctx", ")", "{", "s", ".", "url", ".", "RCS", "=", "backend", ".", "GetRCSBackend", "(", "ctx", ")", "\n", "out", ".", "Debug", "(", "ctx", ",", "\"", "\"", ",", "backend", ".", "RCSBackendName", "(", "s", ".", "url", ".", "RCS", ")", ")", "\n", "}", "\n", "if", "err", ":=", "s", ".", "initRCSBackend", "(", "ctx", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// init crypto backend", "if", "backend", ".", "HasCryptoBackend", "(", "ctx", ")", "{", "s", ".", "url", ".", "Crypto", "=", "backend", ".", "GetCryptoBackend", "(", "ctx", ")", "\n", "out", ".", "Debug", "(", "ctx", ",", "\"", "\"", ",", "backend", ".", "CryptoBackendName", "(", "s", ".", "url", ".", "Crypto", ")", ")", "\n", "}", "\n", "if", "err", ":=", "s", ".", "initCryptoBackend", "(", "ctx", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "out", ".", "Debug", "(", "ctx", ",", "\"", "\"", ",", "s", ".", "storage", ".", "Name", "(", ")", ",", "s", ".", "storage", ",", "s", ".", "rcs", ".", "Name", "(", ")", ",", "s", ".", "rcs", ",", "s", ".", "crypto", ".", "Name", "(", ")", ",", "s", ".", "crypto", ")", "\n", "return", "s", ",", "nil", "\n", "}" ]
// New creates a new store, copying settings from the given root store
[ "New", "creates", "a", "new", "store", "copying", "settings", "from", "the", "given", "root", "store" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/store.go#L42-L83
train
gopasspw/gopass
pkg/store/sub/store.go
idFile
func (s *Store) idFile(ctx context.Context, name string) string { fn := name var cnt uint8 for { cnt++ if cnt > 100 { break } if fn == "" || fn == sep { break } gfn := filepath.Join(fn, s.crypto.IDFile()) if s.storage.Exists(ctx, gfn) { return gfn } fn = filepath.Dir(fn) } return s.crypto.IDFile() }
go
func (s *Store) idFile(ctx context.Context, name string) string { fn := name var cnt uint8 for { cnt++ if cnt > 100 { break } if fn == "" || fn == sep { break } gfn := filepath.Join(fn, s.crypto.IDFile()) if s.storage.Exists(ctx, gfn) { return gfn } fn = filepath.Dir(fn) } return s.crypto.IDFile() }
[ "func", "(", "s", "*", "Store", ")", "idFile", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "string", "{", "fn", ":=", "name", "\n", "var", "cnt", "uint8", "\n", "for", "{", "cnt", "++", "\n", "if", "cnt", ">", "100", "{", "break", "\n", "}", "\n", "if", "fn", "==", "\"", "\"", "||", "fn", "==", "sep", "{", "break", "\n", "}", "\n", "gfn", ":=", "filepath", ".", "Join", "(", "fn", ",", "s", ".", "crypto", ".", "IDFile", "(", ")", ")", "\n", "if", "s", ".", "storage", ".", "Exists", "(", "ctx", ",", "gfn", ")", "{", "return", "gfn", "\n", "}", "\n", "fn", "=", "filepath", ".", "Dir", "(", "fn", ")", "\n", "}", "\n", "return", "s", ".", "crypto", ".", "IDFile", "(", ")", "\n", "}" ]
// idFile returns the path to the recipient list for this.storage // it walks up from the given filename until it finds a directory containing // a gpg id file or it leaves the scope of this.storage.
[ "idFile", "returns", "the", "path", "to", "the", "recipient", "list", "for", "this", ".", "storage", "it", "walks", "up", "from", "the", "given", "filename", "until", "it", "finds", "a", "directory", "containing", "a", "gpg", "id", "file", "or", "it", "leaves", "the", "scope", "of", "this", ".", "storage", "." ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/store.go#L88-L106
train
gopasspw/gopass
pkg/store/sub/store.go
Equals
func (s *Store) Equals(other store.Store) bool { if other == nil { return false } return s.URL() == other.URL() }
go
func (s *Store) Equals(other store.Store) bool { if other == nil { return false } return s.URL() == other.URL() }
[ "func", "(", "s", "*", "Store", ")", "Equals", "(", "other", "store", ".", "Store", ")", "bool", "{", "if", "other", "==", "nil", "{", "return", "false", "\n", "}", "\n", "return", "s", ".", "URL", "(", ")", "==", "other", ".", "URL", "(", ")", "\n", "}" ]
// Equals returns true if this.storage has the same on-disk path as the other
[ "Equals", "returns", "true", "if", "this", ".", "storage", "has", "the", "same", "on", "-", "disk", "path", "as", "the", "other" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/store.go#L109-L114
train
gopasspw/gopass
pkg/store/sub/store.go
IsDir
func (s *Store) IsDir(ctx context.Context, name string) bool { return s.storage.IsDir(ctx, name) }
go
func (s *Store) IsDir(ctx context.Context, name string) bool { return s.storage.IsDir(ctx, name) }
[ "func", "(", "s", "*", "Store", ")", "IsDir", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "bool", "{", "return", "s", ".", "storage", ".", "IsDir", "(", "ctx", ",", "name", ")", "\n", "}" ]
// IsDir returns true if the entry is folder inside the store
[ "IsDir", "returns", "true", "if", "the", "entry", "is", "folder", "inside", "the", "store" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/store.go#L117-L119
train