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/ctxutil/ctxutil.go | WithNoColor | func WithNoColor(ctx context.Context, bv bool) context.Context {
return context.WithValue(ctx, ctxKeyNoColor, bv)
} | go | func WithNoColor(ctx context.Context, bv bool) context.Context {
return context.WithValue(ctx, ctxKeyNoColor, bv)
} | [
"func",
"WithNoColor",
"(",
"ctx",
"context",
".",
"Context",
",",
"bv",
"bool",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"ctxKeyNoColor",
",",
"bv",
")",
"\n",
"}"
] | // WithNoColor returns a context with the value for ask for more set | [
"WithNoColor",
"returns",
"a",
"context",
"with",
"the",
"value",
"for",
"ask",
"for",
"more",
"set"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/ctxutil/ctxutil.go#L281-L283 | train |
gopasspw/gopass | pkg/ctxutil/ctxutil.go | HasNoColor | func HasNoColor(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyNoColor).(bool)
return ok
} | go | func HasNoColor(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyNoColor).(bool)
return ok
} | [
"func",
"HasNoColor",
"(",
"ctx",
"context",
".",
"Context",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"ctxKeyNoColor",
")",
".",
"(",
"bool",
")",
"\n",
"return",
"ok",
"\n",
"}"
] | // HasNoColor returns true if a value for NoColor has been set in this context | [
"HasNoColor",
"returns",
"true",
"if",
"a",
"value",
"for",
"NoColor",
"has",
"been",
"set",
"in",
"this",
"context"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/ctxutil/ctxutil.go#L286-L289 | train |
gopasspw/gopass | pkg/ctxutil/ctxutil.go | WithAlwaysYes | func WithAlwaysYes(ctx context.Context, bv bool) context.Context {
return context.WithValue(ctx, ctxKeyAlwaysYes, bv)
} | go | func WithAlwaysYes(ctx context.Context, bv bool) context.Context {
return context.WithValue(ctx, ctxKeyAlwaysYes, bv)
} | [
"func",
"WithAlwaysYes",
"(",
"ctx",
"context",
".",
"Context",
",",
"bv",
"bool",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"ctxKeyAlwaysYes",
",",
"bv",
")",
"\n",
"}"
] | // WithAlwaysYes returns a context with the value of always yes set | [
"WithAlwaysYes",
"returns",
"a",
"context",
"with",
"the",
"value",
"of",
"always",
"yes",
"set"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/ctxutil/ctxutil.go#L301-L303 | train |
gopasspw/gopass | pkg/ctxutil/ctxutil.go | HasAlwaysYes | func HasAlwaysYes(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyAlwaysYes).(bool)
return ok
} | go | func HasAlwaysYes(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyAlwaysYes).(bool)
return ok
} | [
"func",
"HasAlwaysYes",
"(",
"ctx",
"context",
".",
"Context",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"ctxKeyAlwaysYes",
")",
".",
"(",
"bool",
")",
"\n",
"return",
"ok",
"\n",
"}"
] | // HasAlwaysYes returns true if a value for AlwaysYes has been set in this context | [
"HasAlwaysYes",
"returns",
"true",
"if",
"a",
"value",
"for",
"AlwaysYes",
"has",
"been",
"set",
"in",
"this",
"context"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/ctxutil/ctxutil.go#L306-L309 | train |
gopasspw/gopass | pkg/ctxutil/ctxutil.go | WithFuzzySearch | func WithFuzzySearch(ctx context.Context, fuzzy bool) context.Context {
return context.WithValue(ctx, ctxKeyFuzzySearch, fuzzy)
} | go | func WithFuzzySearch(ctx context.Context, fuzzy bool) context.Context {
return context.WithValue(ctx, ctxKeyFuzzySearch, fuzzy)
} | [
"func",
"WithFuzzySearch",
"(",
"ctx",
"context",
".",
"Context",
",",
"fuzzy",
"bool",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"ctxKeyFuzzySearch",
",",
"fuzzy",
")",
"\n",
"}"
] | // WithFuzzySearch returns a context with the value for fuzzy search set | [
"WithFuzzySearch",
"returns",
"a",
"context",
"with",
"the",
"value",
"for",
"fuzzy",
"search",
"set"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/ctxutil/ctxutil.go#L321-L323 | train |
gopasspw/gopass | pkg/ctxutil/ctxutil.go | HasFuzzySearch | func HasFuzzySearch(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyFuzzySearch).(bool)
return ok
} | go | func HasFuzzySearch(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyFuzzySearch).(bool)
return ok
} | [
"func",
"HasFuzzySearch",
"(",
"ctx",
"context",
".",
"Context",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"ctxKeyFuzzySearch",
")",
".",
"(",
"bool",
")",
"\n",
"return",
"ok",
"\n",
"}"
] | // HasFuzzySearch returns true if a value for FuzzySearch has been set in this context | [
"HasFuzzySearch",
"returns",
"true",
"if",
"a",
"value",
"for",
"FuzzySearch",
"has",
"been",
"set",
"in",
"this",
"context"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/ctxutil/ctxutil.go#L326-L329 | train |
gopasspw/gopass | pkg/ctxutil/ctxutil.go | WithVerbose | func WithVerbose(ctx context.Context, verbose bool) context.Context {
return context.WithValue(ctx, ctxKeyVerbose, verbose)
} | go | func WithVerbose(ctx context.Context, verbose bool) context.Context {
return context.WithValue(ctx, ctxKeyVerbose, verbose)
} | [
"func",
"WithVerbose",
"(",
"ctx",
"context",
".",
"Context",
",",
"verbose",
"bool",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"ctxKeyVerbose",
",",
"verbose",
")",
"\n",
"}"
] | // WithVerbose returns a context with the value for verbose set | [
"WithVerbose",
"returns",
"a",
"context",
"with",
"the",
"value",
"for",
"verbose",
"set"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/ctxutil/ctxutil.go#L341-L343 | train |
gopasspw/gopass | pkg/ctxutil/ctxutil.go | HasVerbose | func HasVerbose(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyVerbose).(bool)
return ok
} | go | func HasVerbose(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyVerbose).(bool)
return ok
} | [
"func",
"HasVerbose",
"(",
"ctx",
"context",
".",
"Context",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"ctxKeyVerbose",
")",
".",
"(",
"bool",
")",
"\n",
"return",
"ok",
"\n",
"}"
] | // HasVerbose returns true if a value for Verbose has been set in this context | [
"HasVerbose",
"returns",
"true",
"if",
"a",
"value",
"for",
"Verbose",
"has",
"been",
"set",
"in",
"this",
"context"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/ctxutil/ctxutil.go#L346-L349 | train |
gopasspw/gopass | pkg/ctxutil/ctxutil.go | WithNotifications | func WithNotifications(ctx context.Context, verbose bool) context.Context {
return context.WithValue(ctx, ctxKeyNotifications, verbose)
} | go | func WithNotifications(ctx context.Context, verbose bool) context.Context {
return context.WithValue(ctx, ctxKeyNotifications, verbose)
} | [
"func",
"WithNotifications",
"(",
"ctx",
"context",
".",
"Context",
",",
"verbose",
"bool",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"ctxKeyNotifications",
",",
"verbose",
")",
"\n",
"}"
] | // WithNotifications returns a context with the value for Notifications set | [
"WithNotifications",
"returns",
"a",
"context",
"with",
"the",
"value",
"for",
"Notifications",
"set"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/ctxutil/ctxutil.go#L361-L363 | train |
gopasspw/gopass | pkg/ctxutil/ctxutil.go | HasNotifications | func HasNotifications(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyNotifications).(bool)
return ok
} | go | func HasNotifications(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyNotifications).(bool)
return ok
} | [
"func",
"HasNotifications",
"(",
"ctx",
"context",
".",
"Context",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"ctxKeyNotifications",
")",
".",
"(",
"bool",
")",
"\n",
"return",
"ok",
"\n",
"}"
] | // HasNotifications returns true if a value for Notifications has been set in this context | [
"HasNotifications",
"returns",
"true",
"if",
"a",
"value",
"for",
"Notifications",
"has",
"been",
"set",
"in",
"this",
"context"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/ctxutil/ctxutil.go#L366-L369 | train |
gopasspw/gopass | pkg/ctxutil/ctxutil.go | WithAutoClip | func WithAutoClip(ctx context.Context, bv bool) context.Context {
return context.WithValue(ctx, ctxKeyAutoClip, bv)
} | go | func WithAutoClip(ctx context.Context, bv bool) context.Context {
return context.WithValue(ctx, ctxKeyAutoClip, bv)
} | [
"func",
"WithAutoClip",
"(",
"ctx",
"context",
".",
"Context",
",",
"bv",
"bool",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"ctxKeyAutoClip",
",",
"bv",
")",
"\n",
"}"
] | // WithAutoClip returns a context with the value for AutoClip set | [
"WithAutoClip",
"returns",
"a",
"context",
"with",
"the",
"value",
"for",
"AutoClip",
"set"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/ctxutil/ctxutil.go#L381-L383 | train |
gopasspw/gopass | pkg/ctxutil/ctxutil.go | HasAutoClip | func HasAutoClip(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyAutoClip).(bool)
return ok
} | go | func HasAutoClip(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyAutoClip).(bool)
return ok
} | [
"func",
"HasAutoClip",
"(",
"ctx",
"context",
".",
"Context",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"ctxKeyAutoClip",
")",
".",
"(",
"bool",
")",
"\n",
"return",
"ok",
"\n",
"}"
] | // HasAutoClip returns true if a value for AutoClip has been set in this context | [
"HasAutoClip",
"returns",
"true",
"if",
"a",
"value",
"for",
"AutoClip",
"has",
"been",
"set",
"in",
"this",
"context"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/ctxutil/ctxutil.go#L386-L389 | train |
gopasspw/gopass | pkg/ctxutil/ctxutil.go | WithEditRecipients | func WithEditRecipients(ctx context.Context, bv bool) context.Context {
return context.WithValue(ctx, ctxKeyEditRecipients, bv)
} | go | func WithEditRecipients(ctx context.Context, bv bool) context.Context {
return context.WithValue(ctx, ctxKeyEditRecipients, bv)
} | [
"func",
"WithEditRecipients",
"(",
"ctx",
"context",
".",
"Context",
",",
"bv",
"bool",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"ctxKeyEditRecipients",
",",
"bv",
")",
"\n",
"}"
] | // WithEditRecipients returns a context with the value for EditRecipients set | [
"WithEditRecipients",
"returns",
"a",
"context",
"with",
"the",
"value",
"for",
"EditRecipients",
"set"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/ctxutil/ctxutil.go#L401-L403 | train |
gopasspw/gopass | pkg/ctxutil/ctxutil.go | HasEditRecipients | func HasEditRecipients(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyEditRecipients).(bool)
return ok
} | go | func HasEditRecipients(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyEditRecipients).(bool)
return ok
} | [
"func",
"HasEditRecipients",
"(",
"ctx",
"context",
".",
"Context",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"ctxKeyEditRecipients",
")",
".",
"(",
"bool",
")",
"\n",
"return",
"ok",
"\n",
"}"
] | // HasEditRecipients returns true if a value for EditRecipients has been set in this context | [
"HasEditRecipients",
"returns",
"true",
"if",
"a",
"value",
"for",
"EditRecipients",
"has",
"been",
"set",
"in",
"this",
"context"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/ctxutil/ctxutil.go#L406-L409 | train |
gopasspw/gopass | pkg/ctxutil/ctxutil.go | WithConcurrency | func WithConcurrency(ctx context.Context, to int) context.Context {
return context.WithValue(ctx, ctxKeyConcurrency, to)
} | go | func WithConcurrency(ctx context.Context, to int) context.Context {
return context.WithValue(ctx, ctxKeyConcurrency, to)
} | [
"func",
"WithConcurrency",
"(",
"ctx",
"context",
".",
"Context",
",",
"to",
"int",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"ctxKeyConcurrency",
",",
"to",
")",
"\n",
"}"
] | // WithConcurrency returns a context with the value for clip timeout set | [
"WithConcurrency",
"returns",
"a",
"context",
"with",
"the",
"value",
"for",
"clip",
"timeout",
"set"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/ctxutil/ctxutil.go#L421-L423 | train |
gopasspw/gopass | pkg/ctxutil/ctxutil.go | HasConcurrency | func HasConcurrency(ctx context.Context) bool {
iv, ok := ctx.Value(ctxKeyConcurrency).(int)
if iv <= 1 {
return false
}
return ok
} | go | func HasConcurrency(ctx context.Context) bool {
iv, ok := ctx.Value(ctxKeyConcurrency).(int)
if iv <= 1 {
return false
}
return ok
} | [
"func",
"HasConcurrency",
"(",
"ctx",
"context",
".",
"Context",
")",
"bool",
"{",
"iv",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"ctxKeyConcurrency",
")",
".",
"(",
"int",
")",
"\n",
"if",
"iv",
"<=",
"1",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"ok",
"\n",
"}"
] | // HasConcurrency returns true if a value for Concurrency has been set in this context and is bigger than 1
// since if it is equal to 1, we are not working concurrently. | [
"HasConcurrency",
"returns",
"true",
"if",
"a",
"value",
"for",
"Concurrency",
"has",
"been",
"set",
"in",
"this",
"context",
"and",
"is",
"bigger",
"than",
"1",
"since",
"if",
"it",
"is",
"equal",
"to",
"1",
"we",
"are",
"not",
"working",
"concurrently",
"."
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/ctxutil/ctxutil.go#L427-L433 | train |
gopasspw/gopass | pkg/ctxutil/ctxutil.go | WithProgressCallback | func WithProgressCallback(ctx context.Context, cb ProgressCallback) context.Context {
return context.WithValue(ctx, ctxKeyProgressCallback, cb)
} | go | func WithProgressCallback(ctx context.Context, cb ProgressCallback) context.Context {
return context.WithValue(ctx, ctxKeyProgressCallback, cb)
} | [
"func",
"WithProgressCallback",
"(",
"ctx",
"context",
".",
"Context",
",",
"cb",
"ProgressCallback",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"ctxKeyProgressCallback",
",",
"cb",
")",
"\n",
"}"
] | // WithProgressCallback returns a context with the value of ProgressCallback set | [
"WithProgressCallback",
"returns",
"a",
"context",
"with",
"the",
"value",
"of",
"ProgressCallback",
"set"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/ctxutil/ctxutil.go#L445-L447 | train |
gopasspw/gopass | pkg/ctxutil/ctxutil.go | HasProgressCallback | func HasProgressCallback(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyProgressCallback).(ProgressCallback)
return ok
} | go | func HasProgressCallback(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyProgressCallback).(ProgressCallback)
return ok
} | [
"func",
"HasProgressCallback",
"(",
"ctx",
"context",
".",
"Context",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"ctxKeyProgressCallback",
")",
".",
"(",
"ProgressCallback",
")",
"\n",
"return",
"ok",
"\n",
"}"
] | // HasProgressCallback returns true if a ProgressCallback has been set | [
"HasProgressCallback",
"returns",
"true",
"if",
"a",
"ProgressCallback",
"has",
"been",
"set"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/ctxutil/ctxutil.go#L450-L453 | train |
gopasspw/gopass | pkg/ctxutil/ctxutil.go | GetProgressCallback | func GetProgressCallback(ctx context.Context) ProgressCallback {
cb, ok := ctx.Value(ctxKeyProgressCallback).(ProgressCallback)
if !ok || cb == nil {
return func() {}
}
return cb
} | go | func GetProgressCallback(ctx context.Context) ProgressCallback {
cb, ok := ctx.Value(ctxKeyProgressCallback).(ProgressCallback)
if !ok || cb == nil {
return func() {}
}
return cb
} | [
"func",
"GetProgressCallback",
"(",
"ctx",
"context",
".",
"Context",
")",
"ProgressCallback",
"{",
"cb",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"ctxKeyProgressCallback",
")",
".",
"(",
"ProgressCallback",
")",
"\n",
"if",
"!",
"ok",
"||",
"cb",
"==",
"nil",
"{",
"return",
"func",
"(",
")",
"{",
"}",
"\n",
"}",
"\n",
"return",
"cb",
"\n",
"}"
] | // GetProgressCallback return the set progress callback or a default one.
// It never returns nil | [
"GetProgressCallback",
"return",
"the",
"set",
"progress",
"callback",
"or",
"a",
"default",
"one",
".",
"It",
"never",
"returns",
"nil"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/ctxutil/ctxutil.go#L457-L463 | train |
gopasspw/gopass | pkg/ctxutil/ctxutil.go | WithConfigDir | func WithConfigDir(ctx context.Context, cfgdir string) context.Context {
return context.WithValue(ctx, ctxKeyConfigDir, cfgdir)
} | go | func WithConfigDir(ctx context.Context, cfgdir string) context.Context {
return context.WithValue(ctx, ctxKeyConfigDir, cfgdir)
} | [
"func",
"WithConfigDir",
"(",
"ctx",
"context",
".",
"Context",
",",
"cfgdir",
"string",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"ctxKeyConfigDir",
",",
"cfgdir",
")",
"\n",
"}"
] | // WithConfigDir returns a context with the config dir set. | [
"WithConfigDir",
"returns",
"a",
"context",
"with",
"the",
"config",
"dir",
"set",
"."
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/ctxutil/ctxutil.go#L466-L468 | train |
gopasspw/gopass | pkg/ctxutil/ctxutil.go | HasConfigDir | func HasConfigDir(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyConfigDir).(string)
return ok
} | go | func HasConfigDir(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyConfigDir).(string)
return ok
} | [
"func",
"HasConfigDir",
"(",
"ctx",
"context",
".",
"Context",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"ctxKeyConfigDir",
")",
".",
"(",
"string",
")",
"\n",
"return",
"ok",
"\n",
"}"
] | // HasConfigDir returns true if a config dir has been set. | [
"HasConfigDir",
"returns",
"true",
"if",
"a",
"config",
"dir",
"has",
"been",
"set",
"."
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/ctxutil/ctxutil.go#L471-L474 | train |
gopasspw/gopass | pkg/ctxutil/ctxutil.go | GetConfigDir | func GetConfigDir(ctx context.Context) string {
cd, ok := ctx.Value(ctxKeyConfigDir).(string)
if !ok {
return ""
}
return cd
} | go | func GetConfigDir(ctx context.Context) string {
cd, ok := ctx.Value(ctxKeyConfigDir).(string)
if !ok {
return ""
}
return cd
} | [
"func",
"GetConfigDir",
"(",
"ctx",
"context",
".",
"Context",
")",
"string",
"{",
"cd",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"ctxKeyConfigDir",
")",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"cd",
"\n",
"}"
] | // GetConfigDir returns the config dir if set or an empty string. | [
"GetConfigDir",
"returns",
"the",
"config",
"dir",
"if",
"set",
"or",
"an",
"empty",
"string",
"."
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/ctxutil/ctxutil.go#L477-L483 | train |
gopasspw/gopass | pkg/ctxutil/ctxutil.go | WithAlias | func WithAlias(ctx context.Context, alias string) context.Context {
return context.WithValue(ctx, ctxKeyAlias, alias)
} | go | func WithAlias(ctx context.Context, alias string) context.Context {
return context.WithValue(ctx, ctxKeyAlias, alias)
} | [
"func",
"WithAlias",
"(",
"ctx",
"context",
".",
"Context",
",",
"alias",
"string",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"ctxKeyAlias",
",",
"alias",
")",
"\n",
"}"
] | // WithAlias returns an context with the alias set. | [
"WithAlias",
"returns",
"an",
"context",
"with",
"the",
"alias",
"set",
"."
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/ctxutil/ctxutil.go#L486-L488 | train |
gopasspw/gopass | pkg/ctxutil/ctxutil.go | HasAlias | func HasAlias(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyAlias).(string)
return ok
} | go | func HasAlias(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyAlias).(string)
return ok
} | [
"func",
"HasAlias",
"(",
"ctx",
"context",
".",
"Context",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"ctxKeyAlias",
")",
".",
"(",
"string",
")",
"\n",
"return",
"ok",
"\n",
"}"
] | // HasAlias returns true if a value for alias has been set. | [
"HasAlias",
"returns",
"true",
"if",
"a",
"value",
"for",
"alias",
"has",
"been",
"set",
"."
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/ctxutil/ctxutil.go#L491-L494 | train |
gopasspw/gopass | pkg/ctxutil/ctxutil.go | GetAlias | func GetAlias(ctx context.Context) string {
a, ok := ctx.Value(ctxKeyAlias).(string)
if !ok {
return ""
}
return a
} | go | func GetAlias(ctx context.Context) string {
a, ok := ctx.Value(ctxKeyAlias).(string)
if !ok {
return ""
}
return a
} | [
"func",
"GetAlias",
"(",
"ctx",
"context",
".",
"Context",
")",
"string",
"{",
"a",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"ctxKeyAlias",
")",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"a",
"\n",
"}"
] | // GetAlias returns an alias if it has been set or an empty string otherwise. | [
"GetAlias",
"returns",
"an",
"alias",
"if",
"it",
"has",
"been",
"set",
"or",
"an",
"empty",
"string",
"otherwise",
"."
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/ctxutil/ctxutil.go#L497-L503 | train |
gopasspw/gopass | pkg/ctxutil/ctxutil.go | WithAutoPrint | func WithAutoPrint(ctx context.Context, bv bool) context.Context {
return context.WithValue(ctx, ctxKeyAutoPrint, bv)
} | go | func WithAutoPrint(ctx context.Context, bv bool) context.Context {
return context.WithValue(ctx, ctxKeyAutoPrint, bv)
} | [
"func",
"WithAutoPrint",
"(",
"ctx",
"context",
".",
"Context",
",",
"bv",
"bool",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"ctxKeyAutoPrint",
",",
"bv",
")",
"\n",
"}"
] | // WithAutoPrint returns a context with the value for auto print set. | [
"WithAutoPrint",
"returns",
"a",
"context",
"with",
"the",
"value",
"for",
"auto",
"print",
"set",
"."
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/ctxutil/ctxutil.go#L506-L508 | train |
gopasspw/gopass | pkg/ctxutil/ctxutil.go | HasAutoPrint | func HasAutoPrint(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyAutoPrint).(bool)
return ok
} | go | func HasAutoPrint(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyAutoPrint).(bool)
return ok
} | [
"func",
"HasAutoPrint",
"(",
"ctx",
"context",
".",
"Context",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"ctxKeyAutoPrint",
")",
".",
"(",
"bool",
")",
"\n",
"return",
"ok",
"\n",
"}"
] | // HasAutoPrint returns true if a specific value for auto print was set. | [
"HasAutoPrint",
"returns",
"true",
"if",
"a",
"specific",
"value",
"for",
"auto",
"print",
"was",
"set",
"."
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/ctxutil/ctxutil.go#L511-L514 | train |
gopasspw/gopass | pkg/ctxutil/ctxutil.go | IsAutoPrint | func IsAutoPrint(ctx context.Context) bool {
bv, ok := ctx.Value(ctxKeyAutoPrint).(bool)
if !ok {
return false
}
return bv
} | go | func IsAutoPrint(ctx context.Context) bool {
bv, ok := ctx.Value(ctxKeyAutoPrint).(bool)
if !ok {
return false
}
return bv
} | [
"func",
"IsAutoPrint",
"(",
"ctx",
"context",
".",
"Context",
")",
"bool",
"{",
"bv",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"ctxKeyAutoPrint",
")",
".",
"(",
"bool",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"bv",
"\n",
"}"
] | // IsAutoPrint returns the value of auto print or false if none was set. | [
"IsAutoPrint",
"returns",
"the",
"value",
"of",
"auto",
"print",
"or",
"false",
"if",
"none",
"was",
"set",
"."
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/ctxutil/ctxutil.go#L517-L523 | train |
gopasspw/gopass | pkg/ctxutil/ctxutil.go | WithGitInit | func WithGitInit(ctx context.Context, bv bool) context.Context {
return context.WithValue(ctx, ctxKeyGitInit, bv)
} | go | func WithGitInit(ctx context.Context, bv bool) context.Context {
return context.WithValue(ctx, ctxKeyGitInit, bv)
} | [
"func",
"WithGitInit",
"(",
"ctx",
"context",
".",
"Context",
",",
"bv",
"bool",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"ctxKeyGitInit",
",",
"bv",
")",
"\n",
"}"
] | // WithGitInit returns a context with the value for the git init flag set. | [
"WithGitInit",
"returns",
"a",
"context",
"with",
"the",
"value",
"for",
"the",
"git",
"init",
"flag",
"set",
"."
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/ctxutil/ctxutil.go#L526-L528 | train |
gopasspw/gopass | pkg/ctxutil/ctxutil.go | HasGitInit | func HasGitInit(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyGitInit).(bool)
return ok
} | go | func HasGitInit(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyGitInit).(bool)
return ok
} | [
"func",
"HasGitInit",
"(",
"ctx",
"context",
".",
"Context",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"ctxKeyGitInit",
")",
".",
"(",
"bool",
")",
"\n",
"return",
"ok",
"\n",
"}"
] | // HasGitInit returns true if the git init flag was set. | [
"HasGitInit",
"returns",
"true",
"if",
"the",
"git",
"init",
"flag",
"was",
"set",
"."
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/ctxutil/ctxutil.go#L531-L534 | train |
gopasspw/gopass | pkg/ctxutil/ctxutil.go | IsGitInit | func IsGitInit(ctx context.Context) bool {
bv, ok := ctx.Value(ctxKeyGitInit).(bool)
if !ok {
return true
}
return bv
} | go | func IsGitInit(ctx context.Context) bool {
bv, ok := ctx.Value(ctxKeyGitInit).(bool)
if !ok {
return true
}
return bv
} | [
"func",
"IsGitInit",
"(",
"ctx",
"context",
".",
"Context",
")",
"bool",
"{",
"bv",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"ctxKeyGitInit",
")",
".",
"(",
"bool",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"true",
"\n",
"}",
"\n",
"return",
"bv",
"\n",
"}"
] | // IsGitInit returns the value of the git init flag or ture if none was set. | [
"IsGitInit",
"returns",
"the",
"value",
"of",
"the",
"git",
"init",
"flag",
"or",
"ture",
"if",
"none",
"was",
"set",
"."
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/ctxutil/ctxutil.go#L537-L543 | train |
gopasspw/gopass | pkg/completion/zsh/completion.go | GetCompletion | func GetCompletion(a *cli.App) (string, error) {
tplFuncs := template.FuncMap{
"formatFlag": formatFlagFunc(),
}
tpl, err := template.New("zsh").Funcs(tplFuncs).Parse(zshTemplate)
if err != nil {
return "", err
}
buf := &bytes.Buffer{}
if err := tpl.Execute(buf, a); err != nil {
return "", err
}
return buf.String(), nil
} | go | func GetCompletion(a *cli.App) (string, error) {
tplFuncs := template.FuncMap{
"formatFlag": formatFlagFunc(),
}
tpl, err := template.New("zsh").Funcs(tplFuncs).Parse(zshTemplate)
if err != nil {
return "", err
}
buf := &bytes.Buffer{}
if err := tpl.Execute(buf, a); err != nil {
return "", err
}
return buf.String(), nil
} | [
"func",
"GetCompletion",
"(",
"a",
"*",
"cli",
".",
"App",
")",
"(",
"string",
",",
"error",
")",
"{",
"tplFuncs",
":=",
"template",
".",
"FuncMap",
"{",
"\"",
"\"",
":",
"formatFlagFunc",
"(",
")",
",",
"}",
"\n",
"tpl",
",",
"err",
":=",
"template",
".",
"New",
"(",
"\"",
"\"",
")",
".",
"Funcs",
"(",
"tplFuncs",
")",
".",
"Parse",
"(",
"zshTemplate",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"buf",
":=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"if",
"err",
":=",
"tpl",
".",
"Execute",
"(",
"buf",
",",
"a",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"buf",
".",
"String",
"(",
")",
",",
"nil",
"\n",
"}"
] | // GetCompletion returns a zsh completion script | [
"GetCompletion",
"returns",
"a",
"zsh",
"completion",
"script"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/completion/zsh/completion.go#L56-L69 | train |
gopasspw/gopass | pkg/action/binary/sum.go | Sum | func Sum(ctx context.Context, c *cli.Context, store storer) error {
name := c.Args().First()
if name == "" {
return action.ExitError(ctx, action.ExitUsage, nil, "Usage: %s sha256 name", c.App.Name)
}
if !strings.HasSuffix(name, Suffix) {
name += Suffix
}
buf, err := binaryGet(ctx, name, store)
if err != nil {
return action.ExitError(ctx, action.ExitDecrypt, err, "failed to read secret: %s", err)
}
h := sha256.New()
_, _ = h.Write(buf)
out.Yellow(ctx, "%x", h.Sum(nil))
return nil
} | go | func Sum(ctx context.Context, c *cli.Context, store storer) error {
name := c.Args().First()
if name == "" {
return action.ExitError(ctx, action.ExitUsage, nil, "Usage: %s sha256 name", c.App.Name)
}
if !strings.HasSuffix(name, Suffix) {
name += Suffix
}
buf, err := binaryGet(ctx, name, store)
if err != nil {
return action.ExitError(ctx, action.ExitDecrypt, err, "failed to read secret: %s", err)
}
h := sha256.New()
_, _ = h.Write(buf)
out.Yellow(ctx, "%x", h.Sum(nil))
return nil
} | [
"func",
"Sum",
"(",
"ctx",
"context",
".",
"Context",
",",
"c",
"*",
"cli",
".",
"Context",
",",
"store",
"storer",
")",
"error",
"{",
"name",
":=",
"c",
".",
"Args",
"(",
")",
".",
"First",
"(",
")",
"\n",
"if",
"name",
"==",
"\"",
"\"",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitUsage",
",",
"nil",
",",
"\"",
"\"",
",",
"c",
".",
"App",
".",
"Name",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"strings",
".",
"HasSuffix",
"(",
"name",
",",
"Suffix",
")",
"{",
"name",
"+=",
"Suffix",
"\n",
"}",
"\n\n",
"buf",
",",
"err",
":=",
"binaryGet",
"(",
"ctx",
",",
"name",
",",
"store",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitDecrypt",
",",
"err",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"h",
":=",
"sha256",
".",
"New",
"(",
")",
"\n",
"_",
",",
"_",
"=",
"h",
".",
"Write",
"(",
"buf",
")",
"\n",
"out",
".",
"Yellow",
"(",
"ctx",
",",
"\"",
"\"",
",",
"h",
".",
"Sum",
"(",
"nil",
")",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Sum decodes binary content and computes the SHA256 checksum | [
"Sum",
"decodes",
"binary",
"content",
"and",
"computes",
"the",
"SHA256",
"checksum"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/binary/sum.go#L15-L35 | train |
gopasspw/gopass | pkg/store/sub/read.go | Get | func (s *Store) Get(ctx context.Context, name string) (store.Secret, error) {
p := s.passfile(name)
ciphertext, err := s.storage.Get(ctx, p)
if err != nil {
out.Debug(ctx, "File %s not found: %s", p, err)
return nil, store.ErrNotFound
}
content, err := s.crypto.Decrypt(ctx, ciphertext)
if err != nil {
out.Debug(ctx, "Decryption failed: %s", err)
return nil, store.ErrDecrypt
}
sec, err := secret.Parse(content)
if err != nil {
out.Debug(ctx, "Failed to parse YAML: %s", err)
}
return sec, nil
} | go | func (s *Store) Get(ctx context.Context, name string) (store.Secret, error) {
p := s.passfile(name)
ciphertext, err := s.storage.Get(ctx, p)
if err != nil {
out.Debug(ctx, "File %s not found: %s", p, err)
return nil, store.ErrNotFound
}
content, err := s.crypto.Decrypt(ctx, ciphertext)
if err != nil {
out.Debug(ctx, "Decryption failed: %s", err)
return nil, store.ErrDecrypt
}
sec, err := secret.Parse(content)
if err != nil {
out.Debug(ctx, "Failed to parse YAML: %s", err)
}
return sec, nil
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"Get",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
"string",
")",
"(",
"store",
".",
"Secret",
",",
"error",
")",
"{",
"p",
":=",
"s",
".",
"passfile",
"(",
"name",
")",
"\n\n",
"ciphertext",
",",
"err",
":=",
"s",
".",
"storage",
".",
"Get",
"(",
"ctx",
",",
"p",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"out",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"p",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"store",
".",
"ErrNotFound",
"\n",
"}",
"\n\n",
"content",
",",
"err",
":=",
"s",
".",
"crypto",
".",
"Decrypt",
"(",
"ctx",
",",
"ciphertext",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"out",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"store",
".",
"ErrDecrypt",
"\n",
"}",
"\n\n",
"sec",
",",
"err",
":=",
"secret",
".",
"Parse",
"(",
"content",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"out",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"sec",
",",
"nil",
"\n",
"}"
] | // Get returns the plaintext of a single key | [
"Get",
"returns",
"the",
"plaintext",
"of",
"a",
"single",
"key"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/read.go#L12-L32 | train |
gopasspw/gopass | pkg/action/jsonapi.go | JSONAPI | func (s *Action) JSONAPI(ctx context.Context, c *cli.Context) error {
api := jsonapi.API{Store: s.Store, Reader: stdin, Writer: stdout, Version: s.version}
if err := api.ReadAndRespond(ctx); err != nil {
return api.RespondError(err)
}
return nil
} | go | func (s *Action) JSONAPI(ctx context.Context, c *cli.Context) error {
api := jsonapi.API{Store: s.Store, Reader: stdin, Writer: stdout, Version: s.version}
if err := api.ReadAndRespond(ctx); err != nil {
return api.RespondError(err)
}
return nil
} | [
"func",
"(",
"s",
"*",
"Action",
")",
"JSONAPI",
"(",
"ctx",
"context",
".",
"Context",
",",
"c",
"*",
"cli",
".",
"Context",
")",
"error",
"{",
"api",
":=",
"jsonapi",
".",
"API",
"{",
"Store",
":",
"s",
".",
"Store",
",",
"Reader",
":",
"stdin",
",",
"Writer",
":",
"stdout",
",",
"Version",
":",
"s",
".",
"version",
"}",
"\n",
"if",
"err",
":=",
"api",
".",
"ReadAndRespond",
"(",
"ctx",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"api",
".",
"RespondError",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // JSONAPI reads a json message on stdin and responds on stdout | [
"JSONAPI",
"reads",
"a",
"json",
"message",
"on",
"stdin",
"and",
"responds",
"on",
"stdout"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/jsonapi.go#L19-L25 | train |
gopasspw/gopass | pkg/backend/storage/kv/inmem/store.go | Get | func (m *InMem) Get(ctx context.Context, name string) ([]byte, error) {
m.Lock()
defer m.Unlock()
sec, found := m.data[name]
if !found {
return nil, fmt.Errorf("entry not found")
}
return sec, nil
} | go | func (m *InMem) Get(ctx context.Context, name string) ([]byte, error) {
m.Lock()
defer m.Unlock()
sec, found := m.data[name]
if !found {
return nil, fmt.Errorf("entry not found")
}
return sec, nil
} | [
"func",
"(",
"m",
"*",
"InMem",
")",
"Get",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"Unlock",
"(",
")",
"\n\n",
"sec",
",",
"found",
":=",
"m",
".",
"data",
"[",
"name",
"]",
"\n",
"if",
"!",
"found",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"sec",
",",
"nil",
"\n",
"}"
] | // Get retrieves a value | [
"Get",
"retrieves",
"a",
"value"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/storage/kv/inmem/store.go#L27-L36 | train |
gopasspw/gopass | pkg/backend/storage/kv/inmem/store.go | Set | func (m *InMem) Set(ctx context.Context, name string, value []byte) error {
m.Lock()
defer m.Unlock()
m.data[name] = value
return nil
} | go | func (m *InMem) Set(ctx context.Context, name string, value []byte) error {
m.Lock()
defer m.Unlock()
m.data[name] = value
return nil
} | [
"func",
"(",
"m",
"*",
"InMem",
")",
"Set",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
"string",
",",
"value",
"[",
"]",
"byte",
")",
"error",
"{",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"Unlock",
"(",
")",
"\n\n",
"m",
".",
"data",
"[",
"name",
"]",
"=",
"value",
"\n",
"return",
"nil",
"\n",
"}"
] | // Set writes a value | [
"Set",
"writes",
"a",
"value"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/storage/kv/inmem/store.go#L39-L45 | train |
gopasspw/gopass | pkg/backend/storage/kv/inmem/store.go | Delete | func (m *InMem) Delete(ctx context.Context, name string) error {
m.Lock()
defer m.Unlock()
delete(m.data, name)
return nil
} | go | func (m *InMem) Delete(ctx context.Context, name string) error {
m.Lock()
defer m.Unlock()
delete(m.data, name)
return nil
} | [
"func",
"(",
"m",
"*",
"InMem",
")",
"Delete",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
"string",
")",
"error",
"{",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"Unlock",
"(",
")",
"\n\n",
"delete",
"(",
"m",
".",
"data",
",",
"name",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Delete removes a value | [
"Delete",
"removes",
"a",
"value"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/storage/kv/inmem/store.go#L48-L54 | train |
gopasspw/gopass | pkg/backend/storage/kv/inmem/store.go | Exists | func (m *InMem) Exists(ctx context.Context, name string) bool {
m.Lock()
defer m.Unlock()
_, found := m.data[name]
return found
} | go | func (m *InMem) Exists(ctx context.Context, name string) bool {
m.Lock()
defer m.Unlock()
_, found := m.data[name]
return found
} | [
"func",
"(",
"m",
"*",
"InMem",
")",
"Exists",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
"string",
")",
"bool",
"{",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"Unlock",
"(",
")",
"\n\n",
"_",
",",
"found",
":=",
"m",
".",
"data",
"[",
"name",
"]",
"\n",
"return",
"found",
"\n",
"}"
] | // Exists checks is a value exists | [
"Exists",
"checks",
"is",
"a",
"value",
"exists"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/storage/kv/inmem/store.go#L57-L63 | train |
gopasspw/gopass | pkg/backend/storage/kv/inmem/store.go | List | func (m *InMem) List(ctx context.Context, prefix string) ([]string, error) {
m.Lock()
defer m.Unlock()
keys := make([]string, 0, len(m.data))
for k := range m.data {
keys = append(keys, k)
}
sort.Strings(keys)
return keys, nil
} | go | func (m *InMem) List(ctx context.Context, prefix string) ([]string, error) {
m.Lock()
defer m.Unlock()
keys := make([]string, 0, len(m.data))
for k := range m.data {
keys = append(keys, k)
}
sort.Strings(keys)
return keys, nil
} | [
"func",
"(",
"m",
"*",
"InMem",
")",
"List",
"(",
"ctx",
"context",
".",
"Context",
",",
"prefix",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"Unlock",
"(",
")",
"\n\n",
"keys",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"m",
".",
"data",
")",
")",
"\n",
"for",
"k",
":=",
"range",
"m",
".",
"data",
"{",
"keys",
"=",
"append",
"(",
"keys",
",",
"k",
")",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"keys",
")",
"\n",
"return",
"keys",
",",
"nil",
"\n",
"}"
] | // List shows all values | [
"List",
"shows",
"all",
"values"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/storage/kv/inmem/store.go#L66-L76 | train |
gopasspw/gopass | pkg/backend/storage/kv/inmem/store.go | IsDir | func (m *InMem) IsDir(ctx context.Context, name string) bool {
m.Lock()
defer m.Unlock()
for k := range m.data {
if strings.HasPrefix(k, name+"/") {
return true
}
}
return false
} | go | func (m *InMem) IsDir(ctx context.Context, name string) bool {
m.Lock()
defer m.Unlock()
for k := range m.data {
if strings.HasPrefix(k, name+"/") {
return true
}
}
return false
} | [
"func",
"(",
"m",
"*",
"InMem",
")",
"IsDir",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
"string",
")",
"bool",
"{",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"Unlock",
"(",
")",
"\n\n",
"for",
"k",
":=",
"range",
"m",
".",
"data",
"{",
"if",
"strings",
".",
"HasPrefix",
"(",
"k",
",",
"name",
"+",
"\"",
"\"",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // IsDir returns true if the entry is a directory | [
"IsDir",
"returns",
"true",
"if",
"the",
"entry",
"is",
"a",
"directory"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/storage/kv/inmem/store.go#L79-L89 | train |
gopasspw/gopass | pkg/backend/storage/kv/inmem/store.go | Prune | func (m *InMem) Prune(ctx context.Context, prefix string) error {
m.Lock()
defer m.Unlock()
deleted := 0
for k := range m.data {
if strings.HasPrefix(k, prefix+"/") {
delete(m.data, k)
deleted++
}
}
if deleted < 1 {
return fmt.Errorf("not found")
}
return nil
} | go | func (m *InMem) Prune(ctx context.Context, prefix string) error {
m.Lock()
defer m.Unlock()
deleted := 0
for k := range m.data {
if strings.HasPrefix(k, prefix+"/") {
delete(m.data, k)
deleted++
}
}
if deleted < 1 {
return fmt.Errorf("not found")
}
return nil
} | [
"func",
"(",
"m",
"*",
"InMem",
")",
"Prune",
"(",
"ctx",
"context",
".",
"Context",
",",
"prefix",
"string",
")",
"error",
"{",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"Unlock",
"(",
")",
"\n\n",
"deleted",
":=",
"0",
"\n",
"for",
"k",
":=",
"range",
"m",
".",
"data",
"{",
"if",
"strings",
".",
"HasPrefix",
"(",
"k",
",",
"prefix",
"+",
"\"",
"\"",
")",
"{",
"delete",
"(",
"m",
".",
"data",
",",
"k",
")",
"\n",
"deleted",
"++",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"deleted",
"<",
"1",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Prune removes a directory | [
"Prune",
"removes",
"a",
"directory"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/storage/kv/inmem/store.go#L92-L107 | train |
gopasspw/gopass | pkg/backend/crypto/xc/keyring/private_key.go | GenerateKeypair | func GenerateKeypair(passphrase string) (*PrivateKey, error) {
pub, priv, err := box.GenerateKey(crypto_rand.Reader)
if err != nil {
return nil, err
}
k := &PrivateKey{
PublicKey: PublicKey{
CreationTime: time.Now(),
PubKeyAlgo: PubKeyNaCl,
PublicKey: *pub,
Identity: &xcpb.Identity{},
},
Encrypted: true,
privateKey: *priv,
}
err = k.Encrypt(passphrase)
return k, err
} | go | func GenerateKeypair(passphrase string) (*PrivateKey, error) {
pub, priv, err := box.GenerateKey(crypto_rand.Reader)
if err != nil {
return nil, err
}
k := &PrivateKey{
PublicKey: PublicKey{
CreationTime: time.Now(),
PubKeyAlgo: PubKeyNaCl,
PublicKey: *pub,
Identity: &xcpb.Identity{},
},
Encrypted: true,
privateKey: *priv,
}
err = k.Encrypt(passphrase)
return k, err
} | [
"func",
"GenerateKeypair",
"(",
"passphrase",
"string",
")",
"(",
"*",
"PrivateKey",
",",
"error",
")",
"{",
"pub",
",",
"priv",
",",
"err",
":=",
"box",
".",
"GenerateKey",
"(",
"crypto_rand",
".",
"Reader",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"k",
":=",
"&",
"PrivateKey",
"{",
"PublicKey",
":",
"PublicKey",
"{",
"CreationTime",
":",
"time",
".",
"Now",
"(",
")",
",",
"PubKeyAlgo",
":",
"PubKeyNaCl",
",",
"PublicKey",
":",
"*",
"pub",
",",
"Identity",
":",
"&",
"xcpb",
".",
"Identity",
"{",
"}",
",",
"}",
",",
"Encrypted",
":",
"true",
",",
"privateKey",
":",
"*",
"priv",
",",
"}",
"\n",
"err",
"=",
"k",
".",
"Encrypt",
"(",
"passphrase",
")",
"\n",
"return",
"k",
",",
"err",
"\n",
"}"
] | // GenerateKeypair generates a new keypair | [
"GenerateKeypair",
"generates",
"a",
"new",
"keypair"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/keyring/private_key.go#L41-L58 | train |
gopasspw/gopass | pkg/backend/crypto/xc/keyring/private_key.go | Encrypt | func (p *PrivateKey) Encrypt(passphrase string) error {
p.Salt = make([]byte, saltLength)
if n, err := crypto_rand.Read(p.Salt); err != nil || n < len(p.Salt) {
return err
}
secretKey := p.deriveKey(passphrase)
var nonce [nonceLength]byte
if _, err := io.ReadFull(crypto_rand.Reader, nonce[:]); err != nil {
return err
}
p.Nonce = nonce
p.EncryptedData = secretbox.Seal(nil, p.privateKey[:], &nonce, &secretKey)
return nil
} | go | func (p *PrivateKey) Encrypt(passphrase string) error {
p.Salt = make([]byte, saltLength)
if n, err := crypto_rand.Read(p.Salt); err != nil || n < len(p.Salt) {
return err
}
secretKey := p.deriveKey(passphrase)
var nonce [nonceLength]byte
if _, err := io.ReadFull(crypto_rand.Reader, nonce[:]); err != nil {
return err
}
p.Nonce = nonce
p.EncryptedData = secretbox.Seal(nil, p.privateKey[:], &nonce, &secretKey)
return nil
} | [
"func",
"(",
"p",
"*",
"PrivateKey",
")",
"Encrypt",
"(",
"passphrase",
"string",
")",
"error",
"{",
"p",
".",
"Salt",
"=",
"make",
"(",
"[",
"]",
"byte",
",",
"saltLength",
")",
"\n",
"if",
"n",
",",
"err",
":=",
"crypto_rand",
".",
"Read",
"(",
"p",
".",
"Salt",
")",
";",
"err",
"!=",
"nil",
"||",
"n",
"<",
"len",
"(",
"p",
".",
"Salt",
")",
"{",
"return",
"err",
"\n",
"}",
"\n",
"secretKey",
":=",
"p",
".",
"deriveKey",
"(",
"passphrase",
")",
"\n\n",
"var",
"nonce",
"[",
"nonceLength",
"]",
"byte",
"\n",
"if",
"_",
",",
"err",
":=",
"io",
".",
"ReadFull",
"(",
"crypto_rand",
".",
"Reader",
",",
"nonce",
"[",
":",
"]",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"p",
".",
"Nonce",
"=",
"nonce",
"\n\n",
"p",
".",
"EncryptedData",
"=",
"secretbox",
".",
"Seal",
"(",
"nil",
",",
"p",
".",
"privateKey",
"[",
":",
"]",
",",
"&",
"nonce",
",",
"&",
"secretKey",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Encrypt encrypts the private key material with the given passphrase | [
"Encrypt",
"encrypts",
"the",
"private",
"key",
"material",
"with",
"the",
"given",
"passphrase"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/keyring/private_key.go#L61-L76 | train |
gopasspw/gopass | pkg/backend/crypto/xc/keyring/private_key.go | Decrypt | func (p *PrivateKey) Decrypt(passphrase string) error {
if !p.Encrypted {
return nil
}
secretKey := p.deriveKey(passphrase)
decrypted, ok := secretbox.Open(nil, p.EncryptedData, &p.Nonce, &secretKey)
if !ok {
return fmt.Errorf("decryption error")
}
copy(p.privateKey[:], decrypted)
p.Encrypted = false
return nil
} | go | func (p *PrivateKey) Decrypt(passphrase string) error {
if !p.Encrypted {
return nil
}
secretKey := p.deriveKey(passphrase)
decrypted, ok := secretbox.Open(nil, p.EncryptedData, &p.Nonce, &secretKey)
if !ok {
return fmt.Errorf("decryption error")
}
copy(p.privateKey[:], decrypted)
p.Encrypted = false
return nil
} | [
"func",
"(",
"p",
"*",
"PrivateKey",
")",
"Decrypt",
"(",
"passphrase",
"string",
")",
"error",
"{",
"if",
"!",
"p",
".",
"Encrypted",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"secretKey",
":=",
"p",
".",
"deriveKey",
"(",
"passphrase",
")",
"\n\n",
"decrypted",
",",
"ok",
":=",
"secretbox",
".",
"Open",
"(",
"nil",
",",
"p",
".",
"EncryptedData",
",",
"&",
"p",
".",
"Nonce",
",",
"&",
"secretKey",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"copy",
"(",
"p",
".",
"privateKey",
"[",
":",
"]",
",",
"decrypted",
")",
"\n\n",
"p",
".",
"Encrypted",
"=",
"false",
"\n",
"return",
"nil",
"\n",
"}"
] | // Decrypt decrypts the private key | [
"Decrypt",
"decrypts",
"the",
"private",
"key"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/keyring/private_key.go#L79-L93 | train |
gopasspw/gopass | pkg/action/create/create.go | Create | func Create(ctx context.Context, c *cli.Context, store storer) error {
s := creator{store: store}
acts := make(cui.Actions, 0, 5)
acts = append(acts, cui.Action{Name: "Website Login", Fn: s.createWebsite})
acts = append(acts, cui.Action{Name: "PIN Code (numerical)", Fn: s.createPIN})
acts = append(acts, cui.Action{Name: "Generic", Fn: s.createGeneric})
acts = append(acts, cui.Action{Name: "AWS Secret Key", Fn: s.createAWS})
acts = append(acts, cui.Action{Name: "GCP Service Account", Fn: s.createGCP})
act, sel := cui.GetSelection(ctx, "Please select the type of secret you would like to create", "<↑/↓> to change the selection, <→> to select, <ESC> to quit", acts.Selection())
switch act {
case "default":
fallthrough
case "show":
return acts.Run(ctx, c, sel)
default:
return action.ExitError(ctx, action.ExitAborted, nil, "user aborted")
}
} | go | func Create(ctx context.Context, c *cli.Context, store storer) error {
s := creator{store: store}
acts := make(cui.Actions, 0, 5)
acts = append(acts, cui.Action{Name: "Website Login", Fn: s.createWebsite})
acts = append(acts, cui.Action{Name: "PIN Code (numerical)", Fn: s.createPIN})
acts = append(acts, cui.Action{Name: "Generic", Fn: s.createGeneric})
acts = append(acts, cui.Action{Name: "AWS Secret Key", Fn: s.createAWS})
acts = append(acts, cui.Action{Name: "GCP Service Account", Fn: s.createGCP})
act, sel := cui.GetSelection(ctx, "Please select the type of secret you would like to create", "<↑/↓> to change the selection, <→> to select, <ESC> to quit", acts.Selection())
switch act {
case "default":
fallthrough
case "show":
return acts.Run(ctx, c, sel)
default:
return action.ExitError(ctx, action.ExitAborted, nil, "user aborted")
}
} | [
"func",
"Create",
"(",
"ctx",
"context",
".",
"Context",
",",
"c",
"*",
"cli",
".",
"Context",
",",
"store",
"storer",
")",
"error",
"{",
"s",
":=",
"creator",
"{",
"store",
":",
"store",
"}",
"\n",
"acts",
":=",
"make",
"(",
"cui",
".",
"Actions",
",",
"0",
",",
"5",
")",
"\n",
"acts",
"=",
"append",
"(",
"acts",
",",
"cui",
".",
"Action",
"{",
"Name",
":",
"\"",
"\"",
",",
"Fn",
":",
"s",
".",
"createWebsite",
"}",
")",
"\n",
"acts",
"=",
"append",
"(",
"acts",
",",
"cui",
".",
"Action",
"{",
"Name",
":",
"\"",
"\"",
",",
"Fn",
":",
"s",
".",
"createPIN",
"}",
")",
"\n",
"acts",
"=",
"append",
"(",
"acts",
",",
"cui",
".",
"Action",
"{",
"Name",
":",
"\"",
"\"",
",",
"Fn",
":",
"s",
".",
"createGeneric",
"}",
")",
"\n",
"acts",
"=",
"append",
"(",
"acts",
",",
"cui",
".",
"Action",
"{",
"Name",
":",
"\"",
"\"",
",",
"Fn",
":",
"s",
".",
"createAWS",
"}",
")",
"\n",
"acts",
"=",
"append",
"(",
"acts",
",",
"cui",
".",
"Action",
"{",
"Name",
":",
"\"",
"\"",
",",
"Fn",
":",
"s",
".",
"createGCP",
"}",
")",
"\n",
"act",
",",
"sel",
":=",
"cui",
".",
"GetSelection",
"(",
"ctx",
",",
"\"",
"\"",
",",
"\"",
"s",
".",
"elec",
"t",
"ion())",
"",
"",
"",
"\n",
"switch",
"act",
"{",
"case",
"\"",
"\"",
":",
"fallthrough",
"\n",
"case",
"\"",
"\"",
":",
"return",
"acts",
".",
"Run",
"(",
"ctx",
",",
"c",
",",
"sel",
")",
"\n",
"default",
":",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitAborted",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
] | // Create displays the password creation wizard | [
"Create",
"displays",
"the",
"password",
"creation",
"wizard"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/create/create.go#L49-L66 | train |
gopasspw/gopass | pkg/action/create/create.go | extractHostname | func extractHostname(in string) string {
if in == "" {
return ""
}
// help url.Parse by adding a scheme if one is missing. This should still
// allow for any scheme, but by default we assume http (only for parsing)
urlStr := in
if !strings.Contains(urlStr, "://") {
urlStr = "http://" + urlStr
}
u, err := url.Parse(urlStr)
if err == nil {
if ch := fsutil.CleanFilename(u.Hostname()); ch != "" {
return ch
}
}
return fsutil.CleanFilename(in)
} | go | func extractHostname(in string) string {
if in == "" {
return ""
}
// help url.Parse by adding a scheme if one is missing. This should still
// allow for any scheme, but by default we assume http (only for parsing)
urlStr := in
if !strings.Contains(urlStr, "://") {
urlStr = "http://" + urlStr
}
u, err := url.Parse(urlStr)
if err == nil {
if ch := fsutil.CleanFilename(u.Hostname()); ch != "" {
return ch
}
}
return fsutil.CleanFilename(in)
} | [
"func",
"extractHostname",
"(",
"in",
"string",
")",
"string",
"{",
"if",
"in",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"// help url.Parse by adding a scheme if one is missing. This should still",
"// allow for any scheme, but by default we assume http (only for parsing)",
"urlStr",
":=",
"in",
"\n",
"if",
"!",
"strings",
".",
"Contains",
"(",
"urlStr",
",",
"\"",
"\"",
")",
"{",
"urlStr",
"=",
"\"",
"\"",
"+",
"urlStr",
"\n",
"}",
"\n",
"u",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"urlStr",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"if",
"ch",
":=",
"fsutil",
".",
"CleanFilename",
"(",
"u",
".",
"Hostname",
"(",
")",
")",
";",
"ch",
"!=",
"\"",
"\"",
"{",
"return",
"ch",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"fsutil",
".",
"CleanFilename",
"(",
"in",
")",
"\n",
"}"
] | // extractHostname tries to extract the hostname from a URL in a filepath-safe
// way for use in the name of a secret | [
"extractHostname",
"tries",
"to",
"extract",
"the",
"hostname",
"from",
"a",
"URL",
"in",
"a",
"filepath",
"-",
"safe",
"way",
"for",
"use",
"in",
"the",
"name",
"of",
"a",
"secret"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/create/create.go#L70-L87 | train |
gopasspw/gopass | pkg/action/create/create.go | createAWS | func (s *creator) createAWS(ctx context.Context, c *cli.Context) error {
var (
account = c.Args().Get(0)
username = c.Args().Get(1)
accesskey = c.Args().Get(2)
secretkey string
region string
store = c.String("store")
err error
)
out.Green(ctx, "=> Creating AWS credentials ...")
account, err = termio.AskForString(ctx, fmtfn(2, "1", "AWS Account"), account)
if err != nil {
return err
}
if account == "" {
return action.ExitError(ctx, action.ExitUnknown, nil, "Account must not be empty")
}
username, err = termio.AskForString(ctx, fmtfn(2, "2", "AWS IAM User"), username)
if err != nil {
return err
}
if username == "" {
return action.ExitError(ctx, action.ExitUnknown, nil, "Username must not be empty")
}
accesskey, err = termio.AskForString(ctx, fmtfn(2, "3", "AWS_ACCESS_KEY_ID"), accesskey)
if err != nil {
return err
}
secretkey, err = termio.AskForPassword(ctx, "AWS_SECRET_ACCESS_KEY")
if err != nil {
return err
}
region, _ = termio.AskForString(ctx, fmtfn(2, "5", "AWS_DEFAULT_REGION"), "")
// select store
if store == "" {
store = cui.AskForStore(ctx, s.store)
}
// generate name, ask for override if already taken
if store != "" {
store += "/"
}
name := fmt.Sprintf("%saws/iam/%s/%s", store, fsutil.CleanFilename(account), fsutil.CleanFilename(username))
if s.store.Exists(ctx, name) {
name, err = termio.AskForString(ctx, "Secret already exists, please choose another path", name)
if err != nil {
return err
}
}
sec := secret.New(secretkey, "")
_ = sec.SetValue("account", account)
_ = sec.SetValue("username", username)
_ = sec.SetValue("accesskey", accesskey)
_ = sec.SetValue("region", region)
if err := s.store.Set(sub.WithReason(ctx, "Created new entry"), name, sec); err != nil {
return action.ExitError(ctx, action.ExitEncrypt, err, "failed to set '%s': %s", name, err)
}
return nil
} | go | func (s *creator) createAWS(ctx context.Context, c *cli.Context) error {
var (
account = c.Args().Get(0)
username = c.Args().Get(1)
accesskey = c.Args().Get(2)
secretkey string
region string
store = c.String("store")
err error
)
out.Green(ctx, "=> Creating AWS credentials ...")
account, err = termio.AskForString(ctx, fmtfn(2, "1", "AWS Account"), account)
if err != nil {
return err
}
if account == "" {
return action.ExitError(ctx, action.ExitUnknown, nil, "Account must not be empty")
}
username, err = termio.AskForString(ctx, fmtfn(2, "2", "AWS IAM User"), username)
if err != nil {
return err
}
if username == "" {
return action.ExitError(ctx, action.ExitUnknown, nil, "Username must not be empty")
}
accesskey, err = termio.AskForString(ctx, fmtfn(2, "3", "AWS_ACCESS_KEY_ID"), accesskey)
if err != nil {
return err
}
secretkey, err = termio.AskForPassword(ctx, "AWS_SECRET_ACCESS_KEY")
if err != nil {
return err
}
region, _ = termio.AskForString(ctx, fmtfn(2, "5", "AWS_DEFAULT_REGION"), "")
// select store
if store == "" {
store = cui.AskForStore(ctx, s.store)
}
// generate name, ask for override if already taken
if store != "" {
store += "/"
}
name := fmt.Sprintf("%saws/iam/%s/%s", store, fsutil.CleanFilename(account), fsutil.CleanFilename(username))
if s.store.Exists(ctx, name) {
name, err = termio.AskForString(ctx, "Secret already exists, please choose another path", name)
if err != nil {
return err
}
}
sec := secret.New(secretkey, "")
_ = sec.SetValue("account", account)
_ = sec.SetValue("username", username)
_ = sec.SetValue("accesskey", accesskey)
_ = sec.SetValue("region", region)
if err := s.store.Set(sub.WithReason(ctx, "Created new entry"), name, sec); err != nil {
return action.ExitError(ctx, action.ExitEncrypt, err, "failed to set '%s': %s", name, err)
}
return nil
} | [
"func",
"(",
"s",
"*",
"creator",
")",
"createAWS",
"(",
"ctx",
"context",
".",
"Context",
",",
"c",
"*",
"cli",
".",
"Context",
")",
"error",
"{",
"var",
"(",
"account",
"=",
"c",
".",
"Args",
"(",
")",
".",
"Get",
"(",
"0",
")",
"\n",
"username",
"=",
"c",
".",
"Args",
"(",
")",
".",
"Get",
"(",
"1",
")",
"\n",
"accesskey",
"=",
"c",
".",
"Args",
"(",
")",
".",
"Get",
"(",
"2",
")",
"\n",
"secretkey",
"string",
"\n",
"region",
"string",
"\n",
"store",
"=",
"c",
".",
"String",
"(",
"\"",
"\"",
")",
"\n",
"err",
"error",
"\n",
")",
"\n",
"out",
".",
"Green",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"account",
",",
"err",
"=",
"termio",
".",
"AskForString",
"(",
"ctx",
",",
"fmtfn",
"(",
"2",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"account",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"account",
"==",
"\"",
"\"",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitUnknown",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"username",
",",
"err",
"=",
"termio",
".",
"AskForString",
"(",
"ctx",
",",
"fmtfn",
"(",
"2",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"username",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"username",
"==",
"\"",
"\"",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitUnknown",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"accesskey",
",",
"err",
"=",
"termio",
".",
"AskForString",
"(",
"ctx",
",",
"fmtfn",
"(",
"2",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"accesskey",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"secretkey",
",",
"err",
"=",
"termio",
".",
"AskForPassword",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"region",
",",
"_",
"=",
"termio",
".",
"AskForString",
"(",
"ctx",
",",
"fmtfn",
"(",
"2",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
")",
"\n\n",
"// select store",
"if",
"store",
"==",
"\"",
"\"",
"{",
"store",
"=",
"cui",
".",
"AskForStore",
"(",
"ctx",
",",
"s",
".",
"store",
")",
"\n",
"}",
"\n\n",
"// generate name, ask for override if already taken",
"if",
"store",
"!=",
"\"",
"\"",
"{",
"store",
"+=",
"\"",
"\"",
"\n",
"}",
"\n",
"name",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"store",
",",
"fsutil",
".",
"CleanFilename",
"(",
"account",
")",
",",
"fsutil",
".",
"CleanFilename",
"(",
"username",
")",
")",
"\n",
"if",
"s",
".",
"store",
".",
"Exists",
"(",
"ctx",
",",
"name",
")",
"{",
"name",
",",
"err",
"=",
"termio",
".",
"AskForString",
"(",
"ctx",
",",
"\"",
"\"",
",",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"sec",
":=",
"secret",
".",
"New",
"(",
"secretkey",
",",
"\"",
"\"",
")",
"\n",
"_",
"=",
"sec",
".",
"SetValue",
"(",
"\"",
"\"",
",",
"account",
")",
"\n",
"_",
"=",
"sec",
".",
"SetValue",
"(",
"\"",
"\"",
",",
"username",
")",
"\n",
"_",
"=",
"sec",
".",
"SetValue",
"(",
"\"",
"\"",
",",
"accesskey",
")",
"\n",
"_",
"=",
"sec",
".",
"SetValue",
"(",
"\"",
"\"",
",",
"region",
")",
"\n",
"if",
"err",
":=",
"s",
".",
"store",
".",
"Set",
"(",
"sub",
".",
"WithReason",
"(",
"ctx",
",",
"\"",
"\"",
")",
",",
"name",
",",
"sec",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitEncrypt",
",",
"err",
",",
"\"",
"\"",
",",
"name",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // createAWS will walk through the AWS credential creation wizard | [
"createAWS",
"will",
"walk",
"through",
"the",
"AWS",
"credential",
"creation",
"wizard"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/create/create.go#L254-L314 | train |
gopasspw/gopass | pkg/action/create/create.go | createGCP | func (s *creator) createGCP(ctx context.Context, c *cli.Context) error {
var (
project string
username string
svcaccfn = c.Args().Get(0)
store = c.String("store")
err error
)
out.Green(ctx, "=> Creating GCP credentials ...")
svcaccfn, err = termio.AskForString(ctx, fmtfn(2, "1", "Service Account JSON"), svcaccfn)
if err != nil {
return err
}
buf, err := ioutil.ReadFile(svcaccfn)
if err != nil {
return err
}
username, project, err = extractGCPInfo(buf)
if err != nil {
return err
}
if username == "" {
username, err = termio.AskForString(ctx, fmtfn(4, "a", "Account name"), "")
if err != nil {
return err
}
}
if username == "" {
return action.ExitError(ctx, action.ExitUnknown, nil, "Username must not be empty")
}
if project == "" {
project, err = termio.AskForString(ctx, fmtfn(4, "b", "Project name"), "")
if err != nil {
return err
}
}
if project == "" {
return action.ExitError(ctx, action.ExitUnknown, nil, "Project must not be empty")
}
// select store
if store == "" {
store = cui.AskForStore(ctx, s.store)
}
// generate name, ask for override if already taken
if store != "" {
store += "/"
}
name := fmt.Sprintf("%sgcp/iam/%s/%s", store, fsutil.CleanFilename(project), fsutil.CleanFilename(username))
if s.store.Exists(ctx, name) {
name, err = termio.AskForString(ctx, fmtfn(2, "2", "Secret already exists, please choose another path"), name)
if err != nil {
return err
}
}
sec := secret.New("", string(buf))
if err := s.store.Set(sub.WithReason(ctx, "Created new entry"), name, sec); err != nil {
return action.ExitError(ctx, action.ExitEncrypt, err, "failed to set '%s': %s", name, err)
}
return nil
} | go | func (s *creator) createGCP(ctx context.Context, c *cli.Context) error {
var (
project string
username string
svcaccfn = c.Args().Get(0)
store = c.String("store")
err error
)
out.Green(ctx, "=> Creating GCP credentials ...")
svcaccfn, err = termio.AskForString(ctx, fmtfn(2, "1", "Service Account JSON"), svcaccfn)
if err != nil {
return err
}
buf, err := ioutil.ReadFile(svcaccfn)
if err != nil {
return err
}
username, project, err = extractGCPInfo(buf)
if err != nil {
return err
}
if username == "" {
username, err = termio.AskForString(ctx, fmtfn(4, "a", "Account name"), "")
if err != nil {
return err
}
}
if username == "" {
return action.ExitError(ctx, action.ExitUnknown, nil, "Username must not be empty")
}
if project == "" {
project, err = termio.AskForString(ctx, fmtfn(4, "b", "Project name"), "")
if err != nil {
return err
}
}
if project == "" {
return action.ExitError(ctx, action.ExitUnknown, nil, "Project must not be empty")
}
// select store
if store == "" {
store = cui.AskForStore(ctx, s.store)
}
// generate name, ask for override if already taken
if store != "" {
store += "/"
}
name := fmt.Sprintf("%sgcp/iam/%s/%s", store, fsutil.CleanFilename(project), fsutil.CleanFilename(username))
if s.store.Exists(ctx, name) {
name, err = termio.AskForString(ctx, fmtfn(2, "2", "Secret already exists, please choose another path"), name)
if err != nil {
return err
}
}
sec := secret.New("", string(buf))
if err := s.store.Set(sub.WithReason(ctx, "Created new entry"), name, sec); err != nil {
return action.ExitError(ctx, action.ExitEncrypt, err, "failed to set '%s': %s", name, err)
}
return nil
} | [
"func",
"(",
"s",
"*",
"creator",
")",
"createGCP",
"(",
"ctx",
"context",
".",
"Context",
",",
"c",
"*",
"cli",
".",
"Context",
")",
"error",
"{",
"var",
"(",
"project",
"string",
"\n",
"username",
"string",
"\n",
"svcaccfn",
"=",
"c",
".",
"Args",
"(",
")",
".",
"Get",
"(",
"0",
")",
"\n",
"store",
"=",
"c",
".",
"String",
"(",
"\"",
"\"",
")",
"\n",
"err",
"error",
"\n",
")",
"\n",
"out",
".",
"Green",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"svcaccfn",
",",
"err",
"=",
"termio",
".",
"AskForString",
"(",
"ctx",
",",
"fmtfn",
"(",
"2",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"svcaccfn",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"buf",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"svcaccfn",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"username",
",",
"project",
",",
"err",
"=",
"extractGCPInfo",
"(",
"buf",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"username",
"==",
"\"",
"\"",
"{",
"username",
",",
"err",
"=",
"termio",
".",
"AskForString",
"(",
"ctx",
",",
"fmtfn",
"(",
"4",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"username",
"==",
"\"",
"\"",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitUnknown",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"project",
"==",
"\"",
"\"",
"{",
"project",
",",
"err",
"=",
"termio",
".",
"AskForString",
"(",
"ctx",
",",
"fmtfn",
"(",
"4",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"project",
"==",
"\"",
"\"",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitUnknown",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// select store",
"if",
"store",
"==",
"\"",
"\"",
"{",
"store",
"=",
"cui",
".",
"AskForStore",
"(",
"ctx",
",",
"s",
".",
"store",
")",
"\n",
"}",
"\n\n",
"// generate name, ask for override if already taken",
"if",
"store",
"!=",
"\"",
"\"",
"{",
"store",
"+=",
"\"",
"\"",
"\n",
"}",
"\n",
"name",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"store",
",",
"fsutil",
".",
"CleanFilename",
"(",
"project",
")",
",",
"fsutil",
".",
"CleanFilename",
"(",
"username",
")",
")",
"\n",
"if",
"s",
".",
"store",
".",
"Exists",
"(",
"ctx",
",",
"name",
")",
"{",
"name",
",",
"err",
"=",
"termio",
".",
"AskForString",
"(",
"ctx",
",",
"fmtfn",
"(",
"2",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"sec",
":=",
"secret",
".",
"New",
"(",
"\"",
"\"",
",",
"string",
"(",
"buf",
")",
")",
"\n",
"if",
"err",
":=",
"s",
".",
"store",
".",
"Set",
"(",
"sub",
".",
"WithReason",
"(",
"ctx",
",",
"\"",
"\"",
")",
",",
"name",
",",
"sec",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitEncrypt",
",",
"err",
",",
"\"",
"\"",
",",
"name",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // createGCP will walk through the GCP credential creation wizard | [
"createGCP",
"will",
"walk",
"through",
"the",
"GCP",
"credential",
"creation",
"wizard"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/create/create.go#L317-L378 | train |
gopasspw/gopass | pkg/action/create/create.go | extractGCPInfo | func extractGCPInfo(buf []byte) (string, string, error) {
var m map[string]string
if err := json.Unmarshal(buf, &m); err != nil {
return "", "", err
}
p := strings.Split(m["client_email"], "@")
if len(p) < 2 {
return "", "", fmt.Errorf("client_email contains no email")
}
username := p[0]
p = strings.Split(p[1], ".")
if len(p) < 1 {
return username, "", fmt.Errorf("hostname contains not enough separators")
}
return username, p[0], nil
} | go | func extractGCPInfo(buf []byte) (string, string, error) {
var m map[string]string
if err := json.Unmarshal(buf, &m); err != nil {
return "", "", err
}
p := strings.Split(m["client_email"], "@")
if len(p) < 2 {
return "", "", fmt.Errorf("client_email contains no email")
}
username := p[0]
p = strings.Split(p[1], ".")
if len(p) < 1 {
return username, "", fmt.Errorf("hostname contains not enough separators")
}
return username, p[0], nil
} | [
"func",
"extractGCPInfo",
"(",
"buf",
"[",
"]",
"byte",
")",
"(",
"string",
",",
"string",
",",
"error",
")",
"{",
"var",
"m",
"map",
"[",
"string",
"]",
"string",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"buf",
",",
"&",
"m",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"p",
":=",
"strings",
".",
"Split",
"(",
"m",
"[",
"\"",
"\"",
"]",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"p",
")",
"<",
"2",
"{",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"username",
":=",
"p",
"[",
"0",
"]",
"\n",
"p",
"=",
"strings",
".",
"Split",
"(",
"p",
"[",
"1",
"]",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"p",
")",
"<",
"1",
"{",
"return",
"username",
",",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"username",
",",
"p",
"[",
"0",
"]",
",",
"nil",
"\n",
"}"
] | // extractGCPInfo will extract the GCP details from the given json blob | [
"extractGCPInfo",
"will",
"extract",
"the",
"GCP",
"details",
"from",
"the",
"given",
"json",
"blob"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/create/create.go#L381-L396 | train |
gopasspw/gopass | pkg/action/create/create.go | createGeneric | func (s *creator) createGeneric(ctx context.Context, c *cli.Context) error {
var (
shortname = c.Args().Get(0)
password string
store = c.String("store")
err error
genPw bool
)
out.Green(ctx, "=> Creating generic secret ...")
shortname, err = termio.AskForString(ctx, fmtfn(2, "1", "Name"), shortname)
if err != nil {
return err
}
if shortname == "" {
return action.ExitError(ctx, action.ExitUnknown, nil, "Name must not be empty")
}
genPw, err = termio.AskForBool(ctx, fmtfn(2, "2", "Generate password?"), true)
if err != nil {
return err
}
if genPw {
password, err = s.createGeneratePassword(ctx)
if err != nil {
return err
}
} else {
password, err = termio.AskForPassword(ctx, shortname)
if err != nil {
return err
}
}
// select store
if store == "" {
store = cui.AskForStore(ctx, s.store)
}
// generate name, ask for override if already taken
if store != "" {
store += "/"
}
name := fmt.Sprintf("%smisc/%s", store, fsutil.CleanFilename(shortname))
if s.store.Exists(ctx, name) {
name, err = termio.AskForString(ctx, "Secret already exists, please choose another path", name)
if err != nil {
return err
}
}
sec := secret.New(password, "")
out.Print(ctx, fmtfn(2, "3", "Enter zero or more key value pairs for this secret:"))
for {
key, err := termio.AskForString(ctx, fmtfn(4, "a", "Name (enter to quit)"), "")
if err != nil {
return err
}
if key == "" {
break
}
val, err := termio.AskForString(ctx, fmtfn(4, "b", "Value for Key '"+key+"'"), "")
if err != nil {
return err
}
_ = sec.SetValue(key, val)
}
if err := s.store.Set(sub.WithReason(ctx, "Created new entry"), name, sec); err != nil {
return action.ExitError(ctx, action.ExitEncrypt, err, "failed to set '%s': %s", name, err)
}
return s.createPrintOrCopy(ctx, c, name, password, genPw)
} | go | func (s *creator) createGeneric(ctx context.Context, c *cli.Context) error {
var (
shortname = c.Args().Get(0)
password string
store = c.String("store")
err error
genPw bool
)
out.Green(ctx, "=> Creating generic secret ...")
shortname, err = termio.AskForString(ctx, fmtfn(2, "1", "Name"), shortname)
if err != nil {
return err
}
if shortname == "" {
return action.ExitError(ctx, action.ExitUnknown, nil, "Name must not be empty")
}
genPw, err = termio.AskForBool(ctx, fmtfn(2, "2", "Generate password?"), true)
if err != nil {
return err
}
if genPw {
password, err = s.createGeneratePassword(ctx)
if err != nil {
return err
}
} else {
password, err = termio.AskForPassword(ctx, shortname)
if err != nil {
return err
}
}
// select store
if store == "" {
store = cui.AskForStore(ctx, s.store)
}
// generate name, ask for override if already taken
if store != "" {
store += "/"
}
name := fmt.Sprintf("%smisc/%s", store, fsutil.CleanFilename(shortname))
if s.store.Exists(ctx, name) {
name, err = termio.AskForString(ctx, "Secret already exists, please choose another path", name)
if err != nil {
return err
}
}
sec := secret.New(password, "")
out.Print(ctx, fmtfn(2, "3", "Enter zero or more key value pairs for this secret:"))
for {
key, err := termio.AskForString(ctx, fmtfn(4, "a", "Name (enter to quit)"), "")
if err != nil {
return err
}
if key == "" {
break
}
val, err := termio.AskForString(ctx, fmtfn(4, "b", "Value for Key '"+key+"'"), "")
if err != nil {
return err
}
_ = sec.SetValue(key, val)
}
if err := s.store.Set(sub.WithReason(ctx, "Created new entry"), name, sec); err != nil {
return action.ExitError(ctx, action.ExitEncrypt, err, "failed to set '%s': %s", name, err)
}
return s.createPrintOrCopy(ctx, c, name, password, genPw)
} | [
"func",
"(",
"s",
"*",
"creator",
")",
"createGeneric",
"(",
"ctx",
"context",
".",
"Context",
",",
"c",
"*",
"cli",
".",
"Context",
")",
"error",
"{",
"var",
"(",
"shortname",
"=",
"c",
".",
"Args",
"(",
")",
".",
"Get",
"(",
"0",
")",
"\n",
"password",
"string",
"\n",
"store",
"=",
"c",
".",
"String",
"(",
"\"",
"\"",
")",
"\n",
"err",
"error",
"\n",
"genPw",
"bool",
"\n",
")",
"\n",
"out",
".",
"Green",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"shortname",
",",
"err",
"=",
"termio",
".",
"AskForString",
"(",
"ctx",
",",
"fmtfn",
"(",
"2",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"shortname",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"shortname",
"==",
"\"",
"\"",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitUnknown",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"genPw",
",",
"err",
"=",
"termio",
".",
"AskForBool",
"(",
"ctx",
",",
"fmtfn",
"(",
"2",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"genPw",
"{",
"password",
",",
"err",
"=",
"s",
".",
"createGeneratePassword",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"else",
"{",
"password",
",",
"err",
"=",
"termio",
".",
"AskForPassword",
"(",
"ctx",
",",
"shortname",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// select store",
"if",
"store",
"==",
"\"",
"\"",
"{",
"store",
"=",
"cui",
".",
"AskForStore",
"(",
"ctx",
",",
"s",
".",
"store",
")",
"\n",
"}",
"\n\n",
"// generate name, ask for override if already taken",
"if",
"store",
"!=",
"\"",
"\"",
"{",
"store",
"+=",
"\"",
"\"",
"\n",
"}",
"\n",
"name",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"store",
",",
"fsutil",
".",
"CleanFilename",
"(",
"shortname",
")",
")",
"\n",
"if",
"s",
".",
"store",
".",
"Exists",
"(",
"ctx",
",",
"name",
")",
"{",
"name",
",",
"err",
"=",
"termio",
".",
"AskForString",
"(",
"ctx",
",",
"\"",
"\"",
",",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"sec",
":=",
"secret",
".",
"New",
"(",
"password",
",",
"\"",
"\"",
")",
"\n",
"out",
".",
"Print",
"(",
"ctx",
",",
"fmtfn",
"(",
"2",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
")",
"\n",
"for",
"{",
"key",
",",
"err",
":=",
"termio",
".",
"AskForString",
"(",
"ctx",
",",
"fmtfn",
"(",
"4",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"key",
"==",
"\"",
"\"",
"{",
"break",
"\n",
"}",
"\n",
"val",
",",
"err",
":=",
"termio",
".",
"AskForString",
"(",
"ctx",
",",
"fmtfn",
"(",
"4",
",",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"key",
"+",
"\"",
"\"",
")",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"_",
"=",
"sec",
".",
"SetValue",
"(",
"key",
",",
"val",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"s",
".",
"store",
".",
"Set",
"(",
"sub",
".",
"WithReason",
"(",
"ctx",
",",
"\"",
"\"",
")",
",",
"name",
",",
"sec",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"action",
".",
"ExitError",
"(",
"ctx",
",",
"action",
".",
"ExitEncrypt",
",",
"err",
",",
"\"",
"\"",
",",
"name",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"s",
".",
"createPrintOrCopy",
"(",
"ctx",
",",
"c",
",",
"name",
",",
"password",
",",
"genPw",
")",
"\n",
"}"
] | // createGeneric will walk through the generic secret wizard | [
"createGeneric",
"will",
"walk",
"through",
"the",
"generic",
"secret",
"wizard"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/create/create.go#L399-L468 | train |
gopasspw/gopass | pkg/action/create/create.go | createGeneratePassword | func (s *creator) createGeneratePassword(ctx context.Context) (string, error) {
noXkcd, err := termio.AskForBool(ctx, fmtfn(4, "a", "Cryptic Password?"), true)
if err != nil {
return "", err
}
if !noXkcd {
length, err := termio.AskForInt(ctx, fmtfn(4, "b", "How many words?"), 4)
if err != nil {
return "", err
}
g := xkcdpwgen.NewGenerator()
g.SetNumWords(length)
g.SetDelimiter(" ")
g.SetCapitalize(true)
return string(g.GeneratePassword()), nil
}
length, err := termio.AskForInt(ctx, fmtfn(4, "b", "How long?"), defaultLength)
if err != nil {
return "", err
}
symbols, err := termio.AskForBool(ctx, fmtfn(4, "c", "Include symbols?"), false)
if err != nil {
return "", err
}
corp, err := termio.AskForBool(ctx, fmtfn(4, "d", "Strict rules?"), false)
if err != nil {
return "", err
}
if corp {
return pwgen.GeneratePasswordWithAllClasses(length)
}
return pwgen.GeneratePassword(length, symbols), nil
} | go | func (s *creator) createGeneratePassword(ctx context.Context) (string, error) {
noXkcd, err := termio.AskForBool(ctx, fmtfn(4, "a", "Cryptic Password?"), true)
if err != nil {
return "", err
}
if !noXkcd {
length, err := termio.AskForInt(ctx, fmtfn(4, "b", "How many words?"), 4)
if err != nil {
return "", err
}
g := xkcdpwgen.NewGenerator()
g.SetNumWords(length)
g.SetDelimiter(" ")
g.SetCapitalize(true)
return string(g.GeneratePassword()), nil
}
length, err := termio.AskForInt(ctx, fmtfn(4, "b", "How long?"), defaultLength)
if err != nil {
return "", err
}
symbols, err := termio.AskForBool(ctx, fmtfn(4, "c", "Include symbols?"), false)
if err != nil {
return "", err
}
corp, err := termio.AskForBool(ctx, fmtfn(4, "d", "Strict rules?"), false)
if err != nil {
return "", err
}
if corp {
return pwgen.GeneratePasswordWithAllClasses(length)
}
return pwgen.GeneratePassword(length, symbols), nil
} | [
"func",
"(",
"s",
"*",
"creator",
")",
"createGeneratePassword",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"string",
",",
"error",
")",
"{",
"noXkcd",
",",
"err",
":=",
"termio",
".",
"AskForBool",
"(",
"ctx",
",",
"fmtfn",
"(",
"4",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"!",
"noXkcd",
"{",
"length",
",",
"err",
":=",
"termio",
".",
"AskForInt",
"(",
"ctx",
",",
"fmtfn",
"(",
"4",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"4",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"g",
":=",
"xkcdpwgen",
".",
"NewGenerator",
"(",
")",
"\n",
"g",
".",
"SetNumWords",
"(",
"length",
")",
"\n",
"g",
".",
"SetDelimiter",
"(",
"\"",
"\"",
")",
"\n",
"g",
".",
"SetCapitalize",
"(",
"true",
")",
"\n",
"return",
"string",
"(",
"g",
".",
"GeneratePassword",
"(",
")",
")",
",",
"nil",
"\n",
"}",
"\n\n",
"length",
",",
"err",
":=",
"termio",
".",
"AskForInt",
"(",
"ctx",
",",
"fmtfn",
"(",
"4",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"defaultLength",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"symbols",
",",
"err",
":=",
"termio",
".",
"AskForBool",
"(",
"ctx",
",",
"fmtfn",
"(",
"4",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"false",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"corp",
",",
"err",
":=",
"termio",
".",
"AskForBool",
"(",
"ctx",
",",
"fmtfn",
"(",
"4",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"false",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"corp",
"{",
"return",
"pwgen",
".",
"GeneratePasswordWithAllClasses",
"(",
"length",
")",
"\n",
"}",
"\n",
"return",
"pwgen",
".",
"GeneratePassword",
"(",
"length",
",",
"symbols",
")",
",",
"nil",
"\n",
"}"
] | // createGeneratePasssword will walk through the password generation steps | [
"createGeneratePasssword",
"will",
"walk",
"through",
"the",
"password",
"generation",
"steps"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/create/create.go#L471-L504 | train |
gopasspw/gopass | pkg/action/create/create.go | createGeneratePIN | func (s *creator) createGeneratePIN(ctx context.Context) (string, error) {
length, err := termio.AskForInt(ctx, fmtfn(4, "a", "How long?"), 4)
if err != nil {
return "", err
}
return pwgen.GeneratePasswordCharset(length, "0123456789"), nil
} | go | func (s *creator) createGeneratePIN(ctx context.Context) (string, error) {
length, err := termio.AskForInt(ctx, fmtfn(4, "a", "How long?"), 4)
if err != nil {
return "", err
}
return pwgen.GeneratePasswordCharset(length, "0123456789"), nil
} | [
"func",
"(",
"s",
"*",
"creator",
")",
"createGeneratePIN",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"string",
",",
"error",
")",
"{",
"length",
",",
"err",
":=",
"termio",
".",
"AskForInt",
"(",
"ctx",
",",
"fmtfn",
"(",
"4",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"4",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"pwgen",
".",
"GeneratePasswordCharset",
"(",
"length",
",",
"\"",
"\"",
")",
",",
"nil",
"\n",
"}"
] | // createGeneratePIN will walk through the PIN generation steps | [
"createGeneratePIN",
"will",
"walk",
"through",
"the",
"PIN",
"generation",
"steps"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/create/create.go#L507-L513 | train |
gopasspw/gopass | pkg/backend/context.go | WithCryptoBackendString | func WithCryptoBackendString(ctx context.Context, be string) context.Context {
if cb := cryptoBackendFromName(be); cb >= 0 {
ctx = WithCryptoBackend(ctx, cb)
}
return ctx
} | go | func WithCryptoBackendString(ctx context.Context, be string) context.Context {
if cb := cryptoBackendFromName(be); cb >= 0 {
ctx = WithCryptoBackend(ctx, cb)
}
return ctx
} | [
"func",
"WithCryptoBackendString",
"(",
"ctx",
"context",
".",
"Context",
",",
"be",
"string",
")",
"context",
".",
"Context",
"{",
"if",
"cb",
":=",
"cryptoBackendFromName",
"(",
"be",
")",
";",
"cb",
">=",
"0",
"{",
"ctx",
"=",
"WithCryptoBackend",
"(",
"ctx",
",",
"cb",
")",
"\n",
"}",
"\n",
"return",
"ctx",
"\n",
"}"
] | // WithCryptoBackendString returns a context with the given crypto backend set | [
"WithCryptoBackendString",
"returns",
"a",
"context",
"with",
"the",
"given",
"crypto",
"backend",
"set"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/context.go#L19-L24 | train |
gopasspw/gopass | pkg/backend/context.go | WithCryptoBackend | func WithCryptoBackend(ctx context.Context, be CryptoBackend) context.Context {
return context.WithValue(ctx, ctxKeyCryptoBackend, be)
} | go | func WithCryptoBackend(ctx context.Context, be CryptoBackend) context.Context {
return context.WithValue(ctx, ctxKeyCryptoBackend, be)
} | [
"func",
"WithCryptoBackend",
"(",
"ctx",
"context",
".",
"Context",
",",
"be",
"CryptoBackend",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"ctxKeyCryptoBackend",
",",
"be",
")",
"\n",
"}"
] | // WithCryptoBackend returns a context with the given crypto backend set | [
"WithCryptoBackend",
"returns",
"a",
"context",
"with",
"the",
"given",
"crypto",
"backend",
"set"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/context.go#L27-L29 | train |
gopasspw/gopass | pkg/backend/context.go | HasCryptoBackend | func HasCryptoBackend(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyCryptoBackend).(CryptoBackend)
return ok
} | go | func HasCryptoBackend(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyCryptoBackend).(CryptoBackend)
return ok
} | [
"func",
"HasCryptoBackend",
"(",
"ctx",
"context",
".",
"Context",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"ctxKeyCryptoBackend",
")",
".",
"(",
"CryptoBackend",
")",
"\n",
"return",
"ok",
"\n",
"}"
] | // HasCryptoBackend returns true if a value for crypto backend has been set in the context | [
"HasCryptoBackend",
"returns",
"true",
"if",
"a",
"value",
"for",
"crypto",
"backend",
"has",
"been",
"set",
"in",
"the",
"context"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/context.go#L32-L35 | train |
gopasspw/gopass | pkg/backend/context.go | WithRCSBackendString | func WithRCSBackendString(ctx context.Context, sb string) context.Context {
if be := rcsBackendFromName(sb); be >= 0 {
return WithRCSBackend(ctx, be)
}
return WithRCSBackend(ctx, Noop)
} | go | func WithRCSBackendString(ctx context.Context, sb string) context.Context {
if be := rcsBackendFromName(sb); be >= 0 {
return WithRCSBackend(ctx, be)
}
return WithRCSBackend(ctx, Noop)
} | [
"func",
"WithRCSBackendString",
"(",
"ctx",
"context",
".",
"Context",
",",
"sb",
"string",
")",
"context",
".",
"Context",
"{",
"if",
"be",
":=",
"rcsBackendFromName",
"(",
"sb",
")",
";",
"be",
">=",
"0",
"{",
"return",
"WithRCSBackend",
"(",
"ctx",
",",
"be",
")",
"\n",
"}",
"\n",
"return",
"WithRCSBackend",
"(",
"ctx",
",",
"Noop",
")",
"\n",
"}"
] | // WithRCSBackendString returns a context with the given sync backend set | [
"WithRCSBackendString",
"returns",
"a",
"context",
"with",
"the",
"given",
"sync",
"backend",
"set"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/context.go#L52-L57 | train |
gopasspw/gopass | pkg/backend/context.go | WithRCSBackend | func WithRCSBackend(ctx context.Context, sb RCSBackend) context.Context {
return context.WithValue(ctx, ctxKeyRCSBackend, sb)
} | go | func WithRCSBackend(ctx context.Context, sb RCSBackend) context.Context {
return context.WithValue(ctx, ctxKeyRCSBackend, sb)
} | [
"func",
"WithRCSBackend",
"(",
"ctx",
"context",
".",
"Context",
",",
"sb",
"RCSBackend",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"ctxKeyRCSBackend",
",",
"sb",
")",
"\n",
"}"
] | // WithRCSBackend returns a context with the given sync backend set | [
"WithRCSBackend",
"returns",
"a",
"context",
"with",
"the",
"given",
"sync",
"backend",
"set"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/context.go#L60-L62 | train |
gopasspw/gopass | pkg/backend/context.go | HasRCSBackend | func HasRCSBackend(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyRCSBackend).(RCSBackend)
return ok
} | go | func HasRCSBackend(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyRCSBackend).(RCSBackend)
return ok
} | [
"func",
"HasRCSBackend",
"(",
"ctx",
"context",
".",
"Context",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"ctxKeyRCSBackend",
")",
".",
"(",
"RCSBackend",
")",
"\n",
"return",
"ok",
"\n",
"}"
] | // HasRCSBackend returns true if a value for sync backend has been set in the context | [
"HasRCSBackend",
"returns",
"true",
"if",
"a",
"value",
"for",
"sync",
"backend",
"has",
"been",
"set",
"in",
"the",
"context"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/context.go#L65-L68 | train |
gopasspw/gopass | pkg/backend/context.go | WithStorageBackendString | func WithStorageBackendString(ctx context.Context, sb string) context.Context {
return WithStorageBackend(ctx, storageBackendFromName(sb))
} | go | func WithStorageBackendString(ctx context.Context, sb string) context.Context {
return WithStorageBackend(ctx, storageBackendFromName(sb))
} | [
"func",
"WithStorageBackendString",
"(",
"ctx",
"context",
".",
"Context",
",",
"sb",
"string",
")",
"context",
".",
"Context",
"{",
"return",
"WithStorageBackend",
"(",
"ctx",
",",
"storageBackendFromName",
"(",
"sb",
")",
")",
"\n",
"}"
] | // WithStorageBackendString returns a context with the given store backend set | [
"WithStorageBackendString",
"returns",
"a",
"context",
"with",
"the",
"given",
"store",
"backend",
"set"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/context.go#L80-L82 | train |
gopasspw/gopass | pkg/backend/context.go | WithStorageBackend | func WithStorageBackend(ctx context.Context, sb StorageBackend) context.Context {
return context.WithValue(ctx, ctxKeyStorageBackend, sb)
} | go | func WithStorageBackend(ctx context.Context, sb StorageBackend) context.Context {
return context.WithValue(ctx, ctxKeyStorageBackend, sb)
} | [
"func",
"WithStorageBackend",
"(",
"ctx",
"context",
".",
"Context",
",",
"sb",
"StorageBackend",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"ctxKeyStorageBackend",
",",
"sb",
")",
"\n",
"}"
] | // WithStorageBackend returns a context with the given store backend set | [
"WithStorageBackend",
"returns",
"a",
"context",
"with",
"the",
"given",
"store",
"backend",
"set"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/context.go#L85-L87 | train |
gopasspw/gopass | pkg/backend/context.go | HasStorageBackend | func HasStorageBackend(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyStorageBackend).(StorageBackend)
return ok
} | go | func HasStorageBackend(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyStorageBackend).(StorageBackend)
return ok
} | [
"func",
"HasStorageBackend",
"(",
"ctx",
"context",
".",
"Context",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"ctxKeyStorageBackend",
")",
".",
"(",
"StorageBackend",
")",
"\n",
"return",
"ok",
"\n",
"}"
] | // HasStorageBackend returns true if a value for store backend was set | [
"HasStorageBackend",
"returns",
"true",
"if",
"a",
"value",
"for",
"store",
"backend",
"was",
"set"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/context.go#L99-L102 | train |
gopasspw/gopass | pkg/config/config.go | New | func New() *Config {
return &Config{
Path: configLocation(),
Root: &StoreConfig{
AskForMore: false,
AutoClip: true,
AutoImport: true,
AutoSync: true,
ClipTimeout: 45,
Concurrency: 1,
NoColor: false,
NoConfirm: false,
NoPager: false,
SafeContent: false,
UseSymbols: false,
Notifications: true,
},
Mounts: make(map[string]*StoreConfig),
}
} | go | func New() *Config {
return &Config{
Path: configLocation(),
Root: &StoreConfig{
AskForMore: false,
AutoClip: true,
AutoImport: true,
AutoSync: true,
ClipTimeout: 45,
Concurrency: 1,
NoColor: false,
NoConfirm: false,
NoPager: false,
SafeContent: false,
UseSymbols: false,
Notifications: true,
},
Mounts: make(map[string]*StoreConfig),
}
} | [
"func",
"New",
"(",
")",
"*",
"Config",
"{",
"return",
"&",
"Config",
"{",
"Path",
":",
"configLocation",
"(",
")",
",",
"Root",
":",
"&",
"StoreConfig",
"{",
"AskForMore",
":",
"false",
",",
"AutoClip",
":",
"true",
",",
"AutoImport",
":",
"true",
",",
"AutoSync",
":",
"true",
",",
"ClipTimeout",
":",
"45",
",",
"Concurrency",
":",
"1",
",",
"NoColor",
":",
"false",
",",
"NoConfirm",
":",
"false",
",",
"NoPager",
":",
"false",
",",
"SafeContent",
":",
"false",
",",
"UseSymbols",
":",
"false",
",",
"Notifications",
":",
"true",
",",
"}",
",",
"Mounts",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"StoreConfig",
")",
",",
"}",
"\n",
"}"
] | // New creates a new config with sane default values | [
"New",
"creates",
"a",
"new",
"config",
"with",
"sane",
"default",
"values"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/config/config.go#L37-L56 | train |
gopasspw/gopass | pkg/config/config.go | GetRecipientHash | func (c *Config) GetRecipientHash(alias, name string) string {
if alias == "" {
return c.Root.RecipientHash[name]
}
if sc, found := c.Mounts[alias]; found && sc != nil {
return sc.RecipientHash[name]
}
return ""
} | go | func (c *Config) GetRecipientHash(alias, name string) string {
if alias == "" {
return c.Root.RecipientHash[name]
}
if sc, found := c.Mounts[alias]; found && sc != nil {
return sc.RecipientHash[name]
}
return ""
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"GetRecipientHash",
"(",
"alias",
",",
"name",
"string",
")",
"string",
"{",
"if",
"alias",
"==",
"\"",
"\"",
"{",
"return",
"c",
".",
"Root",
".",
"RecipientHash",
"[",
"name",
"]",
"\n",
"}",
"\n",
"if",
"sc",
",",
"found",
":=",
"c",
".",
"Mounts",
"[",
"alias",
"]",
";",
"found",
"&&",
"sc",
"!=",
"nil",
"{",
"return",
"sc",
".",
"RecipientHash",
"[",
"name",
"]",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
] | // GetRecipientHash returns the recipients hash for the given store and file | [
"GetRecipientHash",
"returns",
"the",
"recipients",
"hash",
"for",
"the",
"given",
"store",
"and",
"file"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/config/config.go#L125-L133 | train |
gopasspw/gopass | pkg/config/config.go | SetRecipientHash | func (c *Config) SetRecipientHash(alias, name, value string) error {
if alias == "" {
c.Root.setRecipientHash(name, value)
} else {
if sc, found := c.Mounts[alias]; found && sc != nil {
sc.setRecipientHash(name, value)
}
}
return c.Save()
} | go | func (c *Config) SetRecipientHash(alias, name, value string) error {
if alias == "" {
c.Root.setRecipientHash(name, value)
} else {
if sc, found := c.Mounts[alias]; found && sc != nil {
sc.setRecipientHash(name, value)
}
}
return c.Save()
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"SetRecipientHash",
"(",
"alias",
",",
"name",
",",
"value",
"string",
")",
"error",
"{",
"if",
"alias",
"==",
"\"",
"\"",
"{",
"c",
".",
"Root",
".",
"setRecipientHash",
"(",
"name",
",",
"value",
")",
"\n",
"}",
"else",
"{",
"if",
"sc",
",",
"found",
":=",
"c",
".",
"Mounts",
"[",
"alias",
"]",
";",
"found",
"&&",
"sc",
"!=",
"nil",
"{",
"sc",
".",
"setRecipientHash",
"(",
"name",
",",
"value",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"c",
".",
"Save",
"(",
")",
"\n",
"}"
] | // SetRecipientHash will set and save the recipient hash for the given store
// and file | [
"SetRecipientHash",
"will",
"set",
"and",
"save",
"the",
"recipient",
"hash",
"for",
"the",
"given",
"store",
"and",
"file"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/config/config.go#L137-L147 | train |
gopasspw/gopass | pkg/store/sub/list.go | List | func (s *Store) List(ctx context.Context, prefix string) ([]string, error) {
if s.storage == nil || s.crypto == nil {
return nil, nil
}
lst, err := s.storage.List(ctx, prefix)
if err != nil {
return nil, err
}
out.Debug(ctx, "sub.List(%s): %+v\n", prefix, lst)
out := make([]string, 0, len(lst))
cExt := "." + s.crypto.Ext()
for _, path := range lst {
if !strings.HasSuffix(path, cExt) {
continue
}
path = strings.TrimSuffix(path, cExt)
if s.alias != "" {
path = s.alias + sep + path
}
out = append(out, path)
}
return out, nil
} | go | func (s *Store) List(ctx context.Context, prefix string) ([]string, error) {
if s.storage == nil || s.crypto == nil {
return nil, nil
}
lst, err := s.storage.List(ctx, prefix)
if err != nil {
return nil, err
}
out.Debug(ctx, "sub.List(%s): %+v\n", prefix, lst)
out := make([]string, 0, len(lst))
cExt := "." + s.crypto.Ext()
for _, path := range lst {
if !strings.HasSuffix(path, cExt) {
continue
}
path = strings.TrimSuffix(path, cExt)
if s.alias != "" {
path = s.alias + sep + path
}
out = append(out, path)
}
return out, nil
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"List",
"(",
"ctx",
"context",
".",
"Context",
",",
"prefix",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"if",
"s",
".",
"storage",
"==",
"nil",
"||",
"s",
".",
"crypto",
"==",
"nil",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"lst",
",",
"err",
":=",
"s",
".",
"storage",
".",
"List",
"(",
"ctx",
",",
"prefix",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"out",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\\n",
"\"",
",",
"prefix",
",",
"lst",
")",
"\n",
"out",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"lst",
")",
")",
"\n",
"cExt",
":=",
"\"",
"\"",
"+",
"s",
".",
"crypto",
".",
"Ext",
"(",
")",
"\n",
"for",
"_",
",",
"path",
":=",
"range",
"lst",
"{",
"if",
"!",
"strings",
".",
"HasSuffix",
"(",
"path",
",",
"cExt",
")",
"{",
"continue",
"\n",
"}",
"\n",
"path",
"=",
"strings",
".",
"TrimSuffix",
"(",
"path",
",",
"cExt",
")",
"\n",
"if",
"s",
".",
"alias",
"!=",
"\"",
"\"",
"{",
"path",
"=",
"s",
".",
"alias",
"+",
"sep",
"+",
"path",
"\n",
"}",
"\n",
"out",
"=",
"append",
"(",
"out",
",",
"path",
")",
"\n",
"}",
"\n",
"return",
"out",
",",
"nil",
"\n",
"}"
] | // List will list all entries in this store | [
"List",
"will",
"list",
"all",
"entries",
"in",
"this",
"store"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/list.go#L16-L39 | train |
gopasspw/gopass | pkg/action/init.go | Initialized | func (s *Action) Initialized(ctx context.Context, c *cli.Context) error {
inited, err := s.Store.Initialized(ctx)
if err != nil {
return ExitError(ctx, ExitUnknown, err, "Failed to initialize store: %s", err)
}
if inited {
out.Debug(ctx, "Store is already initialized")
return nil
}
out.Debug(ctx, "Store needs to be initialized")
if !ctxutil.IsInteractive(ctx) {
return ExitError(ctx, ExitNotInitialized, nil, "password-store is not initialized. Try '%s init'", s.Name)
}
if ok, err := termio.AskForBool(ctx, "It seems you are new to gopass. Do you want to run the onboarding wizard?", true); err == nil && ok {
if err := s.InitOnboarding(ctx, c); err != nil {
return ExitError(ctx, ExitUnknown, err, "failed to run onboarding wizard: %s", err)
}
return nil
}
return nil
} | go | func (s *Action) Initialized(ctx context.Context, c *cli.Context) error {
inited, err := s.Store.Initialized(ctx)
if err != nil {
return ExitError(ctx, ExitUnknown, err, "Failed to initialize store: %s", err)
}
if inited {
out.Debug(ctx, "Store is already initialized")
return nil
}
out.Debug(ctx, "Store needs to be initialized")
if !ctxutil.IsInteractive(ctx) {
return ExitError(ctx, ExitNotInitialized, nil, "password-store is not initialized. Try '%s init'", s.Name)
}
if ok, err := termio.AskForBool(ctx, "It seems you are new to gopass. Do you want to run the onboarding wizard?", true); err == nil && ok {
if err := s.InitOnboarding(ctx, c); err != nil {
return ExitError(ctx, ExitUnknown, err, "failed to run onboarding wizard: %s", err)
}
return nil
}
return nil
} | [
"func",
"(",
"s",
"*",
"Action",
")",
"Initialized",
"(",
"ctx",
"context",
".",
"Context",
",",
"c",
"*",
"cli",
".",
"Context",
")",
"error",
"{",
"inited",
",",
"err",
":=",
"s",
".",
"Store",
".",
"Initialized",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"ExitError",
"(",
"ctx",
",",
"ExitUnknown",
",",
"err",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"inited",
"{",
"out",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"out",
".",
"Debug",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"if",
"!",
"ctxutil",
".",
"IsInteractive",
"(",
"ctx",
")",
"{",
"return",
"ExitError",
"(",
"ctx",
",",
"ExitNotInitialized",
",",
"nil",
",",
"\"",
"\"",
",",
"s",
".",
"Name",
")",
"\n",
"}",
"\n",
"if",
"ok",
",",
"err",
":=",
"termio",
".",
"AskForBool",
"(",
"ctx",
",",
"\"",
"\"",
",",
"true",
")",
";",
"err",
"==",
"nil",
"&&",
"ok",
"{",
"if",
"err",
":=",
"s",
".",
"InitOnboarding",
"(",
"ctx",
",",
"c",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"ExitError",
"(",
"ctx",
",",
"ExitUnknown",
",",
"err",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Initialized returns an error if the store is not properly
// prepared. | [
"Initialized",
"returns",
"an",
"error",
"if",
"the",
"store",
"is",
"not",
"properly",
"prepared",
"."
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/init.go#L25-L46 | train |
gopasspw/gopass | pkg/action/init.go | Init | func (s *Action) Init(ctx context.Context, c *cli.Context) error {
path := c.String("path")
alias := c.String("store")
ctx = initParseContext(ctx, c)
inited, err := s.Store.Initialized(ctx)
if err != nil {
return ExitError(ctx, ExitUnknown, err, "Failed to initialized store: %s", err)
}
if inited {
out.Error(ctx, "WARNING: Store is already initialized")
}
if err := s.init(ctx, alias, path, c.Args()...); err != nil {
return ExitError(ctx, ExitUnknown, err, "failed to initialize store: %s", err)
}
return nil
} | go | func (s *Action) Init(ctx context.Context, c *cli.Context) error {
path := c.String("path")
alias := c.String("store")
ctx = initParseContext(ctx, c)
inited, err := s.Store.Initialized(ctx)
if err != nil {
return ExitError(ctx, ExitUnknown, err, "Failed to initialized store: %s", err)
}
if inited {
out.Error(ctx, "WARNING: Store is already initialized")
}
if err := s.init(ctx, alias, path, c.Args()...); err != nil {
return ExitError(ctx, ExitUnknown, err, "failed to initialize store: %s", err)
}
return nil
} | [
"func",
"(",
"s",
"*",
"Action",
")",
"Init",
"(",
"ctx",
"context",
".",
"Context",
",",
"c",
"*",
"cli",
".",
"Context",
")",
"error",
"{",
"path",
":=",
"c",
".",
"String",
"(",
"\"",
"\"",
")",
"\n",
"alias",
":=",
"c",
".",
"String",
"(",
"\"",
"\"",
")",
"\n\n",
"ctx",
"=",
"initParseContext",
"(",
"ctx",
",",
"c",
")",
"\n",
"inited",
",",
"err",
":=",
"s",
".",
"Store",
".",
"Initialized",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"ExitError",
"(",
"ctx",
",",
"ExitUnknown",
",",
"err",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"inited",
"{",
"out",
".",
"Error",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"s",
".",
"init",
"(",
"ctx",
",",
"alias",
",",
"path",
",",
"c",
".",
"Args",
"(",
")",
"...",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"ExitError",
"(",
"ctx",
",",
"ExitUnknown",
",",
"err",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Init a new password store with a first gpg id | [
"Init",
"a",
"new",
"password",
"store",
"with",
"a",
"first",
"gpg",
"id"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/init.go#L49-L66 | train |
gopasspw/gopass | pkg/action/init.go | initLocal | func (s *Action) initLocal(ctx context.Context, c *cli.Context) error {
ctx = out.AddPrefix(ctx, "[local] ")
path := ""
if s.Store != nil {
path = s.Store.URL()
}
out.Print(ctx, "Initializing your local store ...")
if err := s.init(out.WithHidden(ctx, true), "", path); err != nil {
return errors.Wrapf(err, "failed to init local store")
}
out.Green(ctx, " -> OK")
out.Print(ctx, "Configuring your local store ...")
if want, err := termio.AskForBool(ctx, out.Prefix(ctx)+"Do you want to add a git remote?", false); err == nil && want {
out.Print(ctx, "Configuring the git remote ...")
if err := s.initSetupGitRemote(ctx, "", ""); err != nil {
return errors.Wrapf(err, "failed to setup git remote")
}
// autosync
if want, err := termio.AskForBool(ctx, out.Prefix(ctx)+"Do you want to automatically push any changes to the git remote (if any)?", true); err == nil {
s.cfg.Root.AutoSync = want
}
} else {
s.cfg.Root.AutoSync = false
}
// noconfirm
if want, err := termio.AskForBool(ctx, out.Prefix(ctx)+"Do you want to always confirm recipients when encrypting?", false); err == nil {
s.cfg.Root.NoConfirm = !want
}
// save config
if err := s.cfg.Save(); err != nil {
return errors.Wrapf(err, "failed to save config")
}
out.Green(ctx, " -> OK")
return nil
} | go | func (s *Action) initLocal(ctx context.Context, c *cli.Context) error {
ctx = out.AddPrefix(ctx, "[local] ")
path := ""
if s.Store != nil {
path = s.Store.URL()
}
out.Print(ctx, "Initializing your local store ...")
if err := s.init(out.WithHidden(ctx, true), "", path); err != nil {
return errors.Wrapf(err, "failed to init local store")
}
out.Green(ctx, " -> OK")
out.Print(ctx, "Configuring your local store ...")
if want, err := termio.AskForBool(ctx, out.Prefix(ctx)+"Do you want to add a git remote?", false); err == nil && want {
out.Print(ctx, "Configuring the git remote ...")
if err := s.initSetupGitRemote(ctx, "", ""); err != nil {
return errors.Wrapf(err, "failed to setup git remote")
}
// autosync
if want, err := termio.AskForBool(ctx, out.Prefix(ctx)+"Do you want to automatically push any changes to the git remote (if any)?", true); err == nil {
s.cfg.Root.AutoSync = want
}
} else {
s.cfg.Root.AutoSync = false
}
// noconfirm
if want, err := termio.AskForBool(ctx, out.Prefix(ctx)+"Do you want to always confirm recipients when encrypting?", false); err == nil {
s.cfg.Root.NoConfirm = !want
}
// save config
if err := s.cfg.Save(); err != nil {
return errors.Wrapf(err, "failed to save config")
}
out.Green(ctx, " -> OK")
return nil
} | [
"func",
"(",
"s",
"*",
"Action",
")",
"initLocal",
"(",
"ctx",
"context",
".",
"Context",
",",
"c",
"*",
"cli",
".",
"Context",
")",
"error",
"{",
"ctx",
"=",
"out",
".",
"AddPrefix",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n\n",
"path",
":=",
"\"",
"\"",
"\n",
"if",
"s",
".",
"Store",
"!=",
"nil",
"{",
"path",
"=",
"s",
".",
"Store",
".",
"URL",
"(",
")",
"\n",
"}",
"\n\n",
"out",
".",
"Print",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
":=",
"s",
".",
"init",
"(",
"out",
".",
"WithHidden",
"(",
"ctx",
",",
"true",
")",
",",
"\"",
"\"",
",",
"path",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"out",
".",
"Green",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n\n",
"out",
".",
"Print",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n\n",
"if",
"want",
",",
"err",
":=",
"termio",
".",
"AskForBool",
"(",
"ctx",
",",
"out",
".",
"Prefix",
"(",
"ctx",
")",
"+",
"\"",
"\"",
",",
"false",
")",
";",
"err",
"==",
"nil",
"&&",
"want",
"{",
"out",
".",
"Print",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
":=",
"s",
".",
"initSetupGitRemote",
"(",
"ctx",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// autosync",
"if",
"want",
",",
"err",
":=",
"termio",
".",
"AskForBool",
"(",
"ctx",
",",
"out",
".",
"Prefix",
"(",
"ctx",
")",
"+",
"\"",
"\"",
",",
"true",
")",
";",
"err",
"==",
"nil",
"{",
"s",
".",
"cfg",
".",
"Root",
".",
"AutoSync",
"=",
"want",
"\n",
"}",
"\n",
"}",
"else",
"{",
"s",
".",
"cfg",
".",
"Root",
".",
"AutoSync",
"=",
"false",
"\n",
"}",
"\n\n",
"// noconfirm",
"if",
"want",
",",
"err",
":=",
"termio",
".",
"AskForBool",
"(",
"ctx",
",",
"out",
".",
"Prefix",
"(",
"ctx",
")",
"+",
"\"",
"\"",
",",
"false",
")",
";",
"err",
"==",
"nil",
"{",
"s",
".",
"cfg",
".",
"Root",
".",
"NoConfirm",
"=",
"!",
"want",
"\n",
"}",
"\n\n",
"// save config",
"if",
"err",
":=",
"s",
".",
"cfg",
".",
"Save",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"out",
".",
"Green",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // initLocal will initialize a local store, useful for local-only setups or as
// part of team setups to create the root store | [
"initLocal",
"will",
"initialize",
"a",
"local",
"store",
"useful",
"for",
"local",
"-",
"only",
"setups",
"or",
"as",
"part",
"of",
"team",
"setups",
"to",
"create",
"the",
"root",
"store"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/init.go#L323-L364 | train |
gopasspw/gopass | pkg/action/init.go | initCreateTeam | func (s *Action) initCreateTeam(ctx context.Context, c *cli.Context, team, remote string) error {
var err error
out.Print(ctx, "Creating a new team ...")
if err := s.initLocal(ctx, c); err != nil {
return errors.Wrapf(err, "failed to create local store")
}
// name of the new team
team, err = termio.AskForString(ctx, out.Prefix(ctx)+"Please enter the name of your team (may contain slashes)", team)
if err != nil {
return errors.Wrapf(err, "failed to read user input")
}
ctx = out.AddPrefix(ctx, "["+team+"] ")
out.Print(ctx, "Initializing your shared store ...")
if err := s.init(out.WithHidden(ctx, true), team, ""); err != nil {
return errors.Wrapf(err, "failed to init shared store")
}
out.Green(ctx, " -> OK")
out.Print(ctx, "Configuring the git remote ...")
if err := s.initSetupGitRemote(ctx, team, remote); err != nil {
return errors.Wrapf(err, "failed to setup git remote")
}
out.Green(ctx, " -> OK")
out.Green(ctx, "Created Team '%s'", team)
return nil
} | go | func (s *Action) initCreateTeam(ctx context.Context, c *cli.Context, team, remote string) error {
var err error
out.Print(ctx, "Creating a new team ...")
if err := s.initLocal(ctx, c); err != nil {
return errors.Wrapf(err, "failed to create local store")
}
// name of the new team
team, err = termio.AskForString(ctx, out.Prefix(ctx)+"Please enter the name of your team (may contain slashes)", team)
if err != nil {
return errors.Wrapf(err, "failed to read user input")
}
ctx = out.AddPrefix(ctx, "["+team+"] ")
out.Print(ctx, "Initializing your shared store ...")
if err := s.init(out.WithHidden(ctx, true), team, ""); err != nil {
return errors.Wrapf(err, "failed to init shared store")
}
out.Green(ctx, " -> OK")
out.Print(ctx, "Configuring the git remote ...")
if err := s.initSetupGitRemote(ctx, team, remote); err != nil {
return errors.Wrapf(err, "failed to setup git remote")
}
out.Green(ctx, " -> OK")
out.Green(ctx, "Created Team '%s'", team)
return nil
} | [
"func",
"(",
"s",
"*",
"Action",
")",
"initCreateTeam",
"(",
"ctx",
"context",
".",
"Context",
",",
"c",
"*",
"cli",
".",
"Context",
",",
"team",
",",
"remote",
"string",
")",
"error",
"{",
"var",
"err",
"error",
"\n\n",
"out",
".",
"Print",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
":=",
"s",
".",
"initLocal",
"(",
"ctx",
",",
"c",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// name of the new team",
"team",
",",
"err",
"=",
"termio",
".",
"AskForString",
"(",
"ctx",
",",
"out",
".",
"Prefix",
"(",
"ctx",
")",
"+",
"\"",
"\"",
",",
"team",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"ctx",
"=",
"out",
".",
"AddPrefix",
"(",
"ctx",
",",
"\"",
"\"",
"+",
"team",
"+",
"\"",
"\"",
")",
"\n\n",
"out",
".",
"Print",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
":=",
"s",
".",
"init",
"(",
"out",
".",
"WithHidden",
"(",
"ctx",
",",
"true",
")",
",",
"team",
",",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"out",
".",
"Green",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n\n",
"out",
".",
"Print",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
":=",
"s",
".",
"initSetupGitRemote",
"(",
"ctx",
",",
"team",
",",
"remote",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"out",
".",
"Green",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"out",
".",
"Green",
"(",
"ctx",
",",
"\"",
"\"",
",",
"team",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // initCreateTeam will create a local root store and a shared team store | [
"initCreateTeam",
"will",
"create",
"a",
"local",
"root",
"store",
"and",
"a",
"shared",
"team",
"store"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/init.go#L367-L395 | train |
gopasspw/gopass | pkg/notify/notify_dbus.go | Notify | func Notify(ctx context.Context, subj, msg string) error {
if os.Getenv("GOPASS_NO_NOTIFY") != "" || !ctxutil.IsNotifications(ctx) {
return nil
}
conn, err := dbus.SessionBus()
if err != nil {
return err
}
obj := conn.Object("org.freedesktop.Notifications", "/org/freedesktop/Notifications")
call := obj.Call("org.freedesktop.Notifications.Notify", 0, "gopass", uint32(0), iconURI(), subj, msg, []string{}, map[string]dbus.Variant{}, int32(5000))
if call.Err != nil {
return err
}
return nil
} | go | func Notify(ctx context.Context, subj, msg string) error {
if os.Getenv("GOPASS_NO_NOTIFY") != "" || !ctxutil.IsNotifications(ctx) {
return nil
}
conn, err := dbus.SessionBus()
if err != nil {
return err
}
obj := conn.Object("org.freedesktop.Notifications", "/org/freedesktop/Notifications")
call := obj.Call("org.freedesktop.Notifications.Notify", 0, "gopass", uint32(0), iconURI(), subj, msg, []string{}, map[string]dbus.Variant{}, int32(5000))
if call.Err != nil {
return err
}
return nil
} | [
"func",
"Notify",
"(",
"ctx",
"context",
".",
"Context",
",",
"subj",
",",
"msg",
"string",
")",
"error",
"{",
"if",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
"!=",
"\"",
"\"",
"||",
"!",
"ctxutil",
".",
"IsNotifications",
"(",
"ctx",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"conn",
",",
"err",
":=",
"dbus",
".",
"SessionBus",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"obj",
":=",
"conn",
".",
"Object",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"call",
":=",
"obj",
".",
"Call",
"(",
"\"",
"\"",
",",
"0",
",",
"\"",
"\"",
",",
"uint32",
"(",
"0",
")",
",",
"iconURI",
"(",
")",
",",
"subj",
",",
"msg",
",",
"[",
"]",
"string",
"{",
"}",
",",
"map",
"[",
"string",
"]",
"dbus",
".",
"Variant",
"{",
"}",
",",
"int32",
"(",
"5000",
")",
")",
"\n",
"if",
"call",
".",
"Err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Notify displays a desktop notification with dbus | [
"Notify",
"displays",
"a",
"desktop",
"notification",
"with",
"dbus"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/notify/notify_dbus.go#L15-L31 | train |
gopasspw/gopass | pkg/backend/crypto/xc/keyring/public_key.go | Fingerprint | func (p PublicKey) Fingerprint() string {
h := make([]byte, 20)
d := sha3.NewShake256()
_, _ = d.Write([]byte{0x42})
_ = binary.Write(d, binary.LittleEndian, p.PubKeyAlgo)
_, _ = d.Write(p.PublicKey[:])
_, _ = d.Read(h)
return fmt.Sprintf("%x", h)
} | go | func (p PublicKey) Fingerprint() string {
h := make([]byte, 20)
d := sha3.NewShake256()
_, _ = d.Write([]byte{0x42})
_ = binary.Write(d, binary.LittleEndian, p.PubKeyAlgo)
_, _ = d.Write(p.PublicKey[:])
_, _ = d.Read(h)
return fmt.Sprintf("%x", h)
} | [
"func",
"(",
"p",
"PublicKey",
")",
"Fingerprint",
"(",
")",
"string",
"{",
"h",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"20",
")",
"\n",
"d",
":=",
"sha3",
".",
"NewShake256",
"(",
")",
"\n",
"_",
",",
"_",
"=",
"d",
".",
"Write",
"(",
"[",
"]",
"byte",
"{",
"0x42",
"}",
")",
"\n",
"_",
"=",
"binary",
".",
"Write",
"(",
"d",
",",
"binary",
".",
"LittleEndian",
",",
"p",
".",
"PubKeyAlgo",
")",
"\n",
"_",
",",
"_",
"=",
"d",
".",
"Write",
"(",
"p",
".",
"PublicKey",
"[",
":",
"]",
")",
"\n",
"_",
",",
"_",
"=",
"d",
".",
"Read",
"(",
"h",
")",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"h",
")",
"\n",
"}"
] | // Fingerprint calculates the unique ID of a public key | [
"Fingerprint",
"calculates",
"the",
"unique",
"ID",
"of",
"a",
"public",
"key"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/keyring/public_key.go#L30-L38 | train |
gopasspw/gopass | pkg/action/completion.go | bashEscape | func bashEscape(s string) string {
return escapeRegExp.ReplaceAllStringFunc(s, func(c string) string {
if c == `\` {
return `\\\\`
}
return `\\` + c
})
} | go | func bashEscape(s string) string {
return escapeRegExp.ReplaceAllStringFunc(s, func(c string) string {
if c == `\` {
return `\\\\`
}
return `\\` + c
})
} | [
"func",
"bashEscape",
"(",
"s",
"string",
")",
"string",
"{",
"return",
"escapeRegExp",
".",
"ReplaceAllStringFunc",
"(",
"s",
",",
"func",
"(",
"c",
"string",
")",
"string",
"{",
"if",
"c",
"==",
"`\\`",
"{",
"return",
"`\\\\\\\\`",
"\n",
"}",
"\n",
"return",
"`\\\\`",
"+",
"c",
"\n",
"}",
")",
"\n",
"}"
] | // bashEscape Escape special characters with `\` | [
"bashEscape",
"Escape",
"special",
"characters",
"with",
"\\"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/completion.go#L20-L27 | train |
gopasspw/gopass | pkg/action/completion.go | Complete | func (s *Action) Complete(ctx context.Context, c *cli.Context) {
_, 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
}
for _, v := range list {
fmt.Fprintln(stdout, bashEscape(v))
}
} | go | func (s *Action) Complete(ctx context.Context, c *cli.Context) {
_, 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
}
for _, v := range list {
fmt.Fprintln(stdout, bashEscape(v))
}
} | [
"func",
"(",
"s",
"*",
"Action",
")",
"Complete",
"(",
"ctx",
"context",
".",
"Context",
",",
"c",
"*",
"cli",
".",
"Context",
")",
"{",
"_",
",",
"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",
"for",
"_",
",",
"v",
":=",
"range",
"list",
"{",
"fmt",
".",
"Fprintln",
"(",
"stdout",
",",
"bashEscape",
"(",
"v",
")",
")",
"\n",
"}",
"\n",
"}"
] | // Complete prints a list of all password names to os.Stdout | [
"Complete",
"prints",
"a",
"list",
"of",
"all",
"password",
"names",
"to",
"os",
".",
"Stdout"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/completion.go#L30-L44 | train |
gopasspw/gopass | pkg/action/completion.go | CompletionOpenBSDKsh | func (s *Action) CompletionOpenBSDKsh(c *cli.Context, a *cli.App) error {
out := `
PASS_LIST=$(gopass ls -f)
set -A complete_gopass -- $PASS_LIST %s
`
if a == nil {
return fmt.Errorf("can not parse command options")
}
var opts []string
for _, opt := range a.Commands {
opts = append(opts, opt.Name)
if len(opt.Aliases) > 0 {
opts = append(opts, strings.Join(opt.Aliases, " "))
}
}
fmt.Fprintf(stdout, out, strings.Join(opts, " "))
return nil
} | go | func (s *Action) CompletionOpenBSDKsh(c *cli.Context, a *cli.App) error {
out := `
PASS_LIST=$(gopass ls -f)
set -A complete_gopass -- $PASS_LIST %s
`
if a == nil {
return fmt.Errorf("can not parse command options")
}
var opts []string
for _, opt := range a.Commands {
opts = append(opts, opt.Name)
if len(opt.Aliases) > 0 {
opts = append(opts, strings.Join(opt.Aliases, " "))
}
}
fmt.Fprintf(stdout, out, strings.Join(opts, " "))
return nil
} | [
"func",
"(",
"s",
"*",
"Action",
")",
"CompletionOpenBSDKsh",
"(",
"c",
"*",
"cli",
".",
"Context",
",",
"a",
"*",
"cli",
".",
"App",
")",
"error",
"{",
"out",
":=",
"`\nPASS_LIST=$(gopass ls -f)\nset -A complete_gopass -- $PASS_LIST %s\n`",
"\n\n",
"if",
"a",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"var",
"opts",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"opt",
":=",
"range",
"a",
".",
"Commands",
"{",
"opts",
"=",
"append",
"(",
"opts",
",",
"opt",
".",
"Name",
")",
"\n",
"if",
"len",
"(",
"opt",
".",
"Aliases",
")",
">",
"0",
"{",
"opts",
"=",
"append",
"(",
"opts",
",",
"strings",
".",
"Join",
"(",
"opt",
".",
"Aliases",
",",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"fmt",
".",
"Fprintf",
"(",
"stdout",
",",
"out",
",",
"strings",
".",
"Join",
"(",
"opts",
",",
"\"",
"\"",
")",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // CompletionOpenBSDKsh returns an OpenBSD ksh script used for auto completion | [
"CompletionOpenBSDKsh",
"returns",
"an",
"OpenBSD",
"ksh",
"script",
"used",
"for",
"auto",
"completion"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/completion.go#L47-L67 | train |
gopasspw/gopass | pkg/action/completion.go | CompletionBash | func (s *Action) CompletionBash(c *cli.Context) error {
out := `_gopass_bash_autocomplete() {
local cur opts base
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion )
local IFS=$'\n'
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
}
`
out += "complete -F _gopass_bash_autocomplete " + s.Name
if runtime.GOOS == "windows" {
out += "\ncomplete -F _gopass_bash_autocomplete " + s.Name + ".exe"
}
fmt.Fprintln(stdout, out)
return nil
} | go | func (s *Action) CompletionBash(c *cli.Context) error {
out := `_gopass_bash_autocomplete() {
local cur opts base
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion )
local IFS=$'\n'
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
}
`
out += "complete -F _gopass_bash_autocomplete " + s.Name
if runtime.GOOS == "windows" {
out += "\ncomplete -F _gopass_bash_autocomplete " + s.Name + ".exe"
}
fmt.Fprintln(stdout, out)
return nil
} | [
"func",
"(",
"s",
"*",
"Action",
")",
"CompletionBash",
"(",
"c",
"*",
"cli",
".",
"Context",
")",
"error",
"{",
"out",
":=",
"`_gopass_bash_autocomplete() {\n local cur opts base\n COMPREPLY=()\n cur=\"${COMP_WORDS[COMP_CWORD]}\"\n opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion )\n local IFS=$'\\n'\n COMPREPLY=( $(compgen -W \"${opts}\" -- ${cur}) )\n return 0\n }\n\n`",
"\n",
"out",
"+=",
"\"",
"\"",
"+",
"s",
".",
"Name",
"\n",
"if",
"runtime",
".",
"GOOS",
"==",
"\"",
"\"",
"{",
"out",
"+=",
"\"",
"\\n",
"\"",
"+",
"s",
".",
"Name",
"+",
"\"",
"\"",
"\n",
"}",
"\n",
"fmt",
".",
"Fprintln",
"(",
"stdout",
",",
"out",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // CompletionBash returns a bash script used for auto completion | [
"CompletionBash",
"returns",
"a",
"bash",
"script",
"used",
"for",
"auto",
"completion"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/completion.go#L70-L89 | train |
gopasspw/gopass | pkg/action/completion.go | CompletionFish | func (s *Action) CompletionFish(c *cli.Context, a *cli.App) error {
comp, err := fishcomp.GetCompletion(a)
if err != nil {
return err
}
fmt.Fprintln(stdout, comp)
return nil
} | go | func (s *Action) CompletionFish(c *cli.Context, a *cli.App) error {
comp, err := fishcomp.GetCompletion(a)
if err != nil {
return err
}
fmt.Fprintln(stdout, comp)
return nil
} | [
"func",
"(",
"s",
"*",
"Action",
")",
"CompletionFish",
"(",
"c",
"*",
"cli",
".",
"Context",
",",
"a",
"*",
"cli",
".",
"App",
")",
"error",
"{",
"comp",
",",
"err",
":=",
"fishcomp",
".",
"GetCompletion",
"(",
"a",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"fmt",
".",
"Fprintln",
"(",
"stdout",
",",
"comp",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // CompletionFish returns an autocompletion script for fish | [
"CompletionFish",
"returns",
"an",
"autocompletion",
"script",
"for",
"fish"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/completion.go#L92-L100 | train |
gopasspw/gopass | pkg/action/completion.go | CompletionZSH | func (s *Action) CompletionZSH(c *cli.Context, a *cli.App) error {
comp, err := zshcomp.GetCompletion(a)
if err != nil {
return err
}
fmt.Fprintln(stdout, comp)
return nil
} | go | func (s *Action) CompletionZSH(c *cli.Context, a *cli.App) error {
comp, err := zshcomp.GetCompletion(a)
if err != nil {
return err
}
fmt.Fprintln(stdout, comp)
return nil
} | [
"func",
"(",
"s",
"*",
"Action",
")",
"CompletionZSH",
"(",
"c",
"*",
"cli",
".",
"Context",
",",
"a",
"*",
"cli",
".",
"App",
")",
"error",
"{",
"comp",
",",
"err",
":=",
"zshcomp",
".",
"GetCompletion",
"(",
"a",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"fmt",
".",
"Fprintln",
"(",
"stdout",
",",
"comp",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // CompletionZSH returns a zsh completion script | [
"CompletionZSH",
"returns",
"a",
"zsh",
"completion",
"script"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/completion.go#L103-L111 | train |
gopasspw/gopass | pkg/agent/client/client.go | New | func New(dir string) *Client {
socket := filepath.Join(dir, ".gopass-agent.sock")
return &Client{
http: &http.Client{
Transport: &http.Transport{
DialContext: func(context.Context, string, string) (net.Conn, error) {
return net.Dial("unix", socket)
},
},
Timeout: 10 * time.Minute,
},
}
} | go | func New(dir string) *Client {
socket := filepath.Join(dir, ".gopass-agent.sock")
return &Client{
http: &http.Client{
Transport: &http.Transport{
DialContext: func(context.Context, string, string) (net.Conn, error) {
return net.Dial("unix", socket)
},
},
Timeout: 10 * time.Minute,
},
}
} | [
"func",
"New",
"(",
"dir",
"string",
")",
"*",
"Client",
"{",
"socket",
":=",
"filepath",
".",
"Join",
"(",
"dir",
",",
"\"",
"\"",
")",
"\n",
"return",
"&",
"Client",
"{",
"http",
":",
"&",
"http",
".",
"Client",
"{",
"Transport",
":",
"&",
"http",
".",
"Transport",
"{",
"DialContext",
":",
"func",
"(",
"context",
".",
"Context",
",",
"string",
",",
"string",
")",
"(",
"net",
".",
"Conn",
",",
"error",
")",
"{",
"return",
"net",
".",
"Dial",
"(",
"\"",
"\"",
",",
"socket",
")",
"\n",
"}",
",",
"}",
",",
"Timeout",
":",
"10",
"*",
"time",
".",
"Minute",
",",
"}",
",",
"}",
"\n",
"}"
] | // New creates a new client | [
"New",
"creates",
"a",
"new",
"client"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/agent/client/client.go#L24-L36 | train |
gopasspw/gopass | pkg/agent/client/client.go | Ping | func (c *Client) Ping(ctx context.Context) error {
pc := &http.Client{
Transport: c.http.Transport,
Timeout: 5 * time.Second,
}
resp, err := pc.Get("http://unix/ping")
if err != nil {
return err
}
_ = resp.Body.Close()
return nil
} | go | func (c *Client) Ping(ctx context.Context) error {
pc := &http.Client{
Transport: c.http.Transport,
Timeout: 5 * time.Second,
}
resp, err := pc.Get("http://unix/ping")
if err != nil {
return err
}
_ = resp.Body.Close()
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Ping",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"pc",
":=",
"&",
"http",
".",
"Client",
"{",
"Transport",
":",
"c",
".",
"http",
".",
"Transport",
",",
"Timeout",
":",
"5",
"*",
"time",
".",
"Second",
",",
"}",
"\n",
"resp",
",",
"err",
":=",
"pc",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"_",
"=",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Ping checks connectivity to the agent | [
"Ping",
"checks",
"connectivity",
"to",
"the",
"agent"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/agent/client/client.go#L39-L50 | train |
gopasspw/gopass | pkg/agent/client/client.go | Remove | func (c *Client) Remove(ctx context.Context, key string) error {
if err := c.checkAgent(ctx); err != nil {
return errors.Wrapf(err, "agent not available: %s", err)
}
u, err := url.Parse("http://unix/cache/remove")
if err != nil {
return errors.Wrapf(err, "failed to build request url")
}
values := u.Query()
values.Set("key", key)
u.RawQuery = values.Encode()
resp, err := c.http.Get(u.String())
if err != nil {
return errors.Wrapf(err, "failed to talk to agent")
}
defer func() { _ = resp.Body.Close() }()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("request failed: %d", resp.StatusCode)
}
return nil
} | go | func (c *Client) Remove(ctx context.Context, key string) error {
if err := c.checkAgent(ctx); err != nil {
return errors.Wrapf(err, "agent not available: %s", err)
}
u, err := url.Parse("http://unix/cache/remove")
if err != nil {
return errors.Wrapf(err, "failed to build request url")
}
values := u.Query()
values.Set("key", key)
u.RawQuery = values.Encode()
resp, err := c.http.Get(u.String())
if err != nil {
return errors.Wrapf(err, "failed to talk to agent")
}
defer func() { _ = resp.Body.Close() }()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("request failed: %d", resp.StatusCode)
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Remove",
"(",
"ctx",
"context",
".",
"Context",
",",
"key",
"string",
")",
"error",
"{",
"if",
"err",
":=",
"c",
".",
"checkAgent",
"(",
"ctx",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"u",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"values",
":=",
"u",
".",
"Query",
"(",
")",
"\n",
"values",
".",
"Set",
"(",
"\"",
"\"",
",",
"key",
")",
"\n",
"u",
".",
"RawQuery",
"=",
"values",
".",
"Encode",
"(",
")",
"\n\n",
"resp",
",",
"err",
":=",
"c",
".",
"http",
".",
"Get",
"(",
"u",
".",
"String",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"_",
"=",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"}",
"(",
")",
"\n\n",
"if",
"resp",
".",
"StatusCode",
"!=",
"http",
".",
"StatusOK",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"resp",
".",
"StatusCode",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Remove un-caches a single key | [
"Remove",
"un",
"-",
"caches",
"a",
"single",
"key"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/agent/client/client.go#L72-L97 | train |
gopasspw/gopass | pkg/backend/crypto/xc/import.go | ImportPublicKey | func (x *XC) ImportPublicKey(ctx context.Context, buf []byte) error {
if err := x.pubring.Import(buf); err != nil {
return err
}
return x.pubring.Save()
} | go | func (x *XC) ImportPublicKey(ctx context.Context, buf []byte) error {
if err := x.pubring.Import(buf); err != nil {
return err
}
return x.pubring.Save()
} | [
"func",
"(",
"x",
"*",
"XC",
")",
"ImportPublicKey",
"(",
"ctx",
"context",
".",
"Context",
",",
"buf",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"err",
":=",
"x",
".",
"pubring",
".",
"Import",
"(",
"buf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"x",
".",
"pubring",
".",
"Save",
"(",
")",
"\n",
"}"
] | // ImportPublicKey imports a given public key into the keyring | [
"ImportPublicKey",
"imports",
"a",
"given",
"public",
"key",
"into",
"the",
"keyring"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/import.go#L6-L11 | train |
gopasspw/gopass | pkg/backend/crypto/xc/import.go | ImportPrivateKey | func (x *XC) ImportPrivateKey(ctx context.Context, buf []byte) error {
if err := x.secring.Import(buf); err != nil {
return err
}
return x.secring.Save()
} | go | func (x *XC) ImportPrivateKey(ctx context.Context, buf []byte) error {
if err := x.secring.Import(buf); err != nil {
return err
}
return x.secring.Save()
} | [
"func",
"(",
"x",
"*",
"XC",
")",
"ImportPrivateKey",
"(",
"ctx",
"context",
".",
"Context",
",",
"buf",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"err",
":=",
"x",
".",
"secring",
".",
"Import",
"(",
"buf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"x",
".",
"secring",
".",
"Save",
"(",
")",
"\n",
"}"
] | // ImportPrivateKey imports a given private key into the keyring | [
"ImportPrivateKey",
"imports",
"a",
"given",
"private",
"key",
"into",
"the",
"keyring"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/import.go#L14-L19 | train |
gopasspw/gopass | pkg/backend/crypto/xc/xc.go | New | func New(dir string, client agentClient) (*XC, error) {
skr, _ := keyring.LoadSecring(filepath.Join(dir, secringFilename))
pkr, _ := keyring.LoadPubring(filepath.Join(dir, pubringFilename), skr)
return &XC{
dir: dir,
pubring: pkr,
secring: skr,
client: client,
}, nil
} | go | func New(dir string, client agentClient) (*XC, error) {
skr, _ := keyring.LoadSecring(filepath.Join(dir, secringFilename))
pkr, _ := keyring.LoadPubring(filepath.Join(dir, pubringFilename), skr)
return &XC{
dir: dir,
pubring: pkr,
secring: skr,
client: client,
}, nil
} | [
"func",
"New",
"(",
"dir",
"string",
",",
"client",
"agentClient",
")",
"(",
"*",
"XC",
",",
"error",
")",
"{",
"skr",
",",
"_",
":=",
"keyring",
".",
"LoadSecring",
"(",
"filepath",
".",
"Join",
"(",
"dir",
",",
"secringFilename",
")",
")",
"\n",
"pkr",
",",
"_",
":=",
"keyring",
".",
"LoadPubring",
"(",
"filepath",
".",
"Join",
"(",
"dir",
",",
"pubringFilename",
")",
",",
"skr",
")",
"\n",
"return",
"&",
"XC",
"{",
"dir",
":",
"dir",
",",
"pubring",
":",
"pkr",
",",
"secring",
":",
"skr",
",",
"client",
":",
"client",
",",
"}",
",",
"nil",
"\n",
"}"
] | // New creates a new XC backend | [
"New",
"creates",
"a",
"new",
"XC",
"backend"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/xc.go#L37-L46 | train |
gopasspw/gopass | pkg/backend/crypto/xc/xc.go | RemoveKey | func (x *XC) RemoveKey(id string) error {
if x.secring.Contains(id) {
if err := x.secring.Remove(id); err != nil {
return err
}
return x.secring.Save()
}
if x.pubring.Contains(id) {
if err := x.pubring.Remove(id); err != nil {
return err
}
return x.pubring.Save()
}
return fmt.Errorf("not found")
} | go | func (x *XC) RemoveKey(id string) error {
if x.secring.Contains(id) {
if err := x.secring.Remove(id); err != nil {
return err
}
return x.secring.Save()
}
if x.pubring.Contains(id) {
if err := x.pubring.Remove(id); err != nil {
return err
}
return x.pubring.Save()
}
return fmt.Errorf("not found")
} | [
"func",
"(",
"x",
"*",
"XC",
")",
"RemoveKey",
"(",
"id",
"string",
")",
"error",
"{",
"if",
"x",
".",
"secring",
".",
"Contains",
"(",
"id",
")",
"{",
"if",
"err",
":=",
"x",
".",
"secring",
".",
"Remove",
"(",
"id",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"x",
".",
"secring",
".",
"Save",
"(",
")",
"\n",
"}",
"\n",
"if",
"x",
".",
"pubring",
".",
"Contains",
"(",
"id",
")",
"{",
"if",
"err",
":=",
"x",
".",
"pubring",
".",
"Remove",
"(",
"id",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"x",
".",
"pubring",
".",
"Save",
"(",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // RemoveKey removes a single key from the keyring | [
"RemoveKey",
"removes",
"a",
"single",
"key",
"from",
"the",
"keyring"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/xc.go#L49-L63 | train |
gopasspw/gopass | pkg/backend/crypto/xc/xc.go | Initialized | func (x *XC) Initialized(ctx context.Context) error {
if x == nil {
return fmt.Errorf("XC not initialized")
}
if x.pubring == nil {
return fmt.Errorf("pubring not initialized")
}
if x.secring == nil {
return fmt.Errorf("secring not initialized")
}
if x.client == nil {
return fmt.Errorf("client not initialized")
}
if err := x.client.Ping(ctx); err != nil {
return fmt.Errorf("agent not running")
}
return nil
} | go | func (x *XC) Initialized(ctx context.Context) error {
if x == nil {
return fmt.Errorf("XC not initialized")
}
if x.pubring == nil {
return fmt.Errorf("pubring not initialized")
}
if x.secring == nil {
return fmt.Errorf("secring not initialized")
}
if x.client == nil {
return fmt.Errorf("client not initialized")
}
if err := x.client.Ping(ctx); err != nil {
return fmt.Errorf("agent not running")
}
return nil
} | [
"func",
"(",
"x",
"*",
"XC",
")",
"Initialized",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"if",
"x",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"x",
".",
"pubring",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"x",
".",
"secring",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"x",
".",
"client",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"x",
".",
"client",
".",
"Ping",
"(",
"ctx",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Initialized returns an error if this backend is not properly initialized | [
"Initialized",
"returns",
"an",
"error",
"if",
"this",
"backend",
"is",
"not",
"properly",
"initialized"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/xc.go#L66-L83 | train |
gopasspw/gopass | pkg/backend/crypto/xc/xc.go | Version | func (x *XC) Version(ctx context.Context) semver.Version {
return semver.Version{
Patch: 1,
}
} | go | func (x *XC) Version(ctx context.Context) semver.Version {
return semver.Version{
Patch: 1,
}
} | [
"func",
"(",
"x",
"*",
"XC",
")",
"Version",
"(",
"ctx",
"context",
".",
"Context",
")",
"semver",
".",
"Version",
"{",
"return",
"semver",
".",
"Version",
"{",
"Patch",
":",
"1",
",",
"}",
"\n",
"}"
] | // Version returns 0.0.1 | [
"Version",
"returns",
"0",
".",
"0",
".",
"1"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/xc.go#L91-L95 | train |
gopasspw/gopass | pkg/backend/crypto/gpg/cli/binary.go | Binary | func Binary(ctx context.Context, bin string) (string, error) {
bins, err := detectBinaryCandidates(bin)
if err != nil {
return "", err
}
bv := make(byVersion, 0, len(bins))
for _, b := range bins {
//out.Debug(ctx, "gpg.detectBinary - Looking for '%s' ...", b)
if p, err := exec.LookPath(b); err == nil {
gb := gpgBin{
path: p,
ver: version(ctx, p),
}
//out.Debug(ctx, "gpg.detectBinary - Found '%s' at '%s' (%s)", b, p, gb.ver.String())
bv = append(bv, gb)
}
}
if len(bv) < 1 {
return "", errors.New("no gpg binary found")
}
sort.Sort(bv)
binary := bv[len(bv)-1].path
//out.Debug(ctx, "gpg.detectBinary - using '%s'", binary)
return binary, nil
} | go | func Binary(ctx context.Context, bin string) (string, error) {
bins, err := detectBinaryCandidates(bin)
if err != nil {
return "", err
}
bv := make(byVersion, 0, len(bins))
for _, b := range bins {
//out.Debug(ctx, "gpg.detectBinary - Looking for '%s' ...", b)
if p, err := exec.LookPath(b); err == nil {
gb := gpgBin{
path: p,
ver: version(ctx, p),
}
//out.Debug(ctx, "gpg.detectBinary - Found '%s' at '%s' (%s)", b, p, gb.ver.String())
bv = append(bv, gb)
}
}
if len(bv) < 1 {
return "", errors.New("no gpg binary found")
}
sort.Sort(bv)
binary := bv[len(bv)-1].path
//out.Debug(ctx, "gpg.detectBinary - using '%s'", binary)
return binary, nil
} | [
"func",
"Binary",
"(",
"ctx",
"context",
".",
"Context",
",",
"bin",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"bins",
",",
"err",
":=",
"detectBinaryCandidates",
"(",
"bin",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"bv",
":=",
"make",
"(",
"byVersion",
",",
"0",
",",
"len",
"(",
"bins",
")",
")",
"\n",
"for",
"_",
",",
"b",
":=",
"range",
"bins",
"{",
"//out.Debug(ctx, \"gpg.detectBinary - Looking for '%s' ...\", b)",
"if",
"p",
",",
"err",
":=",
"exec",
".",
"LookPath",
"(",
"b",
")",
";",
"err",
"==",
"nil",
"{",
"gb",
":=",
"gpgBin",
"{",
"path",
":",
"p",
",",
"ver",
":",
"version",
"(",
"ctx",
",",
"p",
")",
",",
"}",
"\n",
"//out.Debug(ctx, \"gpg.detectBinary - Found '%s' at '%s' (%s)\", b, p, gb.ver.String())",
"bv",
"=",
"append",
"(",
"bv",
",",
"gb",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"bv",
")",
"<",
"1",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"sort",
".",
"Sort",
"(",
"bv",
")",
"\n",
"binary",
":=",
"bv",
"[",
"len",
"(",
"bv",
")",
"-",
"1",
"]",
".",
"path",
"\n",
"//out.Debug(ctx, \"gpg.detectBinary - using '%s'\", binary)",
"return",
"binary",
",",
"nil",
"\n",
"}"
] | // Binary reutrns the GGP binary location | [
"Binary",
"reutrns",
"the",
"GGP",
"binary",
"location"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/cli/binary.go#L19-L43 | train |
gopasspw/gopass | pkg/out/context.go | WithPrefix | func WithPrefix(ctx context.Context, prefix string) context.Context {
return context.WithValue(ctx, ctxKeyPrefix, prefix)
} | go | func WithPrefix(ctx context.Context, prefix string) context.Context {
return context.WithValue(ctx, ctxKeyPrefix, prefix)
} | [
"func",
"WithPrefix",
"(",
"ctx",
"context",
".",
"Context",
",",
"prefix",
"string",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"ctxKeyPrefix",
",",
"prefix",
")",
"\n",
"}"
] | // WithPrefix returns a context with the given prefix set | [
"WithPrefix",
"returns",
"a",
"context",
"with",
"the",
"given",
"prefix",
"set"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/out/context.go#L14-L16 | train |
gopasspw/gopass | pkg/out/context.go | AddPrefix | func AddPrefix(ctx context.Context, prefix string) context.Context {
if prefix == "" {
return ctx
}
pfx := Prefix(ctx)
if pfx == "" {
return WithPrefix(ctx, prefix)
}
return WithPrefix(ctx, pfx+prefix)
} | go | func AddPrefix(ctx context.Context, prefix string) context.Context {
if prefix == "" {
return ctx
}
pfx := Prefix(ctx)
if pfx == "" {
return WithPrefix(ctx, prefix)
}
return WithPrefix(ctx, pfx+prefix)
} | [
"func",
"AddPrefix",
"(",
"ctx",
"context",
".",
"Context",
",",
"prefix",
"string",
")",
"context",
".",
"Context",
"{",
"if",
"prefix",
"==",
"\"",
"\"",
"{",
"return",
"ctx",
"\n",
"}",
"\n",
"pfx",
":=",
"Prefix",
"(",
"ctx",
")",
"\n",
"if",
"pfx",
"==",
"\"",
"\"",
"{",
"return",
"WithPrefix",
"(",
"ctx",
",",
"prefix",
")",
"\n",
"}",
"\n",
"return",
"WithPrefix",
"(",
"ctx",
",",
"pfx",
"+",
"prefix",
")",
"\n",
"}"
] | // AddPrefix returns a context with the given prefix added to end of the
// existing prefix | [
"AddPrefix",
"returns",
"a",
"context",
"with",
"the",
"given",
"prefix",
"added",
"to",
"end",
"of",
"the",
"existing",
"prefix"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/out/context.go#L20-L29 | train |
gopasspw/gopass | pkg/out/context.go | Prefix | func Prefix(ctx context.Context) string {
sv, ok := ctx.Value(ctxKeyPrefix).(string)
if !ok {
return ""
}
return sv
} | go | func Prefix(ctx context.Context) string {
sv, ok := ctx.Value(ctxKeyPrefix).(string)
if !ok {
return ""
}
return sv
} | [
"func",
"Prefix",
"(",
"ctx",
"context",
".",
"Context",
")",
"string",
"{",
"sv",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"ctxKeyPrefix",
")",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"sv",
"\n",
"}"
] | // Prefix returns the prefix or an empty string | [
"Prefix",
"returns",
"the",
"prefix",
"or",
"an",
"empty",
"string"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/out/context.go#L32-L38 | train |
gopasspw/gopass | pkg/out/context.go | WithHidden | func WithHidden(ctx context.Context, hidden bool) context.Context {
return context.WithValue(ctx, ctxKeyHidden, hidden)
} | go | func WithHidden(ctx context.Context, hidden bool) context.Context {
return context.WithValue(ctx, ctxKeyHidden, hidden)
} | [
"func",
"WithHidden",
"(",
"ctx",
"context",
".",
"Context",
",",
"hidden",
"bool",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"ctxKeyHidden",
",",
"hidden",
")",
"\n",
"}"
] | // WithHidden returns a context with the flag value for hidden set | [
"WithHidden",
"returns",
"a",
"context",
"with",
"the",
"flag",
"value",
"for",
"hidden",
"set"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/out/context.go#L41-L43 | train |
gopasspw/gopass | pkg/out/context.go | IsHidden | func IsHidden(ctx context.Context) bool {
bv, ok := ctx.Value(ctxKeyHidden).(bool)
if !ok {
return false
}
return bv
} | go | func IsHidden(ctx context.Context) bool {
bv, ok := ctx.Value(ctxKeyHidden).(bool)
if !ok {
return false
}
return bv
} | [
"func",
"IsHidden",
"(",
"ctx",
"context",
".",
"Context",
")",
"bool",
"{",
"bv",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"ctxKeyHidden",
")",
".",
"(",
"bool",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"bv",
"\n",
"}"
] | // IsHidden returns true if any output should be hidden in this context | [
"IsHidden",
"returns",
"true",
"if",
"any",
"output",
"should",
"be",
"hidden",
"in",
"this",
"context"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/out/context.go#L46-L52 | train |
gopasspw/gopass | pkg/out/context.go | WithNewline | func WithNewline(ctx context.Context, nl bool) context.Context {
return context.WithValue(ctx, ctxKeyNewline, nl)
} | go | func WithNewline(ctx context.Context, nl bool) context.Context {
return context.WithValue(ctx, ctxKeyNewline, nl)
} | [
"func",
"WithNewline",
"(",
"ctx",
"context",
".",
"Context",
",",
"nl",
"bool",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"ctxKeyNewline",
",",
"nl",
")",
"\n",
"}"
] | // WithNewline returns a context with the flag value for newline set | [
"WithNewline",
"returns",
"a",
"context",
"with",
"the",
"flag",
"value",
"for",
"newline",
"set"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/out/context.go#L55-L57 | train |
gopasspw/gopass | pkg/action/move.go | Move | func (s *Action) Move(ctx context.Context, c *cli.Context) error {
force := c.Bool("force")
if len(c.Args()) != 2 {
return ExitError(ctx, ExitUsage, nil, "Usage: %s mv old-path new-path", s.Name)
}
from := c.Args()[0]
to := c.Args()[1]
if !force {
if s.Store.Exists(ctx, to) && !termio.AskForConfirmation(ctx, fmt.Sprintf("%s already exists. Overwrite it?", to)) {
return ExitError(ctx, ExitAborted, nil, "not overwriting your current secret")
}
}
if err := s.Store.Move(ctx, from, to); err != nil {
return ExitError(ctx, ExitUnknown, err, "%s", err)
}
return nil
} | go | func (s *Action) Move(ctx context.Context, c *cli.Context) error {
force := c.Bool("force")
if len(c.Args()) != 2 {
return ExitError(ctx, ExitUsage, nil, "Usage: %s mv old-path new-path", s.Name)
}
from := c.Args()[0]
to := c.Args()[1]
if !force {
if s.Store.Exists(ctx, to) && !termio.AskForConfirmation(ctx, fmt.Sprintf("%s already exists. Overwrite it?", to)) {
return ExitError(ctx, ExitAborted, nil, "not overwriting your current secret")
}
}
if err := s.Store.Move(ctx, from, to); err != nil {
return ExitError(ctx, ExitUnknown, err, "%s", err)
}
return nil
} | [
"func",
"(",
"s",
"*",
"Action",
")",
"Move",
"(",
"ctx",
"context",
".",
"Context",
",",
"c",
"*",
"cli",
".",
"Context",
")",
"error",
"{",
"force",
":=",
"c",
".",
"Bool",
"(",
"\"",
"\"",
")",
"\n\n",
"if",
"len",
"(",
"c",
".",
"Args",
"(",
")",
")",
"!=",
"2",
"{",
"return",
"ExitError",
"(",
"ctx",
",",
"ExitUsage",
",",
"nil",
",",
"\"",
"\"",
",",
"s",
".",
"Name",
")",
"\n",
"}",
"\n\n",
"from",
":=",
"c",
".",
"Args",
"(",
")",
"[",
"0",
"]",
"\n",
"to",
":=",
"c",
".",
"Args",
"(",
")",
"[",
"1",
"]",
"\n\n",
"if",
"!",
"force",
"{",
"if",
"s",
".",
"Store",
".",
"Exists",
"(",
"ctx",
",",
"to",
")",
"&&",
"!",
"termio",
".",
"AskForConfirmation",
"(",
"ctx",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"to",
")",
")",
"{",
"return",
"ExitError",
"(",
"ctx",
",",
"ExitAborted",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"s",
".",
"Store",
".",
"Move",
"(",
"ctx",
",",
"from",
",",
"to",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"ExitError",
"(",
"ctx",
",",
"ExitUnknown",
",",
"err",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Move the content from one secret to another | [
"Move",
"the",
"content",
"from",
"one",
"secret",
"to",
"another"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/move.go#L13-L34 | train |
gopasspw/gopass | pkg/config/secrets/config.go | New | func New(dir, passphrase string) (*Config, error) {
if dir == "" || dir == "." {
return nil, fmt.Errorf("dir must not be empty")
}
fn := filepath.Join(dir, filename)
c := &Config{
filename: fn,
passphrase: passphrase,
}
if !fsutil.IsFile(fn) {
err := save(c.filename, c.passphrase, map[string]string{})
return c, err
}
_, err := c.Get("")
if err != nil {
return nil, errors.Wrapf(err, "failed to open existing secrects config %s: %s", fn, err)
}
return c, nil
} | go | func New(dir, passphrase string) (*Config, error) {
if dir == "" || dir == "." {
return nil, fmt.Errorf("dir must not be empty")
}
fn := filepath.Join(dir, filename)
c := &Config{
filename: fn,
passphrase: passphrase,
}
if !fsutil.IsFile(fn) {
err := save(c.filename, c.passphrase, map[string]string{})
return c, err
}
_, err := c.Get("")
if err != nil {
return nil, errors.Wrapf(err, "failed to open existing secrects config %s: %s", fn, err)
}
return c, nil
} | [
"func",
"New",
"(",
"dir",
",",
"passphrase",
"string",
")",
"(",
"*",
"Config",
",",
"error",
")",
"{",
"if",
"dir",
"==",
"\"",
"\"",
"||",
"dir",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"fn",
":=",
"filepath",
".",
"Join",
"(",
"dir",
",",
"filename",
")",
"\n\n",
"c",
":=",
"&",
"Config",
"{",
"filename",
":",
"fn",
",",
"passphrase",
":",
"passphrase",
",",
"}",
"\n\n",
"if",
"!",
"fsutil",
".",
"IsFile",
"(",
"fn",
")",
"{",
"err",
":=",
"save",
"(",
"c",
".",
"filename",
",",
"c",
".",
"passphrase",
",",
"map",
"[",
"string",
"]",
"string",
"{",
"}",
")",
"\n",
"return",
"c",
",",
"err",
"\n",
"}",
"\n\n",
"_",
",",
"err",
":=",
"c",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"fn",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"c",
",",
"nil",
"\n",
"}"
] | // New will load the given file from disk and try to unseal it | [
"New",
"will",
"load",
"the",
"given",
"file",
"from",
"disk",
"and",
"try",
"to",
"unseal",
"it"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/config/secrets/config.go#L33-L54 | train |
gopasspw/gopass | pkg/config/secrets/config.go | Get | func (c *Config) Get(key string) (string, error) {
data, err := load(c.filename, c.passphrase)
return data[key], err
} | go | func (c *Config) Get(key string) (string, error) {
data, err := load(c.filename, c.passphrase)
return data[key], err
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"Get",
"(",
"key",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"data",
",",
"err",
":=",
"load",
"(",
"c",
".",
"filename",
",",
"c",
".",
"passphrase",
")",
"\n",
"return",
"data",
"[",
"key",
"]",
",",
"err",
"\n",
"}"
] | // Get loads the requested key from disk | [
"Get",
"loads",
"the",
"requested",
"key",
"from",
"disk"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/config/secrets/config.go#L57-L60 | train |
gopasspw/gopass | pkg/config/secrets/config.go | Set | func (c *Config) Set(key, value string) error {
data, err := load(c.filename, c.passphrase)
if err != nil {
return errors.Wrapf(err, "failed to read secrects config %s: %s", c.filename, err)
}
old := data[key]
if value == old {
return nil
}
data[key] = value
return save(c.filename, c.passphrase, data)
} | go | func (c *Config) Set(key, value string) error {
data, err := load(c.filename, c.passphrase)
if err != nil {
return errors.Wrapf(err, "failed to read secrects config %s: %s", c.filename, err)
}
old := data[key]
if value == old {
return nil
}
data[key] = value
return save(c.filename, c.passphrase, data)
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"Set",
"(",
"key",
",",
"value",
"string",
")",
"error",
"{",
"data",
",",
"err",
":=",
"load",
"(",
"c",
".",
"filename",
",",
"c",
".",
"passphrase",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"c",
".",
"filename",
",",
"err",
")",
"\n",
"}",
"\n\n",
"old",
":=",
"data",
"[",
"key",
"]",
"\n",
"if",
"value",
"==",
"old",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"data",
"[",
"key",
"]",
"=",
"value",
"\n",
"return",
"save",
"(",
"c",
".",
"filename",
",",
"c",
".",
"passphrase",
",",
"data",
")",
"\n",
"}"
] | // Set writes the requested key to disk | [
"Set",
"writes",
"the",
"requested",
"key",
"to",
"disk"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/config/secrets/config.go#L63-L76 | train |
gopasspw/gopass | pkg/config/secrets/config.go | Unset | func (c *Config) Unset(key string) error {
data, err := load(c.filename, c.passphrase)
if err != nil {
return errors.Wrapf(err, "failed to read secrects config %s: %s", c.filename, err)
}
_, found := data[key]
if !found {
return nil
}
delete(data, key)
return save(c.filename, c.passphrase, data)
} | go | func (c *Config) Unset(key string) error {
data, err := load(c.filename, c.passphrase)
if err != nil {
return errors.Wrapf(err, "failed to read secrects config %s: %s", c.filename, err)
}
_, found := data[key]
if !found {
return nil
}
delete(data, key)
return save(c.filename, c.passphrase, data)
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"Unset",
"(",
"key",
"string",
")",
"error",
"{",
"data",
",",
"err",
":=",
"load",
"(",
"c",
".",
"filename",
",",
"c",
".",
"passphrase",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"c",
".",
"filename",
",",
"err",
")",
"\n",
"}",
"\n\n",
"_",
",",
"found",
":=",
"data",
"[",
"key",
"]",
"\n",
"if",
"!",
"found",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"delete",
"(",
"data",
",",
"key",
")",
"\n",
"return",
"save",
"(",
"c",
".",
"filename",
",",
"c",
".",
"passphrase",
",",
"data",
")",
"\n",
"}"
] | // Unset removes the key from the storage | [
"Unset",
"removes",
"the",
"key",
"from",
"the",
"storage"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/config/secrets/config.go#L79-L92 | train |
gopasspw/gopass | pkg/config/secrets/config.go | open | func open(buf []byte, passphrase string) (map[string]string, error) {
salt := make([]byte, saltLength)
copy(salt, buf[:saltLength])
var nonce [nonceLength]byte
copy(nonce[:], buf[saltLength:nonceLength+saltLength])
secretKey := deriveKey(passphrase, salt)
decrypted, ok := secretbox.Open(nil, buf[nonceLength+saltLength:], &nonce, &secretKey)
if !ok {
return nil, fmt.Errorf("failed to decrypt")
}
data := map[string]string{}
if err := json.Unmarshal(decrypted, &data); err != nil {
return nil, err
}
return data, nil
} | go | func open(buf []byte, passphrase string) (map[string]string, error) {
salt := make([]byte, saltLength)
copy(salt, buf[:saltLength])
var nonce [nonceLength]byte
copy(nonce[:], buf[saltLength:nonceLength+saltLength])
secretKey := deriveKey(passphrase, salt)
decrypted, ok := secretbox.Open(nil, buf[nonceLength+saltLength:], &nonce, &secretKey)
if !ok {
return nil, fmt.Errorf("failed to decrypt")
}
data := map[string]string{}
if err := json.Unmarshal(decrypted, &data); err != nil {
return nil, err
}
return data, nil
} | [
"func",
"open",
"(",
"buf",
"[",
"]",
"byte",
",",
"passphrase",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"salt",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"saltLength",
")",
"\n",
"copy",
"(",
"salt",
",",
"buf",
"[",
":",
"saltLength",
"]",
")",
"\n",
"var",
"nonce",
"[",
"nonceLength",
"]",
"byte",
"\n",
"copy",
"(",
"nonce",
"[",
":",
"]",
",",
"buf",
"[",
"saltLength",
":",
"nonceLength",
"+",
"saltLength",
"]",
")",
"\n",
"secretKey",
":=",
"deriveKey",
"(",
"passphrase",
",",
"salt",
")",
"\n",
"decrypted",
",",
"ok",
":=",
"secretbox",
".",
"Open",
"(",
"nil",
",",
"buf",
"[",
"nonceLength",
"+",
"saltLength",
":",
"]",
",",
"&",
"nonce",
",",
"&",
"secretKey",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"data",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"decrypted",
",",
"&",
"data",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"data",
",",
"nil",
"\n",
"}"
] | // open will try to unseal the given buffer | [
"open",
"will",
"try",
"to",
"unseal",
"the",
"given",
"buffer"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/config/secrets/config.go#L103-L118 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.