repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequence
docstring
stringlengths
6
2.61k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
gopasspw/gopass
pkg/action/edit.go
Edit
func (s *Action) Edit(ctx context.Context, c *cli.Context) error { name := c.Args().First() if name == "" { return ExitError(ctx, ExitUsage, nil, "Usage: %s edit secret", s.Name) } return s.edit(ctx, c, name) }
go
func (s *Action) Edit(ctx context.Context, c *cli.Context) error { name := c.Args().First() if name == "" { return ExitError(ctx, ExitUsage, nil, "Usage: %s edit secret", s.Name) } return s.edit(ctx, c, name) }
[ "func", "(", "s", "*", "Action", ")", "Edit", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "name", ":=", "c", ".", "Args", "(", ")", ".", "First", "(", ")", "\n", "if", "name", "==", "\"", "\"", "{", "return", "ExitError", "(", "ctx", ",", "ExitUsage", ",", "nil", ",", "\"", "\"", ",", "s", ".", "Name", ")", "\n", "}", "\n\n", "return", "s", ".", "edit", "(", "ctx", ",", "c", ",", "name", ")", "\n", "}" ]
// Edit the content of a password file
[ "Edit", "the", "content", "of", "a", "password", "file" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/edit.go#L20-L27
train
gopasspw/gopass
pkg/backend/crypto/xc/encrypt.go
Encrypt
func (x *XC) Encrypt(ctx context.Context, plaintext []byte, recipients []string) ([]byte, error) { privKeyIDs := x.secring.KeyIDs() if len(privKeyIDs) < 1 { return nil, fmt.Errorf("no signing keys available on our keyring") } privKey := x.secring.Get(privKeyIDs[0]) var compressed bool plaintext, compressed = compress(plaintext) // encrypt body (also generates a random session key) sk, chunks, err := encryptBody(plaintext) if err != nil { return nil, errors.Wrapf(err, "failed to encrypt body: %s", err) } // encrypt the session key per recipient header, err := x.encryptHeader(ctx, privKey, sk, recipients) if err != nil { return nil, errors.Wrapf(err, "failed to encrypt header: %s", err) } msg := &xcpb.Message{ Version: OnDiskVersion, Header: header, Chunks: chunks, Compressed: compressed, } return proto.Marshal(msg) }
go
func (x *XC) Encrypt(ctx context.Context, plaintext []byte, recipients []string) ([]byte, error) { privKeyIDs := x.secring.KeyIDs() if len(privKeyIDs) < 1 { return nil, fmt.Errorf("no signing keys available on our keyring") } privKey := x.secring.Get(privKeyIDs[0]) var compressed bool plaintext, compressed = compress(plaintext) // encrypt body (also generates a random session key) sk, chunks, err := encryptBody(plaintext) if err != nil { return nil, errors.Wrapf(err, "failed to encrypt body: %s", err) } // encrypt the session key per recipient header, err := x.encryptHeader(ctx, privKey, sk, recipients) if err != nil { return nil, errors.Wrapf(err, "failed to encrypt header: %s", err) } msg := &xcpb.Message{ Version: OnDiskVersion, Header: header, Chunks: chunks, Compressed: compressed, } return proto.Marshal(msg) }
[ "func", "(", "x", "*", "XC", ")", "Encrypt", "(", "ctx", "context", ".", "Context", ",", "plaintext", "[", "]", "byte", ",", "recipients", "[", "]", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "privKeyIDs", ":=", "x", ".", "secring", ".", "KeyIDs", "(", ")", "\n", "if", "len", "(", "privKeyIDs", ")", "<", "1", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "privKey", ":=", "x", ".", "secring", ".", "Get", "(", "privKeyIDs", "[", "0", "]", ")", "\n\n", "var", "compressed", "bool", "\n", "plaintext", ",", "compressed", "=", "compress", "(", "plaintext", ")", "\n\n", "// encrypt body (also generates a random session key)", "sk", ",", "chunks", ",", "err", ":=", "encryptBody", "(", "plaintext", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// encrypt the session key per recipient", "header", ",", "err", ":=", "x", ".", "encryptHeader", "(", "ctx", ",", "privKey", ",", "sk", ",", "recipients", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "msg", ":=", "&", "xcpb", ".", "Message", "{", "Version", ":", "OnDiskVersion", ",", "Header", ":", "header", ",", "Chunks", ":", "chunks", ",", "Compressed", ":", "compressed", ",", "}", "\n\n", "return", "proto", ".", "Marshal", "(", "msg", ")", "\n", "}" ]
// Encrypt encrypts the given plaintext for all the given recipients and returns the // ciphertext
[ "Encrypt", "encrypts", "the", "given", "plaintext", "for", "all", "the", "given", "recipients", "and", "returns", "the", "ciphertext" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/encrypt.go#L32-L62
train
gopasspw/gopass
pkg/backend/crypto/xc/encrypt.go
encryptForRecipient
func (x *XC) encryptForRecipient(ctx context.Context, sender *keyring.PrivateKey, sk []byte, recipient string) ([]byte, error) { recp := x.pubring.Get(recipient) if recp == nil { return nil, fmt.Errorf("recipient public key not available for %s", recipient) } var recipientPublicKey [32]byte copy(recipientPublicKey[:], recp.PublicKey[:]) // unlock sender key if err := x.decryptPrivateKey(ctx, sender); err != nil { return nil, err } // we need to copy the byte silces to byte arrays for box var senderPrivateKey [32]byte pk := sender.PrivateKey() copy(senderPrivateKey[:], pk[:]) var nonce [24]byte if _, err := io.ReadFull(crypto_rand.Reader, nonce[:]); err != nil { return nil, err } return box.Seal(nonce[:], sk, &nonce, &recipientPublicKey, &senderPrivateKey), nil }
go
func (x *XC) encryptForRecipient(ctx context.Context, sender *keyring.PrivateKey, sk []byte, recipient string) ([]byte, error) { recp := x.pubring.Get(recipient) if recp == nil { return nil, fmt.Errorf("recipient public key not available for %s", recipient) } var recipientPublicKey [32]byte copy(recipientPublicKey[:], recp.PublicKey[:]) // unlock sender key if err := x.decryptPrivateKey(ctx, sender); err != nil { return nil, err } // we need to copy the byte silces to byte arrays for box var senderPrivateKey [32]byte pk := sender.PrivateKey() copy(senderPrivateKey[:], pk[:]) var nonce [24]byte if _, err := io.ReadFull(crypto_rand.Reader, nonce[:]); err != nil { return nil, err } return box.Seal(nonce[:], sk, &nonce, &recipientPublicKey, &senderPrivateKey), nil }
[ "func", "(", "x", "*", "XC", ")", "encryptForRecipient", "(", "ctx", "context", ".", "Context", ",", "sender", "*", "keyring", ".", "PrivateKey", ",", "sk", "[", "]", "byte", ",", "recipient", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "recp", ":=", "x", ".", "pubring", ".", "Get", "(", "recipient", ")", "\n", "if", "recp", "==", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "recipient", ")", "\n", "}", "\n\n", "var", "recipientPublicKey", "[", "32", "]", "byte", "\n", "copy", "(", "recipientPublicKey", "[", ":", "]", ",", "recp", ".", "PublicKey", "[", ":", "]", ")", "\n\n", "// unlock sender key", "if", "err", ":=", "x", ".", "decryptPrivateKey", "(", "ctx", ",", "sender", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// we need to copy the byte silces to byte arrays for box", "var", "senderPrivateKey", "[", "32", "]", "byte", "\n", "pk", ":=", "sender", ".", "PrivateKey", "(", ")", "\n", "copy", "(", "senderPrivateKey", "[", ":", "]", ",", "pk", "[", ":", "]", ")", "\n\n", "var", "nonce", "[", "24", "]", "byte", "\n", "if", "_", ",", "err", ":=", "io", ".", "ReadFull", "(", "crypto_rand", ".", "Reader", ",", "nonce", "[", ":", "]", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "box", ".", "Seal", "(", "nonce", "[", ":", "]", ",", "sk", ",", "&", "nonce", ",", "&", "recipientPublicKey", ",", "&", "senderPrivateKey", ")", ",", "nil", "\n", "}" ]
// encryptForRecipients encrypts the given session key for the given recipient
[ "encryptForRecipients", "encrypts", "the", "given", "session", "key", "for", "the", "given", "recipient" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/encrypt.go#L93-L118
train
gopasspw/gopass
pkg/backend/crypto/xc/encrypt.go
encryptBody
func encryptBody(plaintext []byte) ([]byte, []*xcpb.Chunk, error) { // generate session / encryption key var sessionKey [32]byte if _, err := crypto_rand.Read(sessionKey[:]); err != nil { return nil, nil, err } chunks := make([]*xcpb.Chunk, 0, (len(plaintext)/chunkSizeMax)+1) offset := 0 for offset < len(plaintext) { // use a sequential nonce to prevent chunk reordering. // since the pair of key and nonce has to be unique and we're // generating a new random key for each message, this is OK var nonce [24]byte binary.BigEndian.PutUint64(nonce[:], uint64(len(chunks))) // encrypt the plaintext using the random nonce chunks = append(chunks, &xcpb.Chunk{ Body: secretbox.Seal(nil, plaintext[offset:min(len(plaintext), offset+chunkSizeMax)], &nonce, &sessionKey), }) offset += chunkSizeMax } return sessionKey[:], chunks, nil }
go
func encryptBody(plaintext []byte) ([]byte, []*xcpb.Chunk, error) { // generate session / encryption key var sessionKey [32]byte if _, err := crypto_rand.Read(sessionKey[:]); err != nil { return nil, nil, err } chunks := make([]*xcpb.Chunk, 0, (len(plaintext)/chunkSizeMax)+1) offset := 0 for offset < len(plaintext) { // use a sequential nonce to prevent chunk reordering. // since the pair of key and nonce has to be unique and we're // generating a new random key for each message, this is OK var nonce [24]byte binary.BigEndian.PutUint64(nonce[:], uint64(len(chunks))) // encrypt the plaintext using the random nonce chunks = append(chunks, &xcpb.Chunk{ Body: secretbox.Seal(nil, plaintext[offset:min(len(plaintext), offset+chunkSizeMax)], &nonce, &sessionKey), }) offset += chunkSizeMax } return sessionKey[:], chunks, nil }
[ "func", "encryptBody", "(", "plaintext", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "[", "]", "*", "xcpb", ".", "Chunk", ",", "error", ")", "{", "// generate session / encryption key", "var", "sessionKey", "[", "32", "]", "byte", "\n", "if", "_", ",", "err", ":=", "crypto_rand", ".", "Read", "(", "sessionKey", "[", ":", "]", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n\n", "chunks", ":=", "make", "(", "[", "]", "*", "xcpb", ".", "Chunk", ",", "0", ",", "(", "len", "(", "plaintext", ")", "/", "chunkSizeMax", ")", "+", "1", ")", "\n", "offset", ":=", "0", "\n\n", "for", "offset", "<", "len", "(", "plaintext", ")", "{", "// use a sequential nonce to prevent chunk reordering.", "// since the pair of key and nonce has to be unique and we're", "// generating a new random key for each message, this is OK", "var", "nonce", "[", "24", "]", "byte", "\n", "binary", ".", "BigEndian", ".", "PutUint64", "(", "nonce", "[", ":", "]", ",", "uint64", "(", "len", "(", "chunks", ")", ")", ")", "\n\n", "// encrypt the plaintext using the random nonce", "chunks", "=", "append", "(", "chunks", ",", "&", "xcpb", ".", "Chunk", "{", "Body", ":", "secretbox", ".", "Seal", "(", "nil", ",", "plaintext", "[", "offset", ":", "min", "(", "len", "(", "plaintext", ")", ",", "offset", "+", "chunkSizeMax", ")", "]", ",", "&", "nonce", ",", "&", "sessionKey", ")", ",", "}", ")", "\n", "offset", "+=", "chunkSizeMax", "\n", "}", "\n\n", "return", "sessionKey", "[", ":", "]", ",", "chunks", ",", "nil", "\n", "}" ]
// encryptBody generates a random session key and a nonce and encrypts the given // plaintext with those. it returns all three
[ "encryptBody", "generates", "a", "random", "session", "key", "and", "a", "nonce", "and", "encrypts", "the", "given", "plaintext", "with", "those", ".", "it", "returns", "all", "three" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/encrypt.go#L122-L147
train
gopasspw/gopass
pkg/backend/crypto/gpg/cli/keyring.go
listKeys
func (g *GPG) listKeys(ctx context.Context, typ string, search ...string) (gpg.KeyList, error) { args := []string{"--with-colons", "--with-fingerprint", "--fixed-list-mode", "--list-" + typ + "-keys"} args = append(args, search...) if e, found := g.listCache.Get(strings.Join(args, ",")); found { if ev, ok := e.(gpg.KeyList); ok { return ev, nil } } cmd := exec.CommandContext(ctx, g.binary, args...) cmd.Stderr = nil out.Debug(ctx, "gpg.listKeys: %s %+v\n", cmd.Path, cmd.Args) cmdout, err := cmd.Output() if err != nil { if bytes.Contains(cmdout, []byte("secret key not available")) { return gpg.KeyList{}, nil } return gpg.KeyList{}, err } kl := parseColons(bytes.NewBuffer(cmdout)) g.listCache.Add(strings.Join(args, ","), kl) return kl, nil }
go
func (g *GPG) listKeys(ctx context.Context, typ string, search ...string) (gpg.KeyList, error) { args := []string{"--with-colons", "--with-fingerprint", "--fixed-list-mode", "--list-" + typ + "-keys"} args = append(args, search...) if e, found := g.listCache.Get(strings.Join(args, ",")); found { if ev, ok := e.(gpg.KeyList); ok { return ev, nil } } cmd := exec.CommandContext(ctx, g.binary, args...) cmd.Stderr = nil out.Debug(ctx, "gpg.listKeys: %s %+v\n", cmd.Path, cmd.Args) cmdout, err := cmd.Output() if err != nil { if bytes.Contains(cmdout, []byte("secret key not available")) { return gpg.KeyList{}, nil } return gpg.KeyList{}, err } kl := parseColons(bytes.NewBuffer(cmdout)) g.listCache.Add(strings.Join(args, ","), kl) return kl, nil }
[ "func", "(", "g", "*", "GPG", ")", "listKeys", "(", "ctx", "context", ".", "Context", ",", "typ", "string", ",", "search", "...", "string", ")", "(", "gpg", ".", "KeyList", ",", "error", ")", "{", "args", ":=", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", "+", "typ", "+", "\"", "\"", "}", "\n", "args", "=", "append", "(", "args", ",", "search", "...", ")", "\n", "if", "e", ",", "found", ":=", "g", ".", "listCache", ".", "Get", "(", "strings", ".", "Join", "(", "args", ",", "\"", "\"", ")", ")", ";", "found", "{", "if", "ev", ",", "ok", ":=", "e", ".", "(", "gpg", ".", "KeyList", ")", ";", "ok", "{", "return", "ev", ",", "nil", "\n", "}", "\n", "}", "\n", "cmd", ":=", "exec", ".", "CommandContext", "(", "ctx", ",", "g", ".", "binary", ",", "args", "...", ")", "\n", "cmd", ".", "Stderr", "=", "nil", "\n\n", "out", ".", "Debug", "(", "ctx", ",", "\"", "\\n", "\"", ",", "cmd", ".", "Path", ",", "cmd", ".", "Args", ")", "\n", "cmdout", ",", "err", ":=", "cmd", ".", "Output", "(", ")", "\n", "if", "err", "!=", "nil", "{", "if", "bytes", ".", "Contains", "(", "cmdout", ",", "[", "]", "byte", "(", "\"", "\"", ")", ")", "{", "return", "gpg", ".", "KeyList", "{", "}", ",", "nil", "\n", "}", "\n", "return", "gpg", ".", "KeyList", "{", "}", ",", "err", "\n", "}", "\n\n", "kl", ":=", "parseColons", "(", "bytes", ".", "NewBuffer", "(", "cmdout", ")", ")", "\n", "g", ".", "listCache", ".", "Add", "(", "strings", ".", "Join", "(", "args", ",", "\"", "\"", ")", ",", "kl", ")", "\n", "return", "kl", ",", "nil", "\n", "}" ]
// listKey lists all keys of the given type and matching the search strings
[ "listKey", "lists", "all", "keys", "of", "the", "given", "type", "and", "matching", "the", "search", "strings" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/cli/keyring.go#L14-L37
train
gopasspw/gopass
pkg/backend/crypto/gpg/cli/keyring.go
ListPublicKeyIDs
func (g *GPG) ListPublicKeyIDs(ctx context.Context) ([]string, error) { if g.pubKeys == nil { kl, err := g.listKeys(ctx, "public") if err != nil { return nil, err } g.pubKeys = kl } if gpg.IsAlwaysTrust(ctx) { return g.pubKeys.Recipients(), nil } return g.pubKeys.UseableKeys().Recipients(), nil }
go
func (g *GPG) ListPublicKeyIDs(ctx context.Context) ([]string, error) { if g.pubKeys == nil { kl, err := g.listKeys(ctx, "public") if err != nil { return nil, err } g.pubKeys = kl } if gpg.IsAlwaysTrust(ctx) { return g.pubKeys.Recipients(), nil } return g.pubKeys.UseableKeys().Recipients(), nil }
[ "func", "(", "g", "*", "GPG", ")", "ListPublicKeyIDs", "(", "ctx", "context", ".", "Context", ")", "(", "[", "]", "string", ",", "error", ")", "{", "if", "g", ".", "pubKeys", "==", "nil", "{", "kl", ",", "err", ":=", "g", ".", "listKeys", "(", "ctx", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "g", ".", "pubKeys", "=", "kl", "\n", "}", "\n", "if", "gpg", ".", "IsAlwaysTrust", "(", "ctx", ")", "{", "return", "g", ".", "pubKeys", ".", "Recipients", "(", ")", ",", "nil", "\n", "}", "\n", "return", "g", ".", "pubKeys", ".", "UseableKeys", "(", ")", ".", "Recipients", "(", ")", ",", "nil", "\n", "}" ]
// ListPublicKeyIDs returns a parsed list of GPG public keys
[ "ListPublicKeyIDs", "returns", "a", "parsed", "list", "of", "GPG", "public", "keys" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/cli/keyring.go#L40-L52
train
gopasspw/gopass
pkg/backend/crypto/gpg/cli/keyring.go
FindPublicKeys
func (g *GPG) FindPublicKeys(ctx context.Context, search ...string) ([]string, error) { kl, err := g.listKeys(ctx, "public", search...) if err != nil || kl == nil { return nil, err } if gpg.IsAlwaysTrust(ctx) { return kl.Recipients(), nil } return kl.UseableKeys().Recipients(), nil }
go
func (g *GPG) FindPublicKeys(ctx context.Context, search ...string) ([]string, error) { kl, err := g.listKeys(ctx, "public", search...) if err != nil || kl == nil { return nil, err } if gpg.IsAlwaysTrust(ctx) { return kl.Recipients(), nil } return kl.UseableKeys().Recipients(), nil }
[ "func", "(", "g", "*", "GPG", ")", "FindPublicKeys", "(", "ctx", "context", ".", "Context", ",", "search", "...", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "kl", ",", "err", ":=", "g", ".", "listKeys", "(", "ctx", ",", "\"", "\"", ",", "search", "...", ")", "\n", "if", "err", "!=", "nil", "||", "kl", "==", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "gpg", ".", "IsAlwaysTrust", "(", "ctx", ")", "{", "return", "kl", ".", "Recipients", "(", ")", ",", "nil", "\n", "}", "\n", "return", "kl", ".", "UseableKeys", "(", ")", ".", "Recipients", "(", ")", ",", "nil", "\n", "}" ]
// FindPublicKeys searches for the given public keys
[ "FindPublicKeys", "searches", "for", "the", "given", "public", "keys" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/cli/keyring.go#L55-L64
train
gopasspw/gopass
pkg/backend/crypto/gpg/cli/keyring.go
ListPrivateKeyIDs
func (g *GPG) ListPrivateKeyIDs(ctx context.Context) ([]string, error) { if g.privKeys == nil { kl, err := g.listKeys(ctx, "secret") if err != nil { return nil, err } g.privKeys = kl } if gpg.IsAlwaysTrust(ctx) { return g.privKeys.Recipients(), nil } return g.privKeys.UseableKeys().Recipients(), nil }
go
func (g *GPG) ListPrivateKeyIDs(ctx context.Context) ([]string, error) { if g.privKeys == nil { kl, err := g.listKeys(ctx, "secret") if err != nil { return nil, err } g.privKeys = kl } if gpg.IsAlwaysTrust(ctx) { return g.privKeys.Recipients(), nil } return g.privKeys.UseableKeys().Recipients(), nil }
[ "func", "(", "g", "*", "GPG", ")", "ListPrivateKeyIDs", "(", "ctx", "context", ".", "Context", ")", "(", "[", "]", "string", ",", "error", ")", "{", "if", "g", ".", "privKeys", "==", "nil", "{", "kl", ",", "err", ":=", "g", ".", "listKeys", "(", "ctx", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "g", ".", "privKeys", "=", "kl", "\n", "}", "\n", "if", "gpg", ".", "IsAlwaysTrust", "(", "ctx", ")", "{", "return", "g", ".", "privKeys", ".", "Recipients", "(", ")", ",", "nil", "\n", "}", "\n", "return", "g", ".", "privKeys", ".", "UseableKeys", "(", ")", ".", "Recipients", "(", ")", ",", "nil", "\n", "}" ]
// ListPrivateKeyIDs returns a parsed list of GPG secret keys
[ "ListPrivateKeyIDs", "returns", "a", "parsed", "list", "of", "GPG", "secret", "keys" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/cli/keyring.go#L67-L79
train
gopasspw/gopass
pkg/backend/crypto/gpg/cli/keyring.go
EmailFromKey
func (g *GPG) EmailFromKey(ctx context.Context, id string) string { return g.findKey(ctx, id).Identity().Email }
go
func (g *GPG) EmailFromKey(ctx context.Context, id string) string { return g.findKey(ctx, id).Identity().Email }
[ "func", "(", "g", "*", "GPG", ")", "EmailFromKey", "(", "ctx", "context", ".", "Context", ",", "id", "string", ")", "string", "{", "return", "g", ".", "findKey", "(", "ctx", ",", "id", ")", ".", "Identity", "(", ")", ".", "Email", "\n", "}" ]
// EmailFromKey extracts the email from a key id
[ "EmailFromKey", "extracts", "the", "email", "from", "a", "key", "id" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/cli/keyring.go#L108-L110
train
gopasspw/gopass
pkg/backend/crypto/gpg/cli/keyring.go
NameFromKey
func (g *GPG) NameFromKey(ctx context.Context, id string) string { return g.findKey(ctx, id).Identity().Name }
go
func (g *GPG) NameFromKey(ctx context.Context, id string) string { return g.findKey(ctx, id).Identity().Name }
[ "func", "(", "g", "*", "GPG", ")", "NameFromKey", "(", "ctx", "context", ".", "Context", ",", "id", "string", ")", "string", "{", "return", "g", ".", "findKey", "(", "ctx", ",", "id", ")", ".", "Identity", "(", ")", ".", "Name", "\n", "}" ]
// NameFromKey extracts the name from a key id
[ "NameFromKey", "extracts", "the", "name", "from", "a", "key", "id" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/cli/keyring.go#L113-L115
train
gopasspw/gopass
pkg/backend/crypto/gpg/cli/keyring.go
FormatKey
func (g *GPG) FormatKey(ctx context.Context, id string) string { return g.findKey(ctx, id).OneLine() }
go
func (g *GPG) FormatKey(ctx context.Context, id string) string { return g.findKey(ctx, id).OneLine() }
[ "func", "(", "g", "*", "GPG", ")", "FormatKey", "(", "ctx", "context", ".", "Context", ",", "id", "string", ")", "string", "{", "return", "g", ".", "findKey", "(", "ctx", ",", "id", ")", ".", "OneLine", "(", ")", "\n", "}" ]
// FormatKey formats the details of a key id
[ "FormatKey", "formats", "the", "details", "of", "a", "key", "id" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/cli/keyring.go#L118-L120
train
gopasspw/gopass
pkg/action/grep.go
Grep
func (s *Action) Grep(ctx context.Context, c *cli.Context) error { if !c.Args().Present() { return ExitError(ctx, ExitUsage, nil, "Usage: %s grep arg", s.Name) } // get the search term needle := c.Args().First() haystack, err := s.Store.List(ctx, 0) if err != nil { return ExitError(ctx, ExitList, err, "failed to list store: %s", err) } var matches int var errors int for _, v := range haystack { sec, err := s.Store.Get(ctx, v) if err != nil { out.Error(ctx, "failed to decrypt %s: %v", v, err) continue } if strings.Contains(sec.Password(), needle) { out.Print(ctx, "%s:\n%s", color.BlueString(v), sec.Password()) } if strings.Contains(sec.Body(), needle) { out.Print(ctx, "%s:\n%s", color.BlueString(v), sec.Body()) } } if errors > 0 { return ExitError(ctx, ExitDecrypt, nil, "some secrets failed to decrypt") } if matches < 1 { return ExitError(ctx, ExitNotFound, nil, "no matches found") } out.Print(ctx, "\nScanned %d secrets. %d matches, %d errors", len(haystack), matches, errors) return nil }
go
func (s *Action) Grep(ctx context.Context, c *cli.Context) error { if !c.Args().Present() { return ExitError(ctx, ExitUsage, nil, "Usage: %s grep arg", s.Name) } // get the search term needle := c.Args().First() haystack, err := s.Store.List(ctx, 0) if err != nil { return ExitError(ctx, ExitList, err, "failed to list store: %s", err) } var matches int var errors int for _, v := range haystack { sec, err := s.Store.Get(ctx, v) if err != nil { out.Error(ctx, "failed to decrypt %s: %v", v, err) continue } if strings.Contains(sec.Password(), needle) { out.Print(ctx, "%s:\n%s", color.BlueString(v), sec.Password()) } if strings.Contains(sec.Body(), needle) { out.Print(ctx, "%s:\n%s", color.BlueString(v), sec.Body()) } } if errors > 0 { return ExitError(ctx, ExitDecrypt, nil, "some secrets failed to decrypt") } if matches < 1 { return ExitError(ctx, ExitNotFound, nil, "no matches found") } out.Print(ctx, "\nScanned %d secrets. %d matches, %d errors", len(haystack), matches, errors) return nil }
[ "func", "(", "s", "*", "Action", ")", "Grep", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "if", "!", "c", ".", "Args", "(", ")", ".", "Present", "(", ")", "{", "return", "ExitError", "(", "ctx", ",", "ExitUsage", ",", "nil", ",", "\"", "\"", ",", "s", ".", "Name", ")", "\n", "}", "\n\n", "// get the search term", "needle", ":=", "c", ".", "Args", "(", ")", ".", "First", "(", ")", "\n\n", "haystack", ",", "err", ":=", "s", ".", "Store", ".", "List", "(", "ctx", ",", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitList", ",", "err", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "var", "matches", "int", "\n", "var", "errors", "int", "\n", "for", "_", ",", "v", ":=", "range", "haystack", "{", "sec", ",", "err", ":=", "s", ".", "Store", ".", "Get", "(", "ctx", ",", "v", ")", "\n", "if", "err", "!=", "nil", "{", "out", ".", "Error", "(", "ctx", ",", "\"", "\"", ",", "v", ",", "err", ")", "\n", "continue", "\n", "}", "\n\n", "if", "strings", ".", "Contains", "(", "sec", ".", "Password", "(", ")", ",", "needle", ")", "{", "out", ".", "Print", "(", "ctx", ",", "\"", "\\n", "\"", ",", "color", ".", "BlueString", "(", "v", ")", ",", "sec", ".", "Password", "(", ")", ")", "\n", "}", "\n", "if", "strings", ".", "Contains", "(", "sec", ".", "Body", "(", ")", ",", "needle", ")", "{", "out", ".", "Print", "(", "ctx", ",", "\"", "\\n", "\"", ",", "color", ".", "BlueString", "(", "v", ")", ",", "sec", ".", "Body", "(", ")", ")", "\n", "}", "\n", "}", "\n\n", "if", "errors", ">", "0", "{", "return", "ExitError", "(", "ctx", ",", "ExitDecrypt", ",", "nil", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "matches", "<", "1", "{", "return", "ExitError", "(", "ctx", ",", "ExitNotFound", ",", "nil", ",", "\"", "\"", ")", "\n", "}", "\n\n", "out", ".", "Print", "(", "ctx", ",", "\"", "\\n", "\"", ",", "len", "(", "haystack", ")", ",", "matches", ",", "errors", ")", "\n", "return", "nil", "\n", "}" ]
// Grep searches a string inside the content of all files
[ "Grep", "searches", "a", "string", "inside", "the", "content", "of", "all", "files" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/grep.go#L14-L53
train
gopasspw/gopass
pkg/backend/crypto/gpg/openpgp/gpg.go
New
func New(ctx context.Context) (*GPG, error) { pubfn := filepath.Join(gpgHome(ctx), "pubring.gpg") pubring, err := readKeyring(pubfn) if err != nil { return nil, err } secfn := filepath.Join(gpgHome(ctx), "secring.gpg") secring, err := readKeyring(secfn) if err != nil { return nil, err } g := &GPG{ pubring: pubring, secring: secring, pubfn: pubfn, secfn: secfn, } return g, nil }
go
func New(ctx context.Context) (*GPG, error) { pubfn := filepath.Join(gpgHome(ctx), "pubring.gpg") pubring, err := readKeyring(pubfn) if err != nil { return nil, err } secfn := filepath.Join(gpgHome(ctx), "secring.gpg") secring, err := readKeyring(secfn) if err != nil { return nil, err } g := &GPG{ pubring: pubring, secring: secring, pubfn: pubfn, secfn: secfn, } return g, nil }
[ "func", "New", "(", "ctx", "context", ".", "Context", ")", "(", "*", "GPG", ",", "error", ")", "{", "pubfn", ":=", "filepath", ".", "Join", "(", "gpgHome", "(", "ctx", ")", ",", "\"", "\"", ")", "\n", "pubring", ",", "err", ":=", "readKeyring", "(", "pubfn", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "secfn", ":=", "filepath", ".", "Join", "(", "gpgHome", "(", "ctx", ")", ",", "\"", "\"", ")", "\n", "secring", ",", "err", ":=", "readKeyring", "(", "secfn", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "g", ":=", "&", "GPG", "{", "pubring", ":", "pubring", ",", "secring", ":", "secring", ",", "pubfn", ":", "pubfn", ",", "secfn", ":", "secfn", ",", "}", "\n", "return", "g", ",", "nil", "\n", "}" ]
// New creates a new pure-Go GPG backend
[ "New", "creates", "a", "new", "pure", "-", "Go", "GPG", "backend" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/openpgp/gpg.go#L30-L48
train
gopasspw/gopass
pkg/backend/crypto/gpg/openpgp/gpg.go
RecipientIDs
func (g *GPG) RecipientIDs(ctx context.Context, ciphertext []byte) ([]string, error) { recps := make([]string, 0, 1) packets := packet.NewReader(bytes.NewReader(ciphertext)) for { p, err := packets.Next() if err != nil { if err == io.EOF { break } return nil, err } switch p := p.(type) { case *packet.EncryptedKey: for _, key := range g.pubring { if key.PrimaryKey == nil { continue } if key.PrimaryKey.KeyId == p.KeyId { recps = append(recps, key.PrimaryKey.KeyIdString()) } } } } return recps, nil }
go
func (g *GPG) RecipientIDs(ctx context.Context, ciphertext []byte) ([]string, error) { recps := make([]string, 0, 1) packets := packet.NewReader(bytes.NewReader(ciphertext)) for { p, err := packets.Next() if err != nil { if err == io.EOF { break } return nil, err } switch p := p.(type) { case *packet.EncryptedKey: for _, key := range g.pubring { if key.PrimaryKey == nil { continue } if key.PrimaryKey.KeyId == p.KeyId { recps = append(recps, key.PrimaryKey.KeyIdString()) } } } } return recps, nil }
[ "func", "(", "g", "*", "GPG", ")", "RecipientIDs", "(", "ctx", "context", ".", "Context", ",", "ciphertext", "[", "]", "byte", ")", "(", "[", "]", "string", ",", "error", ")", "{", "recps", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "1", ")", "\n", "packets", ":=", "packet", ".", "NewReader", "(", "bytes", ".", "NewReader", "(", "ciphertext", ")", ")", "\n", "for", "{", "p", ",", "err", ":=", "packets", ".", "Next", "(", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "==", "io", ".", "EOF", "{", "break", "\n", "}", "\n", "return", "nil", ",", "err", "\n", "}", "\n", "switch", "p", ":=", "p", ".", "(", "type", ")", "{", "case", "*", "packet", ".", "EncryptedKey", ":", "for", "_", ",", "key", ":=", "range", "g", ".", "pubring", "{", "if", "key", ".", "PrimaryKey", "==", "nil", "{", "continue", "\n", "}", "\n", "if", "key", ".", "PrimaryKey", ".", "KeyId", "==", "p", ".", "KeyId", "{", "recps", "=", "append", "(", "recps", ",", "key", ".", "PrimaryKey", ".", "KeyIdString", "(", ")", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "recps", ",", "nil", "\n", "}" ]
// RecipientIDs returns the recipients of the encrypted message
[ "RecipientIDs", "returns", "the", "recipients", "of", "the", "encrypted", "message" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/openpgp/gpg.go#L51-L75
train
gopasspw/gopass
pkg/backend/crypto/gpg/openpgp/gpg.go
Encrypt
func (g *GPG) Encrypt(ctx context.Context, plaintext []byte, recipients []string) ([]byte, error) { ciphertext := &bytes.Buffer{} ents := g.recipientsToEntities(recipients) wc, err := openpgp.Encrypt(ciphertext, ents, nil, nil, nil) if err != nil { return nil, errors.Wrapf(err, "failed to encrypt") } if _, err := io.Copy(wc, bytes.NewReader(plaintext)); err != nil { return nil, errors.Wrapf(err, "failed to write plaintext to encoder") } if err := wc.Close(); err != nil { return nil, errors.Wrapf(err, "failed to finalize encryption") } return ciphertext.Bytes(), nil }
go
func (g *GPG) Encrypt(ctx context.Context, plaintext []byte, recipients []string) ([]byte, error) { ciphertext := &bytes.Buffer{} ents := g.recipientsToEntities(recipients) wc, err := openpgp.Encrypt(ciphertext, ents, nil, nil, nil) if err != nil { return nil, errors.Wrapf(err, "failed to encrypt") } if _, err := io.Copy(wc, bytes.NewReader(plaintext)); err != nil { return nil, errors.Wrapf(err, "failed to write plaintext to encoder") } if err := wc.Close(); err != nil { return nil, errors.Wrapf(err, "failed to finalize encryption") } return ciphertext.Bytes(), nil }
[ "func", "(", "g", "*", "GPG", ")", "Encrypt", "(", "ctx", "context", ".", "Context", ",", "plaintext", "[", "]", "byte", ",", "recipients", "[", "]", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "ciphertext", ":=", "&", "bytes", ".", "Buffer", "{", "}", "\n", "ents", ":=", "g", ".", "recipientsToEntities", "(", "recipients", ")", "\n", "wc", ",", "err", ":=", "openpgp", ".", "Encrypt", "(", "ciphertext", ",", "ents", ",", "nil", ",", "nil", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "_", ",", "err", ":=", "io", ".", "Copy", "(", "wc", ",", "bytes", ".", "NewReader", "(", "plaintext", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "err", ":=", "wc", ".", "Close", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "ciphertext", ".", "Bytes", "(", ")", ",", "nil", "\n", "}" ]
// Encrypt encrypts the plaintext for the given recipients
[ "Encrypt", "encrypts", "the", "plaintext", "for", "the", "given", "recipients" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/openpgp/gpg.go#L78-L92
train
gopasspw/gopass
pkg/backend/crypto/gpg/openpgp/gpg.go
ImportPublicKey
func (g *GPG) ImportPublicKey(ctx context.Context, buf []byte) error { el, err := openpgp.ReadArmoredKeyRing(bytes.NewReader(buf)) if err != nil { return err } g.pubring = append(g.pubring, el...) return nil }
go
func (g *GPG) ImportPublicKey(ctx context.Context, buf []byte) error { el, err := openpgp.ReadArmoredKeyRing(bytes.NewReader(buf)) if err != nil { return err } g.pubring = append(g.pubring, el...) return nil }
[ "func", "(", "g", "*", "GPG", ")", "ImportPublicKey", "(", "ctx", "context", ".", "Context", ",", "buf", "[", "]", "byte", ")", "error", "{", "el", ",", "err", ":=", "openpgp", ".", "ReadArmoredKeyRing", "(", "bytes", ".", "NewReader", "(", "buf", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "g", ".", "pubring", "=", "append", "(", "g", ".", "pubring", ",", "el", "...", ")", "\n", "return", "nil", "\n", "}" ]
// ImportPublicKey does nothing
[ "ImportPublicKey", "does", "nothing" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/openpgp/gpg.go#L121-L128
train
gopasspw/gopass
pkg/backend/crypto/gpg/openpgp/gpg.go
Version
func (g *GPG) Version(context.Context) semver.Version { return semver.Version{Major: 1} }
go
func (g *GPG) Version(context.Context) semver.Version { return semver.Version{Major: 1} }
[ "func", "(", "g", "*", "GPG", ")", "Version", "(", "context", ".", "Context", ")", "semver", ".", "Version", "{", "return", "semver", ".", "Version", "{", "Major", ":", "1", "}", "\n", "}" ]
// Version returns dummy version info
[ "Version", "returns", "dummy", "version", "info" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/openpgp/gpg.go#L131-L133
train
gopasspw/gopass
pkg/backend/crypto/gpg/openpgp/gpg.go
Sign
func (g *GPG) Sign(ctx context.Context, in string, sigf string) error { signKeys := g.SigningKeys() if len(signKeys) < 1 { return fmt.Errorf("no signing keys available") } sigfh, err := os.OpenFile(sigf, os.O_WRONLY|os.O_CREATE, 0644) if err != nil { return err } defer sigfh.Close() wc, err := clearsign.Encode(sigfh, signKeys[0].PrivateKey, nil) if err != nil { return err } infh, err := os.Open(in) if err != nil { return err } defer infh.Close() if _, err := io.Copy(wc, infh); err != nil { return err } return wc.Close() }
go
func (g *GPG) Sign(ctx context.Context, in string, sigf string) error { signKeys := g.SigningKeys() if len(signKeys) < 1 { return fmt.Errorf("no signing keys available") } sigfh, err := os.OpenFile(sigf, os.O_WRONLY|os.O_CREATE, 0644) if err != nil { return err } defer sigfh.Close() wc, err := clearsign.Encode(sigfh, signKeys[0].PrivateKey, nil) if err != nil { return err } infh, err := os.Open(in) if err != nil { return err } defer infh.Close() if _, err := io.Copy(wc, infh); err != nil { return err } return wc.Close() }
[ "func", "(", "g", "*", "GPG", ")", "Sign", "(", "ctx", "context", ".", "Context", ",", "in", "string", ",", "sigf", "string", ")", "error", "{", "signKeys", ":=", "g", ".", "SigningKeys", "(", ")", "\n", "if", "len", "(", "signKeys", ")", "<", "1", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "sigfh", ",", "err", ":=", "os", ".", "OpenFile", "(", "sigf", ",", "os", ".", "O_WRONLY", "|", "os", ".", "O_CREATE", ",", "0644", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "sigfh", ".", "Close", "(", ")", "\n\n", "wc", ",", "err", ":=", "clearsign", ".", "Encode", "(", "sigfh", ",", "signKeys", "[", "0", "]", ".", "PrivateKey", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "infh", ",", "err", ":=", "os", ".", "Open", "(", "in", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "infh", ".", "Close", "(", ")", "\n\n", "if", "_", ",", "err", ":=", "io", ".", "Copy", "(", "wc", ",", "infh", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "wc", ".", "Close", "(", ")", "\n", "}" ]
// Sign is not implemented
[ "Sign", "is", "not", "implemented" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/openpgp/gpg.go#L141-L167
train
gopasspw/gopass
pkg/backend/crypto/gpg/openpgp/gpg.go
Verify
func (g *GPG) Verify(ctx context.Context, sigf string, in string) error { sig, err := ioutil.ReadFile(sigf) if err != nil { return err } b, _ := clearsign.Decode(sig) infh, err := os.Open(in) if err != nil { return err } defer infh.Close() _, err = openpgp.CheckDetachedSignature(g.pubring, infh, bytes.NewReader(b.Bytes)) if err != nil { return err } return nil }
go
func (g *GPG) Verify(ctx context.Context, sigf string, in string) error { sig, err := ioutil.ReadFile(sigf) if err != nil { return err } b, _ := clearsign.Decode(sig) infh, err := os.Open(in) if err != nil { return err } defer infh.Close() _, err = openpgp.CheckDetachedSignature(g.pubring, infh, bytes.NewReader(b.Bytes)) if err != nil { return err } return nil }
[ "func", "(", "g", "*", "GPG", ")", "Verify", "(", "ctx", "context", ".", "Context", ",", "sigf", "string", ",", "in", "string", ")", "error", "{", "sig", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "sigf", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "b", ",", "_", ":=", "clearsign", ".", "Decode", "(", "sig", ")", "\n", "infh", ",", "err", ":=", "os", ".", "Open", "(", "in", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "infh", ".", "Close", "(", ")", "\n", "_", ",", "err", "=", "openpgp", ".", "CheckDetachedSignature", "(", "g", ".", "pubring", ",", "infh", ",", "bytes", ".", "NewReader", "(", "b", ".", "Bytes", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Verify is not implemented
[ "Verify", "is", "not", "implemented" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/openpgp/gpg.go#L170-L186
train
gopasspw/gopass
pkg/backend/crypto/gpg/openpgp/gpg.go
EmailFromKey
func (g *GPG) EmailFromKey(ctx context.Context, id string) string { ent := g.findEntity(id) if ent == nil || ent.Identities == nil { return "" } for name, id := range ent.Identities { if id.UserId == nil { return name } return id.UserId.Email } return "" }
go
func (g *GPG) EmailFromKey(ctx context.Context, id string) string { ent := g.findEntity(id) if ent == nil || ent.Identities == nil { return "" } for name, id := range ent.Identities { if id.UserId == nil { return name } return id.UserId.Email } return "" }
[ "func", "(", "g", "*", "GPG", ")", "EmailFromKey", "(", "ctx", "context", ".", "Context", ",", "id", "string", ")", "string", "{", "ent", ":=", "g", ".", "findEntity", "(", "id", ")", "\n", "if", "ent", "==", "nil", "||", "ent", ".", "Identities", "==", "nil", "{", "return", "\"", "\"", "\n", "}", "\n", "for", "name", ",", "id", ":=", "range", "ent", ".", "Identities", "{", "if", "id", ".", "UserId", "==", "nil", "{", "return", "name", "\n", "}", "\n", "return", "id", ".", "UserId", ".", "Email", "\n", "}", "\n", "return", "\"", "\"", "\n", "}" ]
// EmailFromKey returns the email for this key
[ "EmailFromKey", "returns", "the", "email", "for", "this", "key" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/openpgp/gpg.go#L206-L218
train
gopasspw/gopass
pkg/backend/crypto/gpg/openpgp/gpg.go
NameFromKey
func (g *GPG) NameFromKey(ctx context.Context, id string) string { ent := g.findEntity(id) if ent == nil || ent.Identities == nil { return "" } for name, id := range ent.Identities { if id.UserId == nil { return name } return id.UserId.Name } return "" }
go
func (g *GPG) NameFromKey(ctx context.Context, id string) string { ent := g.findEntity(id) if ent == nil || ent.Identities == nil { return "" } for name, id := range ent.Identities { if id.UserId == nil { return name } return id.UserId.Name } return "" }
[ "func", "(", "g", "*", "GPG", ")", "NameFromKey", "(", "ctx", "context", ".", "Context", ",", "id", "string", ")", "string", "{", "ent", ":=", "g", ".", "findEntity", "(", "id", ")", "\n", "if", "ent", "==", "nil", "||", "ent", ".", "Identities", "==", "nil", "{", "return", "\"", "\"", "\n", "}", "\n", "for", "name", ",", "id", ":=", "range", "ent", ".", "Identities", "{", "if", "id", ".", "UserId", "==", "nil", "{", "return", "name", "\n", "}", "\n", "return", "id", ".", "UserId", ".", "Name", "\n", "}", "\n", "return", "\"", "\"", "\n", "}" ]
// NameFromKey is returns the name for this key
[ "NameFromKey", "is", "returns", "the", "name", "for", "this", "key" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/openpgp/gpg.go#L221-L233
train
gopasspw/gopass
pkg/backend/crypto/gpg/openpgp/gpg.go
ReadNamesFromKey
func (g *GPG) ReadNamesFromKey(ctx context.Context, buf []byte) ([]string, error) { el, err := openpgp.ReadArmoredKeyRing(bytes.NewReader(buf)) if err != nil { return nil, errors.Wrapf(err, "failed to read key ring") } if len(el) != 1 { return nil, errors.Errorf("Public Key must contain exactly one Entity") } names := make([]string, 0, len(el[0].Identities)) for _, v := range el[0].Identities { names = append(names, v.Name) } return names, nil }
go
func (g *GPG) ReadNamesFromKey(ctx context.Context, buf []byte) ([]string, error) { el, err := openpgp.ReadArmoredKeyRing(bytes.NewReader(buf)) if err != nil { return nil, errors.Wrapf(err, "failed to read key ring") } if len(el) != 1 { return nil, errors.Errorf("Public Key must contain exactly one Entity") } names := make([]string, 0, len(el[0].Identities)) for _, v := range el[0].Identities { names = append(names, v.Name) } return names, nil }
[ "func", "(", "g", "*", "GPG", ")", "ReadNamesFromKey", "(", "ctx", "context", ".", "Context", ",", "buf", "[", "]", "byte", ")", "(", "[", "]", "string", ",", "error", ")", "{", "el", ",", "err", ":=", "openpgp", ".", "ReadArmoredKeyRing", "(", "bytes", ".", "NewReader", "(", "buf", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "len", "(", "el", ")", "!=", "1", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "names", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "el", "[", "0", "]", ".", "Identities", ")", ")", "\n", "for", "_", ",", "v", ":=", "range", "el", "[", "0", "]", ".", "Identities", "{", "names", "=", "append", "(", "names", ",", "v", ".", "Name", ")", "\n", "}", "\n", "return", "names", ",", "nil", "\n", "}" ]
// ReadNamesFromKey unmarshals and returns the names associated with the given public key
[ "ReadNamesFromKey", "unmarshals", "and", "returns", "the", "names", "associated", "with", "the", "given", "public", "key" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/openpgp/gpg.go#L277-L290
train
gopasspw/gopass
pkg/action/unclip.go
Unclip
func (s *Action) Unclip(ctx context.Context, c *cli.Context) error { force := c.Bool("force") timeout := c.Int("timeout") checksum := os.Getenv("GOPASS_UNCLIP_CHECKSUM") time.Sleep(time.Second * time.Duration(timeout)) if err := clipboard.Clear(ctx, checksum, force); err != nil { return ExitError(ctx, ExitIO, err, "Failed to clear clipboard: %s", err) } return nil }
go
func (s *Action) Unclip(ctx context.Context, c *cli.Context) error { force := c.Bool("force") timeout := c.Int("timeout") checksum := os.Getenv("GOPASS_UNCLIP_CHECKSUM") time.Sleep(time.Second * time.Duration(timeout)) if err := clipboard.Clear(ctx, checksum, force); err != nil { return ExitError(ctx, ExitIO, err, "Failed to clear clipboard: %s", err) } return nil }
[ "func", "(", "s", "*", "Action", ")", "Unclip", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "force", ":=", "c", ".", "Bool", "(", "\"", "\"", ")", "\n", "timeout", ":=", "c", ".", "Int", "(", "\"", "\"", ")", "\n", "checksum", ":=", "os", ".", "Getenv", "(", "\"", "\"", ")", "\n\n", "time", ".", "Sleep", "(", "time", ".", "Second", "*", "time", ".", "Duration", "(", "timeout", ")", ")", "\n", "if", "err", ":=", "clipboard", ".", "Clear", "(", "ctx", ",", "checksum", ",", "force", ")", ";", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitIO", ",", "err", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Unclip tries to erase the content of the clipboard
[ "Unclip", "tries", "to", "erase", "the", "content", "of", "the", "clipboard" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/unclip.go#L14-L24
train
gopasspw/gopass
pkg/action/find.go
Find
func (s *Action) Find(ctx context.Context, c *cli.Context) error { if c.IsSet("clip") { ctx = WithClip(ctx, c.Bool("clip")) } if !c.Args().Present() { return ExitError(ctx, ExitUsage, nil, "Usage: %s find <NEEDLE>", s.Name) } return s.find(ctx, c, c.Args().First(), s.show) }
go
func (s *Action) Find(ctx context.Context, c *cli.Context) error { if c.IsSet("clip") { ctx = WithClip(ctx, c.Bool("clip")) } if !c.Args().Present() { return ExitError(ctx, ExitUsage, nil, "Usage: %s find <NEEDLE>", s.Name) } return s.find(ctx, c, c.Args().First(), s.show) }
[ "func", "(", "s", "*", "Action", ")", "Find", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "if", "c", ".", "IsSet", "(", "\"", "\"", ")", "{", "ctx", "=", "WithClip", "(", "ctx", ",", "c", ".", "Bool", "(", "\"", "\"", ")", ")", "\n", "}", "\n\n", "if", "!", "c", ".", "Args", "(", ")", ".", "Present", "(", ")", "{", "return", "ExitError", "(", "ctx", ",", "ExitUsage", ",", "nil", ",", "\"", "\"", ",", "s", ".", "Name", ")", "\n", "}", "\n\n", "return", "s", ".", "find", "(", "ctx", ",", "c", ",", "c", ".", "Args", "(", ")", ".", "First", "(", ")", ",", "s", ".", "show", ")", "\n", "}" ]
// Find a string in the secret file's name
[ "Find", "a", "string", "in", "the", "secret", "file", "s", "name" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/find.go#L18-L28
train
gopasspw/gopass
pkg/action/find.go
findSelection
func (s *Action) findSelection(ctx context.Context, c *cli.Context, choices []string, needle string, cb showFunc) error { sort.Strings(choices) act, sel := cui.GetSelection(ctx, "Found secrets - Please select an entry", "<↑/↓> to change the selection, <→> to show, <←> to copy, <s> to sync, <e> to edit, <ESC> to quit", choices) out.Debug(ctx, "Action: %s - Selection: %d", act, sel) switch act { case "default": // display or copy selected entry fmt.Fprintln(stdout, choices[sel]) return cb(ctx, c, choices[sel], "", false) case "copy": // display selected entry fmt.Fprintln(stdout, choices[sel]) return cb(WithClip(ctx, true), c, choices[sel], "", false) case "show": // display selected entry fmt.Fprintln(stdout, choices[sel]) return cb(WithClip(ctx, false), c, choices[sel], "", false) case "sync": // run sync and re-run show/find workflow if err := s.Sync(ctx, c); err != nil { return err } return cb(ctx, c, needle, "", true) case "edit": // edit selected entry fmt.Fprintln(stdout, choices[sel]) return s.edit(ctx, c, choices[sel]) default: return ExitError(ctx, ExitAborted, nil, "user aborted") } }
go
func (s *Action) findSelection(ctx context.Context, c *cli.Context, choices []string, needle string, cb showFunc) error { sort.Strings(choices) act, sel := cui.GetSelection(ctx, "Found secrets - Please select an entry", "<↑/↓> to change the selection, <→> to show, <←> to copy, <s> to sync, <e> to edit, <ESC> to quit", choices) out.Debug(ctx, "Action: %s - Selection: %d", act, sel) switch act { case "default": // display or copy selected entry fmt.Fprintln(stdout, choices[sel]) return cb(ctx, c, choices[sel], "", false) case "copy": // display selected entry fmt.Fprintln(stdout, choices[sel]) return cb(WithClip(ctx, true), c, choices[sel], "", false) case "show": // display selected entry fmt.Fprintln(stdout, choices[sel]) return cb(WithClip(ctx, false), c, choices[sel], "", false) case "sync": // run sync and re-run show/find workflow if err := s.Sync(ctx, c); err != nil { return err } return cb(ctx, c, needle, "", true) case "edit": // edit selected entry fmt.Fprintln(stdout, choices[sel]) return s.edit(ctx, c, choices[sel]) default: return ExitError(ctx, ExitAborted, nil, "user aborted") } }
[ "func", "(", "s", "*", "Action", ")", "findSelection", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ",", "choices", "[", "]", "string", ",", "needle", "string", ",", "cb", "showFunc", ")", "error", "{", "sort", ".", "Strings", "(", "choices", ")", "\n", "act", ",", "sel", ":=", "cui", ".", "GetSelection", "(", "ctx", ",", "\"", "\"", ",", "\"", "e", "s", "", "", "\n", "out", ".", "Debug", "(", "ctx", ",", "\"", "\"", ",", "act", ",", "sel", ")", "\n", "switch", "act", "{", "case", "\"", "\"", ":", "// display or copy selected entry", "fmt", ".", "Fprintln", "(", "stdout", ",", "choices", "[", "sel", "]", ")", "\n", "return", "cb", "(", "ctx", ",", "c", ",", "choices", "[", "sel", "]", ",", "\"", "\"", ",", "false", ")", "\n", "case", "\"", "\"", ":", "// display selected entry", "fmt", ".", "Fprintln", "(", "stdout", ",", "choices", "[", "sel", "]", ")", "\n", "return", "cb", "(", "WithClip", "(", "ctx", ",", "true", ")", ",", "c", ",", "choices", "[", "sel", "]", ",", "\"", "\"", ",", "false", ")", "\n", "case", "\"", "\"", ":", "// display selected entry", "fmt", ".", "Fprintln", "(", "stdout", ",", "choices", "[", "sel", "]", ")", "\n", "return", "cb", "(", "WithClip", "(", "ctx", ",", "false", ")", ",", "c", ",", "choices", "[", "sel", "]", ",", "\"", "\"", ",", "false", ")", "\n", "case", "\"", "\"", ":", "// run sync and re-run show/find workflow", "if", "err", ":=", "s", ".", "Sync", "(", "ctx", ",", "c", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "cb", "(", "ctx", ",", "c", ",", "needle", ",", "\"", "\"", ",", "true", ")", "\n", "case", "\"", "\"", ":", "// edit selected entry", "fmt", ".", "Fprintln", "(", "stdout", ",", "choices", "[", "sel", "]", ")", "\n", "return", "s", ".", "edit", "(", "ctx", ",", "c", ",", "choices", "[", "sel", "]", ")", "\n", "default", ":", "return", "ExitError", "(", "ctx", ",", "ExitAborted", ",", "nil", ",", "\"", "\"", ")", "\n", "}", "\n", "}" ]
// findSelection runs a wizard that lets the user select an entry
[ "findSelection", "runs", "a", "wizard", "that", "lets", "the", "user", "select", "an", "entry" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/find.go#L75-L105
train
gopasspw/gopass
pkg/qrcon/qrcon.go
QRCode
func QRCode(content string) (string, error) { q, err := qrcode.New(content, qrcode.Medium) if err != nil { return "", err } buf := bytes.Buffer{} i := q.Image(0) b := i.Bounds() for x := b.Min.X; x < b.Max.X; x++ { for y := b.Min.Y; y < b.Max.Y; y++ { col := i.At(x, y) if sameColor(col, q.ForegroundColor) { _, _ = buf.WriteString(black) } else if sameColor(col, q.BackgroundColor) { _, _ = buf.WriteString(white) } else { return "", errors.Errorf("Unexpected color at (%d,%d): %+v", x, y, col) } } _, _ = buf.WriteString("\n") } return buf.String(), nil }
go
func QRCode(content string) (string, error) { q, err := qrcode.New(content, qrcode.Medium) if err != nil { return "", err } buf := bytes.Buffer{} i := q.Image(0) b := i.Bounds() for x := b.Min.X; x < b.Max.X; x++ { for y := b.Min.Y; y < b.Max.Y; y++ { col := i.At(x, y) if sameColor(col, q.ForegroundColor) { _, _ = buf.WriteString(black) } else if sameColor(col, q.BackgroundColor) { _, _ = buf.WriteString(white) } else { return "", errors.Errorf("Unexpected color at (%d,%d): %+v", x, y, col) } } _, _ = buf.WriteString("\n") } return buf.String(), nil }
[ "func", "QRCode", "(", "content", "string", ")", "(", "string", ",", "error", ")", "{", "q", ",", "err", ":=", "qrcode", ".", "New", "(", "content", ",", "qrcode", ".", "Medium", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "buf", ":=", "bytes", ".", "Buffer", "{", "}", "\n", "i", ":=", "q", ".", "Image", "(", "0", ")", "\n", "b", ":=", "i", ".", "Bounds", "(", ")", "\n", "for", "x", ":=", "b", ".", "Min", ".", "X", ";", "x", "<", "b", ".", "Max", ".", "X", ";", "x", "++", "{", "for", "y", ":=", "b", ".", "Min", ".", "Y", ";", "y", "<", "b", ".", "Max", ".", "Y", ";", "y", "++", "{", "col", ":=", "i", ".", "At", "(", "x", ",", "y", ")", "\n", "if", "sameColor", "(", "col", ",", "q", ".", "ForegroundColor", ")", "{", "_", ",", "_", "=", "buf", ".", "WriteString", "(", "black", ")", "\n", "}", "else", "if", "sameColor", "(", "col", ",", "q", ".", "BackgroundColor", ")", "{", "_", ",", "_", "=", "buf", ".", "WriteString", "(", "white", ")", "\n", "}", "else", "{", "return", "\"", "\"", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "x", ",", "y", ",", "col", ")", "\n", "}", "\n", "}", "\n", "_", ",", "_", "=", "buf", ".", "WriteString", "(", "\"", "\\n", "\"", ")", "\n", "}", "\n", "return", "buf", ".", "String", "(", ")", ",", "nil", "\n", "}" ]
// QRCode returns a string containing an ANSI encoded // QR Code
[ "QRCode", "returns", "a", "string", "containing", "an", "ANSI", "encoded", "QR", "Code" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/qrcon/qrcon.go#L18-L40
train
gopasspw/gopass
pkg/store/root/read.go
GetContext
func (r *Store) GetContext(ctx context.Context, name string) (store.Secret, context.Context, error) { // forward to substore ctx, store, name := r.getStore(ctx, name) sec, err := store.Get(ctx, name) return sec, ctx, err }
go
func (r *Store) GetContext(ctx context.Context, name string) (store.Secret, context.Context, error) { // forward to substore ctx, store, name := r.getStore(ctx, name) sec, err := store.Get(ctx, name) return sec, ctx, err }
[ "func", "(", "r", "*", "Store", ")", "GetContext", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "(", "store", ".", "Secret", ",", "context", ".", "Context", ",", "error", ")", "{", "// forward to substore", "ctx", ",", "store", ",", "name", ":=", "r", ".", "getStore", "(", "ctx", ",", "name", ")", "\n", "sec", ",", "err", ":=", "store", ".", "Get", "(", "ctx", ",", "name", ")", "\n", "return", "sec", ",", "ctx", ",", "err", "\n", "}" ]
// GetContext returns the plaintext and the context of a single key
[ "GetContext", "returns", "the", "plaintext", "and", "the", "context", "of", "a", "single", "key" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/read.go#L17-L22
train
gopasspw/gopass
pkg/tree/simple/tree.go
New
func New(name string) *Folder { f := newFolder(name) f.Root = true return f }
go
func New(name string) *Folder { f := newFolder(name) f.Root = true return f }
[ "func", "New", "(", "name", "string", ")", "*", "Folder", "{", "f", ":=", "newFolder", "(", "name", ")", "\n", "f", ".", "Root", "=", "true", "\n", "return", "f", "\n", "}" ]
// New create a new root folder
[ "New", "create", "a", "new", "root", "folder" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/tree/simple/tree.go#L27-L31
train
gopasspw/gopass
pkg/updater/update_others.go
IsUpdateable
func IsUpdateable(ctx context.Context) error { fn, err := executable(ctx) if err != nil { return err } out.Debug(ctx, "isUpdateable - File: %s", fn) // check if this is a test binary if strings.HasSuffix(filepath.Base(fn), ".test") { return nil } // check if we want to force updateability if uf := os.Getenv("GOPASS_FORCE_UPDATE"); uf != "" { out.Debug(ctx, "updateable due to force flag") return nil } // check if file is in GOPATH if gp := os.Getenv("GOPATH"); strings.HasPrefix(fn, gp) { return fmt.Errorf("use go get -u to update binary in GOPATH") } // check file fi, err := os.Stat(fn) if err != nil { return err } if !fi.Mode().IsRegular() { return fmt.Errorf("not a regular file") } if err := unix.Access(fn, unix.W_OK); err != nil { return err } // check dir fdir := filepath.Dir(fn) return unix.Access(fdir, unix.W_OK) }
go
func IsUpdateable(ctx context.Context) error { fn, err := executable(ctx) if err != nil { return err } out.Debug(ctx, "isUpdateable - File: %s", fn) // check if this is a test binary if strings.HasSuffix(filepath.Base(fn), ".test") { return nil } // check if we want to force updateability if uf := os.Getenv("GOPASS_FORCE_UPDATE"); uf != "" { out.Debug(ctx, "updateable due to force flag") return nil } // check if file is in GOPATH if gp := os.Getenv("GOPATH"); strings.HasPrefix(fn, gp) { return fmt.Errorf("use go get -u to update binary in GOPATH") } // check file fi, err := os.Stat(fn) if err != nil { return err } if !fi.Mode().IsRegular() { return fmt.Errorf("not a regular file") } if err := unix.Access(fn, unix.W_OK); err != nil { return err } // check dir fdir := filepath.Dir(fn) return unix.Access(fdir, unix.W_OK) }
[ "func", "IsUpdateable", "(", "ctx", "context", ".", "Context", ")", "error", "{", "fn", ",", "err", ":=", "executable", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "out", ".", "Debug", "(", "ctx", ",", "\"", "\"", ",", "fn", ")", "\n", "// check if this is a test binary", "if", "strings", ".", "HasSuffix", "(", "filepath", ".", "Base", "(", "fn", ")", ",", "\"", "\"", ")", "{", "return", "nil", "\n", "}", "\n\n", "// check if we want to force updateability", "if", "uf", ":=", "os", ".", "Getenv", "(", "\"", "\"", ")", ";", "uf", "!=", "\"", "\"", "{", "out", ".", "Debug", "(", "ctx", ",", "\"", "\"", ")", "\n", "return", "nil", "\n", "}", "\n\n", "// check if file is in GOPATH", "if", "gp", ":=", "os", ".", "Getenv", "(", "\"", "\"", ")", ";", "strings", ".", "HasPrefix", "(", "fn", ",", "gp", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// check file", "fi", ",", "err", ":=", "os", ".", "Stat", "(", "fn", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "!", "fi", ".", "Mode", "(", ")", ".", "IsRegular", "(", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "err", ":=", "unix", ".", "Access", "(", "fn", ",", "unix", ".", "W_OK", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// check dir", "fdir", ":=", "filepath", ".", "Dir", "(", "fn", ")", "\n", "return", "unix", ".", "Access", "(", "fdir", ",", "unix", ".", "W_OK", ")", "\n", "}" ]
// IsUpdateable returns an error if this binary is not updateable
[ "IsUpdateable", "returns", "an", "error", "if", "this", "binary", "is", "not", "updateable" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/updater/update_others.go#L77-L114
train
gopasspw/gopass
pkg/config/location.go
Homedir
func Homedir() string { if hd := os.Getenv("GOPASS_HOMEDIR"); hd != "" { return hd } hd, err := homedir.Dir() if err != nil { if debug { fmt.Printf("[DEBUG] Failed to get homedir: %s\n", err) } return "" } return hd }
go
func Homedir() string { if hd := os.Getenv("GOPASS_HOMEDIR"); hd != "" { return hd } hd, err := homedir.Dir() if err != nil { if debug { fmt.Printf("[DEBUG] Failed to get homedir: %s\n", err) } return "" } return hd }
[ "func", "Homedir", "(", ")", "string", "{", "if", "hd", ":=", "os", ".", "Getenv", "(", "\"", "\"", ")", ";", "hd", "!=", "\"", "\"", "{", "return", "hd", "\n", "}", "\n", "hd", ",", "err", ":=", "homedir", ".", "Dir", "(", ")", "\n", "if", "err", "!=", "nil", "{", "if", "debug", "{", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "err", ")", "\n", "}", "\n", "return", "\"", "\"", "\n", "}", "\n", "return", "hd", "\n", "}" ]
// Homedir returns the users home dir or an empty string if the lookup fails
[ "Homedir", "returns", "the", "users", "home", "dir", "or", "an", "empty", "string", "if", "the", "lookup", "fails" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/config/location.go#L15-L27
train
gopasspw/gopass
pkg/config/location.go
configLocations
func configLocations() []string { l := []string{} if cf := os.Getenv("GOPASS_CONFIG"); cf != "" { l = append(l, cf) } if xch := os.Getenv("XDG_CONFIG_HOME"); xch != "" { l = append(l, filepath.Join(xch, "gopass", "config.yml")) } l = append(l, filepath.Join(Homedir(), ".config", "gopass", "config.yml")) l = append(l, filepath.Join(Homedir(), ".gopass.yml")) return l }
go
func configLocations() []string { l := []string{} if cf := os.Getenv("GOPASS_CONFIG"); cf != "" { l = append(l, cf) } if xch := os.Getenv("XDG_CONFIG_HOME"); xch != "" { l = append(l, filepath.Join(xch, "gopass", "config.yml")) } l = append(l, filepath.Join(Homedir(), ".config", "gopass", "config.yml")) l = append(l, filepath.Join(Homedir(), ".gopass.yml")) return l }
[ "func", "configLocations", "(", ")", "[", "]", "string", "{", "l", ":=", "[", "]", "string", "{", "}", "\n", "if", "cf", ":=", "os", ".", "Getenv", "(", "\"", "\"", ")", ";", "cf", "!=", "\"", "\"", "{", "l", "=", "append", "(", "l", ",", "cf", ")", "\n", "}", "\n", "if", "xch", ":=", "os", ".", "Getenv", "(", "\"", "\"", ")", ";", "xch", "!=", "\"", "\"", "{", "l", "=", "append", "(", "l", ",", "filepath", ".", "Join", "(", "xch", ",", "\"", "\"", ",", "\"", "\"", ")", ")", "\n", "}", "\n", "l", "=", "append", "(", "l", ",", "filepath", ".", "Join", "(", "Homedir", "(", ")", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", ")", "\n", "l", "=", "append", "(", "l", ",", "filepath", ".", "Join", "(", "Homedir", "(", ")", ",", "\"", "\"", ")", ")", "\n", "return", "l", "\n", "}" ]
// configLocations returns the possible locations of gopass config files, // in decreasing priority
[ "configLocations", "returns", "the", "possible", "locations", "of", "gopass", "config", "files", "in", "decreasing", "priority" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/config/location.go#L49-L60
train
gopasspw/gopass
pkg/jsonapi/manifest/wrapper.go
Render
func Render(browser, wrapperPath, binPath string, global bool) ([]byte, []byte, error) { mf, err := getManifestContent(browser, wrapperPath) if err != nil { return nil, nil, err } if binPath == "" { binPath = gopassPath(global) } wrap, err := getWrapperContent(binPath) if err != nil { return nil, nil, err } return wrap, mf, nil }
go
func Render(browser, wrapperPath, binPath string, global bool) ([]byte, []byte, error) { mf, err := getManifestContent(browser, wrapperPath) if err != nil { return nil, nil, err } if binPath == "" { binPath = gopassPath(global) } wrap, err := getWrapperContent(binPath) if err != nil { return nil, nil, err } return wrap, mf, nil }
[ "func", "Render", "(", "browser", ",", "wrapperPath", ",", "binPath", "string", ",", "global", "bool", ")", "(", "[", "]", "byte", ",", "[", "]", "byte", ",", "error", ")", "{", "mf", ",", "err", ":=", "getManifestContent", "(", "browser", ",", "wrapperPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n\n", "if", "binPath", "==", "\"", "\"", "{", "binPath", "=", "gopassPath", "(", "global", ")", "\n", "}", "\n", "wrap", ",", "err", ":=", "getWrapperContent", "(", "binPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n\n", "return", "wrap", ",", "mf", ",", "nil", "\n", "}" ]
// Render returns the rendered wrapper and manifest
[ "Render", "returns", "the", "rendered", "wrapper", "and", "manifest" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/jsonapi/manifest/wrapper.go#L31-L46
train
gopasspw/gopass
pkg/store/root/git.go
GitInit
func (r *Store) GitInit(ctx context.Context, name, userName, userEmail string) error { ctx, store, _ := r.getStore(ctx, name) return store.GitInit(ctx, userName, userEmail) }
go
func (r *Store) GitInit(ctx context.Context, name, userName, userEmail string) error { ctx, store, _ := r.getStore(ctx, name) return store.GitInit(ctx, userName, userEmail) }
[ "func", "(", "r", "*", "Store", ")", "GitInit", "(", "ctx", "context", ".", "Context", ",", "name", ",", "userName", ",", "userEmail", "string", ")", "error", "{", "ctx", ",", "store", ",", "_", ":=", "r", ".", "getStore", "(", "ctx", ",", "name", ")", "\n", "return", "store", ".", "GitInit", "(", "ctx", ",", "userName", ",", "userEmail", ")", "\n", "}" ]
// GitInit initializes the git repo
[ "GitInit", "initializes", "the", "git", "repo" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/git.go#L22-L25
train
gopasspw/gopass
pkg/store/root/git.go
GitInitConfig
func (r *Store) GitInitConfig(ctx context.Context, name, userName, userEmail string) error { ctx, store, _ := r.getStore(ctx, name) return store.RCS().InitConfig(ctx, userName, userEmail) }
go
func (r *Store) GitInitConfig(ctx context.Context, name, userName, userEmail string) error { ctx, store, _ := r.getStore(ctx, name) return store.RCS().InitConfig(ctx, userName, userEmail) }
[ "func", "(", "r", "*", "Store", ")", "GitInitConfig", "(", "ctx", "context", ".", "Context", ",", "name", ",", "userName", ",", "userEmail", "string", ")", "error", "{", "ctx", ",", "store", ",", "_", ":=", "r", ".", "getStore", "(", "ctx", ",", "name", ")", "\n", "return", "store", ".", "RCS", "(", ")", ".", "InitConfig", "(", "ctx", ",", "userName", ",", "userEmail", ")", "\n", "}" ]
// GitInitConfig initializes the git repos local config
[ "GitInitConfig", "initializes", "the", "git", "repos", "local", "config" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/git.go#L28-L31
train
gopasspw/gopass
pkg/store/root/git.go
GitVersion
func (r *Store) GitVersion(ctx context.Context) semver.Version { return r.store.RCS().Version(ctx) }
go
func (r *Store) GitVersion(ctx context.Context) semver.Version { return r.store.RCS().Version(ctx) }
[ "func", "(", "r", "*", "Store", ")", "GitVersion", "(", "ctx", "context", ".", "Context", ")", "semver", ".", "Version", "{", "return", "r", ".", "store", ".", "RCS", "(", ")", ".", "Version", "(", "ctx", ")", "\n", "}" ]
// GitVersion returns git version information
[ "GitVersion", "returns", "git", "version", "information" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/git.go#L34-L36
train
gopasspw/gopass
pkg/store/root/git.go
GitAddRemote
func (r *Store) GitAddRemote(ctx context.Context, name, remote, url string) error { ctx, store, _ := r.getStore(ctx, name) return store.RCS().AddRemote(ctx, remote, url) }
go
func (r *Store) GitAddRemote(ctx context.Context, name, remote, url string) error { ctx, store, _ := r.getStore(ctx, name) return store.RCS().AddRemote(ctx, remote, url) }
[ "func", "(", "r", "*", "Store", ")", "GitAddRemote", "(", "ctx", "context", ".", "Context", ",", "name", ",", "remote", ",", "url", "string", ")", "error", "{", "ctx", ",", "store", ",", "_", ":=", "r", ".", "getStore", "(", "ctx", ",", "name", ")", "\n", "return", "store", ".", "RCS", "(", ")", ".", "AddRemote", "(", "ctx", ",", "remote", ",", "url", ")", "\n", "}" ]
// GitAddRemote adds a git remote
[ "GitAddRemote", "adds", "a", "git", "remote" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/git.go#L39-L42
train
gopasspw/gopass
pkg/store/root/git.go
GitRemoveRemote
func (r *Store) GitRemoveRemote(ctx context.Context, name, remote string) error { ctx, store, _ := r.getStore(ctx, name) return store.RCS().RemoveRemote(ctx, remote) }
go
func (r *Store) GitRemoveRemote(ctx context.Context, name, remote string) error { ctx, store, _ := r.getStore(ctx, name) return store.RCS().RemoveRemote(ctx, remote) }
[ "func", "(", "r", "*", "Store", ")", "GitRemoveRemote", "(", "ctx", "context", ".", "Context", ",", "name", ",", "remote", "string", ")", "error", "{", "ctx", ",", "store", ",", "_", ":=", "r", ".", "getStore", "(", "ctx", ",", "name", ")", "\n", "return", "store", ".", "RCS", "(", ")", ".", "RemoveRemote", "(", "ctx", ",", "remote", ")", "\n", "}" ]
// GitRemoveRemote removes a git remote
[ "GitRemoveRemote", "removes", "a", "git", "remote" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/git.go#L45-L48
train
gopasspw/gopass
pkg/store/root/git.go
GitPull
func (r *Store) GitPull(ctx context.Context, name, origin, remote string) error { ctx, store, _ := r.getStore(ctx, name) return store.RCS().Pull(ctx, origin, remote) }
go
func (r *Store) GitPull(ctx context.Context, name, origin, remote string) error { ctx, store, _ := r.getStore(ctx, name) return store.RCS().Pull(ctx, origin, remote) }
[ "func", "(", "r", "*", "Store", ")", "GitPull", "(", "ctx", "context", ".", "Context", ",", "name", ",", "origin", ",", "remote", "string", ")", "error", "{", "ctx", ",", "store", ",", "_", ":=", "r", ".", "getStore", "(", "ctx", ",", "name", ")", "\n", "return", "store", ".", "RCS", "(", ")", ".", "Pull", "(", "ctx", ",", "origin", ",", "remote", ")", "\n", "}" ]
// GitPull performs a git pull
[ "GitPull", "performs", "a", "git", "pull" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/git.go#L51-L54
train
gopasspw/gopass
pkg/store/root/git.go
GitPush
func (r *Store) GitPush(ctx context.Context, name, origin, remote string) error { ctx, store, _ := r.getStore(ctx, name) return store.RCS().Push(ctx, origin, remote) }
go
func (r *Store) GitPush(ctx context.Context, name, origin, remote string) error { ctx, store, _ := r.getStore(ctx, name) return store.RCS().Push(ctx, origin, remote) }
[ "func", "(", "r", "*", "Store", ")", "GitPush", "(", "ctx", "context", ".", "Context", ",", "name", ",", "origin", ",", "remote", "string", ")", "error", "{", "ctx", ",", "store", ",", "_", ":=", "r", ".", "getStore", "(", "ctx", ",", "name", ")", "\n", "return", "store", ".", "RCS", "(", ")", ".", "Push", "(", "ctx", ",", "origin", ",", "remote", ")", "\n", "}" ]
// GitPush performs a git push
[ "GitPush", "performs", "a", "git", "push" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/git.go#L57-L60
train
gopasspw/gopass
pkg/store/root/git.go
ListRevisions
func (r *Store) ListRevisions(ctx context.Context, name string) ([]backend.Revision, error) { ctx, store, name := r.getStore(ctx, name) return store.ListRevisions(ctx, name) }
go
func (r *Store) ListRevisions(ctx context.Context, name string) ([]backend.Revision, error) { ctx, store, name := r.getStore(ctx, name) return store.ListRevisions(ctx, name) }
[ "func", "(", "r", "*", "Store", ")", "ListRevisions", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "(", "[", "]", "backend", ".", "Revision", ",", "error", ")", "{", "ctx", ",", "store", ",", "name", ":=", "r", ".", "getStore", "(", "ctx", ",", "name", ")", "\n", "return", "store", ".", "ListRevisions", "(", "ctx", ",", "name", ")", "\n", "}" ]
// ListRevisions will list all revisions for the named entity
[ "ListRevisions", "will", "list", "all", "revisions", "for", "the", "named", "entity" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/git.go#L63-L66
train
gopasspw/gopass
pkg/store/root/git.go
GetRevision
func (r *Store) GetRevision(ctx context.Context, name, revision string) (store.Secret, error) { ctx, store, name := r.getStore(ctx, name) return store.GetRevision(ctx, name, revision) }
go
func (r *Store) GetRevision(ctx context.Context, name, revision string) (store.Secret, error) { ctx, store, name := r.getStore(ctx, name) return store.GetRevision(ctx, name, revision) }
[ "func", "(", "r", "*", "Store", ")", "GetRevision", "(", "ctx", "context", ".", "Context", ",", "name", ",", "revision", "string", ")", "(", "store", ".", "Secret", ",", "error", ")", "{", "ctx", ",", "store", ",", "name", ":=", "r", ".", "getStore", "(", "ctx", ",", "name", ")", "\n", "return", "store", ".", "GetRevision", "(", "ctx", ",", "name", ",", "revision", ")", "\n", "}" ]
// GetRevision will try to retrieve the given revision from the sync backend
[ "GetRevision", "will", "try", "to", "retrieve", "the", "given", "revision", "from", "the", "sync", "backend" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/git.go#L69-L72
train
gopasspw/gopass
pkg/backend/rcs/git/gogit/loader.go
Init
func (l loader) Init(ctx context.Context, path, username, email string) (backend.RCS, error) { return Init(ctx, path) }
go
func (l loader) Init(ctx context.Context, path, username, email string) (backend.RCS, error) { return Init(ctx, path) }
[ "func", "(", "l", "loader", ")", "Init", "(", "ctx", "context", ".", "Context", ",", "path", ",", "username", ",", "email", "string", ")", "(", "backend", ".", "RCS", ",", "error", ")", "{", "return", "Init", "(", "ctx", ",", "path", ")", "\n", "}" ]
// Init implements backend.RCSLoader
[ "Init", "implements", "backend", ".", "RCSLoader" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/gogit/loader.go#L32-L34
train
gopasspw/gopass
pkg/action/insert.go
Insert
func (s *Action) Insert(ctx context.Context, c *cli.Context) error { echo := c.Bool("echo") multiline := c.Bool("multiline") force := c.Bool("force") append := c.Bool("append") args, kvps := parseArgs(c) name := args.Get(0) key := args.Get(1) if name == "" { return ExitError(ctx, ExitNoName, nil, "Usage: %s insert name", s.Name) } return s.insert(ctx, c, name, key, echo, multiline, force, append, kvps) }
go
func (s *Action) Insert(ctx context.Context, c *cli.Context) error { echo := c.Bool("echo") multiline := c.Bool("multiline") force := c.Bool("force") append := c.Bool("append") args, kvps := parseArgs(c) name := args.Get(0) key := args.Get(1) if name == "" { return ExitError(ctx, ExitNoName, nil, "Usage: %s insert name", s.Name) } return s.insert(ctx, c, name, key, echo, multiline, force, append, kvps) }
[ "func", "(", "s", "*", "Action", ")", "Insert", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "echo", ":=", "c", ".", "Bool", "(", "\"", "\"", ")", "\n", "multiline", ":=", "c", ".", "Bool", "(", "\"", "\"", ")", "\n", "force", ":=", "c", ".", "Bool", "(", "\"", "\"", ")", "\n", "append", ":=", "c", ".", "Bool", "(", "\"", "\"", ")", "\n\n", "args", ",", "kvps", ":=", "parseArgs", "(", "c", ")", "\n", "name", ":=", "args", ".", "Get", "(", "0", ")", "\n", "key", ":=", "args", ".", "Get", "(", "1", ")", "\n\n", "if", "name", "==", "\"", "\"", "{", "return", "ExitError", "(", "ctx", ",", "ExitNoName", ",", "nil", ",", "\"", "\"", ",", "s", ".", "Name", ")", "\n", "}", "\n\n", "return", "s", ".", "insert", "(", "ctx", ",", "c", ",", "name", ",", "key", ",", "echo", ",", "multiline", ",", "force", ",", "append", ",", "kvps", ")", "\n", "}" ]
// Insert a string as content to a secret file
[ "Insert", "a", "string", "as", "content", "to", "a", "secret", "file" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/insert.go#L23-L38
train
gopasspw/gopass
pkg/config/io.go
Load
func Load() *Config { for _, l := range configLocations() { if debug { fmt.Printf("[DEBUG] Trying to load config from %s\n", l) } cfg, err := load(l) if err == ErrConfigNotFound { continue } if err != nil { panic(err) } _ = cfg.checkDefaults() if debug { fmt.Printf("[DEBUG] Loaded config from %s: %+v\n", l, cfg) } return cfg } cfg := New() cfg.Root.Path = backend.FromPath(PwStoreDir("")) _ = cfg.checkDefaults() if debug { fmt.Printf("[DEBUG] config.Load(): %+v\n", cfg) } return cfg }
go
func Load() *Config { for _, l := range configLocations() { if debug { fmt.Printf("[DEBUG] Trying to load config from %s\n", l) } cfg, err := load(l) if err == ErrConfigNotFound { continue } if err != nil { panic(err) } _ = cfg.checkDefaults() if debug { fmt.Printf("[DEBUG] Loaded config from %s: %+v\n", l, cfg) } return cfg } cfg := New() cfg.Root.Path = backend.FromPath(PwStoreDir("")) _ = cfg.checkDefaults() if debug { fmt.Printf("[DEBUG] config.Load(): %+v\n", cfg) } return cfg }
[ "func", "Load", "(", ")", "*", "Config", "{", "for", "_", ",", "l", ":=", "range", "configLocations", "(", ")", "{", "if", "debug", "{", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "l", ")", "\n", "}", "\n", "cfg", ",", "err", ":=", "load", "(", "l", ")", "\n", "if", "err", "==", "ErrConfigNotFound", "{", "continue", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "_", "=", "cfg", ".", "checkDefaults", "(", ")", "\n", "if", "debug", "{", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "l", ",", "cfg", ")", "\n", "}", "\n", "return", "cfg", "\n", "}", "\n", "cfg", ":=", "New", "(", ")", "\n", "cfg", ".", "Root", ".", "Path", "=", "backend", ".", "FromPath", "(", "PwStoreDir", "(", "\"", "\"", ")", ")", "\n", "_", "=", "cfg", ".", "checkDefaults", "(", ")", "\n", "if", "debug", "{", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "cfg", ")", "\n", "}", "\n", "return", "cfg", "\n", "}" ]
// Load will try to load the config from one of the default locations
[ "Load", "will", "try", "to", "load", "the", "config", "from", "one", "of", "the", "default", "locations" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/config/io.go#L17-L42
train
gopasspw/gopass
pkg/config/io.go
Save
func (c *Config) Save() error { if err := c.checkDefaults(); err != nil { return err } buf, err := yaml.Marshal(c) if err != nil { return errors.Wrapf(err, "failed to marshal YAML") } cfgLoc := configLocation() cfgDir := filepath.Dir(cfgLoc) if !fsutil.IsDir(cfgDir) { if err := os.MkdirAll(cfgDir, 0700); err != nil { return errors.Wrapf(err, "failed to create dir '%s'", cfgDir) } } if err := ioutil.WriteFile(cfgLoc, buf, 0600); err != nil { return errors.Wrapf(err, "failed to write config file to '%s'", cfgLoc) } if debug { fmt.Printf("[DEBUG] Saved config to %s: %+v\n", cfgLoc, c) } return nil }
go
func (c *Config) Save() error { if err := c.checkDefaults(); err != nil { return err } buf, err := yaml.Marshal(c) if err != nil { return errors.Wrapf(err, "failed to marshal YAML") } cfgLoc := configLocation() cfgDir := filepath.Dir(cfgLoc) if !fsutil.IsDir(cfgDir) { if err := os.MkdirAll(cfgDir, 0700); err != nil { return errors.Wrapf(err, "failed to create dir '%s'", cfgDir) } } if err := ioutil.WriteFile(cfgLoc, buf, 0600); err != nil { return errors.Wrapf(err, "failed to write config file to '%s'", cfgLoc) } if debug { fmt.Printf("[DEBUG] Saved config to %s: %+v\n", cfgLoc, c) } return nil }
[ "func", "(", "c", "*", "Config", ")", "Save", "(", ")", "error", "{", "if", "err", ":=", "c", ".", "checkDefaults", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "buf", ",", "err", ":=", "yaml", ".", "Marshal", "(", "c", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "cfgLoc", ":=", "configLocation", "(", ")", "\n", "cfgDir", ":=", "filepath", ".", "Dir", "(", "cfgLoc", ")", "\n", "if", "!", "fsutil", ".", "IsDir", "(", "cfgDir", ")", "{", "if", "err", ":=", "os", ".", "MkdirAll", "(", "cfgDir", ",", "0700", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "cfgDir", ")", "\n", "}", "\n", "}", "\n", "if", "err", ":=", "ioutil", ".", "WriteFile", "(", "cfgLoc", ",", "buf", ",", "0600", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "cfgLoc", ")", "\n", "}", "\n", "if", "debug", "{", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "cfgLoc", ",", "c", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Save saves the config
[ "Save", "saves", "the", "config" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/config/io.go#L119-L143
train
gopasspw/gopass
pkg/action/delete.go
Delete
func (s *Action) Delete(ctx context.Context, c *cli.Context) error { force := c.Bool("force") recursive := c.Bool("recursive") name := c.Args().First() if name == "" { return ExitError(ctx, ExitUsage, nil, "Usage: %s rm name", s.Name) } if !recursive && s.Store.IsDir(ctx, name) { return ExitError(ctx, ExitUsage, nil, "Cannot remove '%s': Is a directory. Use 'gopass rm -r %s' to delete", name, name) } // specifying a key is optional key := c.Args().Get(1) if !force { // don't check if it's force anyway recStr := "" if recursive { recStr = "recursively " } if (s.Store.Exists(ctx, name) || s.Store.IsDir(ctx, name)) && key == "" && !termio.AskForConfirmation(ctx, fmt.Sprintf("Are you sure you would like to %sdelete %s?", recStr, name)) { return nil } } if recursive { if err := s.Store.Prune(ctx, name); err != nil { return ExitError(ctx, ExitUnknown, err, "failed to prune '%s': %s", name, err) } return nil } // deletes a single key from a YAML doc if key != "" { return s.deleteKeyFromYAML(ctx, name, key) } if err := s.Store.Delete(ctx, name); err != nil { return ExitError(ctx, ExitIO, err, "Can not delete '%s': %s", name, err) } return nil }
go
func (s *Action) Delete(ctx context.Context, c *cli.Context) error { force := c.Bool("force") recursive := c.Bool("recursive") name := c.Args().First() if name == "" { return ExitError(ctx, ExitUsage, nil, "Usage: %s rm name", s.Name) } if !recursive && s.Store.IsDir(ctx, name) { return ExitError(ctx, ExitUsage, nil, "Cannot remove '%s': Is a directory. Use 'gopass rm -r %s' to delete", name, name) } // specifying a key is optional key := c.Args().Get(1) if !force { // don't check if it's force anyway recStr := "" if recursive { recStr = "recursively " } if (s.Store.Exists(ctx, name) || s.Store.IsDir(ctx, name)) && key == "" && !termio.AskForConfirmation(ctx, fmt.Sprintf("Are you sure you would like to %sdelete %s?", recStr, name)) { return nil } } if recursive { if err := s.Store.Prune(ctx, name); err != nil { return ExitError(ctx, ExitUnknown, err, "failed to prune '%s': %s", name, err) } return nil } // deletes a single key from a YAML doc if key != "" { return s.deleteKeyFromYAML(ctx, name, key) } if err := s.Store.Delete(ctx, name); err != nil { return ExitError(ctx, ExitIO, err, "Can not delete '%s': %s", name, err) } return nil }
[ "func", "(", "s", "*", "Action", ")", "Delete", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "force", ":=", "c", ".", "Bool", "(", "\"", "\"", ")", "\n", "recursive", ":=", "c", ".", "Bool", "(", "\"", "\"", ")", "\n\n", "name", ":=", "c", ".", "Args", "(", ")", ".", "First", "(", ")", "\n", "if", "name", "==", "\"", "\"", "{", "return", "ExitError", "(", "ctx", ",", "ExitUsage", ",", "nil", ",", "\"", "\"", ",", "s", ".", "Name", ")", "\n", "}", "\n\n", "if", "!", "recursive", "&&", "s", ".", "Store", ".", "IsDir", "(", "ctx", ",", "name", ")", "{", "return", "ExitError", "(", "ctx", ",", "ExitUsage", ",", "nil", ",", "\"", "\"", ",", "name", ",", "name", ")", "\n", "}", "\n\n", "// specifying a key is optional", "key", ":=", "c", ".", "Args", "(", ")", ".", "Get", "(", "1", ")", "\n\n", "if", "!", "force", "{", "// don't check if it's force anyway", "recStr", ":=", "\"", "\"", "\n", "if", "recursive", "{", "recStr", "=", "\"", "\"", "\n", "}", "\n", "if", "(", "s", ".", "Store", ".", "Exists", "(", "ctx", ",", "name", ")", "||", "s", ".", "Store", ".", "IsDir", "(", "ctx", ",", "name", ")", ")", "&&", "key", "==", "\"", "\"", "&&", "!", "termio", ".", "AskForConfirmation", "(", "ctx", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "recStr", ",", "name", ")", ")", "{", "return", "nil", "\n", "}", "\n", "}", "\n\n", "if", "recursive", "{", "if", "err", ":=", "s", ".", "Store", ".", "Prune", "(", "ctx", ",", "name", ")", ";", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitUnknown", ",", "err", ",", "\"", "\"", ",", "name", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}", "\n\n", "// deletes a single key from a YAML doc", "if", "key", "!=", "\"", "\"", "{", "return", "s", ".", "deleteKeyFromYAML", "(", "ctx", ",", "name", ",", "key", ")", "\n", "}", "\n\n", "if", "err", ":=", "s", ".", "Store", ".", "Delete", "(", "ctx", ",", "name", ")", ";", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitIO", ",", "err", ",", "\"", "\"", ",", "name", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Delete a secret file with its content
[ "Delete", "a", "secret", "file", "with", "its", "content" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/delete.go#L14-L56
train
gopasspw/gopass
pkg/action/delete.go
deleteKeyFromYAML
func (s *Action) deleteKeyFromYAML(ctx context.Context, name, key string) error { sec, err := s.Store.Get(ctx, name) if err != nil { return ExitError(ctx, ExitIO, err, "Can not delete key '%s' from '%s': %s", key, name, err) } if err := sec.DeleteKey(key); err != nil { return ExitError(ctx, ExitIO, err, "Can not delete key '%s' from '%s': %s", key, name, err) } if err := s.Store.Set(sub.WithReason(ctx, "Updated Key in YAML"), name, sec); err != nil { return ExitError(ctx, ExitIO, err, "Can not delete key '%s' from '%s': %s", key, name, err) } return nil }
go
func (s *Action) deleteKeyFromYAML(ctx context.Context, name, key string) error { sec, err := s.Store.Get(ctx, name) if err != nil { return ExitError(ctx, ExitIO, err, "Can not delete key '%s' from '%s': %s", key, name, err) } if err := sec.DeleteKey(key); err != nil { return ExitError(ctx, ExitIO, err, "Can not delete key '%s' from '%s': %s", key, name, err) } if err := s.Store.Set(sub.WithReason(ctx, "Updated Key in YAML"), name, sec); err != nil { return ExitError(ctx, ExitIO, err, "Can not delete key '%s' from '%s': %s", key, name, err) } return nil }
[ "func", "(", "s", "*", "Action", ")", "deleteKeyFromYAML", "(", "ctx", "context", ".", "Context", ",", "name", ",", "key", "string", ")", "error", "{", "sec", ",", "err", ":=", "s", ".", "Store", ".", "Get", "(", "ctx", ",", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitIO", ",", "err", ",", "\"", "\"", ",", "key", ",", "name", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "sec", ".", "DeleteKey", "(", "key", ")", ";", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitIO", ",", "err", ",", "\"", "\"", ",", "key", ",", "name", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "s", ".", "Store", ".", "Set", "(", "sub", ".", "WithReason", "(", "ctx", ",", "\"", "\"", ")", ",", "name", ",", "sec", ")", ";", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitIO", ",", "err", ",", "\"", "\"", ",", "key", ",", "name", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// deleteKeyFromYAML deletes a single key from YAML
[ "deleteKeyFromYAML", "deletes", "a", "single", "key", "from", "YAML" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/delete.go#L59-L71
train
gopasspw/gopass
pkg/backend/rcs/git/gogit/git.go
Open
func Open(path string) (*Git, error) { r, err := git.PlainOpen(path) if err != nil { return nil, err } w, err := r.Worktree() if err != nil { return nil, err } return &Git{ path: path, repo: r, wt: w, }, nil }
go
func Open(path string) (*Git, error) { r, err := git.PlainOpen(path) if err != nil { return nil, err } w, err := r.Worktree() if err != nil { return nil, err } return &Git{ path: path, repo: r, wt: w, }, nil }
[ "func", "Open", "(", "path", "string", ")", "(", "*", "Git", ",", "error", ")", "{", "r", ",", "err", ":=", "git", ".", "PlainOpen", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "w", ",", "err", ":=", "r", ".", "Worktree", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "Git", "{", "path", ":", "path", ",", "repo", ":", "r", ",", "wt", ":", "w", ",", "}", ",", "nil", "\n", "}" ]
// Open tries to open an existing git repo on disk
[ "Open", "tries", "to", "open", "an", "existing", "git", "repo", "on", "disk" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/gogit/git.go#L38-L54
train
gopasspw/gopass
pkg/backend/rcs/git/gogit/git.go
Clone
func Clone(ctx context.Context, repo, path string) (*Git, error) { r, err := git.PlainCloneContext(ctx, path, false, &git.CloneOptions{ URL: repo, Progress: Stdout, }) if err != nil { return nil, err } w, err := r.Worktree() if err != nil { return nil, err } return &Git{ path: path, repo: r, wt: w, }, nil }
go
func Clone(ctx context.Context, repo, path string) (*Git, error) { r, err := git.PlainCloneContext(ctx, path, false, &git.CloneOptions{ URL: repo, Progress: Stdout, }) if err != nil { return nil, err } w, err := r.Worktree() if err != nil { return nil, err } return &Git{ path: path, repo: r, wt: w, }, nil }
[ "func", "Clone", "(", "ctx", "context", ".", "Context", ",", "repo", ",", "path", "string", ")", "(", "*", "Git", ",", "error", ")", "{", "r", ",", "err", ":=", "git", ".", "PlainCloneContext", "(", "ctx", ",", "path", ",", "false", ",", "&", "git", ".", "CloneOptions", "{", "URL", ":", "repo", ",", "Progress", ":", "Stdout", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "w", ",", "err", ":=", "r", ".", "Worktree", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "Git", "{", "path", ":", "path", ",", "repo", ":", "r", ",", "wt", ":", "w", ",", "}", ",", "nil", "\n", "}" ]
// Clone tries to clone an git repo from a remote
[ "Clone", "tries", "to", "clone", "an", "git", "repo", "from", "a", "remote" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/gogit/git.go#L57-L76
train
gopasspw/gopass
pkg/backend/rcs/git/gogit/git.go
Init
func Init(ctx context.Context, path string) (*Git, error) { g := &Git{ path: path, } if !g.IsInitialized() { r, err := git.PlainInit(path, false) if err != nil { return nil, errors.Wrapf(err, "Failed to initialize git: %s", err) } g.repo = r wt, err := g.repo.Worktree() if err != nil { return nil, errors.Wrapf(err, "Failed to get worktree: %s", err) } g.wt = wt } if !ctxutil.IsGitInit(ctx) { return g, nil } // add current content of the store if err := g.Add(ctx, g.path); err != nil { return g, errors.Wrapf(err, "failed to add '%s' to git", g.path) } // commit if there is something to commit if !g.HasStagedChanges(ctx) { out.Debug(ctx, "No staged changes") return g, nil } if err := g.Commit(ctx, "Add current content of password store"); err != nil { return nil, errors.Wrapf(err, "failed to commit changes to git") } return g, nil }
go
func Init(ctx context.Context, path string) (*Git, error) { g := &Git{ path: path, } if !g.IsInitialized() { r, err := git.PlainInit(path, false) if err != nil { return nil, errors.Wrapf(err, "Failed to initialize git: %s", err) } g.repo = r wt, err := g.repo.Worktree() if err != nil { return nil, errors.Wrapf(err, "Failed to get worktree: %s", err) } g.wt = wt } if !ctxutil.IsGitInit(ctx) { return g, nil } // add current content of the store if err := g.Add(ctx, g.path); err != nil { return g, errors.Wrapf(err, "failed to add '%s' to git", g.path) } // commit if there is something to commit if !g.HasStagedChanges(ctx) { out.Debug(ctx, "No staged changes") return g, nil } if err := g.Commit(ctx, "Add current content of password store"); err != nil { return nil, errors.Wrapf(err, "failed to commit changes to git") } return g, nil }
[ "func", "Init", "(", "ctx", "context", ".", "Context", ",", "path", "string", ")", "(", "*", "Git", ",", "error", ")", "{", "g", ":=", "&", "Git", "{", "path", ":", "path", ",", "}", "\n\n", "if", "!", "g", ".", "IsInitialized", "(", ")", "{", "r", ",", "err", ":=", "git", ".", "PlainInit", "(", "path", ",", "false", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "g", ".", "repo", "=", "r", "\n", "wt", ",", "err", ":=", "g", ".", "repo", ".", "Worktree", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "g", ".", "wt", "=", "wt", "\n", "}", "\n\n", "if", "!", "ctxutil", ".", "IsGitInit", "(", "ctx", ")", "{", "return", "g", ",", "nil", "\n", "}", "\n\n", "// add current content of the store", "if", "err", ":=", "g", ".", "Add", "(", "ctx", ",", "g", ".", "path", ")", ";", "err", "!=", "nil", "{", "return", "g", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "g", ".", "path", ")", "\n", "}", "\n\n", "// commit if there is something to commit", "if", "!", "g", ".", "HasStagedChanges", "(", "ctx", ")", "{", "out", ".", "Debug", "(", "ctx", ",", "\"", "\"", ")", "\n", "return", "g", ",", "nil", "\n", "}", "\n\n", "if", "err", ":=", "g", ".", "Commit", "(", "ctx", ",", "\"", "\"", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "return", "g", ",", "nil", "\n", "}" ]
// Init creates a new git repo on disk
[ "Init", "creates", "a", "new", "git", "repo", "on", "disk" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/gogit/git.go#L79-L117
train
gopasspw/gopass
pkg/backend/rcs/git/gogit/git.go
IsInitialized
func (g *Git) IsInitialized() bool { _, err := git.PlainOpen(g.path) return err == nil }
go
func (g *Git) IsInitialized() bool { _, err := git.PlainOpen(g.path) return err == nil }
[ "func", "(", "g", "*", "Git", ")", "IsInitialized", "(", ")", "bool", "{", "_", ",", "err", ":=", "git", ".", "PlainOpen", "(", "g", ".", "path", ")", "\n", "return", "err", "==", "nil", "\n", "}" ]
// IsInitialized returns true if this is a valid repo
[ "IsInitialized", "returns", "true", "if", "this", "is", "a", "valid", "repo" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/gogit/git.go#L128-L131
train
gopasspw/gopass
pkg/backend/rcs/git/gogit/git.go
Add
func (g *Git) Add(ctx context.Context, files ...string) error { if len(files) < 1 || (len(files) == 1 && files[0] == g.path) { return g.addAll() } for _, file := range files { if strings.HasPrefix(file, g.path) { file = strings.TrimPrefix(file, g.path+string(filepath.Separator)) } _, err := g.wt.Add(file) if err != nil { return errors.Wrapf(err, "failed to add file '%s': %s", file, err) } } return nil }
go
func (g *Git) Add(ctx context.Context, files ...string) error { if len(files) < 1 || (len(files) == 1 && files[0] == g.path) { return g.addAll() } for _, file := range files { if strings.HasPrefix(file, g.path) { file = strings.TrimPrefix(file, g.path+string(filepath.Separator)) } _, err := g.wt.Add(file) if err != nil { return errors.Wrapf(err, "failed to add file '%s': %s", file, err) } } return nil }
[ "func", "(", "g", "*", "Git", ")", "Add", "(", "ctx", "context", ".", "Context", ",", "files", "...", "string", ")", "error", "{", "if", "len", "(", "files", ")", "<", "1", "||", "(", "len", "(", "files", ")", "==", "1", "&&", "files", "[", "0", "]", "==", "g", ".", "path", ")", "{", "return", "g", ".", "addAll", "(", ")", "\n", "}", "\n", "for", "_", ",", "file", ":=", "range", "files", "{", "if", "strings", ".", "HasPrefix", "(", "file", ",", "g", ".", "path", ")", "{", "file", "=", "strings", ".", "TrimPrefix", "(", "file", ",", "g", ".", "path", "+", "string", "(", "filepath", ".", "Separator", ")", ")", "\n", "}", "\n", "_", ",", "err", ":=", "g", ".", "wt", ".", "Add", "(", "file", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "file", ",", "err", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Add adds any number of files to git
[ "Add", "adds", "any", "number", "of", "files", "to", "git" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/gogit/git.go#L134-L148
train
gopasspw/gopass
pkg/backend/rcs/git/gogit/git.go
HasStagedChanges
func (g *Git) HasStagedChanges(ctx context.Context) bool { st, err := g.wt.Status() if err != nil { out.Error(ctx, "Error: Unable to get status: %s", err) return false } return !st.IsClean() }
go
func (g *Git) HasStagedChanges(ctx context.Context) bool { st, err := g.wt.Status() if err != nil { out.Error(ctx, "Error: Unable to get status: %s", err) return false } return !st.IsClean() }
[ "func", "(", "g", "*", "Git", ")", "HasStagedChanges", "(", "ctx", "context", ".", "Context", ")", "bool", "{", "st", ",", "err", ":=", "g", ".", "wt", ".", "Status", "(", ")", "\n", "if", "err", "!=", "nil", "{", "out", ".", "Error", "(", "ctx", ",", "\"", "\"", ",", "err", ")", "\n", "return", "false", "\n", "}", "\n", "return", "!", "st", ".", "IsClean", "(", ")", "\n", "}" ]
// HasStagedChanges retures true if there are changes which can be committed
[ "HasStagedChanges", "retures", "true", "if", "there", "are", "changes", "which", "can", "be", "committed" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/gogit/git.go#L182-L189
train
gopasspw/gopass
pkg/backend/rcs/git/gogit/git.go
Commit
func (g *Git) Commit(ctx context.Context, msg string) error { if !g.HasStagedChanges(ctx) { return store.ErrGitNothingToCommit } _, err := g.wt.Commit(msg, &git.CommitOptions{ All: true, Author: &object.Signature{ Name: os.Getenv("GIT_AUTHOR_NAME"), Email: os.Getenv("GIT_AUTHOR_EMAIL"), When: time.Now(), }, }) return err }
go
func (g *Git) Commit(ctx context.Context, msg string) error { if !g.HasStagedChanges(ctx) { return store.ErrGitNothingToCommit } _, err := g.wt.Commit(msg, &git.CommitOptions{ All: true, Author: &object.Signature{ Name: os.Getenv("GIT_AUTHOR_NAME"), Email: os.Getenv("GIT_AUTHOR_EMAIL"), When: time.Now(), }, }) return err }
[ "func", "(", "g", "*", "Git", ")", "Commit", "(", "ctx", "context", ".", "Context", ",", "msg", "string", ")", "error", "{", "if", "!", "g", ".", "HasStagedChanges", "(", "ctx", ")", "{", "return", "store", ".", "ErrGitNothingToCommit", "\n", "}", "\n\n", "_", ",", "err", ":=", "g", ".", "wt", ".", "Commit", "(", "msg", ",", "&", "git", ".", "CommitOptions", "{", "All", ":", "true", ",", "Author", ":", "&", "object", ".", "Signature", "{", "Name", ":", "os", ".", "Getenv", "(", "\"", "\"", ")", ",", "Email", ":", "os", ".", "Getenv", "(", "\"", "\"", ")", ",", "When", ":", "time", ".", "Now", "(", ")", ",", "}", ",", "}", ")", "\n", "return", "err", "\n", "}" ]
// Commit creates a new commit
[ "Commit", "creates", "a", "new", "commit" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/gogit/git.go#L192-L206
train
gopasspw/gopass
pkg/backend/rcs/git/gogit/git.go
PushPull
func (g *Git) PushPull(ctx context.Context, op, remote, branch string) error { if err := g.Pull(ctx, remote, branch); err != nil { if op == "pull" { return err } out.Yellow(ctx, "Failed to pull before git push: %s", err) } if op == "pull" { return nil } return g.Push(ctx, remote, branch) }
go
func (g *Git) PushPull(ctx context.Context, op, remote, branch string) error { if err := g.Pull(ctx, remote, branch); err != nil { if op == "pull" { return err } out.Yellow(ctx, "Failed to pull before git push: %s", err) } if op == "pull" { return nil } return g.Push(ctx, remote, branch) }
[ "func", "(", "g", "*", "Git", ")", "PushPull", "(", "ctx", "context", ".", "Context", ",", "op", ",", "remote", ",", "branch", "string", ")", "error", "{", "if", "err", ":=", "g", ".", "Pull", "(", "ctx", ",", "remote", ",", "branch", ")", ";", "err", "!=", "nil", "{", "if", "op", "==", "\"", "\"", "{", "return", "err", "\n", "}", "\n", "out", ".", "Yellow", "(", "ctx", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "if", "op", "==", "\"", "\"", "{", "return", "nil", "\n", "}", "\n", "return", "g", ".", "Push", "(", "ctx", ",", "remote", ",", "branch", ")", "\n", "}" ]
// PushPull will first pull from the remote and then push any changes
[ "PushPull", "will", "first", "pull", "from", "the", "remote", "and", "then", "push", "any", "changes" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/gogit/git.go#L209-L221
train
gopasspw/gopass
pkg/backend/rcs/git/gogit/git.go
Pull
func (g *Git) Pull(ctx context.Context, remote, branch string) error { if !g.IsInitialized() { return store.ErrGitNotInit } if remote == "" { remote = "origin" } if branch == "" { branch = "master" } cfg, err := g.repo.Config() if err != nil { return errors.Wrapf(err, "Failed to get git config: %s", err) } if _, found := cfg.Remotes[remote]; !found { return store.ErrGitNoRemote } return g.wt.PullContext(ctx, &git.PullOptions{ RemoteName: remote, ReferenceName: plumbing.ReferenceName(branch), Progress: Stdout, }) }
go
func (g *Git) Pull(ctx context.Context, remote, branch string) error { if !g.IsInitialized() { return store.ErrGitNotInit } if remote == "" { remote = "origin" } if branch == "" { branch = "master" } cfg, err := g.repo.Config() if err != nil { return errors.Wrapf(err, "Failed to get git config: %s", err) } if _, found := cfg.Remotes[remote]; !found { return store.ErrGitNoRemote } return g.wt.PullContext(ctx, &git.PullOptions{ RemoteName: remote, ReferenceName: plumbing.ReferenceName(branch), Progress: Stdout, }) }
[ "func", "(", "g", "*", "Git", ")", "Pull", "(", "ctx", "context", ".", "Context", ",", "remote", ",", "branch", "string", ")", "error", "{", "if", "!", "g", ".", "IsInitialized", "(", ")", "{", "return", "store", ".", "ErrGitNotInit", "\n", "}", "\n\n", "if", "remote", "==", "\"", "\"", "{", "remote", "=", "\"", "\"", "\n", "}", "\n", "if", "branch", "==", "\"", "\"", "{", "branch", "=", "\"", "\"", "\n", "}", "\n\n", "cfg", ",", "err", ":=", "g", ".", "repo", ".", "Config", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "if", "_", ",", "found", ":=", "cfg", ".", "Remotes", "[", "remote", "]", ";", "!", "found", "{", "return", "store", ".", "ErrGitNoRemote", "\n", "}", "\n\n", "return", "g", ".", "wt", ".", "PullContext", "(", "ctx", ",", "&", "git", ".", "PullOptions", "{", "RemoteName", ":", "remote", ",", "ReferenceName", ":", "plumbing", ".", "ReferenceName", "(", "branch", ")", ",", "Progress", ":", "Stdout", ",", "}", ")", "\n", "}" ]
// Pull will pull any changes
[ "Pull", "will", "pull", "any", "changes" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/gogit/git.go#L224-L249
train
gopasspw/gopass
pkg/backend/rcs/git/gogit/git.go
Push
func (g *Git) Push(ctx context.Context, remote, branch string) error { if !g.IsInitialized() { return store.ErrGitNotInit } if remote == "" { remote = "origin" } cfg, err := g.repo.Config() if err != nil { return errors.Wrapf(err, "Failed to get git config: %s", err) } if _, found := cfg.Remotes[remote]; !found { return store.ErrGitNoRemote } return g.repo.PushContext(ctx, &git.PushOptions{ RemoteName: remote, Progress: Stdout, }) }
go
func (g *Git) Push(ctx context.Context, remote, branch string) error { if !g.IsInitialized() { return store.ErrGitNotInit } if remote == "" { remote = "origin" } cfg, err := g.repo.Config() if err != nil { return errors.Wrapf(err, "Failed to get git config: %s", err) } if _, found := cfg.Remotes[remote]; !found { return store.ErrGitNoRemote } return g.repo.PushContext(ctx, &git.PushOptions{ RemoteName: remote, Progress: Stdout, }) }
[ "func", "(", "g", "*", "Git", ")", "Push", "(", "ctx", "context", ".", "Context", ",", "remote", ",", "branch", "string", ")", "error", "{", "if", "!", "g", ".", "IsInitialized", "(", ")", "{", "return", "store", ".", "ErrGitNotInit", "\n", "}", "\n\n", "if", "remote", "==", "\"", "\"", "{", "remote", "=", "\"", "\"", "\n", "}", "\n\n", "cfg", ",", "err", ":=", "g", ".", "repo", ".", "Config", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "if", "_", ",", "found", ":=", "cfg", ".", "Remotes", "[", "remote", "]", ";", "!", "found", "{", "return", "store", ".", "ErrGitNoRemote", "\n", "}", "\n", "return", "g", ".", "repo", ".", "PushContext", "(", "ctx", ",", "&", "git", ".", "PushOptions", "{", "RemoteName", ":", "remote", ",", "Progress", ":", "Stdout", ",", "}", ")", "\n", "}" ]
// Push will push any changes to the remote
[ "Push", "will", "push", "any", "changes", "to", "the", "remote" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/gogit/git.go#L252-L272
train
gopasspw/gopass
pkg/backend/rcs/git/gogit/git.go
Cmd
func (g *Git) Cmd(context.Context, string, ...string) error { return fmt.Errorf("not supported") }
go
func (g *Git) Cmd(context.Context, string, ...string) error { return fmt.Errorf("not supported") }
[ "func", "(", "g", "*", "Git", ")", "Cmd", "(", "context", ".", "Context", ",", "string", ",", "...", "string", ")", "error", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}" ]
// Cmd is not supported and will go away eventually
[ "Cmd", "is", "not", "supported", "and", "will", "go", "away", "eventually" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/gogit/git.go#L275-L277
train
gopasspw/gopass
pkg/store/root/gpg.go
Crypto
func (r *Store) Crypto(ctx context.Context, name string) backend.Crypto { _, sub, _ := r.getStore(ctx, name) if !sub.Valid() { out.Debug(ctx, "Sub-Store not found for %s. Returning nil crypto backend", name) return nil } return sub.Crypto() }
go
func (r *Store) Crypto(ctx context.Context, name string) backend.Crypto { _, sub, _ := r.getStore(ctx, name) if !sub.Valid() { out.Debug(ctx, "Sub-Store not found for %s. Returning nil crypto backend", name) return nil } return sub.Crypto() }
[ "func", "(", "r", "*", "Store", ")", "Crypto", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "backend", ".", "Crypto", "{", "_", ",", "sub", ",", "_", ":=", "r", ".", "getStore", "(", "ctx", ",", "name", ")", "\n", "if", "!", "sub", ".", "Valid", "(", ")", "{", "out", ".", "Debug", "(", "ctx", ",", "\"", "\"", ",", "name", ")", "\n", "return", "nil", "\n", "}", "\n", "return", "sub", ".", "Crypto", "(", ")", "\n", "}" ]
// Crypto returns the crypto backend
[ "Crypto", "returns", "the", "crypto", "backend" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/gpg.go#L11-L18
train
gopasspw/gopass
pkg/action/audit.go
Audit
func (s *Action) Audit(ctx context.Context, c *cli.Context) error { filter := c.Args().First() ctx = s.Store.WithConfig(ctx, filter) out.Print(ctx, "Auditing passwords for common flaws ...") t, err := s.Store.Tree(ctx) if err != nil { return ExitError(ctx, ExitList, err, "failed to get store tree: %s", err) } if filter != "" { subtree, err := t.FindFolder(filter) if err != nil { return ExitError(ctx, ExitUnknown, err, "failed to find subtree: %s", err) } t = subtree } list := t.List(0) if len(list) < 1 { out.Yellow(ctx, "No secrets found") return nil } return audit.Batch(ctx, list, s.Store) }
go
func (s *Action) Audit(ctx context.Context, c *cli.Context) error { filter := c.Args().First() ctx = s.Store.WithConfig(ctx, filter) out.Print(ctx, "Auditing passwords for common flaws ...") t, err := s.Store.Tree(ctx) if err != nil { return ExitError(ctx, ExitList, err, "failed to get store tree: %s", err) } if filter != "" { subtree, err := t.FindFolder(filter) if err != nil { return ExitError(ctx, ExitUnknown, err, "failed to find subtree: %s", err) } t = subtree } list := t.List(0) if len(list) < 1 { out.Yellow(ctx, "No secrets found") return nil } return audit.Batch(ctx, list, s.Store) }
[ "func", "(", "s", "*", "Action", ")", "Audit", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "filter", ":=", "c", ".", "Args", "(", ")", ".", "First", "(", ")", "\n", "ctx", "=", "s", ".", "Store", ".", "WithConfig", "(", "ctx", ",", "filter", ")", "\n\n", "out", ".", "Print", "(", "ctx", ",", "\"", "\"", ")", "\n\n", "t", ",", "err", ":=", "s", ".", "Store", ".", "Tree", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitList", ",", "err", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "if", "filter", "!=", "\"", "\"", "{", "subtree", ",", "err", ":=", "t", ".", "FindFolder", "(", "filter", ")", "\n", "if", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitUnknown", ",", "err", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "t", "=", "subtree", "\n", "}", "\n", "list", ":=", "t", ".", "List", "(", "0", ")", "\n\n", "if", "len", "(", "list", ")", "<", "1", "{", "out", ".", "Yellow", "(", "ctx", ",", "\"", "\"", ")", "\n", "return", "nil", "\n", "}", "\n\n", "return", "audit", ".", "Batch", "(", "ctx", ",", "list", ",", "s", ".", "Store", ")", "\n", "}" ]
// Audit validates passwords against common flaws
[ "Audit", "validates", "passwords", "against", "common", "flaws" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/audit.go#L13-L38
train
gopasspw/gopass
pkg/backend/crypto/gpg/cli/gpg.go
New
func New(ctx context.Context, cfg Config) (*GPG, error) { // ensure created files don't have group or world perms set // this setting should be inherited by sub-processes umask(cfg.Umask) // make sure GPG_TTY is set (if possible) if gt := os.Getenv("GPG_TTY"); gt == "" { if t := tty(); t != "" { _ = os.Setenv("GPG_TTY", t) } } g := &GPG{ binary: "gpg", args: append(defaultArgs, cfg.Args...), } cache, err := lru.New2Q(1024) if err != nil { return nil, err } g.listCache = cache bin, err := Binary(ctx, cfg.Binary) if err != nil { return nil, err } g.binary = bin return g, nil }
go
func New(ctx context.Context, cfg Config) (*GPG, error) { // ensure created files don't have group or world perms set // this setting should be inherited by sub-processes umask(cfg.Umask) // make sure GPG_TTY is set (if possible) if gt := os.Getenv("GPG_TTY"); gt == "" { if t := tty(); t != "" { _ = os.Setenv("GPG_TTY", t) } } g := &GPG{ binary: "gpg", args: append(defaultArgs, cfg.Args...), } cache, err := lru.New2Q(1024) if err != nil { return nil, err } g.listCache = cache bin, err := Binary(ctx, cfg.Binary) if err != nil { return nil, err } g.binary = bin return g, nil }
[ "func", "New", "(", "ctx", "context", ".", "Context", ",", "cfg", "Config", ")", "(", "*", "GPG", ",", "error", ")", "{", "// ensure created files don't have group or world perms set", "// this setting should be inherited by sub-processes", "umask", "(", "cfg", ".", "Umask", ")", "\n\n", "// make sure GPG_TTY is set (if possible)", "if", "gt", ":=", "os", ".", "Getenv", "(", "\"", "\"", ")", ";", "gt", "==", "\"", "\"", "{", "if", "t", ":=", "tty", "(", ")", ";", "t", "!=", "\"", "\"", "{", "_", "=", "os", ".", "Setenv", "(", "\"", "\"", ",", "t", ")", "\n", "}", "\n", "}", "\n\n", "g", ":=", "&", "GPG", "{", "binary", ":", "\"", "\"", ",", "args", ":", "append", "(", "defaultArgs", ",", "cfg", ".", "Args", "...", ")", ",", "}", "\n\n", "cache", ",", "err", ":=", "lru", ".", "New2Q", "(", "1024", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "g", ".", "listCache", "=", "cache", "\n\n", "bin", ",", "err", ":=", "Binary", "(", "ctx", ",", "cfg", ".", "Binary", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "g", ".", "binary", "=", "bin", "\n\n", "return", "g", ",", "nil", "\n", "}" ]
// New creates a new GPG wrapper
[ "New", "creates", "a", "new", "GPG", "wrapper" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/cli/gpg.go#L43-L73
train
gopasspw/gopass
pkg/backend/crypto/gpg/cli/gpg.go
RecipientIDs
func (g *GPG) RecipientIDs(ctx context.Context, buf []byte) ([]string, error) { _ = os.Setenv("LANGUAGE", "C") recp := make([]string, 0, 5) args := []string{"--batch", "--list-only", "--list-packets", "--no-default-keyring", "--secret-keyring", "/dev/null"} cmd := exec.CommandContext(ctx, g.binary, args...) cmd.Stdin = bytes.NewReader(buf) out.Debug(ctx, "gpg.GetRecipients: %s %+v", cmd.Path, cmd.Args) cmdout, err := cmd.CombinedOutput() if err != nil { return []string{}, err } scanner := bufio.NewScanner(bytes.NewBuffer(cmdout)) for scanner.Scan() { line := strings.TrimSpace(scanner.Text()) out.Debug(ctx, "gpg Output: %s", line) if !strings.HasPrefix(line, ":pubkey enc packet:") { continue } m := splitPacket(line) if keyid, found := m["keyid"]; found { kl, err := g.listKeys(ctx, "public", keyid) if err != nil || len(kl) < 1 { continue } recp = append(recp, kl[0].Fingerprint) } } return recp, nil }
go
func (g *GPG) RecipientIDs(ctx context.Context, buf []byte) ([]string, error) { _ = os.Setenv("LANGUAGE", "C") recp := make([]string, 0, 5) args := []string{"--batch", "--list-only", "--list-packets", "--no-default-keyring", "--secret-keyring", "/dev/null"} cmd := exec.CommandContext(ctx, g.binary, args...) cmd.Stdin = bytes.NewReader(buf) out.Debug(ctx, "gpg.GetRecipients: %s %+v", cmd.Path, cmd.Args) cmdout, err := cmd.CombinedOutput() if err != nil { return []string{}, err } scanner := bufio.NewScanner(bytes.NewBuffer(cmdout)) for scanner.Scan() { line := strings.TrimSpace(scanner.Text()) out.Debug(ctx, "gpg Output: %s", line) if !strings.HasPrefix(line, ":pubkey enc packet:") { continue } m := splitPacket(line) if keyid, found := m["keyid"]; found { kl, err := g.listKeys(ctx, "public", keyid) if err != nil || len(kl) < 1 { continue } recp = append(recp, kl[0].Fingerprint) } } return recp, nil }
[ "func", "(", "g", "*", "GPG", ")", "RecipientIDs", "(", "ctx", "context", ".", "Context", ",", "buf", "[", "]", "byte", ")", "(", "[", "]", "string", ",", "error", ")", "{", "_", "=", "os", ".", "Setenv", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "recp", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "5", ")", "\n\n", "args", ":=", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", "}", "\n", "cmd", ":=", "exec", ".", "CommandContext", "(", "ctx", ",", "g", ".", "binary", ",", "args", "...", ")", "\n", "cmd", ".", "Stdin", "=", "bytes", ".", "NewReader", "(", "buf", ")", "\n", "out", ".", "Debug", "(", "ctx", ",", "\"", "\"", ",", "cmd", ".", "Path", ",", "cmd", ".", "Args", ")", "\n\n", "cmdout", ",", "err", ":=", "cmd", ".", "CombinedOutput", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "]", "string", "{", "}", ",", "err", "\n", "}", "\n\n", "scanner", ":=", "bufio", ".", "NewScanner", "(", "bytes", ".", "NewBuffer", "(", "cmdout", ")", ")", "\n", "for", "scanner", ".", "Scan", "(", ")", "{", "line", ":=", "strings", ".", "TrimSpace", "(", "scanner", ".", "Text", "(", ")", ")", "\n", "out", ".", "Debug", "(", "ctx", ",", "\"", "\"", ",", "line", ")", "\n", "if", "!", "strings", ".", "HasPrefix", "(", "line", ",", "\"", "\"", ")", "{", "continue", "\n", "}", "\n", "m", ":=", "splitPacket", "(", "line", ")", "\n", "if", "keyid", ",", "found", ":=", "m", "[", "\"", "\"", "]", ";", "found", "{", "kl", ",", "err", ":=", "g", ".", "listKeys", "(", "ctx", ",", "\"", "\"", ",", "keyid", ")", "\n", "if", "err", "!=", "nil", "||", "len", "(", "kl", ")", "<", "1", "{", "continue", "\n", "}", "\n", "recp", "=", "append", "(", "recp", ",", "kl", "[", "0", "]", ".", "Fingerprint", ")", "\n", "}", "\n", "}", "\n\n", "return", "recp", ",", "nil", "\n", "}" ]
// RecipientIDs returns a list of recipient IDs for a given file
[ "RecipientIDs", "returns", "a", "list", "of", "recipient", "IDs", "for", "a", "given", "file" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/cli/gpg.go#L76-L108
train
gopasspw/gopass
pkg/backend/crypto/gpg/cli/gpg.go
Decrypt
func (g *GPG) Decrypt(ctx context.Context, ciphertext []byte) ([]byte, error) { args := append(g.args, "--decrypt") cmd := exec.CommandContext(ctx, g.binary, args...) cmd.Stdin = bytes.NewReader(ciphertext) cmd.Stderr = os.Stderr out.Debug(ctx, "gpg.Decrypt: %s %+v", cmd.Path, cmd.Args) return cmd.Output() }
go
func (g *GPG) Decrypt(ctx context.Context, ciphertext []byte) ([]byte, error) { args := append(g.args, "--decrypt") cmd := exec.CommandContext(ctx, g.binary, args...) cmd.Stdin = bytes.NewReader(ciphertext) cmd.Stderr = os.Stderr out.Debug(ctx, "gpg.Decrypt: %s %+v", cmd.Path, cmd.Args) return cmd.Output() }
[ "func", "(", "g", "*", "GPG", ")", "Decrypt", "(", "ctx", "context", ".", "Context", ",", "ciphertext", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "args", ":=", "append", "(", "g", ".", "args", ",", "\"", "\"", ")", "\n", "cmd", ":=", "exec", ".", "CommandContext", "(", "ctx", ",", "g", ".", "binary", ",", "args", "...", ")", "\n", "cmd", ".", "Stdin", "=", "bytes", ".", "NewReader", "(", "ciphertext", ")", "\n", "cmd", ".", "Stderr", "=", "os", ".", "Stderr", "\n\n", "out", ".", "Debug", "(", "ctx", ",", "\"", "\"", ",", "cmd", ".", "Path", ",", "cmd", ".", "Args", ")", "\n", "return", "cmd", ".", "Output", "(", ")", "\n", "}" ]
// Decrypt will try to decrypt the given file
[ "Decrypt", "will", "try", "to", "decrypt", "the", "given", "file" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/cli/gpg.go#L137-L145
train
gopasspw/gopass
pkg/otp/otp.go
Calculate
func Calculate(ctx context.Context, name string, sec store.Secret) (twofactor.OTP, string, error) { otpURL := "" // check body for _, line := range strings.Split(sec.Body(), "\n") { if strings.HasPrefix(line, "otpauth://") { otpURL = line break } } if otpURL != "" { return twofactor.FromURL(otpURL) } // check yaml entry and fall back to password if we don't have one label := name secKey, err := sec.Value("totp") if err != nil { secKey = sec.Password() } if strings.HasPrefix(secKey, "otpauth://") { return twofactor.FromURL(secKey) } otp, err := twofactor.NewGoogleTOTP(secKey) return otp, label, err }
go
func Calculate(ctx context.Context, name string, sec store.Secret) (twofactor.OTP, string, error) { otpURL := "" // check body for _, line := range strings.Split(sec.Body(), "\n") { if strings.HasPrefix(line, "otpauth://") { otpURL = line break } } if otpURL != "" { return twofactor.FromURL(otpURL) } // check yaml entry and fall back to password if we don't have one label := name secKey, err := sec.Value("totp") if err != nil { secKey = sec.Password() } if strings.HasPrefix(secKey, "otpauth://") { return twofactor.FromURL(secKey) } otp, err := twofactor.NewGoogleTOTP(secKey) return otp, label, err }
[ "func", "Calculate", "(", "ctx", "context", ".", "Context", ",", "name", "string", ",", "sec", "store", ".", "Secret", ")", "(", "twofactor", ".", "OTP", ",", "string", ",", "error", ")", "{", "otpURL", ":=", "\"", "\"", "\n", "// check body", "for", "_", ",", "line", ":=", "range", "strings", ".", "Split", "(", "sec", ".", "Body", "(", ")", ",", "\"", "\\n", "\"", ")", "{", "if", "strings", ".", "HasPrefix", "(", "line", ",", "\"", "\"", ")", "{", "otpURL", "=", "line", "\n", "break", "\n", "}", "\n", "}", "\n", "if", "otpURL", "!=", "\"", "\"", "{", "return", "twofactor", ".", "FromURL", "(", "otpURL", ")", "\n", "}", "\n\n", "// check yaml entry and fall back to password if we don't have one", "label", ":=", "name", "\n\n", "secKey", ",", "err", ":=", "sec", ".", "Value", "(", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "secKey", "=", "sec", ".", "Password", "(", ")", "\n", "}", "\n\n", "if", "strings", ".", "HasPrefix", "(", "secKey", ",", "\"", "\"", ")", "{", "return", "twofactor", ".", "FromURL", "(", "secKey", ")", "\n", "}", "\n\n", "otp", ",", "err", ":=", "twofactor", ".", "NewGoogleTOTP", "(", "secKey", ")", "\n", "return", "otp", ",", "label", ",", "err", "\n", "}" ]
// Calculate will compute a OTP code from a given secret
[ "Calculate", "will", "compute", "a", "OTP", "code", "from", "a", "given", "secret" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/otp/otp.go#L15-L42
train
gopasspw/gopass
pkg/otp/otp.go
WriteQRFile
func WriteQRFile(ctx context.Context, otp twofactor.OTP, label, file string) error { var qr []byte var err error switch otp.Type() { case twofactor.OATH_HOTP: hotp := otp.(*twofactor.HOTP) qr, err = hotp.QR(label) case twofactor.OATH_TOTP: totp := otp.(*twofactor.TOTP) qr, err = totp.QR(label) default: err = errors.New("QR codes can only be generated for OATH OTPs") } if err != nil { return errors.Wrapf(err, "%s", err) } if err := ioutil.WriteFile(file, qr, 0600); err != nil { return errors.Wrapf(err, "failed to write QR code: %s", err) } return nil }
go
func WriteQRFile(ctx context.Context, otp twofactor.OTP, label, file string) error { var qr []byte var err error switch otp.Type() { case twofactor.OATH_HOTP: hotp := otp.(*twofactor.HOTP) qr, err = hotp.QR(label) case twofactor.OATH_TOTP: totp := otp.(*twofactor.TOTP) qr, err = totp.QR(label) default: err = errors.New("QR codes can only be generated for OATH OTPs") } if err != nil { return errors.Wrapf(err, "%s", err) } if err := ioutil.WriteFile(file, qr, 0600); err != nil { return errors.Wrapf(err, "failed to write QR code: %s", err) } return nil }
[ "func", "WriteQRFile", "(", "ctx", "context", ".", "Context", ",", "otp", "twofactor", ".", "OTP", ",", "label", ",", "file", "string", ")", "error", "{", "var", "qr", "[", "]", "byte", "\n", "var", "err", "error", "\n", "switch", "otp", ".", "Type", "(", ")", "{", "case", "twofactor", ".", "OATH_HOTP", ":", "hotp", ":=", "otp", ".", "(", "*", "twofactor", ".", "HOTP", ")", "\n", "qr", ",", "err", "=", "hotp", ".", "QR", "(", "label", ")", "\n", "case", "twofactor", ".", "OATH_TOTP", ":", "totp", ":=", "otp", ".", "(", "*", "twofactor", ".", "TOTP", ")", "\n", "qr", ",", "err", "=", "totp", ".", "QR", "(", "label", ")", "\n", "default", ":", "err", "=", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "if", "err", ":=", "ioutil", ".", "WriteFile", "(", "file", ",", "qr", ",", "0600", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// WriteQRFile writes the given OTP code as a QR image to disk
[ "WriteQRFile", "writes", "the", "given", "OTP", "code", "as", "a", "QR", "image", "to", "disk" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/otp/otp.go#L45-L66
train
gopasspw/gopass
pkg/store/root/recipients.go
ListRecipients
func (r *Store) ListRecipients(ctx context.Context, store string) []string { ctx, sub, _ := r.getStore(ctx, store) return sub.Recipients(ctx) }
go
func (r *Store) ListRecipients(ctx context.Context, store string) []string { ctx, sub, _ := r.getStore(ctx, store) return sub.Recipients(ctx) }
[ "func", "(", "r", "*", "Store", ")", "ListRecipients", "(", "ctx", "context", ".", "Context", ",", "store", "string", ")", "[", "]", "string", "{", "ctx", ",", "sub", ",", "_", ":=", "r", ".", "getStore", "(", "ctx", ",", "store", ")", "\n", "return", "sub", ".", "Recipients", "(", "ctx", ")", "\n", "}" ]
// ListRecipients lists all recipients for the given store
[ "ListRecipients", "lists", "all", "recipients", "for", "the", "given", "store" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/recipients.go#L18-L21
train
gopasspw/gopass
pkg/store/root/recipients.go
RemoveRecipient
func (r *Store) RemoveRecipient(ctx context.Context, store, rec string) error { ctx, sub, _ := r.getStore(ctx, store) return sub.RemoveRecipient(ctx, rec) }
go
func (r *Store) RemoveRecipient(ctx context.Context, store, rec string) error { ctx, sub, _ := r.getStore(ctx, store) return sub.RemoveRecipient(ctx, rec) }
[ "func", "(", "r", "*", "Store", ")", "RemoveRecipient", "(", "ctx", "context", ".", "Context", ",", "store", ",", "rec", "string", ")", "error", "{", "ctx", ",", "sub", ",", "_", ":=", "r", ".", "getStore", "(", "ctx", ",", "store", ")", "\n", "return", "sub", ".", "RemoveRecipient", "(", "ctx", ",", "rec", ")", "\n", "}" ]
// RemoveRecipient removes a single recipient from the given store
[ "RemoveRecipient", "removes", "a", "single", "recipient", "from", "the", "given", "store" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/recipients.go#L30-L33
train
gopasspw/gopass
pkg/store/root/recipients.go
ImportMissingPublicKeys
func (r *Store) ImportMissingPublicKeys(ctx context.Context) error { for alias, sub := range r.mounts { ctx := r.cfg.Mounts[alias].WithContext(ctx) if err := sub.ImportMissingPublicKeys(ctx); err != nil { out.Error(ctx, "[%s] Failed to import missing public keys: %s", alias, err) } } return r.store.ImportMissingPublicKeys(ctx) }
go
func (r *Store) ImportMissingPublicKeys(ctx context.Context) error { for alias, sub := range r.mounts { ctx := r.cfg.Mounts[alias].WithContext(ctx) if err := sub.ImportMissingPublicKeys(ctx); err != nil { out.Error(ctx, "[%s] Failed to import missing public keys: %s", alias, err) } } return r.store.ImportMissingPublicKeys(ctx) }
[ "func", "(", "r", "*", "Store", ")", "ImportMissingPublicKeys", "(", "ctx", "context", ".", "Context", ")", "error", "{", "for", "alias", ",", "sub", ":=", "range", "r", ".", "mounts", "{", "ctx", ":=", "r", ".", "cfg", ".", "Mounts", "[", "alias", "]", ".", "WithContext", "(", "ctx", ")", "\n", "if", "err", ":=", "sub", ".", "ImportMissingPublicKeys", "(", "ctx", ")", ";", "err", "!=", "nil", "{", "out", ".", "Error", "(", "ctx", ",", "\"", "\"", ",", "alias", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "return", "r", ".", "store", ".", "ImportMissingPublicKeys", "(", "ctx", ")", "\n", "}" ]
// ImportMissingPublicKeys import missing public keys in any substore
[ "ImportMissingPublicKeys", "import", "missing", "public", "keys", "in", "any", "substore" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/recipients.go#L53-L62
train
gopasspw/gopass
pkg/store/root/recipients.go
RecipientsTree
func (r *Store) RecipientsTree(ctx context.Context, pretty bool) (tree.Tree, error) { root := simple.New("gopass") for _, recp := range r.store.Recipients(ctx) { if err := r.addRecipient(ctx, "", root, recp, pretty); err != nil { color.Yellow("Failed to add recipient to tree %s: %s", recp, err) } } mps := r.MountPoints() sort.Sort(store.ByPathLen(mps)) for _, alias := range mps { substore := r.mounts[alias] if substore == nil { continue } if err := root.AddMount(alias, substore.Path()); err != nil { return nil, errors.Errorf("failed to add mount: %s", err) } for _, recp := range substore.Recipients(ctx) { if err := r.addRecipient(ctx, alias+"/", root, recp, pretty); err != nil { out.Debug(ctx, "Failed to add recipient to tree %s: %s", recp, err) } } } return root, nil }
go
func (r *Store) RecipientsTree(ctx context.Context, pretty bool) (tree.Tree, error) { root := simple.New("gopass") for _, recp := range r.store.Recipients(ctx) { if err := r.addRecipient(ctx, "", root, recp, pretty); err != nil { color.Yellow("Failed to add recipient to tree %s: %s", recp, err) } } mps := r.MountPoints() sort.Sort(store.ByPathLen(mps)) for _, alias := range mps { substore := r.mounts[alias] if substore == nil { continue } if err := root.AddMount(alias, substore.Path()); err != nil { return nil, errors.Errorf("failed to add mount: %s", err) } for _, recp := range substore.Recipients(ctx) { if err := r.addRecipient(ctx, alias+"/", root, recp, pretty); err != nil { out.Debug(ctx, "Failed to add recipient to tree %s: %s", recp, err) } } } return root, nil }
[ "func", "(", "r", "*", "Store", ")", "RecipientsTree", "(", "ctx", "context", ".", "Context", ",", "pretty", "bool", ")", "(", "tree", ".", "Tree", ",", "error", ")", "{", "root", ":=", "simple", ".", "New", "(", "\"", "\"", ")", "\n\n", "for", "_", ",", "recp", ":=", "range", "r", ".", "store", ".", "Recipients", "(", "ctx", ")", "{", "if", "err", ":=", "r", ".", "addRecipient", "(", "ctx", ",", "\"", "\"", ",", "root", ",", "recp", ",", "pretty", ")", ";", "err", "!=", "nil", "{", "color", ".", "Yellow", "(", "\"", "\"", ",", "recp", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "mps", ":=", "r", ".", "MountPoints", "(", ")", "\n", "sort", ".", "Sort", "(", "store", ".", "ByPathLen", "(", "mps", ")", ")", "\n", "for", "_", ",", "alias", ":=", "range", "mps", "{", "substore", ":=", "r", ".", "mounts", "[", "alias", "]", "\n", "if", "substore", "==", "nil", "{", "continue", "\n", "}", "\n", "if", "err", ":=", "root", ".", "AddMount", "(", "alias", ",", "substore", ".", "Path", "(", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "for", "_", ",", "recp", ":=", "range", "substore", ".", "Recipients", "(", "ctx", ")", "{", "if", "err", ":=", "r", ".", "addRecipient", "(", "ctx", ",", "alias", "+", "\"", "\"", ",", "root", ",", "recp", ",", "pretty", ")", ";", "err", "!=", "nil", "{", "out", ".", "Debug", "(", "ctx", ",", "\"", "\"", ",", "recp", ",", "err", ")", "\n", "}", "\n", "}", "\n", "}", "\n\n", "return", "root", ",", "nil", "\n", "}" ]
// RecipientsTree returns a tree view of all stores' recipients
[ "RecipientsTree", "returns", "a", "tree", "view", "of", "all", "stores", "recipients" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/recipients.go#L78-L105
train
gopasspw/gopass
pkg/backend/crypto/gpg/openpgp/utils.go
gpgHome
func gpgHome(ctx context.Context) string { if gh := os.Getenv("GNUPGHOME"); gh != "" { return gh } hd, err := homedir.Dir() if err != nil { out.Debug(ctx, "Failed to get homedir: %s", err) return "" } return filepath.Join(hd, ".gnupg") }
go
func gpgHome(ctx context.Context) string { if gh := os.Getenv("GNUPGHOME"); gh != "" { return gh } hd, err := homedir.Dir() if err != nil { out.Debug(ctx, "Failed to get homedir: %s", err) return "" } return filepath.Join(hd, ".gnupg") }
[ "func", "gpgHome", "(", "ctx", "context", ".", "Context", ")", "string", "{", "if", "gh", ":=", "os", ".", "Getenv", "(", "\"", "\"", ")", ";", "gh", "!=", "\"", "\"", "{", "return", "gh", "\n", "}", "\n", "hd", ",", "err", ":=", "homedir", ".", "Dir", "(", ")", "\n", "if", "err", "!=", "nil", "{", "out", ".", "Debug", "(", "ctx", ",", "\"", "\"", ",", "err", ")", "\n", "return", "\"", "\"", "\n", "}", "\n", "return", "filepath", ".", "Join", "(", "hd", ",", "\"", "\"", ")", "\n", "}" ]
// gpgHome returns the gnupg homedir
[ "gpgHome", "returns", "the", "gnupg", "homedir" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/openpgp/utils.go#L115-L125
train
gopasspw/gopass
pkg/store/sub/context.go
WithFsckCheck
func WithFsckCheck(ctx context.Context, check bool) context.Context { return context.WithValue(ctx, ctxKeyFsckCheck, check) }
go
func WithFsckCheck(ctx context.Context, check bool) context.Context { return context.WithValue(ctx, ctxKeyFsckCheck, check) }
[ "func", "WithFsckCheck", "(", "ctx", "context", ".", "Context", ",", "check", "bool", ")", "context", ".", "Context", "{", "return", "context", ".", "WithValue", "(", "ctx", ",", "ctxKeyFsckCheck", ",", "check", ")", "\n", "}" ]
// WithFsckCheck returns a context with the flag for fscks check set
[ "WithFsckCheck", "returns", "a", "context", "with", "the", "flag", "for", "fscks", "check", "set" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/context.go#L23-L25
train
gopasspw/gopass
pkg/store/sub/context.go
HasFsckCheck
func HasFsckCheck(ctx context.Context) bool { _, ok := ctx.Value(ctxKeyFsckCheck).(bool) return ok }
go
func HasFsckCheck(ctx context.Context) bool { _, ok := ctx.Value(ctxKeyFsckCheck).(bool) return ok }
[ "func", "HasFsckCheck", "(", "ctx", "context", ".", "Context", ")", "bool", "{", "_", ",", "ok", ":=", "ctx", ".", "Value", "(", "ctxKeyFsckCheck", ")", ".", "(", "bool", ")", "\n", "return", "ok", "\n", "}" ]
// HasFsckCheck returns true if a value for fsck check has been set in this // context
[ "HasFsckCheck", "returns", "true", "if", "a", "value", "for", "fsck", "check", "has", "been", "set", "in", "this", "context" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/context.go#L29-L32
train
gopasspw/gopass
pkg/store/sub/context.go
IsFsckCheck
func IsFsckCheck(ctx context.Context) bool { bv, ok := ctx.Value(ctxKeyFsckCheck).(bool) if !ok { return false } return bv }
go
func IsFsckCheck(ctx context.Context) bool { bv, ok := ctx.Value(ctxKeyFsckCheck).(bool) if !ok { return false } return bv }
[ "func", "IsFsckCheck", "(", "ctx", "context", ".", "Context", ")", "bool", "{", "bv", ",", "ok", ":=", "ctx", ".", "Value", "(", "ctxKeyFsckCheck", ")", ".", "(", "bool", ")", "\n", "if", "!", "ok", "{", "return", "false", "\n", "}", "\n", "return", "bv", "\n", "}" ]
// IsFsckCheck returns the value of fsck check
[ "IsFsckCheck", "returns", "the", "value", "of", "fsck", "check" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/context.go#L35-L41
train
gopasspw/gopass
pkg/store/sub/context.go
WithFsckForce
func WithFsckForce(ctx context.Context, force bool) context.Context { return context.WithValue(ctx, ctxKeyFsckForce, force) }
go
func WithFsckForce(ctx context.Context, force bool) context.Context { return context.WithValue(ctx, ctxKeyFsckForce, force) }
[ "func", "WithFsckForce", "(", "ctx", "context", ".", "Context", ",", "force", "bool", ")", "context", ".", "Context", "{", "return", "context", ".", "WithValue", "(", "ctx", ",", "ctxKeyFsckForce", ",", "force", ")", "\n", "}" ]
// WithFsckForce returns a context with the flag for fsck force set
[ "WithFsckForce", "returns", "a", "context", "with", "the", "flag", "for", "fsck", "force", "set" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/context.go#L44-L46
train
gopasspw/gopass
pkg/store/sub/context.go
HasFsckForce
func HasFsckForce(ctx context.Context) bool { _, ok := ctx.Value(ctxKeyFsckForce).(bool) return ok }
go
func HasFsckForce(ctx context.Context) bool { _, ok := ctx.Value(ctxKeyFsckForce).(bool) return ok }
[ "func", "HasFsckForce", "(", "ctx", "context", ".", "Context", ")", "bool", "{", "_", ",", "ok", ":=", "ctx", ".", "Value", "(", "ctxKeyFsckForce", ")", ".", "(", "bool", ")", "\n", "return", "ok", "\n", "}" ]
// HasFsckForce returns true if a value for fsck force has been set in this // context
[ "HasFsckForce", "returns", "true", "if", "a", "value", "for", "fsck", "force", "has", "been", "set", "in", "this", "context" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/context.go#L50-L53
train
gopasspw/gopass
pkg/store/sub/context.go
IsFsckForce
func IsFsckForce(ctx context.Context) bool { bv, ok := ctx.Value(ctxKeyFsckForce).(bool) if !ok { return false } return bv }
go
func IsFsckForce(ctx context.Context) bool { bv, ok := ctx.Value(ctxKeyFsckForce).(bool) if !ok { return false } return bv }
[ "func", "IsFsckForce", "(", "ctx", "context", ".", "Context", ")", "bool", "{", "bv", ",", "ok", ":=", "ctx", ".", "Value", "(", "ctxKeyFsckForce", ")", ".", "(", "bool", ")", "\n", "if", "!", "ok", "{", "return", "false", "\n", "}", "\n", "return", "bv", "\n", "}" ]
// IsFsckForce returns the value of fsck force
[ "IsFsckForce", "returns", "the", "value", "of", "fsck", "force" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/context.go#L56-L62
train
gopasspw/gopass
pkg/store/sub/context.go
WithAutoSync
func WithAutoSync(ctx context.Context, sync bool) context.Context { return context.WithValue(ctx, ctxKeyAutoSync, sync) }
go
func WithAutoSync(ctx context.Context, sync bool) context.Context { return context.WithValue(ctx, ctxKeyAutoSync, sync) }
[ "func", "WithAutoSync", "(", "ctx", "context", ".", "Context", ",", "sync", "bool", ")", "context", ".", "Context", "{", "return", "context", ".", "WithValue", "(", "ctx", ",", "ctxKeyAutoSync", ",", "sync", ")", "\n", "}" ]
// WithAutoSync returns a context with the flag for autosync set
[ "WithAutoSync", "returns", "a", "context", "with", "the", "flag", "for", "autosync", "set" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/context.go#L65-L67
train
gopasspw/gopass
pkg/store/sub/context.go
HasAutoSync
func HasAutoSync(ctx context.Context) bool { _, ok := ctx.Value(ctxKeyAutoSync).(bool) return ok }
go
func HasAutoSync(ctx context.Context) bool { _, ok := ctx.Value(ctxKeyAutoSync).(bool) return ok }
[ "func", "HasAutoSync", "(", "ctx", "context", ".", "Context", ")", "bool", "{", "_", ",", "ok", ":=", "ctx", ".", "Value", "(", "ctxKeyAutoSync", ")", ".", "(", "bool", ")", "\n", "return", "ok", "\n", "}" ]
// HasAutoSync has been set if a value for auto sync has been set in this // context
[ "HasAutoSync", "has", "been", "set", "if", "a", "value", "for", "auto", "sync", "has", "been", "set", "in", "this", "context" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/context.go#L71-L74
train
gopasspw/gopass
pkg/store/sub/context.go
IsAutoSync
func IsAutoSync(ctx context.Context) bool { bv, ok := ctx.Value(ctxKeyAutoSync).(bool) if !ok { return true } return bv }
go
func IsAutoSync(ctx context.Context) bool { bv, ok := ctx.Value(ctxKeyAutoSync).(bool) if !ok { return true } return bv }
[ "func", "IsAutoSync", "(", "ctx", "context", ".", "Context", ")", "bool", "{", "bv", ",", "ok", ":=", "ctx", ".", "Value", "(", "ctxKeyAutoSync", ")", ".", "(", "bool", ")", "\n", "if", "!", "ok", "{", "return", "true", "\n", "}", "\n", "return", "bv", "\n", "}" ]
// IsAutoSync returns the value of autosync
[ "IsAutoSync", "returns", "the", "value", "of", "autosync" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/context.go#L77-L83
train
gopasspw/gopass
pkg/store/sub/context.go
HasReason
func HasReason(ctx context.Context) bool { _, ok := ctx.Value(ctxKeyReason).(string) return ok }
go
func HasReason(ctx context.Context) bool { _, ok := ctx.Value(ctxKeyReason).(string) return ok }
[ "func", "HasReason", "(", "ctx", "context", ".", "Context", ")", "bool", "{", "_", ",", "ok", ":=", "ctx", ".", "Value", "(", "ctxKeyReason", ")", ".", "(", "string", ")", "\n", "return", "ok", "\n", "}" ]
// HasReason returns true if a value for reason has been set in this context
[ "HasReason", "returns", "true", "if", "a", "value", "for", "reason", "has", "been", "set", "in", "this", "context" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/context.go#L91-L94
train
gopasspw/gopass
pkg/store/sub/context.go
GetReason
func GetReason(ctx context.Context) string { sv, ok := ctx.Value(ctxKeyReason).(string) if !ok { return "" } return sv }
go
func GetReason(ctx context.Context) string { sv, ok := ctx.Value(ctxKeyReason).(string) if !ok { return "" } return sv }
[ "func", "GetReason", "(", "ctx", "context", ".", "Context", ")", "string", "{", "sv", ",", "ok", ":=", "ctx", ".", "Value", "(", "ctxKeyReason", ")", ".", "(", "string", ")", "\n", "if", "!", "ok", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "sv", "\n", "}" ]
// GetReason returns the value of reason
[ "GetReason", "returns", "the", "value", "of", "reason" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/context.go#L97-L103
train
gopasspw/gopass
pkg/store/sub/context.go
WithImportFunc
func WithImportFunc(ctx context.Context, imf store.ImportCallback) context.Context { return context.WithValue(ctx, ctxKeyImportFunc, imf) }
go
func WithImportFunc(ctx context.Context, imf store.ImportCallback) context.Context { return context.WithValue(ctx, ctxKeyImportFunc, imf) }
[ "func", "WithImportFunc", "(", "ctx", "context", ".", "Context", ",", "imf", "store", ".", "ImportCallback", ")", "context", ".", "Context", "{", "return", "context", ".", "WithValue", "(", "ctx", ",", "ctxKeyImportFunc", ",", "imf", ")", "\n", "}" ]
// WithImportFunc will return a context with the import callback set
[ "WithImportFunc", "will", "return", "a", "context", "with", "the", "import", "callback", "set" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/context.go#L106-L108
train
gopasspw/gopass
pkg/store/sub/context.go
HasImportFunc
func HasImportFunc(ctx context.Context) bool { imf, ok := ctx.Value(ctxKeyImportFunc).(store.ImportCallback) return ok && imf != nil }
go
func HasImportFunc(ctx context.Context) bool { imf, ok := ctx.Value(ctxKeyImportFunc).(store.ImportCallback) return ok && imf != nil }
[ "func", "HasImportFunc", "(", "ctx", "context", ".", "Context", ")", "bool", "{", "imf", ",", "ok", ":=", "ctx", ".", "Value", "(", "ctxKeyImportFunc", ")", ".", "(", "store", ".", "ImportCallback", ")", "\n", "return", "ok", "&&", "imf", "!=", "nil", "\n", "}" ]
// HasImportFunc returns true if a value for import func has been set in this // context
[ "HasImportFunc", "returns", "true", "if", "a", "value", "for", "import", "func", "has", "been", "set", "in", "this", "context" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/context.go#L112-L115
train
gopasspw/gopass
pkg/store/sub/context.go
WithRecipientFunc
func WithRecipientFunc(ctx context.Context, imf store.RecipientCallback) context.Context { return context.WithValue(ctx, ctxKeyRecipientFunc, imf) }
go
func WithRecipientFunc(ctx context.Context, imf store.RecipientCallback) context.Context { return context.WithValue(ctx, ctxKeyRecipientFunc, imf) }
[ "func", "WithRecipientFunc", "(", "ctx", "context", ".", "Context", ",", "imf", "store", ".", "RecipientCallback", ")", "context", ".", "Context", "{", "return", "context", ".", "WithValue", "(", "ctx", ",", "ctxKeyRecipientFunc", ",", "imf", ")", "\n", "}" ]
// WithRecipientFunc will return a context with the recipient callback set
[ "WithRecipientFunc", "will", "return", "a", "context", "with", "the", "recipient", "callback", "set" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/context.go#L130-L132
train
gopasspw/gopass
pkg/store/sub/context.go
HasRecipientFunc
func HasRecipientFunc(ctx context.Context) bool { imf, ok := ctx.Value(ctxKeyRecipientFunc).(store.RecipientCallback) return ok && imf != nil }
go
func HasRecipientFunc(ctx context.Context) bool { imf, ok := ctx.Value(ctxKeyRecipientFunc).(store.RecipientCallback) return ok && imf != nil }
[ "func", "HasRecipientFunc", "(", "ctx", "context", ".", "Context", ")", "bool", "{", "imf", ",", "ok", ":=", "ctx", ".", "Value", "(", "ctxKeyRecipientFunc", ")", ".", "(", "store", ".", "RecipientCallback", ")", "\n", "return", "ok", "&&", "imf", "!=", "nil", "\n", "}" ]
// HasRecipientFunc returns true if a recipient func has been set in this // context
[ "HasRecipientFunc", "returns", "true", "if", "a", "recipient", "func", "has", "been", "set", "in", "this", "context" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/context.go#L136-L139
train
gopasspw/gopass
pkg/store/sub/context.go
WithFsckFunc
func WithFsckFunc(ctx context.Context, imf store.FsckCallback) context.Context { return context.WithValue(ctx, ctxKeyFsckFunc, imf) }
go
func WithFsckFunc(ctx context.Context, imf store.FsckCallback) context.Context { return context.WithValue(ctx, ctxKeyFsckFunc, imf) }
[ "func", "WithFsckFunc", "(", "ctx", "context", ".", "Context", ",", "imf", "store", ".", "FsckCallback", ")", "context", ".", "Context", "{", "return", "context", ".", "WithValue", "(", "ctx", ",", "ctxKeyFsckFunc", ",", "imf", ")", "\n", "}" ]
// WithFsckFunc will return a context with the fsck confirmation callback set
[ "WithFsckFunc", "will", "return", "a", "context", "with", "the", "fsck", "confirmation", "callback", "set" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/context.go#L155-L157
train
gopasspw/gopass
pkg/store/sub/context.go
HasFsckFunc
func HasFsckFunc(ctx context.Context) bool { imf, ok := ctx.Value(ctxKeyFsckFunc).(store.FsckCallback) return ok && imf != nil }
go
func HasFsckFunc(ctx context.Context) bool { imf, ok := ctx.Value(ctxKeyFsckFunc).(store.FsckCallback) return ok && imf != nil }
[ "func", "HasFsckFunc", "(", "ctx", "context", ".", "Context", ")", "bool", "{", "imf", ",", "ok", ":=", "ctx", ".", "Value", "(", "ctxKeyFsckFunc", ")", ".", "(", "store", ".", "FsckCallback", ")", "\n", "return", "ok", "&&", "imf", "!=", "nil", "\n", "}" ]
// HasFsckFunc returns true if a fsck func has been set in this context
[ "HasFsckFunc", "returns", "true", "if", "a", "fsck", "func", "has", "been", "set", "in", "this", "context" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/context.go#L160-L163
train
gopasspw/gopass
pkg/store/sub/context.go
WithCheckRecipients
func WithCheckRecipients(ctx context.Context, cr bool) context.Context { return context.WithValue(ctx, ctxKeyCheckRecipients, cr) }
go
func WithCheckRecipients(ctx context.Context, cr bool) context.Context { return context.WithValue(ctx, ctxKeyCheckRecipients, cr) }
[ "func", "WithCheckRecipients", "(", "ctx", "context", ".", "Context", ",", "cr", "bool", ")", "context", ".", "Context", "{", "return", "context", ".", "WithValue", "(", "ctx", ",", "ctxKeyCheckRecipients", ",", "cr", ")", "\n", "}" ]
// WithCheckRecipients will return a context with the flag for check recipients // set
[ "WithCheckRecipients", "will", "return", "a", "context", "with", "the", "flag", "for", "check", "recipients", "set" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/context.go#L180-L182
train
gopasspw/gopass
pkg/store/sub/context.go
HasCheckRecipients
func HasCheckRecipients(ctx context.Context) bool { _, ok := ctx.Value(ctxKeyCheckRecipients).(bool) return ok }
go
func HasCheckRecipients(ctx context.Context) bool { _, ok := ctx.Value(ctxKeyCheckRecipients).(bool) return ok }
[ "func", "HasCheckRecipients", "(", "ctx", "context", ".", "Context", ")", "bool", "{", "_", ",", "ok", ":=", "ctx", ".", "Value", "(", "ctxKeyCheckRecipients", ")", ".", "(", "bool", ")", "\n", "return", "ok", "\n", "}" ]
// HasCheckRecipients returns true if check recipients has been set in this // context
[ "HasCheckRecipients", "returns", "true", "if", "check", "recipients", "has", "been", "set", "in", "this", "context" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/context.go#L186-L189
train
gopasspw/gopass
pkg/tempfile/file.go
New
func New(ctx context.Context, prefix string) (*File, error) { td, err := ioutil.TempDir(tempdirBase(), prefix) if err != nil { return nil, err } tf := &File{ dir: td, dbg: ctxutil.IsDebug(ctx), } if err := tf.mount(ctx); err != nil { _ = os.RemoveAll(tf.dir) return nil, err } fn := filepath.Join(tf.dir, "secret") fh, err := os.OpenFile(fn, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0600) if err != nil { return nil, errors.Errorf("Failed to open file %s: %s", fn, err) } tf.fh = fh return tf, nil }
go
func New(ctx context.Context, prefix string) (*File, error) { td, err := ioutil.TempDir(tempdirBase(), prefix) if err != nil { return nil, err } tf := &File{ dir: td, dbg: ctxutil.IsDebug(ctx), } if err := tf.mount(ctx); err != nil { _ = os.RemoveAll(tf.dir) return nil, err } fn := filepath.Join(tf.dir, "secret") fh, err := os.OpenFile(fn, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0600) if err != nil { return nil, errors.Errorf("Failed to open file %s: %s", fn, err) } tf.fh = fh return tf, nil }
[ "func", "New", "(", "ctx", "context", ".", "Context", ",", "prefix", "string", ")", "(", "*", "File", ",", "error", ")", "{", "td", ",", "err", ":=", "ioutil", ".", "TempDir", "(", "tempdirBase", "(", ")", ",", "prefix", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "tf", ":=", "&", "File", "{", "dir", ":", "td", ",", "dbg", ":", "ctxutil", ".", "IsDebug", "(", "ctx", ")", ",", "}", "\n\n", "if", "err", ":=", "tf", ".", "mount", "(", "ctx", ")", ";", "err", "!=", "nil", "{", "_", "=", "os", ".", "RemoveAll", "(", "tf", ".", "dir", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "fn", ":=", "filepath", ".", "Join", "(", "tf", ".", "dir", ",", "\"", "\"", ")", "\n", "fh", ",", "err", ":=", "os", ".", "OpenFile", "(", "fn", ",", "os", ".", "O_CREATE", "|", "os", ".", "O_EXCL", "|", "os", ".", "O_WRONLY", ",", "0600", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "fn", ",", "err", ")", "\n", "}", "\n", "tf", ".", "fh", "=", "fh", "\n\n", "return", "tf", ",", "nil", "\n", "}" ]
// New returns a new tempfile wrapper
[ "New", "returns", "a", "new", "tempfile", "wrapper" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/tempfile/file.go#L23-L47
train
gopasspw/gopass
pkg/tempfile/file.go
Name
func (t *File) Name() string { if t.fh == nil { return "" } return t.fh.Name() }
go
func (t *File) Name() string { if t.fh == nil { return "" } return t.fh.Name() }
[ "func", "(", "t", "*", "File", ")", "Name", "(", ")", "string", "{", "if", "t", ".", "fh", "==", "nil", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "t", ".", "fh", ".", "Name", "(", ")", "\n", "}" ]
// Name returns the name of the tempfile
[ "Name", "returns", "the", "name", "of", "the", "tempfile" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/tempfile/file.go#L50-L55
train
gopasspw/gopass
pkg/tempfile/file.go
Write
func (t *File) Write(p []byte) (int, error) { if t.fh == nil { return 0, errors.Errorf("not initialized") } return t.fh.Write(p) }
go
func (t *File) Write(p []byte) (int, error) { if t.fh == nil { return 0, errors.Errorf("not initialized") } return t.fh.Write(p) }
[ "func", "(", "t", "*", "File", ")", "Write", "(", "p", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "if", "t", ".", "fh", "==", "nil", "{", "return", "0", ",", "errors", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "t", ".", "fh", ".", "Write", "(", "p", ")", "\n", "}" ]
// Write implement io.Writer
[ "Write", "implement", "io", ".", "Writer" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/tempfile/file.go#L58-L63
train
gopasspw/gopass
pkg/tempfile/file.go
Close
func (t *File) Close() error { if t.fh == nil { return nil } return t.fh.Close() }
go
func (t *File) Close() error { if t.fh == nil { return nil } return t.fh.Close() }
[ "func", "(", "t", "*", "File", ")", "Close", "(", ")", "error", "{", "if", "t", ".", "fh", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "return", "t", ".", "fh", ".", "Close", "(", ")", "\n", "}" ]
// Close implements io.WriteCloser
[ "Close", "implements", "io", ".", "WriteCloser" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/tempfile/file.go#L66-L71
train
gopasspw/gopass
pkg/tempfile/file.go
Remove
func (t *File) Remove(ctx context.Context) error { _ = t.Close() if err := t.unmount(ctx); err != nil { return errors.Errorf("Failed to unmount %s from %s: %s", t.dev, t.dir, err) } if t.dir == "" { return nil } return os.RemoveAll(t.dir) }
go
func (t *File) Remove(ctx context.Context) error { _ = t.Close() if err := t.unmount(ctx); err != nil { return errors.Errorf("Failed to unmount %s from %s: %s", t.dev, t.dir, err) } if t.dir == "" { return nil } return os.RemoveAll(t.dir) }
[ "func", "(", "t", "*", "File", ")", "Remove", "(", "ctx", "context", ".", "Context", ")", "error", "{", "_", "=", "t", ".", "Close", "(", ")", "\n", "if", "err", ":=", "t", ".", "unmount", "(", "ctx", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "t", ".", "dev", ",", "t", ".", "dir", ",", "err", ")", "\n", "}", "\n", "if", "t", ".", "dir", "==", "\"", "\"", "{", "return", "nil", "\n", "}", "\n", "return", "os", ".", "RemoveAll", "(", "t", ".", "dir", ")", "\n", "}" ]
// Remove attempts to remove the tempfile
[ "Remove", "attempts", "to", "remove", "the", "tempfile" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/tempfile/file.go#L74-L83
train
gopasspw/gopass
pkg/jsonapi/manifest/setup_windows.go
GetRegistryPath
func GetRegistryPath(browser string) (string, error) { path, found := registryPaths[browser] if !found { return "", fmt.Errorf("browser %s on %s is currently not supported", browser, runtime.GOOS) } return path, nil }
go
func GetRegistryPath(browser string) (string, error) { path, found := registryPaths[browser] if !found { return "", fmt.Errorf("browser %s on %s is currently not supported", browser, runtime.GOOS) } return path, nil }
[ "func", "GetRegistryPath", "(", "browser", "string", ")", "(", "string", ",", "error", ")", "{", "path", ",", "found", ":=", "registryPaths", "[", "browser", "]", "\n", "if", "!", "found", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "browser", ",", "runtime", ".", "GOOS", ")", "\n", "}", "\n", "return", "path", ",", "nil", "\n", "}" ]
// GetRegistryPath returns the relative registry path to use in the windows registry key
[ "GetRegistryPath", "returns", "the", "relative", "registry", "path", "to", "use", "in", "the", "windows", "registry", "key" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/jsonapi/manifest/setup_windows.go#L40-L46
train
gopasspw/gopass
pkg/store/sub/fsck.go
Fsck
func (s *Store) Fsck(ctx context.Context, path string) error { ctx = out.AddPrefix(ctx, "["+s.alias+"] ") out.Debug(ctx, "Fsck(%s)", path) // first let the storage backend check itself if err := s.storage.Fsck(ctx); err != nil { return errors.Wrapf(err, "storage backend found errors: %s", err) } pcb := ctxutil.GetProgressCallback(ctx) // then we'll make sure all the secrets are readable by us and every // valid recipient names, err := s.List(ctx, path) if err != nil { return errors.Wrapf(err, "failed to list entries: %s", err) } sort.Strings(names) for _, name := range names { pcb() if strings.HasPrefix(name, s.alias+"/") { name = strings.TrimPrefix(name, s.alias+"/") } out.Debug(ctx, "sub.Fsck(%s) - Checking %s", path, name) if err := s.fsckCheckEntry(ctx, name); err != nil { return errors.Wrapf(err, "failed to check %s: %s", name, err) } } return nil }
go
func (s *Store) Fsck(ctx context.Context, path string) error { ctx = out.AddPrefix(ctx, "["+s.alias+"] ") out.Debug(ctx, "Fsck(%s)", path) // first let the storage backend check itself if err := s.storage.Fsck(ctx); err != nil { return errors.Wrapf(err, "storage backend found errors: %s", err) } pcb := ctxutil.GetProgressCallback(ctx) // then we'll make sure all the secrets are readable by us and every // valid recipient names, err := s.List(ctx, path) if err != nil { return errors.Wrapf(err, "failed to list entries: %s", err) } sort.Strings(names) for _, name := range names { pcb() if strings.HasPrefix(name, s.alias+"/") { name = strings.TrimPrefix(name, s.alias+"/") } out.Debug(ctx, "sub.Fsck(%s) - Checking %s", path, name) if err := s.fsckCheckEntry(ctx, name); err != nil { return errors.Wrapf(err, "failed to check %s: %s", name, err) } } return nil }
[ "func", "(", "s", "*", "Store", ")", "Fsck", "(", "ctx", "context", ".", "Context", ",", "path", "string", ")", "error", "{", "ctx", "=", "out", ".", "AddPrefix", "(", "ctx", ",", "\"", "\"", "+", "s", ".", "alias", "+", "\"", "\"", ")", "\n", "out", ".", "Debug", "(", "ctx", ",", "\"", "\"", ",", "path", ")", "\n\n", "// first let the storage backend check itself", "if", "err", ":=", "s", ".", "storage", ".", "Fsck", "(", "ctx", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "pcb", ":=", "ctxutil", ".", "GetProgressCallback", "(", "ctx", ")", "\n\n", "// then we'll make sure all the secrets are readable by us and every", "// valid recipient", "names", ",", "err", ":=", "s", ".", "List", "(", "ctx", ",", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "sort", ".", "Strings", "(", "names", ")", "\n", "for", "_", ",", "name", ":=", "range", "names", "{", "pcb", "(", ")", "\n", "if", "strings", ".", "HasPrefix", "(", "name", ",", "s", ".", "alias", "+", "\"", "\"", ")", "{", "name", "=", "strings", ".", "TrimPrefix", "(", "name", ",", "s", ".", "alias", "+", "\"", "\"", ")", "\n", "}", "\n", "out", ".", "Debug", "(", "ctx", ",", "\"", "\"", ",", "path", ",", "name", ")", "\n", "if", "err", ":=", "s", ".", "fsckCheckEntry", "(", "ctx", ",", "name", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "name", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Fsck checks all entries matching the given prefix
[ "Fsck", "checks", "all", "entries", "matching", "the", "given", "prefix" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/fsck.go#L15-L45
train
gopasspw/gopass
pkg/config/context.go
WithContext
func (c StoreConfig) WithContext(ctx context.Context) context.Context { if !ctxutil.HasAskForMore(ctx) { ctx = ctxutil.WithAskForMore(ctx, c.AskForMore) } if !ctxutil.HasAutoClip(ctx) { ctx = ctxutil.WithAutoClip(ctx, c.AutoClip) } if !c.AutoImport { ctx = sub.WithImportFunc(ctx, nil) } if !sub.HasAutoSync(ctx) { ctx = sub.WithAutoSync(ctx, c.AutoSync) } if !ctxutil.HasClipTimeout(ctx) { ctx = ctxutil.WithClipTimeout(ctx, c.ClipTimeout) } if !ctxutil.HasConcurrency(ctx) { ctx = ctxutil.WithConcurrency(ctx, c.Concurrency) } if !ctxutil.HasEditRecipients(ctx) { ctx = ctxutil.WithEditRecipients(ctx, c.EditRecipients) } if !ctxutil.HasNoConfirm(ctx) { ctx = ctxutil.WithNoConfirm(ctx, c.NoConfirm) } if !ctxutil.HasNoPager(ctx) { ctx = ctxutil.WithNoPager(ctx, c.NoPager) } if !ctxutil.HasShowSafeContent(ctx) { ctx = ctxutil.WithShowSafeContent(ctx, c.SafeContent) } if !ctxutil.HasUseSymbols(ctx) { ctx = ctxutil.WithUseSymbols(ctx, c.UseSymbols) } return ctx }
go
func (c StoreConfig) WithContext(ctx context.Context) context.Context { if !ctxutil.HasAskForMore(ctx) { ctx = ctxutil.WithAskForMore(ctx, c.AskForMore) } if !ctxutil.HasAutoClip(ctx) { ctx = ctxutil.WithAutoClip(ctx, c.AutoClip) } if !c.AutoImport { ctx = sub.WithImportFunc(ctx, nil) } if !sub.HasAutoSync(ctx) { ctx = sub.WithAutoSync(ctx, c.AutoSync) } if !ctxutil.HasClipTimeout(ctx) { ctx = ctxutil.WithClipTimeout(ctx, c.ClipTimeout) } if !ctxutil.HasConcurrency(ctx) { ctx = ctxutil.WithConcurrency(ctx, c.Concurrency) } if !ctxutil.HasEditRecipients(ctx) { ctx = ctxutil.WithEditRecipients(ctx, c.EditRecipients) } if !ctxutil.HasNoConfirm(ctx) { ctx = ctxutil.WithNoConfirm(ctx, c.NoConfirm) } if !ctxutil.HasNoPager(ctx) { ctx = ctxutil.WithNoPager(ctx, c.NoPager) } if !ctxutil.HasShowSafeContent(ctx) { ctx = ctxutil.WithShowSafeContent(ctx, c.SafeContent) } if !ctxutil.HasUseSymbols(ctx) { ctx = ctxutil.WithUseSymbols(ctx, c.UseSymbols) } return ctx }
[ "func", "(", "c", "StoreConfig", ")", "WithContext", "(", "ctx", "context", ".", "Context", ")", "context", ".", "Context", "{", "if", "!", "ctxutil", ".", "HasAskForMore", "(", "ctx", ")", "{", "ctx", "=", "ctxutil", ".", "WithAskForMore", "(", "ctx", ",", "c", ".", "AskForMore", ")", "\n", "}", "\n", "if", "!", "ctxutil", ".", "HasAutoClip", "(", "ctx", ")", "{", "ctx", "=", "ctxutil", ".", "WithAutoClip", "(", "ctx", ",", "c", ".", "AutoClip", ")", "\n", "}", "\n", "if", "!", "c", ".", "AutoImport", "{", "ctx", "=", "sub", ".", "WithImportFunc", "(", "ctx", ",", "nil", ")", "\n", "}", "\n", "if", "!", "sub", ".", "HasAutoSync", "(", "ctx", ")", "{", "ctx", "=", "sub", ".", "WithAutoSync", "(", "ctx", ",", "c", ".", "AutoSync", ")", "\n", "}", "\n", "if", "!", "ctxutil", ".", "HasClipTimeout", "(", "ctx", ")", "{", "ctx", "=", "ctxutil", ".", "WithClipTimeout", "(", "ctx", ",", "c", ".", "ClipTimeout", ")", "\n", "}", "\n", "if", "!", "ctxutil", ".", "HasConcurrency", "(", "ctx", ")", "{", "ctx", "=", "ctxutil", ".", "WithConcurrency", "(", "ctx", ",", "c", ".", "Concurrency", ")", "\n", "}", "\n", "if", "!", "ctxutil", ".", "HasEditRecipients", "(", "ctx", ")", "{", "ctx", "=", "ctxutil", ".", "WithEditRecipients", "(", "ctx", ",", "c", ".", "EditRecipients", ")", "\n", "}", "\n", "if", "!", "ctxutil", ".", "HasNoConfirm", "(", "ctx", ")", "{", "ctx", "=", "ctxutil", ".", "WithNoConfirm", "(", "ctx", ",", "c", ".", "NoConfirm", ")", "\n", "}", "\n", "if", "!", "ctxutil", ".", "HasNoPager", "(", "ctx", ")", "{", "ctx", "=", "ctxutil", ".", "WithNoPager", "(", "ctx", ",", "c", ".", "NoPager", ")", "\n", "}", "\n", "if", "!", "ctxutil", ".", "HasShowSafeContent", "(", "ctx", ")", "{", "ctx", "=", "ctxutil", ".", "WithShowSafeContent", "(", "ctx", ",", "c", ".", "SafeContent", ")", "\n", "}", "\n", "if", "!", "ctxutil", ".", "HasUseSymbols", "(", "ctx", ")", "{", "ctx", "=", "ctxutil", ".", "WithUseSymbols", "(", "ctx", ",", "c", ".", "UseSymbols", ")", "\n", "}", "\n", "return", "ctx", "\n", "}" ]
// WithContext returns a context with all config options set for this store // config, iff they have not been already set in the context
[ "WithContext", "returns", "a", "context", "with", "all", "config", "options", "set", "for", "this", "store", "config", "iff", "they", "have", "not", "been", "already", "set", "in", "the", "context" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/config/context.go#L12-L47
train
gopasspw/gopass
pkg/jsonapi/manifest/setup_others.go
ValidBrowser
func ValidBrowser(name string) bool { _, found := manifestPath[runtime.GOOS][name] return found }
go
func ValidBrowser(name string) bool { _, found := manifestPath[runtime.GOOS][name] return found }
[ "func", "ValidBrowser", "(", "name", "string", ")", "bool", "{", "_", ",", "found", ":=", "manifestPath", "[", "runtime", ".", "GOOS", "]", "[", "name", "]", "\n", "return", "found", "\n", "}" ]
// ValidBrowser returns true if the given browser is supported on this platform
[ "ValidBrowser", "returns", "true", "if", "the", "given", "browser", "is", "supported", "on", "this", "platform" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/jsonapi/manifest/setup_others.go#L46-L49
train
gopasspw/gopass
pkg/jsonapi/manifest/setup_others.go
Path
func Path(browser, libpath string, globalInstall bool) (string, error) { location, err := getLocation(browser, libpath, globalInstall) if err != nil { return "", err } expanded, err := homedir.Expand(location) if err != nil { return "", err } return filepath.Join(expanded, Name+".json"), nil }
go
func Path(browser, libpath string, globalInstall bool) (string, error) { location, err := getLocation(browser, libpath, globalInstall) if err != nil { return "", err } expanded, err := homedir.Expand(location) if err != nil { return "", err } return filepath.Join(expanded, Name+".json"), nil }
[ "func", "Path", "(", "browser", ",", "libpath", "string", ",", "globalInstall", "bool", ")", "(", "string", ",", "error", ")", "{", "location", ",", "err", ":=", "getLocation", "(", "browser", ",", "libpath", ",", "globalInstall", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "expanded", ",", "err", ":=", "homedir", ".", "Expand", "(", "location", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "return", "filepath", ".", "Join", "(", "expanded", ",", "Name", "+", "\"", "\"", ")", ",", "nil", "\n", "}" ]
// Path returns the manifest file path
[ "Path", "returns", "the", "manifest", "file", "path" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/jsonapi/manifest/setup_others.go#L62-L74
train
gopasspw/gopass
pkg/jsonapi/manifest/setup_others.go
getLocation
func getLocation(browser, libpath string, globalInstall bool) (string, error) { if globalInstall { return getGlobalLocation(browser, libpath) } pm, found := manifestPath[runtime.GOOS] if !found { return "", fmt.Errorf("platform %s is currently not supported", runtime.GOOS) } path, found := pm[browser] if !found { return "", fmt.Errorf("browser %s on %s is currently not supported", browser, runtime.GOOS) } return path, nil }
go
func getLocation(browser, libpath string, globalInstall bool) (string, error) { if globalInstall { return getGlobalLocation(browser, libpath) } pm, found := manifestPath[runtime.GOOS] if !found { return "", fmt.Errorf("platform %s is currently not supported", runtime.GOOS) } path, found := pm[browser] if !found { return "", fmt.Errorf("browser %s on %s is currently not supported", browser, runtime.GOOS) } return path, nil }
[ "func", "getLocation", "(", "browser", ",", "libpath", "string", ",", "globalInstall", "bool", ")", "(", "string", ",", "error", ")", "{", "if", "globalInstall", "{", "return", "getGlobalLocation", "(", "browser", ",", "libpath", ")", "\n", "}", "\n\n", "pm", ",", "found", ":=", "manifestPath", "[", "runtime", ".", "GOOS", "]", "\n", "if", "!", "found", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "runtime", ".", "GOOS", ")", "\n", "}", "\n", "path", ",", "found", ":=", "pm", "[", "browser", "]", "\n", "if", "!", "found", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "browser", ",", "runtime", ".", "GOOS", ")", "\n", "}", "\n", "return", "path", ",", "nil", "\n", "}" ]
// getLocation returns only the manifest path
[ "getLocation", "returns", "only", "the", "manifest", "path" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/jsonapi/manifest/setup_others.go#L77-L91
train