repo stringlengths 5 67 | path stringlengths 4 218 | func_name stringlengths 0 151 | original_string stringlengths 52 373k | language stringclasses 6 values | code stringlengths 52 373k | code_tokens listlengths 10 512 | docstring stringlengths 3 47.2k | docstring_tokens listlengths 3 234 | sha stringlengths 40 40 | url stringlengths 85 339 | partition stringclasses 3 values |
|---|---|---|---|---|---|---|---|---|---|---|---|
gopasspw/gopass | pkg/agent/client/client.go | New | func New(dir string) *Client {
socket := filepath.Join(dir, ".gopass-agent.sock")
return &Client{
http: &http.Client{
Transport: &http.Transport{
DialContext: func(context.Context, string, string) (net.Conn, error) {
return net.Dial("unix", socket)
},
},
Timeout: 10 * time.Minute,
},
}
} | go | func New(dir string) *Client {
socket := filepath.Join(dir, ".gopass-agent.sock")
return &Client{
http: &http.Client{
Transport: &http.Transport{
DialContext: func(context.Context, string, string) (net.Conn, error) {
return net.Dial("unix", socket)
},
},
Timeout: 10 * time.Minute,
},
}
} | [
"func",
"New",
"(",
"dir",
"string",
")",
"*",
"Client",
"{",
"socket",
":=",
"filepath",
".",
"Join",
"(",
"dir",
",",
"\".gopass-agent.sock\"",
")",
"\n",
"return",
"&",
"Client",
"{",
"http",
":",
"&",
"http",
".",
"Client",
"{",
"Transport",
":",
"&",
"http",
".",
"Transport",
"{",
"DialContext",
":",
"func",
"(",
"context",
".",
"Context",
",",
"string",
",",
"string",
")",
"(",
"net",
".",
"Conn",
",",
"error",
")",
"{",
"return",
"net",
".",
"Dial",
"(",
"\"unix\"",
",",
"socket",
")",
"\n",
"}",
",",
"}",
",",
"Timeout",
":",
"10",
"*",
"time",
".",
"Minute",
",",
"}",
",",
"}",
"\n",
"}"
] | // New creates a new client | [
"New",
"creates",
"a",
"new",
"client"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/agent/client/client.go#L24-L36 | train |
gopasspw/gopass | pkg/agent/client/client.go | Ping | func (c *Client) Ping(ctx context.Context) error {
pc := &http.Client{
Transport: c.http.Transport,
Timeout: 5 * time.Second,
}
resp, err := pc.Get("http://unix/ping")
if err != nil {
return err
}
_ = resp.Body.Close()
return nil
} | go | func (c *Client) Ping(ctx context.Context) error {
pc := &http.Client{
Transport: c.http.Transport,
Timeout: 5 * time.Second,
}
resp, err := pc.Get("http://unix/ping")
if err != nil {
return err
}
_ = resp.Body.Close()
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Ping",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"pc",
":=",
"&",
"http",
".",
"Client",
"{",
"Transport",
":",
"c",
".",
"http",
".",
"Transport",
",",
"Timeout",
":",
"5",
"*",
"time",
".",
"Second",
",",
"}",
"\n",
"resp",
",",
"err",
":=",
"pc",
".",
"Get",
"(",
"\"http://unix/ping\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"_",
"=",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Ping checks connectivity to the agent | [
"Ping",
"checks",
"connectivity",
"to",
"the",
"agent"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/agent/client/client.go#L39-L50 | train |
gopasspw/gopass | pkg/agent/client/client.go | Remove | func (c *Client) Remove(ctx context.Context, key string) error {
if err := c.checkAgent(ctx); err != nil {
return errors.Wrapf(err, "agent not available: %s", err)
}
u, err := url.Parse("http://unix/cache/remove")
if err != nil {
return errors.Wrapf(err, "failed to build request url")
}
values := u.Query()
values.Set("key", key)
u.RawQuery = values.Encode()
resp, err := c.http.Get(u.String())
if err != nil {
return errors.Wrapf(err, "failed to talk to agent")
}
defer func() { _ = resp.Body.Close() }()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("request failed: %d", resp.StatusCode)
}
return nil
} | go | func (c *Client) Remove(ctx context.Context, key string) error {
if err := c.checkAgent(ctx); err != nil {
return errors.Wrapf(err, "agent not available: %s", err)
}
u, err := url.Parse("http://unix/cache/remove")
if err != nil {
return errors.Wrapf(err, "failed to build request url")
}
values := u.Query()
values.Set("key", key)
u.RawQuery = values.Encode()
resp, err := c.http.Get(u.String())
if err != nil {
return errors.Wrapf(err, "failed to talk to agent")
}
defer func() { _ = resp.Body.Close() }()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("request failed: %d", resp.StatusCode)
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Remove",
"(",
"ctx",
"context",
".",
"Context",
",",
"key",
"string",
")",
"error",
"{",
"if",
"err",
":=",
"c",
".",
"checkAgent",
"(",
"ctx",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"agent not available: %s\"",
",",
"err",
")",
"\n",
"}",
"\n",
"u",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"\"http://unix/cache/remove\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"failed to build request url\"",
")",
"\n",
"}",
"\n",
"values",
":=",
"u",
".",
"Query",
"(",
")",
"\n",
"values",
".",
"Set",
"(",
"\"key\"",
",",
"key",
")",
"\n",
"u",
".",
"RawQuery",
"=",
"values",
".",
"Encode",
"(",
")",
"\n",
"resp",
",",
"err",
":=",
"c",
".",
"http",
".",
"Get",
"(",
"u",
".",
"String",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"failed to talk to agent\"",
")",
"\n",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"_",
"=",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"}",
"(",
")",
"\n",
"if",
"resp",
".",
"StatusCode",
"!=",
"http",
".",
"StatusOK",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"request failed: %d\"",
",",
"resp",
".",
"StatusCode",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Remove un-caches a single key | [
"Remove",
"un",
"-",
"caches",
"a",
"single",
"key"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/agent/client/client.go#L72-L97 | train |
gopasspw/gopass | pkg/backend/crypto/xc/import.go | ImportPublicKey | func (x *XC) ImportPublicKey(ctx context.Context, buf []byte) error {
if err := x.pubring.Import(buf); err != nil {
return err
}
return x.pubring.Save()
} | go | func (x *XC) ImportPublicKey(ctx context.Context, buf []byte) error {
if err := x.pubring.Import(buf); err != nil {
return err
}
return x.pubring.Save()
} | [
"func",
"(",
"x",
"*",
"XC",
")",
"ImportPublicKey",
"(",
"ctx",
"context",
".",
"Context",
",",
"buf",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"err",
":=",
"x",
".",
"pubring",
".",
"Import",
"(",
"buf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"x",
".",
"pubring",
".",
"Save",
"(",
")",
"\n",
"}"
] | // ImportPublicKey imports a given public key into the keyring | [
"ImportPublicKey",
"imports",
"a",
"given",
"public",
"key",
"into",
"the",
"keyring"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/import.go#L6-L11 | train |
gopasspw/gopass | pkg/backend/crypto/xc/import.go | ImportPrivateKey | func (x *XC) ImportPrivateKey(ctx context.Context, buf []byte) error {
if err := x.secring.Import(buf); err != nil {
return err
}
return x.secring.Save()
} | go | func (x *XC) ImportPrivateKey(ctx context.Context, buf []byte) error {
if err := x.secring.Import(buf); err != nil {
return err
}
return x.secring.Save()
} | [
"func",
"(",
"x",
"*",
"XC",
")",
"ImportPrivateKey",
"(",
"ctx",
"context",
".",
"Context",
",",
"buf",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"err",
":=",
"x",
".",
"secring",
".",
"Import",
"(",
"buf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"x",
".",
"secring",
".",
"Save",
"(",
")",
"\n",
"}"
] | // ImportPrivateKey imports a given private key into the keyring | [
"ImportPrivateKey",
"imports",
"a",
"given",
"private",
"key",
"into",
"the",
"keyring"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/import.go#L14-L19 | train |
gopasspw/gopass | pkg/backend/crypto/xc/xc.go | New | func New(dir string, client agentClient) (*XC, error) {
skr, _ := keyring.LoadSecring(filepath.Join(dir, secringFilename))
pkr, _ := keyring.LoadPubring(filepath.Join(dir, pubringFilename), skr)
return &XC{
dir: dir,
pubring: pkr,
secring: skr,
client: client,
}, nil
} | go | func New(dir string, client agentClient) (*XC, error) {
skr, _ := keyring.LoadSecring(filepath.Join(dir, secringFilename))
pkr, _ := keyring.LoadPubring(filepath.Join(dir, pubringFilename), skr)
return &XC{
dir: dir,
pubring: pkr,
secring: skr,
client: client,
}, nil
} | [
"func",
"New",
"(",
"dir",
"string",
",",
"client",
"agentClient",
")",
"(",
"*",
"XC",
",",
"error",
")",
"{",
"skr",
",",
"_",
":=",
"keyring",
".",
"LoadSecring",
"(",
"filepath",
".",
"Join",
"(",
"dir",
",",
"secringFilename",
")",
")",
"\n",
"pkr",
",",
"_",
":=",
"keyring",
".",
"LoadPubring",
"(",
"filepath",
".",
"Join",
"(",
"dir",
",",
"pubringFilename",
")",
",",
"skr",
")",
"\n",
"return",
"&",
"XC",
"{",
"dir",
":",
"dir",
",",
"pubring",
":",
"pkr",
",",
"secring",
":",
"skr",
",",
"client",
":",
"client",
",",
"}",
",",
"nil",
"\n",
"}"
] | // New creates a new XC backend | [
"New",
"creates",
"a",
"new",
"XC",
"backend"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/xc.go#L37-L46 | train |
gopasspw/gopass | pkg/backend/crypto/xc/xc.go | RemoveKey | func (x *XC) RemoveKey(id string) error {
if x.secring.Contains(id) {
if err := x.secring.Remove(id); err != nil {
return err
}
return x.secring.Save()
}
if x.pubring.Contains(id) {
if err := x.pubring.Remove(id); err != nil {
return err
}
return x.pubring.Save()
}
return fmt.Errorf("not found")
} | go | func (x *XC) RemoveKey(id string) error {
if x.secring.Contains(id) {
if err := x.secring.Remove(id); err != nil {
return err
}
return x.secring.Save()
}
if x.pubring.Contains(id) {
if err := x.pubring.Remove(id); err != nil {
return err
}
return x.pubring.Save()
}
return fmt.Errorf("not found")
} | [
"func",
"(",
"x",
"*",
"XC",
")",
"RemoveKey",
"(",
"id",
"string",
")",
"error",
"{",
"if",
"x",
".",
"secring",
".",
"Contains",
"(",
"id",
")",
"{",
"if",
"err",
":=",
"x",
".",
"secring",
".",
"Remove",
"(",
"id",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"x",
".",
"secring",
".",
"Save",
"(",
")",
"\n",
"}",
"\n",
"if",
"x",
".",
"pubring",
".",
"Contains",
"(",
"id",
")",
"{",
"if",
"err",
":=",
"x",
".",
"pubring",
".",
"Remove",
"(",
"id",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"x",
".",
"pubring",
".",
"Save",
"(",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"not found\"",
")",
"\n",
"}"
] | // RemoveKey removes a single key from the keyring | [
"RemoveKey",
"removes",
"a",
"single",
"key",
"from",
"the",
"keyring"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/xc.go#L49-L63 | train |
gopasspw/gopass | pkg/backend/crypto/xc/xc.go | Initialized | func (x *XC) Initialized(ctx context.Context) error {
if x == nil {
return fmt.Errorf("XC not initialized")
}
if x.pubring == nil {
return fmt.Errorf("pubring not initialized")
}
if x.secring == nil {
return fmt.Errorf("secring not initialized")
}
if x.client == nil {
return fmt.Errorf("client not initialized")
}
if err := x.client.Ping(ctx); err != nil {
return fmt.Errorf("agent not running")
}
return nil
} | go | func (x *XC) Initialized(ctx context.Context) error {
if x == nil {
return fmt.Errorf("XC not initialized")
}
if x.pubring == nil {
return fmt.Errorf("pubring not initialized")
}
if x.secring == nil {
return fmt.Errorf("secring not initialized")
}
if x.client == nil {
return fmt.Errorf("client not initialized")
}
if err := x.client.Ping(ctx); err != nil {
return fmt.Errorf("agent not running")
}
return nil
} | [
"func",
"(",
"x",
"*",
"XC",
")",
"Initialized",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"if",
"x",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"XC not initialized\"",
")",
"\n",
"}",
"\n",
"if",
"x",
".",
"pubring",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"pubring not initialized\"",
")",
"\n",
"}",
"\n",
"if",
"x",
".",
"secring",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"secring not initialized\"",
")",
"\n",
"}",
"\n",
"if",
"x",
".",
"client",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"client not initialized\"",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"x",
".",
"client",
".",
"Ping",
"(",
"ctx",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"agent not running\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Initialized returns an error if this backend is not properly initialized | [
"Initialized",
"returns",
"an",
"error",
"if",
"this",
"backend",
"is",
"not",
"properly",
"initialized"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/xc.go#L66-L83 | train |
gopasspw/gopass | pkg/backend/crypto/xc/xc.go | Version | func (x *XC) Version(ctx context.Context) semver.Version {
return semver.Version{
Patch: 1,
}
} | go | func (x *XC) Version(ctx context.Context) semver.Version {
return semver.Version{
Patch: 1,
}
} | [
"func",
"(",
"x",
"*",
"XC",
")",
"Version",
"(",
"ctx",
"context",
".",
"Context",
")",
"semver",
".",
"Version",
"{",
"return",
"semver",
".",
"Version",
"{",
"Patch",
":",
"1",
",",
"}",
"\n",
"}"
] | // Version returns 0.0.1 | [
"Version",
"returns",
"0",
".",
"0",
".",
"1"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/xc.go#L91-L95 | train |
gopasspw/gopass | pkg/backend/crypto/gpg/cli/binary.go | Binary | func Binary(ctx context.Context, bin string) (string, error) {
bins, err := detectBinaryCandidates(bin)
if err != nil {
return "", err
}
bv := make(byVersion, 0, len(bins))
for _, b := range bins {
//out.Debug(ctx, "gpg.detectBinary - Looking for '%s' ...", b)
if p, err := exec.LookPath(b); err == nil {
gb := gpgBin{
path: p,
ver: version(ctx, p),
}
//out.Debug(ctx, "gpg.detectBinary - Found '%s' at '%s' (%s)", b, p, gb.ver.String())
bv = append(bv, gb)
}
}
if len(bv) < 1 {
return "", errors.New("no gpg binary found")
}
sort.Sort(bv)
binary := bv[len(bv)-1].path
//out.Debug(ctx, "gpg.detectBinary - using '%s'", binary)
return binary, nil
} | go | func Binary(ctx context.Context, bin string) (string, error) {
bins, err := detectBinaryCandidates(bin)
if err != nil {
return "", err
}
bv := make(byVersion, 0, len(bins))
for _, b := range bins {
//out.Debug(ctx, "gpg.detectBinary - Looking for '%s' ...", b)
if p, err := exec.LookPath(b); err == nil {
gb := gpgBin{
path: p,
ver: version(ctx, p),
}
//out.Debug(ctx, "gpg.detectBinary - Found '%s' at '%s' (%s)", b, p, gb.ver.String())
bv = append(bv, gb)
}
}
if len(bv) < 1 {
return "", errors.New("no gpg binary found")
}
sort.Sort(bv)
binary := bv[len(bv)-1].path
//out.Debug(ctx, "gpg.detectBinary - using '%s'", binary)
return binary, nil
} | [
"func",
"Binary",
"(",
"ctx",
"context",
".",
"Context",
",",
"bin",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"bins",
",",
"err",
":=",
"detectBinaryCandidates",
"(",
"bin",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"\"",
",",
"err",
"\n",
"}",
"\n",
"bv",
":=",
"make",
"(",
"byVersion",
",",
"0",
",",
"len",
"(",
"bins",
")",
")",
"\n",
"for",
"_",
",",
"b",
":=",
"range",
"bins",
"{",
"if",
"p",
",",
"err",
":=",
"exec",
".",
"LookPath",
"(",
"b",
")",
";",
"err",
"==",
"nil",
"{",
"gb",
":=",
"gpgBin",
"{",
"path",
":",
"p",
",",
"ver",
":",
"version",
"(",
"ctx",
",",
"p",
")",
",",
"}",
"\n",
"bv",
"=",
"append",
"(",
"bv",
",",
"gb",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"bv",
")",
"<",
"1",
"{",
"return",
"\"\"",
",",
"errors",
".",
"New",
"(",
"\"no gpg binary found\"",
")",
"\n",
"}",
"\n",
"sort",
".",
"Sort",
"(",
"bv",
")",
"\n",
"binary",
":=",
"bv",
"[",
"len",
"(",
"bv",
")",
"-",
"1",
"]",
".",
"path",
"\n",
"return",
"binary",
",",
"nil",
"\n",
"}"
] | // Binary reutrns the GGP binary location | [
"Binary",
"reutrns",
"the",
"GGP",
"binary",
"location"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/cli/binary.go#L19-L43 | train |
gopasspw/gopass | pkg/out/context.go | WithPrefix | func WithPrefix(ctx context.Context, prefix string) context.Context {
return context.WithValue(ctx, ctxKeyPrefix, prefix)
} | go | func WithPrefix(ctx context.Context, prefix string) context.Context {
return context.WithValue(ctx, ctxKeyPrefix, prefix)
} | [
"func",
"WithPrefix",
"(",
"ctx",
"context",
".",
"Context",
",",
"prefix",
"string",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"ctxKeyPrefix",
",",
"prefix",
")",
"\n",
"}"
] | // WithPrefix returns a context with the given prefix set | [
"WithPrefix",
"returns",
"a",
"context",
"with",
"the",
"given",
"prefix",
"set"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/out/context.go#L14-L16 | train |
gopasspw/gopass | pkg/out/context.go | AddPrefix | func AddPrefix(ctx context.Context, prefix string) context.Context {
if prefix == "" {
return ctx
}
pfx := Prefix(ctx)
if pfx == "" {
return WithPrefix(ctx, prefix)
}
return WithPrefix(ctx, pfx+prefix)
} | go | func AddPrefix(ctx context.Context, prefix string) context.Context {
if prefix == "" {
return ctx
}
pfx := Prefix(ctx)
if pfx == "" {
return WithPrefix(ctx, prefix)
}
return WithPrefix(ctx, pfx+prefix)
} | [
"func",
"AddPrefix",
"(",
"ctx",
"context",
".",
"Context",
",",
"prefix",
"string",
")",
"context",
".",
"Context",
"{",
"if",
"prefix",
"==",
"\"\"",
"{",
"return",
"ctx",
"\n",
"}",
"\n",
"pfx",
":=",
"Prefix",
"(",
"ctx",
")",
"\n",
"if",
"pfx",
"==",
"\"\"",
"{",
"return",
"WithPrefix",
"(",
"ctx",
",",
"prefix",
")",
"\n",
"}",
"\n",
"return",
"WithPrefix",
"(",
"ctx",
",",
"pfx",
"+",
"prefix",
")",
"\n",
"}"
] | // AddPrefix returns a context with the given prefix added to end of the
// existing prefix | [
"AddPrefix",
"returns",
"a",
"context",
"with",
"the",
"given",
"prefix",
"added",
"to",
"end",
"of",
"the",
"existing",
"prefix"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/out/context.go#L20-L29 | train |
gopasspw/gopass | pkg/out/context.go | Prefix | func Prefix(ctx context.Context) string {
sv, ok := ctx.Value(ctxKeyPrefix).(string)
if !ok {
return ""
}
return sv
} | go | func Prefix(ctx context.Context) string {
sv, ok := ctx.Value(ctxKeyPrefix).(string)
if !ok {
return ""
}
return sv
} | [
"func",
"Prefix",
"(",
"ctx",
"context",
".",
"Context",
")",
"string",
"{",
"sv",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"ctxKeyPrefix",
")",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\"\"",
"\n",
"}",
"\n",
"return",
"sv",
"\n",
"}"
] | // Prefix returns the prefix or an empty string | [
"Prefix",
"returns",
"the",
"prefix",
"or",
"an",
"empty",
"string"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/out/context.go#L32-L38 | train |
gopasspw/gopass | pkg/out/context.go | WithHidden | func WithHidden(ctx context.Context, hidden bool) context.Context {
return context.WithValue(ctx, ctxKeyHidden, hidden)
} | go | func WithHidden(ctx context.Context, hidden bool) context.Context {
return context.WithValue(ctx, ctxKeyHidden, hidden)
} | [
"func",
"WithHidden",
"(",
"ctx",
"context",
".",
"Context",
",",
"hidden",
"bool",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"ctxKeyHidden",
",",
"hidden",
")",
"\n",
"}"
] | // WithHidden returns a context with the flag value for hidden set | [
"WithHidden",
"returns",
"a",
"context",
"with",
"the",
"flag",
"value",
"for",
"hidden",
"set"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/out/context.go#L41-L43 | train |
gopasspw/gopass | pkg/out/context.go | IsHidden | func IsHidden(ctx context.Context) bool {
bv, ok := ctx.Value(ctxKeyHidden).(bool)
if !ok {
return false
}
return bv
} | go | func IsHidden(ctx context.Context) bool {
bv, ok := ctx.Value(ctxKeyHidden).(bool)
if !ok {
return false
}
return bv
} | [
"func",
"IsHidden",
"(",
"ctx",
"context",
".",
"Context",
")",
"bool",
"{",
"bv",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"ctxKeyHidden",
")",
".",
"(",
"bool",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"bv",
"\n",
"}"
] | // IsHidden returns true if any output should be hidden in this context | [
"IsHidden",
"returns",
"true",
"if",
"any",
"output",
"should",
"be",
"hidden",
"in",
"this",
"context"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/out/context.go#L46-L52 | train |
gopasspw/gopass | pkg/out/context.go | WithNewline | func WithNewline(ctx context.Context, nl bool) context.Context {
return context.WithValue(ctx, ctxKeyNewline, nl)
} | go | func WithNewline(ctx context.Context, nl bool) context.Context {
return context.WithValue(ctx, ctxKeyNewline, nl)
} | [
"func",
"WithNewline",
"(",
"ctx",
"context",
".",
"Context",
",",
"nl",
"bool",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"ctxKeyNewline",
",",
"nl",
")",
"\n",
"}"
] | // WithNewline returns a context with the flag value for newline set | [
"WithNewline",
"returns",
"a",
"context",
"with",
"the",
"flag",
"value",
"for",
"newline",
"set"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/out/context.go#L55-L57 | train |
gopasspw/gopass | pkg/action/move.go | Move | func (s *Action) Move(ctx context.Context, c *cli.Context) error {
force := c.Bool("force")
if len(c.Args()) != 2 {
return ExitError(ctx, ExitUsage, nil, "Usage: %s mv old-path new-path", s.Name)
}
from := c.Args()[0]
to := c.Args()[1]
if !force {
if s.Store.Exists(ctx, to) && !termio.AskForConfirmation(ctx, fmt.Sprintf("%s already exists. Overwrite it?", to)) {
return ExitError(ctx, ExitAborted, nil, "not overwriting your current secret")
}
}
if err := s.Store.Move(ctx, from, to); err != nil {
return ExitError(ctx, ExitUnknown, err, "%s", err)
}
return nil
} | go | func (s *Action) Move(ctx context.Context, c *cli.Context) error {
force := c.Bool("force")
if len(c.Args()) != 2 {
return ExitError(ctx, ExitUsage, nil, "Usage: %s mv old-path new-path", s.Name)
}
from := c.Args()[0]
to := c.Args()[1]
if !force {
if s.Store.Exists(ctx, to) && !termio.AskForConfirmation(ctx, fmt.Sprintf("%s already exists. Overwrite it?", to)) {
return ExitError(ctx, ExitAborted, nil, "not overwriting your current secret")
}
}
if err := s.Store.Move(ctx, from, to); err != nil {
return ExitError(ctx, ExitUnknown, err, "%s", err)
}
return nil
} | [
"func",
"(",
"s",
"*",
"Action",
")",
"Move",
"(",
"ctx",
"context",
".",
"Context",
",",
"c",
"*",
"cli",
".",
"Context",
")",
"error",
"{",
"force",
":=",
"c",
".",
"Bool",
"(",
"\"force\"",
")",
"\n",
"if",
"len",
"(",
"c",
".",
"Args",
"(",
")",
")",
"!=",
"2",
"{",
"return",
"ExitError",
"(",
"ctx",
",",
"ExitUsage",
",",
"nil",
",",
"\"Usage: %s mv old-path new-path\"",
",",
"s",
".",
"Name",
")",
"\n",
"}",
"\n",
"from",
":=",
"c",
".",
"Args",
"(",
")",
"[",
"0",
"]",
"\n",
"to",
":=",
"c",
".",
"Args",
"(",
")",
"[",
"1",
"]",
"\n",
"if",
"!",
"force",
"{",
"if",
"s",
".",
"Store",
".",
"Exists",
"(",
"ctx",
",",
"to",
")",
"&&",
"!",
"termio",
".",
"AskForConfirmation",
"(",
"ctx",
",",
"fmt",
".",
"Sprintf",
"(",
"\"%s already exists. Overwrite it?\"",
",",
"to",
")",
")",
"{",
"return",
"ExitError",
"(",
"ctx",
",",
"ExitAborted",
",",
"nil",
",",
"\"not overwriting your current secret\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"err",
":=",
"s",
".",
"Store",
".",
"Move",
"(",
"ctx",
",",
"from",
",",
"to",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"ExitError",
"(",
"ctx",
",",
"ExitUnknown",
",",
"err",
",",
"\"%s\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Move the content from one secret to another | [
"Move",
"the",
"content",
"from",
"one",
"secret",
"to",
"another"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/move.go#L13-L34 | train |
gopasspw/gopass | pkg/config/secrets/config.go | New | func New(dir, passphrase string) (*Config, error) {
if dir == "" || dir == "." {
return nil, fmt.Errorf("dir must not be empty")
}
fn := filepath.Join(dir, filename)
c := &Config{
filename: fn,
passphrase: passphrase,
}
if !fsutil.IsFile(fn) {
err := save(c.filename, c.passphrase, map[string]string{})
return c, err
}
_, err := c.Get("")
if err != nil {
return nil, errors.Wrapf(err, "failed to open existing secrects config %s: %s", fn, err)
}
return c, nil
} | go | func New(dir, passphrase string) (*Config, error) {
if dir == "" || dir == "." {
return nil, fmt.Errorf("dir must not be empty")
}
fn := filepath.Join(dir, filename)
c := &Config{
filename: fn,
passphrase: passphrase,
}
if !fsutil.IsFile(fn) {
err := save(c.filename, c.passphrase, map[string]string{})
return c, err
}
_, err := c.Get("")
if err != nil {
return nil, errors.Wrapf(err, "failed to open existing secrects config %s: %s", fn, err)
}
return c, nil
} | [
"func",
"New",
"(",
"dir",
",",
"passphrase",
"string",
")",
"(",
"*",
"Config",
",",
"error",
")",
"{",
"if",
"dir",
"==",
"\"\"",
"||",
"dir",
"==",
"\".\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"dir must not be empty\"",
")",
"\n",
"}",
"\n",
"fn",
":=",
"filepath",
".",
"Join",
"(",
"dir",
",",
"filename",
")",
"\n",
"c",
":=",
"&",
"Config",
"{",
"filename",
":",
"fn",
",",
"passphrase",
":",
"passphrase",
",",
"}",
"\n",
"if",
"!",
"fsutil",
".",
"IsFile",
"(",
"fn",
")",
"{",
"err",
":=",
"save",
"(",
"c",
".",
"filename",
",",
"c",
".",
"passphrase",
",",
"map",
"[",
"string",
"]",
"string",
"{",
"}",
")",
"\n",
"return",
"c",
",",
"err",
"\n",
"}",
"\n",
"_",
",",
"err",
":=",
"c",
".",
"Get",
"(",
"\"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"failed to open existing secrects config %s: %s\"",
",",
"fn",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"c",
",",
"nil",
"\n",
"}"
] | // New will load the given file from disk and try to unseal it | [
"New",
"will",
"load",
"the",
"given",
"file",
"from",
"disk",
"and",
"try",
"to",
"unseal",
"it"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/config/secrets/config.go#L33-L54 | train |
gopasspw/gopass | pkg/config/secrets/config.go | Get | func (c *Config) Get(key string) (string, error) {
data, err := load(c.filename, c.passphrase)
return data[key], err
} | go | func (c *Config) Get(key string) (string, error) {
data, err := load(c.filename, c.passphrase)
return data[key], err
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"Get",
"(",
"key",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"data",
",",
"err",
":=",
"load",
"(",
"c",
".",
"filename",
",",
"c",
".",
"passphrase",
")",
"\n",
"return",
"data",
"[",
"key",
"]",
",",
"err",
"\n",
"}"
] | // Get loads the requested key from disk | [
"Get",
"loads",
"the",
"requested",
"key",
"from",
"disk"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/config/secrets/config.go#L57-L60 | train |
gopasspw/gopass | pkg/config/secrets/config.go | Set | func (c *Config) Set(key, value string) error {
data, err := load(c.filename, c.passphrase)
if err != nil {
return errors.Wrapf(err, "failed to read secrects config %s: %s", c.filename, err)
}
old := data[key]
if value == old {
return nil
}
data[key] = value
return save(c.filename, c.passphrase, data)
} | go | func (c *Config) Set(key, value string) error {
data, err := load(c.filename, c.passphrase)
if err != nil {
return errors.Wrapf(err, "failed to read secrects config %s: %s", c.filename, err)
}
old := data[key]
if value == old {
return nil
}
data[key] = value
return save(c.filename, c.passphrase, data)
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"Set",
"(",
"key",
",",
"value",
"string",
")",
"error",
"{",
"data",
",",
"err",
":=",
"load",
"(",
"c",
".",
"filename",
",",
"c",
".",
"passphrase",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"failed to read secrects config %s: %s\"",
",",
"c",
".",
"filename",
",",
"err",
")",
"\n",
"}",
"\n",
"old",
":=",
"data",
"[",
"key",
"]",
"\n",
"if",
"value",
"==",
"old",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"data",
"[",
"key",
"]",
"=",
"value",
"\n",
"return",
"save",
"(",
"c",
".",
"filename",
",",
"c",
".",
"passphrase",
",",
"data",
")",
"\n",
"}"
] | // Set writes the requested key to disk | [
"Set",
"writes",
"the",
"requested",
"key",
"to",
"disk"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/config/secrets/config.go#L63-L76 | train |
gopasspw/gopass | pkg/config/secrets/config.go | Unset | func (c *Config) Unset(key string) error {
data, err := load(c.filename, c.passphrase)
if err != nil {
return errors.Wrapf(err, "failed to read secrects config %s: %s", c.filename, err)
}
_, found := data[key]
if !found {
return nil
}
delete(data, key)
return save(c.filename, c.passphrase, data)
} | go | func (c *Config) Unset(key string) error {
data, err := load(c.filename, c.passphrase)
if err != nil {
return errors.Wrapf(err, "failed to read secrects config %s: %s", c.filename, err)
}
_, found := data[key]
if !found {
return nil
}
delete(data, key)
return save(c.filename, c.passphrase, data)
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"Unset",
"(",
"key",
"string",
")",
"error",
"{",
"data",
",",
"err",
":=",
"load",
"(",
"c",
".",
"filename",
",",
"c",
".",
"passphrase",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"failed to read secrects config %s: %s\"",
",",
"c",
".",
"filename",
",",
"err",
")",
"\n",
"}",
"\n",
"_",
",",
"found",
":=",
"data",
"[",
"key",
"]",
"\n",
"if",
"!",
"found",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"delete",
"(",
"data",
",",
"key",
")",
"\n",
"return",
"save",
"(",
"c",
".",
"filename",
",",
"c",
".",
"passphrase",
",",
"data",
")",
"\n",
"}"
] | // Unset removes the key from the storage | [
"Unset",
"removes",
"the",
"key",
"from",
"the",
"storage"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/config/secrets/config.go#L79-L92 | train |
gopasspw/gopass | pkg/config/secrets/config.go | open | func open(buf []byte, passphrase string) (map[string]string, error) {
salt := make([]byte, saltLength)
copy(salt, buf[:saltLength])
var nonce [nonceLength]byte
copy(nonce[:], buf[saltLength:nonceLength+saltLength])
secretKey := deriveKey(passphrase, salt)
decrypted, ok := secretbox.Open(nil, buf[nonceLength+saltLength:], &nonce, &secretKey)
if !ok {
return nil, fmt.Errorf("failed to decrypt")
}
data := map[string]string{}
if err := json.Unmarshal(decrypted, &data); err != nil {
return nil, err
}
return data, nil
} | go | func open(buf []byte, passphrase string) (map[string]string, error) {
salt := make([]byte, saltLength)
copy(salt, buf[:saltLength])
var nonce [nonceLength]byte
copy(nonce[:], buf[saltLength:nonceLength+saltLength])
secretKey := deriveKey(passphrase, salt)
decrypted, ok := secretbox.Open(nil, buf[nonceLength+saltLength:], &nonce, &secretKey)
if !ok {
return nil, fmt.Errorf("failed to decrypt")
}
data := map[string]string{}
if err := json.Unmarshal(decrypted, &data); err != nil {
return nil, err
}
return data, nil
} | [
"func",
"open",
"(",
"buf",
"[",
"]",
"byte",
",",
"passphrase",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"salt",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"saltLength",
")",
"\n",
"copy",
"(",
"salt",
",",
"buf",
"[",
":",
"saltLength",
"]",
")",
"\n",
"var",
"nonce",
"[",
"nonceLength",
"]",
"byte",
"\n",
"copy",
"(",
"nonce",
"[",
":",
"]",
",",
"buf",
"[",
"saltLength",
":",
"nonceLength",
"+",
"saltLength",
"]",
")",
"\n",
"secretKey",
":=",
"deriveKey",
"(",
"passphrase",
",",
"salt",
")",
"\n",
"decrypted",
",",
"ok",
":=",
"secretbox",
".",
"Open",
"(",
"nil",
",",
"buf",
"[",
"nonceLength",
"+",
"saltLength",
":",
"]",
",",
"&",
"nonce",
",",
"&",
"secretKey",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"failed to decrypt\"",
")",
"\n",
"}",
"\n",
"data",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"decrypted",
",",
"&",
"data",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"data",
",",
"nil",
"\n",
"}"
] | // open will try to unseal the given buffer | [
"open",
"will",
"try",
"to",
"unseal",
"the",
"given",
"buffer"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/config/secrets/config.go#L103-L118 | train |
gopasspw/gopass | pkg/config/secrets/config.go | save | func save(filename, passphrase string, data map[string]string) error {
buf, err := seal(data, passphrase)
if err != nil {
return err
}
return ioutil.WriteFile(filename, buf, 0600)
} | go | func save(filename, passphrase string, data map[string]string) error {
buf, err := seal(data, passphrase)
if err != nil {
return err
}
return ioutil.WriteFile(filename, buf, 0600)
} | [
"func",
"save",
"(",
"filename",
",",
"passphrase",
"string",
",",
"data",
"map",
"[",
"string",
"]",
"string",
")",
"error",
"{",
"buf",
",",
"err",
":=",
"seal",
"(",
"data",
",",
"passphrase",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"ioutil",
".",
"WriteFile",
"(",
"filename",
",",
"buf",
",",
"0600",
")",
"\n",
"}"
] | // save will try to marshal, seal and write to disk | [
"save",
"will",
"try",
"to",
"marshal",
"seal",
"and",
"write",
"to",
"disk"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/config/secrets/config.go#L121-L127 | train |
gopasspw/gopass | pkg/config/secrets/config.go | seal | func seal(data map[string]string, passphrase string) ([]byte, error) {
jstr, err := json.Marshal(data)
if err != nil {
return nil, err
}
var nonce [nonceLength]byte
if _, err := io.ReadFull(crypto_rand.Reader, nonce[:]); err != nil {
return nil, err
}
salt := make([]byte, saltLength)
if _, err := crypto_rand.Read(salt); err != nil {
return nil, err
}
secretKey := deriveKey(passphrase, salt)
prefix := append(salt, nonce[:]...)
return secretbox.Seal(prefix, jstr, &nonce, &secretKey), nil
} | go | func seal(data map[string]string, passphrase string) ([]byte, error) {
jstr, err := json.Marshal(data)
if err != nil {
return nil, err
}
var nonce [nonceLength]byte
if _, err := io.ReadFull(crypto_rand.Reader, nonce[:]); err != nil {
return nil, err
}
salt := make([]byte, saltLength)
if _, err := crypto_rand.Read(salt); err != nil {
return nil, err
}
secretKey := deriveKey(passphrase, salt)
prefix := append(salt, nonce[:]...)
return secretbox.Seal(prefix, jstr, &nonce, &secretKey), nil
} | [
"func",
"seal",
"(",
"data",
"map",
"[",
"string",
"]",
"string",
",",
"passphrase",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"jstr",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"data",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"nonce",
"[",
"nonceLength",
"]",
"byte",
"\n",
"if",
"_",
",",
"err",
":=",
"io",
".",
"ReadFull",
"(",
"crypto_rand",
".",
"Reader",
",",
"nonce",
"[",
":",
"]",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"salt",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"saltLength",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"crypto_rand",
".",
"Read",
"(",
"salt",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"secretKey",
":=",
"deriveKey",
"(",
"passphrase",
",",
"salt",
")",
"\n",
"prefix",
":=",
"append",
"(",
"salt",
",",
"nonce",
"[",
":",
"]",
"...",
")",
"\n",
"return",
"secretbox",
".",
"Seal",
"(",
"prefix",
",",
"jstr",
",",
"&",
"nonce",
",",
"&",
"secretKey",
")",
",",
"nil",
"\n",
"}"
] | // seal will try to marshal and seal the given data | [
"seal",
"will",
"try",
"to",
"marshal",
"and",
"seal",
"the",
"given",
"data"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/config/secrets/config.go#L130-L146 | train |
gopasspw/gopass | pkg/cui/recipients.go | AskForPrivateKey | func AskForPrivateKey(ctx context.Context, crypto backend.Crypto, name, prompt string) (string, error) {
if !ctxutil.IsInteractive(ctx) {
return "", errors.New("can not select private key without terminal")
}
if crypto == nil {
return "", errors.New("can not select private key without valid crypto backend")
}
kl, err := crypto.ListPrivateKeyIDs(gpg.WithAlwaysTrust(ctx, false))
if err != nil {
return "", err
}
if len(kl) < 1 {
return "", errors.New("no useable private keys found")
}
for i := 0; i < maxTries; i++ {
if !ctxutil.IsTerminal(ctx) {
return kl[0], nil
}
// check for context cancelation
select {
case <-ctx.Done():
return "", errors.New("user aborted")
default:
}
fmt.Fprintln(Stdout, prompt)
for i, k := range kl {
fmt.Fprintf(Stdout, "[%d] %s - %s\n", i, crypto.Name(), crypto.FormatKey(ctx, k))
}
iv, err := termio.AskForInt(ctx, fmt.Sprintf("Please enter the number of a key (0-%d, [q]uit)", len(kl)-1), 0)
if err != nil {
if err.Error() == "user aborted" {
return "", err
}
continue
}
if iv >= 0 && iv < len(kl) {
return kl[iv], nil
}
}
return "", errors.New("no valid user input")
} | go | func AskForPrivateKey(ctx context.Context, crypto backend.Crypto, name, prompt string) (string, error) {
if !ctxutil.IsInteractive(ctx) {
return "", errors.New("can not select private key without terminal")
}
if crypto == nil {
return "", errors.New("can not select private key without valid crypto backend")
}
kl, err := crypto.ListPrivateKeyIDs(gpg.WithAlwaysTrust(ctx, false))
if err != nil {
return "", err
}
if len(kl) < 1 {
return "", errors.New("no useable private keys found")
}
for i := 0; i < maxTries; i++ {
if !ctxutil.IsTerminal(ctx) {
return kl[0], nil
}
// check for context cancelation
select {
case <-ctx.Done():
return "", errors.New("user aborted")
default:
}
fmt.Fprintln(Stdout, prompt)
for i, k := range kl {
fmt.Fprintf(Stdout, "[%d] %s - %s\n", i, crypto.Name(), crypto.FormatKey(ctx, k))
}
iv, err := termio.AskForInt(ctx, fmt.Sprintf("Please enter the number of a key (0-%d, [q]uit)", len(kl)-1), 0)
if err != nil {
if err.Error() == "user aborted" {
return "", err
}
continue
}
if iv >= 0 && iv < len(kl) {
return kl[iv], nil
}
}
return "", errors.New("no valid user input")
} | [
"func",
"AskForPrivateKey",
"(",
"ctx",
"context",
".",
"Context",
",",
"crypto",
"backend",
".",
"Crypto",
",",
"name",
",",
"prompt",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"!",
"ctxutil",
".",
"IsInteractive",
"(",
"ctx",
")",
"{",
"return",
"\"\"",
",",
"errors",
".",
"New",
"(",
"\"can not select private key without terminal\"",
")",
"\n",
"}",
"\n",
"if",
"crypto",
"==",
"nil",
"{",
"return",
"\"\"",
",",
"errors",
".",
"New",
"(",
"\"can not select private key without valid crypto backend\"",
")",
"\n",
"}",
"\n",
"kl",
",",
"err",
":=",
"crypto",
".",
"ListPrivateKeyIDs",
"(",
"gpg",
".",
"WithAlwaysTrust",
"(",
"ctx",
",",
"false",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"kl",
")",
"<",
"1",
"{",
"return",
"\"\"",
",",
"errors",
".",
"New",
"(",
"\"no useable private keys found\"",
")",
"\n",
"}",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"maxTries",
";",
"i",
"++",
"{",
"if",
"!",
"ctxutil",
".",
"IsTerminal",
"(",
"ctx",
")",
"{",
"return",
"kl",
"[",
"0",
"]",
",",
"nil",
"\n",
"}",
"\n",
"select",
"{",
"case",
"<-",
"ctx",
".",
"Done",
"(",
")",
":",
"return",
"\"\"",
",",
"errors",
".",
"New",
"(",
"\"user aborted\"",
")",
"\n",
"default",
":",
"}",
"\n",
"fmt",
".",
"Fprintln",
"(",
"Stdout",
",",
"prompt",
")",
"\n",
"for",
"i",
",",
"k",
":=",
"range",
"kl",
"{",
"fmt",
".",
"Fprintf",
"(",
"Stdout",
",",
"\"[%d] %s - %s\\n\"",
",",
"\\n",
",",
"i",
",",
"crypto",
".",
"Name",
"(",
")",
")",
"\n",
"}",
"\n",
"crypto",
".",
"FormatKey",
"(",
"ctx",
",",
"k",
")",
"\n",
"iv",
",",
"err",
":=",
"termio",
".",
"AskForInt",
"(",
"ctx",
",",
"fmt",
".",
"Sprintf",
"(",
"\"Please enter the number of a key (0-%d, [q]uit)\"",
",",
"len",
"(",
"kl",
")",
"-",
"1",
")",
",",
"0",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"err",
".",
"Error",
"(",
")",
"==",
"\"user aborted\"",
"{",
"return",
"\"\"",
",",
"err",
"\n",
"}",
"\n",
"continue",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"iv",
">=",
"0",
"&&",
"iv",
"<",
"len",
"(",
"kl",
")",
"{",
"return",
"kl",
"[",
"iv",
"]",
",",
"nil",
"\n",
"}",
"\n",
"}"
] | // AskForPrivateKey promts the user to select from a list of private keys | [
"AskForPrivateKey",
"promts",
"the",
"user",
"to",
"select",
"from",
"a",
"list",
"of",
"private",
"keys"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/cui/recipients.go#L184-L228 | train |
gopasspw/gopass | pkg/backend/crypto/xc/keyring/secring.go | NewSecring | func NewSecring() *Secring {
return &Secring{
data: &xcpb.Secring{
PrivateKeys: make([]*xcpb.PrivateKey, 0, 10),
},
}
} | go | func NewSecring() *Secring {
return &Secring{
data: &xcpb.Secring{
PrivateKeys: make([]*xcpb.PrivateKey, 0, 10),
},
}
} | [
"func",
"NewSecring",
"(",
")",
"*",
"Secring",
"{",
"return",
"&",
"Secring",
"{",
"data",
":",
"&",
"xcpb",
".",
"Secring",
"{",
"PrivateKeys",
":",
"make",
"(",
"[",
"]",
"*",
"xcpb",
".",
"PrivateKey",
",",
"0",
",",
"10",
")",
",",
"}",
",",
"}",
"\n",
"}"
] | // NewSecring initializes and a new secring | [
"NewSecring",
"initializes",
"and",
"a",
"new",
"secring"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/keyring/secring.go#L26-L32 | train |
gopasspw/gopass | pkg/backend/crypto/xc/keyring/secring.go | LoadSecring | func LoadSecring(file string) (*Secring, error) {
pr := NewSecring()
pr.File = file
buf, err := ioutil.ReadFile(file)
if os.IsNotExist(err) {
return pr, nil
}
if err != nil {
return nil, err
}
if err := proto.Unmarshal(buf, pr.data); err != nil {
return nil, err
}
return pr, nil
} | go | func LoadSecring(file string) (*Secring, error) {
pr := NewSecring()
pr.File = file
buf, err := ioutil.ReadFile(file)
if os.IsNotExist(err) {
return pr, nil
}
if err != nil {
return nil, err
}
if err := proto.Unmarshal(buf, pr.data); err != nil {
return nil, err
}
return pr, nil
} | [
"func",
"LoadSecring",
"(",
"file",
"string",
")",
"(",
"*",
"Secring",
",",
"error",
")",
"{",
"pr",
":=",
"NewSecring",
"(",
")",
"\n",
"pr",
".",
"File",
"=",
"file",
"\n",
"buf",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"file",
")",
"\n",
"if",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"{",
"return",
"pr",
",",
"nil",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"proto",
".",
"Unmarshal",
"(",
"buf",
",",
"pr",
".",
"data",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"pr",
",",
"nil",
"\n",
"}"
] | // LoadSecring loads an existing secring from disk. If the file is not found
// an empty keyring is returned | [
"LoadSecring",
"loads",
"an",
"existing",
"secring",
"from",
"disk",
".",
"If",
"the",
"file",
"is",
"not",
"found",
"an",
"empty",
"keyring",
"is",
"returned"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/keyring/secring.go#L36-L53 | train |
gopasspw/gopass | pkg/backend/crypto/xc/keyring/secring.go | Contains | func (p *Secring) Contains(fp string) bool {
p.Lock()
defer p.Unlock()
for _, pk := range p.data.PrivateKeys {
if pk.PublicKey.Fingerprint == fp {
return true
}
}
return false
} | go | func (p *Secring) Contains(fp string) bool {
p.Lock()
defer p.Unlock()
for _, pk := range p.data.PrivateKeys {
if pk.PublicKey.Fingerprint == fp {
return true
}
}
return false
} | [
"func",
"(",
"p",
"*",
"Secring",
")",
"Contains",
"(",
"fp",
"string",
")",
"bool",
"{",
"p",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"Unlock",
"(",
")",
"\n",
"for",
"_",
",",
"pk",
":=",
"range",
"p",
".",
"data",
".",
"PrivateKeys",
"{",
"if",
"pk",
".",
"PublicKey",
".",
"Fingerprint",
"==",
"fp",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // Contains returns true if the given key is found in the keyring | [
"Contains",
"returns",
"true",
"if",
"the",
"given",
"key",
"is",
"found",
"in",
"the",
"keyring"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/keyring/secring.go#L68-L78 | train |
gopasspw/gopass | pkg/backend/crypto/xc/keyring/secring.go | KeyIDs | func (p *Secring) KeyIDs() []string {
p.Lock()
defer p.Unlock()
ids := make([]string, 0, len(p.data.PrivateKeys))
for _, pk := range p.data.PrivateKeys {
ids = append(ids, pk.PublicKey.Fingerprint)
}
sort.Strings(ids)
return ids
} | go | func (p *Secring) KeyIDs() []string {
p.Lock()
defer p.Unlock()
ids := make([]string, 0, len(p.data.PrivateKeys))
for _, pk := range p.data.PrivateKeys {
ids = append(ids, pk.PublicKey.Fingerprint)
}
sort.Strings(ids)
return ids
} | [
"func",
"(",
"p",
"*",
"Secring",
")",
"KeyIDs",
"(",
")",
"[",
"]",
"string",
"{",
"p",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"Unlock",
"(",
")",
"\n",
"ids",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"p",
".",
"data",
".",
"PrivateKeys",
")",
")",
"\n",
"for",
"_",
",",
"pk",
":=",
"range",
"p",
".",
"data",
".",
"PrivateKeys",
"{",
"ids",
"=",
"append",
"(",
"ids",
",",
"pk",
".",
"PublicKey",
".",
"Fingerprint",
")",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"ids",
")",
"\n",
"return",
"ids",
"\n",
"}"
] | // KeyIDs returns a list of key IDs | [
"KeyIDs",
"returns",
"a",
"list",
"of",
"key",
"IDs"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/keyring/secring.go#L81-L91 | train |
gopasspw/gopass | pkg/backend/crypto/xc/keyring/secring.go | Export | func (p *Secring) Export(id string, withPrivate bool) ([]byte, error) {
p.Lock()
defer p.Unlock()
xpk := p.fetch(id)
if xpk == nil {
return nil, fmt.Errorf("key not found")
}
if withPrivate {
return proto.Marshal(xpk)
}
return proto.Marshal(xpk.PublicKey)
} | go | func (p *Secring) Export(id string, withPrivate bool) ([]byte, error) {
p.Lock()
defer p.Unlock()
xpk := p.fetch(id)
if xpk == nil {
return nil, fmt.Errorf("key not found")
}
if withPrivate {
return proto.Marshal(xpk)
}
return proto.Marshal(xpk.PublicKey)
} | [
"func",
"(",
"p",
"*",
"Secring",
")",
"Export",
"(",
"id",
"string",
",",
"withPrivate",
"bool",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"p",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"Unlock",
"(",
")",
"\n",
"xpk",
":=",
"p",
".",
"fetch",
"(",
"id",
")",
"\n",
"if",
"xpk",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"key not found\"",
")",
"\n",
"}",
"\n",
"if",
"withPrivate",
"{",
"return",
"proto",
".",
"Marshal",
"(",
"xpk",
")",
"\n",
"}",
"\n",
"return",
"proto",
".",
"Marshal",
"(",
"xpk",
".",
"PublicKey",
")",
"\n",
"}"
] | // Export marshals a single private key | [
"Export",
"marshals",
"a",
"single",
"private",
"key"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/keyring/secring.go#L94-L107 | train |
gopasspw/gopass | pkg/backend/crypto/xc/keyring/secring.go | Import | func (p *Secring) Import(buf []byte) error {
pk := &xcpb.PrivateKey{}
if err := proto.Unmarshal(buf, pk); err != nil {
return err
}
p.insert(pk)
return nil
} | go | func (p *Secring) Import(buf []byte) error {
pk := &xcpb.PrivateKey{}
if err := proto.Unmarshal(buf, pk); err != nil {
return err
}
p.insert(pk)
return nil
} | [
"func",
"(",
"p",
"*",
"Secring",
")",
"Import",
"(",
"buf",
"[",
"]",
"byte",
")",
"error",
"{",
"pk",
":=",
"&",
"xcpb",
".",
"PrivateKey",
"{",
"}",
"\n",
"if",
"err",
":=",
"proto",
".",
"Unmarshal",
"(",
"buf",
",",
"pk",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"p",
".",
"insert",
"(",
"pk",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Import unmarshals and imports a previously exported key | [
"Import",
"unmarshals",
"and",
"imports",
"a",
"previously",
"exported",
"key"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/keyring/secring.go#L132-L140 | train |
gopasspw/gopass | pkg/backend/crypto/xc/keyring/secring.go | Set | func (p *Secring) Set(pk *PrivateKey) error {
if !pk.Encrypted {
return fmt.Errorf("private key must be encrypted")
}
p.Lock()
defer p.Unlock()
p.insert(secKRToPB(pk))
return nil
} | go | func (p *Secring) Set(pk *PrivateKey) error {
if !pk.Encrypted {
return fmt.Errorf("private key must be encrypted")
}
p.Lock()
defer p.Unlock()
p.insert(secKRToPB(pk))
return nil
} | [
"func",
"(",
"p",
"*",
"Secring",
")",
"Set",
"(",
"pk",
"*",
"PrivateKey",
")",
"error",
"{",
"if",
"!",
"pk",
".",
"Encrypted",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"private key must be encrypted\"",
")",
"\n",
"}",
"\n",
"p",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"Unlock",
"(",
")",
"\n",
"p",
".",
"insert",
"(",
"secKRToPB",
"(",
"pk",
")",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Set inserts a single key | [
"Set",
"inserts",
"a",
"single",
"key"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/keyring/secring.go#L143-L153 | train |
gopasspw/gopass | pkg/backend/crypto/xc/keyring/secring.go | Remove | func (p *Secring) Remove(id string) error {
p.Lock()
defer p.Unlock()
match := -1
for i, pk := range p.data.PrivateKeys {
if pk.PublicKey.Fingerprint == id {
match = i
break
}
}
if match < 0 || match > len(p.data.PrivateKeys) {
return fmt.Errorf("not found")
}
p.data.PrivateKeys = append(p.data.PrivateKeys[:match], p.data.PrivateKeys[match+1:]...)
return nil
} | go | func (p *Secring) Remove(id string) error {
p.Lock()
defer p.Unlock()
match := -1
for i, pk := range p.data.PrivateKeys {
if pk.PublicKey.Fingerprint == id {
match = i
break
}
}
if match < 0 || match > len(p.data.PrivateKeys) {
return fmt.Errorf("not found")
}
p.data.PrivateKeys = append(p.data.PrivateKeys[:match], p.data.PrivateKeys[match+1:]...)
return nil
} | [
"func",
"(",
"p",
"*",
"Secring",
")",
"Remove",
"(",
"id",
"string",
")",
"error",
"{",
"p",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"Unlock",
"(",
")",
"\n",
"match",
":=",
"-",
"1",
"\n",
"for",
"i",
",",
"pk",
":=",
"range",
"p",
".",
"data",
".",
"PrivateKeys",
"{",
"if",
"pk",
".",
"PublicKey",
".",
"Fingerprint",
"==",
"id",
"{",
"match",
"=",
"i",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"match",
"<",
"0",
"||",
"match",
">",
"len",
"(",
"p",
".",
"data",
".",
"PrivateKeys",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"not found\"",
")",
"\n",
"}",
"\n",
"p",
".",
"data",
".",
"PrivateKeys",
"=",
"append",
"(",
"p",
".",
"data",
".",
"PrivateKeys",
"[",
":",
"match",
"]",
",",
"p",
".",
"data",
".",
"PrivateKeys",
"[",
"match",
"+",
"1",
":",
"]",
"...",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Remove deletes the given key | [
"Remove",
"deletes",
"the",
"given",
"key"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/keyring/secring.go#L166-L182 | train |
gopasspw/gopass | pkg/action/sync.go | Sync | func (s *Action) Sync(ctx context.Context, c *cli.Context) error {
store := c.String("store")
return s.sync(ctx, c, store)
} | go | func (s *Action) Sync(ctx context.Context, c *cli.Context) error {
store := c.String("store")
return s.sync(ctx, c, store)
} | [
"func",
"(",
"s",
"*",
"Action",
")",
"Sync",
"(",
"ctx",
"context",
".",
"Context",
",",
"c",
"*",
"cli",
".",
"Context",
")",
"error",
"{",
"store",
":=",
"c",
".",
"String",
"(",
"\"store\"",
")",
"\n",
"return",
"s",
".",
"sync",
"(",
"ctx",
",",
"c",
",",
"store",
")",
"\n",
"}"
] | // Sync all stores with their remotes | [
"Sync",
"all",
"stores",
"with",
"their",
"remotes"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/sync.go#L18-L21 | train |
gopasspw/gopass | pkg/backend/rcs/git/cli/git.go | Open | func Open(path, gpg string) (*Git, error) {
if !fsutil.IsDir(filepath.Join(path, ".git")) {
return nil, fmt.Errorf("git repo does not exist")
}
return &Git{
path: path,
}, nil
} | go | func Open(path, gpg string) (*Git, error) {
if !fsutil.IsDir(filepath.Join(path, ".git")) {
return nil, fmt.Errorf("git repo does not exist")
}
return &Git{
path: path,
}, nil
} | [
"func",
"Open",
"(",
"path",
",",
"gpg",
"string",
")",
"(",
"*",
"Git",
",",
"error",
")",
"{",
"if",
"!",
"fsutil",
".",
"IsDir",
"(",
"filepath",
".",
"Join",
"(",
"path",
",",
"\".git\"",
")",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"git repo does not exist\"",
")",
"\n",
"}",
"\n",
"return",
"&",
"Git",
"{",
"path",
":",
"path",
",",
"}",
",",
"nil",
"\n",
"}"
] | // Open creates a new git cli based git backend | [
"Open",
"creates",
"a",
"new",
"git",
"cli",
"based",
"git",
"backend"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/cli/git.go#L31-L38 | train |
gopasspw/gopass | pkg/backend/rcs/git/cli/git.go | Clone | func Clone(ctx context.Context, repo, path string) (*Git, error) {
g := &Git{
path: filepath.Dir(path),
}
if err := g.Cmd(ctx, "Clone", "clone", repo, path); err != nil {
return nil, err
}
g.path = path
return g, nil
} | go | func Clone(ctx context.Context, repo, path string) (*Git, error) {
g := &Git{
path: filepath.Dir(path),
}
if err := g.Cmd(ctx, "Clone", "clone", repo, path); err != nil {
return nil, err
}
g.path = path
return g, nil
} | [
"func",
"Clone",
"(",
"ctx",
"context",
".",
"Context",
",",
"repo",
",",
"path",
"string",
")",
"(",
"*",
"Git",
",",
"error",
")",
"{",
"g",
":=",
"&",
"Git",
"{",
"path",
":",
"filepath",
".",
"Dir",
"(",
"path",
")",
",",
"}",
"\n",
"if",
"err",
":=",
"g",
".",
"Cmd",
"(",
"ctx",
",",
"\"Clone\"",
",",
"\"clone\"",
",",
"repo",
",",
"path",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"g",
".",
"path",
"=",
"path",
"\n",
"return",
"g",
",",
"nil",
"\n",
"}"
] | // Clone clones an existing git repo and returns a new cli based git backend
// configured for this clone repo | [
"Clone",
"clones",
"an",
"existing",
"git",
"repo",
"and",
"returns",
"a",
"new",
"cli",
"based",
"git",
"backend",
"configured",
"for",
"this",
"clone",
"repo"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/cli/git.go#L42-L51 | train |
gopasspw/gopass | pkg/backend/rcs/git/cli/git.go | Init | func Init(ctx context.Context, path, userName, userEmail string) (*Git, error) {
g := &Git{
path: path,
}
// the git repo may be empty (i.e. no branches, cloned from a fresh remote)
// or already initialized. Only run git init if the folder is completely empty
if !g.IsInitialized() {
if err := g.Cmd(ctx, "Init", "init"); err != nil {
return nil, errors.Errorf("failed to initialize git: %s", err)
}
out.Red(ctx, "git initialized at %s", g.path)
}
if !ctxutil.IsGitInit(ctx) {
return g, nil
}
// initialize the local git config
if err := g.InitConfig(ctx, userName, userEmail); err != nil {
return g, errors.Errorf("failed to configure git: %s", err)
}
out.Red(ctx, "git configured at %s", g.path)
// 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 g, errors.Wrapf(err, "failed to commit changes to git")
}
return g, nil
} | go | func Init(ctx context.Context, path, userName, userEmail string) (*Git, error) {
g := &Git{
path: path,
}
// the git repo may be empty (i.e. no branches, cloned from a fresh remote)
// or already initialized. Only run git init if the folder is completely empty
if !g.IsInitialized() {
if err := g.Cmd(ctx, "Init", "init"); err != nil {
return nil, errors.Errorf("failed to initialize git: %s", err)
}
out.Red(ctx, "git initialized at %s", g.path)
}
if !ctxutil.IsGitInit(ctx) {
return g, nil
}
// initialize the local git config
if err := g.InitConfig(ctx, userName, userEmail); err != nil {
return g, errors.Errorf("failed to configure git: %s", err)
}
out.Red(ctx, "git configured at %s", g.path)
// 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 g, errors.Wrapf(err, "failed to commit changes to git")
}
return g, nil
} | [
"func",
"Init",
"(",
"ctx",
"context",
".",
"Context",
",",
"path",
",",
"userName",
",",
"userEmail",
"string",
")",
"(",
"*",
"Git",
",",
"error",
")",
"{",
"g",
":=",
"&",
"Git",
"{",
"path",
":",
"path",
",",
"}",
"\n",
"if",
"!",
"g",
".",
"IsInitialized",
"(",
")",
"{",
"if",
"err",
":=",
"g",
".",
"Cmd",
"(",
"ctx",
",",
"\"Init\"",
",",
"\"init\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"failed to initialize git: %s\"",
",",
"err",
")",
"\n",
"}",
"\n",
"out",
".",
"Red",
"(",
"ctx",
",",
"\"git initialized at %s\"",
",",
"g",
".",
"path",
")",
"\n",
"}",
"\n",
"if",
"!",
"ctxutil",
".",
"IsGitInit",
"(",
"ctx",
")",
"{",
"return",
"g",
",",
"nil",
"\n",
"}",
"\n",
"if",
"err",
":=",
"g",
".",
"InitConfig",
"(",
"ctx",
",",
"userName",
",",
"userEmail",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"g",
",",
"errors",
".",
"Errorf",
"(",
"\"failed to configure git: %s\"",
",",
"err",
")",
"\n",
"}",
"\n",
"out",
".",
"Red",
"(",
"ctx",
",",
"\"git configured at %s\"",
",",
"g",
".",
"path",
")",
"\n",
"if",
"err",
":=",
"g",
".",
"Add",
"(",
"ctx",
",",
"g",
".",
"path",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"g",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"failed to add '%s' to git\"",
",",
"g",
".",
"path",
")",
"\n",
"}",
"\n",
"if",
"!",
"g",
".",
"HasStagedChanges",
"(",
"ctx",
")",
"{",
"out",
".",
"Debug",
"(",
"ctx",
",",
"\"No staged changes\"",
")",
"\n",
"return",
"g",
",",
"nil",
"\n",
"}",
"\n",
"if",
"err",
":=",
"g",
".",
"Commit",
"(",
"ctx",
",",
"\"Add current content of password store\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"g",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"failed to commit changes to git\"",
")",
"\n",
"}",
"\n",
"return",
"g",
",",
"nil",
"\n",
"}"
] | // Init initializes this store's git repo | [
"Init",
"initializes",
"this",
"store",
"s",
"git",
"repo"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/cli/git.go#L54-L93 | train |
gopasspw/gopass | pkg/backend/rcs/git/cli/git.go | Cmd | func (g *Git) Cmd(ctx context.Context, name string, args ...string) error {
stdout, stderr, err := g.captureCmd(ctx, name, args...)
if err != nil {
out.Debug(ctx, "Output:\n Stdout: '%s'\n Stderr: '%s'", string(stdout), string(stderr))
return err
}
return nil
} | go | func (g *Git) Cmd(ctx context.Context, name string, args ...string) error {
stdout, stderr, err := g.captureCmd(ctx, name, args...)
if err != nil {
out.Debug(ctx, "Output:\n Stdout: '%s'\n Stderr: '%s'", string(stdout), string(stderr))
return err
}
return nil
} | [
"func",
"(",
"g",
"*",
"Git",
")",
"Cmd",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
"string",
",",
"args",
"...",
"string",
")",
"error",
"{",
"stdout",
",",
"stderr",
",",
"err",
":=",
"g",
".",
"captureCmd",
"(",
"ctx",
",",
"name",
",",
"args",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"out",
".",
"Debug",
"(",
"ctx",
",",
"\"Output:\\n Stdout: '%s'\\n Stderr: '%s'\"",
",",
"\\n",
",",
"\\n",
")",
"\n",
"string",
"(",
"stdout",
")",
"\n",
"}",
"\n",
"string",
"(",
"stderr",
")",
"\n",
"}"
] | // Cmd runs an git command | [
"Cmd",
"runs",
"an",
"git",
"command"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/cli/git.go#L115-L123 | train |
gopasspw/gopass | pkg/backend/rcs/git/cli/git.go | Version | func (g *Git) Version(ctx context.Context) semver.Version {
v := semver.Version{}
cmd := exec.CommandContext(ctx, "git", "version")
cmdout, err := cmd.Output()
if err != nil {
out.Debug(ctx, "Failed to run 'git version': %s", err)
return v
}
svStr := strings.TrimPrefix(string(cmdout), "git version ")
if p := strings.Fields(svStr); len(p) > 0 {
svStr = p[0]
}
sv, err := semver.ParseTolerant(svStr)
if err != nil {
out.Debug(ctx, "Failed to parse '%s' as semver: %s", svStr, err)
return v
}
return sv
} | go | func (g *Git) Version(ctx context.Context) semver.Version {
v := semver.Version{}
cmd := exec.CommandContext(ctx, "git", "version")
cmdout, err := cmd.Output()
if err != nil {
out.Debug(ctx, "Failed to run 'git version': %s", err)
return v
}
svStr := strings.TrimPrefix(string(cmdout), "git version ")
if p := strings.Fields(svStr); len(p) > 0 {
svStr = p[0]
}
sv, err := semver.ParseTolerant(svStr)
if err != nil {
out.Debug(ctx, "Failed to parse '%s' as semver: %s", svStr, err)
return v
}
return sv
} | [
"func",
"(",
"g",
"*",
"Git",
")",
"Version",
"(",
"ctx",
"context",
".",
"Context",
")",
"semver",
".",
"Version",
"{",
"v",
":=",
"semver",
".",
"Version",
"{",
"}",
"\n",
"cmd",
":=",
"exec",
".",
"CommandContext",
"(",
"ctx",
",",
"\"git\"",
",",
"\"version\"",
")",
"\n",
"cmdout",
",",
"err",
":=",
"cmd",
".",
"Output",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"out",
".",
"Debug",
"(",
"ctx",
",",
"\"Failed to run 'git version': %s\"",
",",
"err",
")",
"\n",
"return",
"v",
"\n",
"}",
"\n",
"svStr",
":=",
"strings",
".",
"TrimPrefix",
"(",
"string",
"(",
"cmdout",
")",
",",
"\"git version \"",
")",
"\n",
"if",
"p",
":=",
"strings",
".",
"Fields",
"(",
"svStr",
")",
";",
"len",
"(",
"p",
")",
">",
"0",
"{",
"svStr",
"=",
"p",
"[",
"0",
"]",
"\n",
"}",
"\n",
"sv",
",",
"err",
":=",
"semver",
".",
"ParseTolerant",
"(",
"svStr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"out",
".",
"Debug",
"(",
"ctx",
",",
"\"Failed to parse '%s' as semver: %s\"",
",",
"svStr",
",",
"err",
")",
"\n",
"return",
"v",
"\n",
"}",
"\n",
"return",
"sv",
"\n",
"}"
] | // Version returns the git version as major, minor and patch level | [
"Version",
"returns",
"the",
"git",
"version",
"as",
"major",
"minor",
"and",
"patch",
"level"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/cli/git.go#L131-L152 | train |
gopasspw/gopass | pkg/backend/rcs/git/cli/git.go | Add | func (g *Git) Add(ctx context.Context, files ...string) error {
if !g.IsInitialized() {
return store.ErrGitNotInit
}
for i := range files {
files[i] = strings.TrimPrefix(files[i], g.path+"/")
}
args := []string{"add", "--all", "--force"}
args = append(args, files...)
return g.Cmd(ctx, "gitAdd", args...)
} | go | func (g *Git) Add(ctx context.Context, files ...string) error {
if !g.IsInitialized() {
return store.ErrGitNotInit
}
for i := range files {
files[i] = strings.TrimPrefix(files[i], g.path+"/")
}
args := []string{"add", "--all", "--force"}
args = append(args, files...)
return g.Cmd(ctx, "gitAdd", args...)
} | [
"func",
"(",
"g",
"*",
"Git",
")",
"Add",
"(",
"ctx",
"context",
".",
"Context",
",",
"files",
"...",
"string",
")",
"error",
"{",
"if",
"!",
"g",
".",
"IsInitialized",
"(",
")",
"{",
"return",
"store",
".",
"ErrGitNotInit",
"\n",
"}",
"\n",
"for",
"i",
":=",
"range",
"files",
"{",
"files",
"[",
"i",
"]",
"=",
"strings",
".",
"TrimPrefix",
"(",
"files",
"[",
"i",
"]",
",",
"g",
".",
"path",
"+",
"\"/\"",
")",
"\n",
"}",
"\n",
"args",
":=",
"[",
"]",
"string",
"{",
"\"add\"",
",",
"\"--all\"",
",",
"\"--force\"",
"}",
"\n",
"args",
"=",
"append",
"(",
"args",
",",
"files",
"...",
")",
"\n",
"return",
"g",
".",
"Cmd",
"(",
"ctx",
",",
"\"gitAdd\"",
",",
"args",
"...",
")",
"\n",
"}"
] | // Add adds the listed files to the git index | [
"Add",
"adds",
"the",
"listed",
"files",
"to",
"the",
"git",
"index"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/cli/git.go#L160-L173 | train |
gopasspw/gopass | pkg/backend/rcs/git/cli/git.go | HasStagedChanges | func (g *Git) HasStagedChanges(ctx context.Context) bool {
if err := g.Cmd(ctx, "gitDiffIndex", "diff-index", "--quiet", "HEAD"); err != nil {
return true
}
return false
} | go | func (g *Git) HasStagedChanges(ctx context.Context) bool {
if err := g.Cmd(ctx, "gitDiffIndex", "diff-index", "--quiet", "HEAD"); err != nil {
return true
}
return false
} | [
"func",
"(",
"g",
"*",
"Git",
")",
"HasStagedChanges",
"(",
"ctx",
"context",
".",
"Context",
")",
"bool",
"{",
"if",
"err",
":=",
"g",
".",
"Cmd",
"(",
"ctx",
",",
"\"gitDiffIndex\"",
",",
"\"diff-index\"",
",",
"\"--quiet\"",
",",
"\"HEAD\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // HasStagedChanges returns true if there are any staged changes which can be committed | [
"HasStagedChanges",
"returns",
"true",
"if",
"there",
"are",
"any",
"staged",
"changes",
"which",
"can",
"be",
"committed"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/cli/git.go#L176-L181 | train |
gopasspw/gopass | pkg/backend/rcs/git/cli/git.go | Commit | func (g *Git) Commit(ctx context.Context, msg string) error {
if !g.IsInitialized() {
return store.ErrGitNotInit
}
if !g.HasStagedChanges(ctx) {
return store.ErrGitNothingToCommit
}
return g.Cmd(ctx, "gitCommit", "commit", "-m", msg)
} | go | func (g *Git) Commit(ctx context.Context, msg string) error {
if !g.IsInitialized() {
return store.ErrGitNotInit
}
if !g.HasStagedChanges(ctx) {
return store.ErrGitNothingToCommit
}
return g.Cmd(ctx, "gitCommit", "commit", "-m", msg)
} | [
"func",
"(",
"g",
"*",
"Git",
")",
"Commit",
"(",
"ctx",
"context",
".",
"Context",
",",
"msg",
"string",
")",
"error",
"{",
"if",
"!",
"g",
".",
"IsInitialized",
"(",
")",
"{",
"return",
"store",
".",
"ErrGitNotInit",
"\n",
"}",
"\n",
"if",
"!",
"g",
".",
"HasStagedChanges",
"(",
"ctx",
")",
"{",
"return",
"store",
".",
"ErrGitNothingToCommit",
"\n",
"}",
"\n",
"return",
"g",
".",
"Cmd",
"(",
"ctx",
",",
"\"gitCommit\"",
",",
"\"commit\"",
",",
"\"-m\"",
",",
"msg",
")",
"\n",
"}"
] | // Commit creates a new git commit with the given commit message | [
"Commit",
"creates",
"a",
"new",
"git",
"commit",
"with",
"the",
"given",
"commit",
"message"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/cli/git.go#L184-L194 | train |
gopasspw/gopass | pkg/backend/rcs/git/cli/git.go | Push | func (g *Git) Push(ctx context.Context, remote, branch string) error {
return g.PushPull(ctx, "push", remote, branch)
} | go | func (g *Git) Push(ctx context.Context, remote, branch string) error {
return g.PushPull(ctx, "push", remote, branch)
} | [
"func",
"(",
"g",
"*",
"Git",
")",
"Push",
"(",
"ctx",
"context",
".",
"Context",
",",
"remote",
",",
"branch",
"string",
")",
"error",
"{",
"return",
"g",
".",
"PushPull",
"(",
"ctx",
",",
"\"push\"",
",",
"remote",
",",
"branch",
")",
"\n",
"}"
] | // Push pushes to the git remote | [
"Push",
"pushes",
"to",
"the",
"git",
"remote"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/rcs/git/cli/git.go#L256-L258 | train |
gopasspw/gopass | pkg/store/sub/gpg.go | exportPublicKey | func (s *Store) exportPublicKey(ctx context.Context, r string) (string, error) {
filename := filepath.Join(keyDir, r)
// do not overwrite existing keys
if s.storage.Exists(ctx, filename) {
return "", nil
}
pk, err := s.crypto.ExportPublicKey(ctx, r)
if err != nil {
return "", errors.Wrapf(err, "failed to export public key")
}
// ECC keys are at least 700 byte, RSA should be a lot bigger
if len(pk) < 32 {
return "", errors.New("exported key too small")
}
if err := s.storage.Set(ctx, filename, pk); err != nil {
return "", errors.Wrapf(err, "failed to write exported public key to store")
}
return filename, nil
} | go | func (s *Store) exportPublicKey(ctx context.Context, r string) (string, error) {
filename := filepath.Join(keyDir, r)
// do not overwrite existing keys
if s.storage.Exists(ctx, filename) {
return "", nil
}
pk, err := s.crypto.ExportPublicKey(ctx, r)
if err != nil {
return "", errors.Wrapf(err, "failed to export public key")
}
// ECC keys are at least 700 byte, RSA should be a lot bigger
if len(pk) < 32 {
return "", errors.New("exported key too small")
}
if err := s.storage.Set(ctx, filename, pk); err != nil {
return "", errors.Wrapf(err, "failed to write exported public key to store")
}
return filename, nil
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"exportPublicKey",
"(",
"ctx",
"context",
".",
"Context",
",",
"r",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"filename",
":=",
"filepath",
".",
"Join",
"(",
"keyDir",
",",
"r",
")",
"\n",
"if",
"s",
".",
"storage",
".",
"Exists",
"(",
"ctx",
",",
"filename",
")",
"{",
"return",
"\"\"",
",",
"nil",
"\n",
"}",
"\n",
"pk",
",",
"err",
":=",
"s",
".",
"crypto",
".",
"ExportPublicKey",
"(",
"ctx",
",",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"\"",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"failed to export public key\"",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"pk",
")",
"<",
"32",
"{",
"return",
"\"\"",
",",
"errors",
".",
"New",
"(",
"\"exported key too small\"",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"s",
".",
"storage",
".",
"Set",
"(",
"ctx",
",",
"filename",
",",
"pk",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"\"",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"failed to write exported public key to store\"",
")",
"\n",
"}",
"\n",
"return",
"filename",
",",
"nil",
"\n",
"}"
] | // export an ASCII armored public key | [
"export",
"an",
"ASCII",
"armored",
"public",
"key"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/gpg.go#L85-L108 | train |
gopasspw/gopass | pkg/store/sub/gpg.go | importPublicKey | func (s *Store) importPublicKey(ctx context.Context, r string) error {
for _, kd := range []string{keyDir, oldKeyDir} {
filename := filepath.Join(kd, r)
if !s.storage.Exists(ctx, filename) {
out.Debug(ctx, "Public Key %s not found at %s", r, filename)
continue
}
pk, err := s.storage.Get(ctx, filename)
if err != nil {
return err
}
return s.crypto.ImportPublicKey(ctx, pk)
}
return fmt.Errorf("public key not found in store")
} | go | func (s *Store) importPublicKey(ctx context.Context, r string) error {
for _, kd := range []string{keyDir, oldKeyDir} {
filename := filepath.Join(kd, r)
if !s.storage.Exists(ctx, filename) {
out.Debug(ctx, "Public Key %s not found at %s", r, filename)
continue
}
pk, err := s.storage.Get(ctx, filename)
if err != nil {
return err
}
return s.crypto.ImportPublicKey(ctx, pk)
}
return fmt.Errorf("public key not found in store")
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"importPublicKey",
"(",
"ctx",
"context",
".",
"Context",
",",
"r",
"string",
")",
"error",
"{",
"for",
"_",
",",
"kd",
":=",
"range",
"[",
"]",
"string",
"{",
"keyDir",
",",
"oldKeyDir",
"}",
"{",
"filename",
":=",
"filepath",
".",
"Join",
"(",
"kd",
",",
"r",
")",
"\n",
"if",
"!",
"s",
".",
"storage",
".",
"Exists",
"(",
"ctx",
",",
"filename",
")",
"{",
"out",
".",
"Debug",
"(",
"ctx",
",",
"\"Public Key %s not found at %s\"",
",",
"r",
",",
"filename",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"pk",
",",
"err",
":=",
"s",
".",
"storage",
".",
"Get",
"(",
"ctx",
",",
"filename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"s",
".",
"crypto",
".",
"ImportPublicKey",
"(",
"ctx",
",",
"pk",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"public key not found in store\"",
")",
"\n",
"}"
] | // import an public key into the default keyring | [
"import",
"an",
"public",
"key",
"into",
"the",
"default",
"keyring"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/gpg.go#L111-L125 | train |
gopasspw/gopass | pkg/action/list.go | List | func (s *Action) List(ctx context.Context, c *cli.Context) error {
filter := c.Args().First()
flat := c.Bool("flat")
stripPrefix := c.Bool("strip-prefix")
limit := c.Int("limit")
folders := c.Bool("folders")
// we only support listing folders in flat mode currently
if folders {
flat = true
}
ctx = s.Store.WithConfig(ctx, filter)
l, err := s.Store.Tree(ctx)
if err != nil {
return ExitError(ctx, ExitList, err, "failed to list store: %s", err)
}
if filter == "" {
return s.listAll(ctx, l, limit, flat, folders)
}
return s.listFiltered(ctx, l, limit, flat, folders, stripPrefix, filter)
} | go | func (s *Action) List(ctx context.Context, c *cli.Context) error {
filter := c.Args().First()
flat := c.Bool("flat")
stripPrefix := c.Bool("strip-prefix")
limit := c.Int("limit")
folders := c.Bool("folders")
// we only support listing folders in flat mode currently
if folders {
flat = true
}
ctx = s.Store.WithConfig(ctx, filter)
l, err := s.Store.Tree(ctx)
if err != nil {
return ExitError(ctx, ExitList, err, "failed to list store: %s", err)
}
if filter == "" {
return s.listAll(ctx, l, limit, flat, folders)
}
return s.listFiltered(ctx, l, limit, flat, folders, stripPrefix, filter)
} | [
"func",
"(",
"s",
"*",
"Action",
")",
"List",
"(",
"ctx",
"context",
".",
"Context",
",",
"c",
"*",
"cli",
".",
"Context",
")",
"error",
"{",
"filter",
":=",
"c",
".",
"Args",
"(",
")",
".",
"First",
"(",
")",
"\n",
"flat",
":=",
"c",
".",
"Bool",
"(",
"\"flat\"",
")",
"\n",
"stripPrefix",
":=",
"c",
".",
"Bool",
"(",
"\"strip-prefix\"",
")",
"\n",
"limit",
":=",
"c",
".",
"Int",
"(",
"\"limit\"",
")",
"\n",
"folders",
":=",
"c",
".",
"Bool",
"(",
"\"folders\"",
")",
"\n",
"if",
"folders",
"{",
"flat",
"=",
"true",
"\n",
"}",
"\n",
"ctx",
"=",
"s",
".",
"Store",
".",
"WithConfig",
"(",
"ctx",
",",
"filter",
")",
"\n",
"l",
",",
"err",
":=",
"s",
".",
"Store",
".",
"Tree",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"ExitError",
"(",
"ctx",
",",
"ExitList",
",",
"err",
",",
"\"failed to list store: %s\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"filter",
"==",
"\"\"",
"{",
"return",
"s",
".",
"listAll",
"(",
"ctx",
",",
"l",
",",
"limit",
",",
"flat",
",",
"folders",
")",
"\n",
"}",
"\n",
"return",
"s",
".",
"listFiltered",
"(",
"ctx",
",",
"l",
",",
"limit",
",",
"flat",
",",
"folders",
",",
"stripPrefix",
",",
"filter",
")",
"\n",
"}"
] | // List all secrets as a tree. If the filter argument is non-empty
// display only those that have this prefix | [
"List",
"all",
"secrets",
"as",
"a",
"tree",
".",
"If",
"the",
"filter",
"argument",
"is",
"non",
"-",
"empty",
"display",
"only",
"those",
"that",
"have",
"this",
"prefix"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/list.go#L24-L46 | train |
gopasspw/gopass | pkg/action/list.go | redirectPager | func redirectPager(ctx context.Context, subtree tree.Tree) (io.Writer, *bytes.Buffer) {
if ctxutil.IsNoPager(ctx) {
return stdout, nil
}
rows, _ := termutil.GetTermsize()
if rows <= 0 {
return stdout, nil
}
if subtree == nil || subtree.Len() < rows {
return stdout, nil
}
color.NoColor = true
buf := &bytes.Buffer{}
return buf, buf
} | go | func redirectPager(ctx context.Context, subtree tree.Tree) (io.Writer, *bytes.Buffer) {
if ctxutil.IsNoPager(ctx) {
return stdout, nil
}
rows, _ := termutil.GetTermsize()
if rows <= 0 {
return stdout, nil
}
if subtree == nil || subtree.Len() < rows {
return stdout, nil
}
color.NoColor = true
buf := &bytes.Buffer{}
return buf, buf
} | [
"func",
"redirectPager",
"(",
"ctx",
"context",
".",
"Context",
",",
"subtree",
"tree",
".",
"Tree",
")",
"(",
"io",
".",
"Writer",
",",
"*",
"bytes",
".",
"Buffer",
")",
"{",
"if",
"ctxutil",
".",
"IsNoPager",
"(",
"ctx",
")",
"{",
"return",
"stdout",
",",
"nil",
"\n",
"}",
"\n",
"rows",
",",
"_",
":=",
"termutil",
".",
"GetTermsize",
"(",
")",
"\n",
"if",
"rows",
"<=",
"0",
"{",
"return",
"stdout",
",",
"nil",
"\n",
"}",
"\n",
"if",
"subtree",
"==",
"nil",
"||",
"subtree",
".",
"Len",
"(",
")",
"<",
"rows",
"{",
"return",
"stdout",
",",
"nil",
"\n",
"}",
"\n",
"color",
".",
"NoColor",
"=",
"true",
"\n",
"buf",
":=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"return",
"buf",
",",
"buf",
"\n",
"}"
] | // redirectPager returns a redirected io.Writer if the output would exceed
// the terminal size | [
"redirectPager",
"returns",
"a",
"redirected",
"io",
".",
"Writer",
"if",
"the",
"output",
"would",
"exceed",
"the",
"terminal",
"size"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/list.go#L90-L104 | train |
gopasspw/gopass | pkg/action/list.go | listAll | func (s *Action) listAll(ctx context.Context, l tree.Tree, limit int, flat, folders bool) error {
if flat {
listOver := l.List
if folders {
listOver = l.ListFolders
}
for _, e := range listOver(limit) {
fmt.Fprintln(stdout, e)
}
return nil
}
// we may need to redirect stdout for the pager support
so, buf := redirectPager(ctx, l)
fmt.Fprintln(so, l.Format(limit))
if buf != nil {
if err := s.pager(ctx, buf); err != nil {
return ExitError(ctx, ExitUnknown, err, "failed to invoke pager: %s", err)
}
}
return nil
} | go | func (s *Action) listAll(ctx context.Context, l tree.Tree, limit int, flat, folders bool) error {
if flat {
listOver := l.List
if folders {
listOver = l.ListFolders
}
for _, e := range listOver(limit) {
fmt.Fprintln(stdout, e)
}
return nil
}
// we may need to redirect stdout for the pager support
so, buf := redirectPager(ctx, l)
fmt.Fprintln(so, l.Format(limit))
if buf != nil {
if err := s.pager(ctx, buf); err != nil {
return ExitError(ctx, ExitUnknown, err, "failed to invoke pager: %s", err)
}
}
return nil
} | [
"func",
"(",
"s",
"*",
"Action",
")",
"listAll",
"(",
"ctx",
"context",
".",
"Context",
",",
"l",
"tree",
".",
"Tree",
",",
"limit",
"int",
",",
"flat",
",",
"folders",
"bool",
")",
"error",
"{",
"if",
"flat",
"{",
"listOver",
":=",
"l",
".",
"List",
"\n",
"if",
"folders",
"{",
"listOver",
"=",
"l",
".",
"ListFolders",
"\n",
"}",
"\n",
"for",
"_",
",",
"e",
":=",
"range",
"listOver",
"(",
"limit",
")",
"{",
"fmt",
".",
"Fprintln",
"(",
"stdout",
",",
"e",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"so",
",",
"buf",
":=",
"redirectPager",
"(",
"ctx",
",",
"l",
")",
"\n",
"fmt",
".",
"Fprintln",
"(",
"so",
",",
"l",
".",
"Format",
"(",
"limit",
")",
")",
"\n",
"if",
"buf",
"!=",
"nil",
"{",
"if",
"err",
":=",
"s",
".",
"pager",
"(",
"ctx",
",",
"buf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"ExitError",
"(",
"ctx",
",",
"ExitUnknown",
",",
"err",
",",
"\"failed to invoke pager: %s\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // listAll will unconditionally list all entries, used if no filter is given | [
"listAll",
"will",
"unconditionally",
"list",
"all",
"entries",
"used",
"if",
"no",
"filter",
"is",
"given"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/list.go#L107-L129 | train |
gopasspw/gopass | pkg/action/list.go | pager | func (s *Action) pager(ctx context.Context, buf io.Reader) error {
pager := os.Getenv("PAGER")
if pager == "" {
fmt.Fprintln(stdout, buf)
return nil
}
args, err := shellquote.Split(pager)
if err != nil {
return errors.Wrapf(err, "failed to split pager command")
}
cmd := exec.CommandContext(ctx, args[0], args[1:]...)
cmd.Stdin = buf
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
} | go | func (s *Action) pager(ctx context.Context, buf io.Reader) error {
pager := os.Getenv("PAGER")
if pager == "" {
fmt.Fprintln(stdout, buf)
return nil
}
args, err := shellquote.Split(pager)
if err != nil {
return errors.Wrapf(err, "failed to split pager command")
}
cmd := exec.CommandContext(ctx, args[0], args[1:]...)
cmd.Stdin = buf
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
} | [
"func",
"(",
"s",
"*",
"Action",
")",
"pager",
"(",
"ctx",
"context",
".",
"Context",
",",
"buf",
"io",
".",
"Reader",
")",
"error",
"{",
"pager",
":=",
"os",
".",
"Getenv",
"(",
"\"PAGER\"",
")",
"\n",
"if",
"pager",
"==",
"\"\"",
"{",
"fmt",
".",
"Fprintln",
"(",
"stdout",
",",
"buf",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"args",
",",
"err",
":=",
"shellquote",
".",
"Split",
"(",
"pager",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"failed to split pager command\"",
")",
"\n",
"}",
"\n",
"cmd",
":=",
"exec",
".",
"CommandContext",
"(",
"ctx",
",",
"args",
"[",
"0",
"]",
",",
"args",
"[",
"1",
":",
"]",
"...",
")",
"\n",
"cmd",
".",
"Stdin",
"=",
"buf",
"\n",
"cmd",
".",
"Stdout",
"=",
"os",
".",
"Stdout",
"\n",
"cmd",
".",
"Stderr",
"=",
"os",
".",
"Stderr",
"\n",
"return",
"cmd",
".",
"Run",
"(",
")",
"\n",
"}"
] | // pager invokes the default pager with the given content | [
"pager",
"invokes",
"the",
"default",
"pager",
"with",
"the",
"given",
"content"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/list.go#L132-L150 | train |
gopasspw/gopass | pkg/termutil/termutil_others.go | GetTermsize | func GetTermsize() (int, int) {
ts := termSize{}
ret, _, _ := syscall.Syscall(
syscall.SYS_IOCTL,
uintptr(syscall.Stdin),
uintptr(syscall.TIOCGWINSZ),
uintptr(unsafe.Pointer(&ts)),
)
if int(ret) == -1 {
return -1, -1
}
return int(ts.Rows), int(ts.Cols)
} | go | func GetTermsize() (int, int) {
ts := termSize{}
ret, _, _ := syscall.Syscall(
syscall.SYS_IOCTL,
uintptr(syscall.Stdin),
uintptr(syscall.TIOCGWINSZ),
uintptr(unsafe.Pointer(&ts)),
)
if int(ret) == -1 {
return -1, -1
}
return int(ts.Rows), int(ts.Cols)
} | [
"func",
"GetTermsize",
"(",
")",
"(",
"int",
",",
"int",
")",
"{",
"ts",
":=",
"termSize",
"{",
"}",
"\n",
"ret",
",",
"_",
",",
"_",
":=",
"syscall",
".",
"Syscall",
"(",
"syscall",
".",
"SYS_IOCTL",
",",
"uintptr",
"(",
"syscall",
".",
"Stdin",
")",
",",
"uintptr",
"(",
"syscall",
".",
"TIOCGWINSZ",
")",
",",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"ts",
")",
")",
",",
")",
"\n",
"if",
"int",
"(",
"ret",
")",
"==",
"-",
"1",
"{",
"return",
"-",
"1",
",",
"-",
"1",
"\n",
"}",
"\n",
"return",
"int",
"(",
"ts",
".",
"Rows",
")",
",",
"int",
"(",
"ts",
".",
"Cols",
")",
"\n",
"}"
] | // GetTermsize returns the size of the current terminal | [
"GetTermsize",
"returns",
"the",
"size",
"of",
"the",
"current",
"terminal"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/termutil/termutil_others.go#L18-L30 | train |
gopasspw/gopass | pkg/backend/strings.go | CryptoBackends | func CryptoBackends() []string {
bes := make([]string, 0, len(cryptoNameToBackendMap))
for k := range cryptoNameToBackendMap {
bes = append(bes, k)
}
sort.Strings(bes)
return bes
} | go | func CryptoBackends() []string {
bes := make([]string, 0, len(cryptoNameToBackendMap))
for k := range cryptoNameToBackendMap {
bes = append(bes, k)
}
sort.Strings(bes)
return bes
} | [
"func",
"CryptoBackends",
"(",
")",
"[",
"]",
"string",
"{",
"bes",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"cryptoNameToBackendMap",
")",
")",
"\n",
"for",
"k",
":=",
"range",
"cryptoNameToBackendMap",
"{",
"bes",
"=",
"append",
"(",
"bes",
",",
"k",
")",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"bes",
")",
"\n",
"return",
"bes",
"\n",
"}"
] | // CryptoBackends returns the list of registered crypto backends. | [
"CryptoBackends",
"returns",
"the",
"list",
"of",
"registered",
"crypto",
"backends",
"."
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/strings.go#L27-L34 | train |
gopasspw/gopass | pkg/backend/strings.go | RCSBackends | func RCSBackends() []string {
bes := make([]string, 0, len(rcsNameToBackendMap))
for k := range rcsNameToBackendMap {
bes = append(bes, k)
}
sort.Strings(bes)
return bes
} | go | func RCSBackends() []string {
bes := make([]string, 0, len(rcsNameToBackendMap))
for k := range rcsNameToBackendMap {
bes = append(bes, k)
}
sort.Strings(bes)
return bes
} | [
"func",
"RCSBackends",
"(",
")",
"[",
"]",
"string",
"{",
"bes",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"rcsNameToBackendMap",
")",
")",
"\n",
"for",
"k",
":=",
"range",
"rcsNameToBackendMap",
"{",
"bes",
"=",
"append",
"(",
"bes",
",",
"k",
")",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"bes",
")",
"\n",
"return",
"bes",
"\n",
"}"
] | // RCSBackends returns the list of registered RCS backends. | [
"RCSBackends",
"returns",
"the",
"list",
"of",
"registered",
"RCS",
"backends",
"."
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/strings.go#L37-L44 | train |
gopasspw/gopass | pkg/backend/strings.go | StorageBackends | func StorageBackends() []string {
bes := make([]string, 0, len(storageNameToBackendMap))
for k := range storageNameToBackendMap {
bes = append(bes, k)
}
sort.Strings(bes)
return bes
} | go | func StorageBackends() []string {
bes := make([]string, 0, len(storageNameToBackendMap))
for k := range storageNameToBackendMap {
bes = append(bes, k)
}
sort.Strings(bes)
return bes
} | [
"func",
"StorageBackends",
"(",
")",
"[",
"]",
"string",
"{",
"bes",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"storageNameToBackendMap",
")",
")",
"\n",
"for",
"k",
":=",
"range",
"storageNameToBackendMap",
"{",
"bes",
"=",
"append",
"(",
"bes",
",",
"k",
")",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"bes",
")",
"\n",
"return",
"bes",
"\n",
"}"
] | // StorageBackends returns the list of registered storage backends. | [
"StorageBackends",
"returns",
"the",
"list",
"of",
"registered",
"storage",
"backends",
"."
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/strings.go#L47-L54 | train |
gopasspw/gopass | pkg/store/root/move.go | Copy | func (r *Store) Copy(ctx context.Context, from, to string) error {
return r.move(ctx, from, to, false)
} | go | func (r *Store) Copy(ctx context.Context, from, to string) error {
return r.move(ctx, from, to, false)
} | [
"func",
"(",
"r",
"*",
"Store",
")",
"Copy",
"(",
"ctx",
"context",
".",
"Context",
",",
"from",
",",
"to",
"string",
")",
"error",
"{",
"return",
"r",
".",
"move",
"(",
"ctx",
",",
"from",
",",
"to",
",",
"false",
")",
"\n",
"}"
] | // Copy will copy one entry to another location. Multi-store copies are
// supported. Each entry has to be decoded and encoded for the destination
// to make sure it's encrypted for the right set of recipients. | [
"Copy",
"will",
"copy",
"one",
"entry",
"to",
"another",
"location",
".",
"Multi",
"-",
"store",
"copies",
"are",
"supported",
".",
"Each",
"entry",
"has",
"to",
"be",
"decoded",
"and",
"encoded",
"for",
"the",
"destination",
"to",
"make",
"sure",
"it",
"s",
"encrypted",
"for",
"the",
"right",
"set",
"of",
"recipients",
"."
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/move.go#L19-L21 | train |
gopasspw/gopass | pkg/store/root/move.go | Move | func (r *Store) Move(ctx context.Context, from, to string) error {
return r.move(ctx, from, to, true)
} | go | func (r *Store) Move(ctx context.Context, from, to string) error {
return r.move(ctx, from, to, true)
} | [
"func",
"(",
"r",
"*",
"Store",
")",
"Move",
"(",
"ctx",
"context",
".",
"Context",
",",
"from",
",",
"to",
"string",
")",
"error",
"{",
"return",
"r",
".",
"move",
"(",
"ctx",
",",
"from",
",",
"to",
",",
"true",
")",
"\n",
"}"
] | // Move will move one entry from one location to another. Cross-store moves are
// supported. Moving an entry will decode it from the old location, encode it
// for the destination store with the right set of recipients and remove it
// from the old location afterwards. | [
"Move",
"will",
"move",
"one",
"entry",
"from",
"one",
"location",
"to",
"another",
".",
"Cross",
"-",
"store",
"moves",
"are",
"supported",
".",
"Moving",
"an",
"entry",
"will",
"decode",
"it",
"from",
"the",
"old",
"location",
"encode",
"it",
"for",
"the",
"destination",
"store",
"with",
"the",
"right",
"set",
"of",
"recipients",
"and",
"remove",
"it",
"from",
"the",
"old",
"location",
"afterwards",
"."
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/move.go#L27-L29 | train |
gopasspw/gopass | pkg/backend/storage/fs/store.go | Get | func (s *Store) Get(ctx context.Context, name string) ([]byte, error) {
path := filepath.Join(s.path, filepath.Clean(name))
out.Debug(ctx, "fs.Get(%s) - %s", name, path)
return ioutil.ReadFile(path)
} | go | func (s *Store) Get(ctx context.Context, name string) ([]byte, error) {
path := filepath.Join(s.path, filepath.Clean(name))
out.Debug(ctx, "fs.Get(%s) - %s", name, path)
return ioutil.ReadFile(path)
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"Get",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"path",
":=",
"filepath",
".",
"Join",
"(",
"s",
".",
"path",
",",
"filepath",
".",
"Clean",
"(",
"name",
")",
")",
"\n",
"out",
".",
"Debug",
"(",
"ctx",
",",
"\"fs.Get(%s) - %s\"",
",",
"name",
",",
"path",
")",
"\n",
"return",
"ioutil",
".",
"ReadFile",
"(",
"path",
")",
"\n",
"}"
] | // Get retrieves the named content | [
"Get",
"retrieves",
"the",
"named",
"content"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/storage/fs/store.go#L35-L39 | train |
gopasspw/gopass | pkg/backend/storage/fs/store.go | Set | func (s *Store) Set(ctx context.Context, name string, value []byte) error {
filename := filepath.Join(s.path, filepath.Clean(name))
filedir := filepath.Dir(filename)
if !fsutil.IsDir(filedir) {
if err := os.MkdirAll(filedir, 0700); err != nil {
return err
}
}
out.Debug(ctx, "fs.Set(%s) - %s", name, filepath.Join(s.path, name))
return ioutil.WriteFile(filepath.Join(s.path, name), value, 0644)
} | go | func (s *Store) Set(ctx context.Context, name string, value []byte) error {
filename := filepath.Join(s.path, filepath.Clean(name))
filedir := filepath.Dir(filename)
if !fsutil.IsDir(filedir) {
if err := os.MkdirAll(filedir, 0700); err != nil {
return err
}
}
out.Debug(ctx, "fs.Set(%s) - %s", name, filepath.Join(s.path, name))
return ioutil.WriteFile(filepath.Join(s.path, name), value, 0644)
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"Set",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
"string",
",",
"value",
"[",
"]",
"byte",
")",
"error",
"{",
"filename",
":=",
"filepath",
".",
"Join",
"(",
"s",
".",
"path",
",",
"filepath",
".",
"Clean",
"(",
"name",
")",
")",
"\n",
"filedir",
":=",
"filepath",
".",
"Dir",
"(",
"filename",
")",
"\n",
"if",
"!",
"fsutil",
".",
"IsDir",
"(",
"filedir",
")",
"{",
"if",
"err",
":=",
"os",
".",
"MkdirAll",
"(",
"filedir",
",",
"0700",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"out",
".",
"Debug",
"(",
"ctx",
",",
"\"fs.Set(%s) - %s\"",
",",
"name",
",",
"filepath",
".",
"Join",
"(",
"s",
".",
"path",
",",
"name",
")",
")",
"\n",
"return",
"ioutil",
".",
"WriteFile",
"(",
"filepath",
".",
"Join",
"(",
"s",
".",
"path",
",",
"name",
")",
",",
"value",
",",
"0644",
")",
"\n",
"}"
] | // Set writes the given content | [
"Set",
"writes",
"the",
"given",
"content"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/storage/fs/store.go#L42-L52 | train |
gopasspw/gopass | pkg/backend/storage/fs/store.go | Delete | func (s *Store) Delete(ctx context.Context, name string) error {
path := filepath.Join(s.path, filepath.Clean(name))
out.Debug(ctx, "fs.Delete(%s) - %s", name, path)
if err := os.Remove(path); err != nil {
return err
}
return s.removeEmptyParentDirectories(path)
} | go | func (s *Store) Delete(ctx context.Context, name string) error {
path := filepath.Join(s.path, filepath.Clean(name))
out.Debug(ctx, "fs.Delete(%s) - %s", name, path)
if err := os.Remove(path); err != nil {
return err
}
return s.removeEmptyParentDirectories(path)
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"Delete",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
"string",
")",
"error",
"{",
"path",
":=",
"filepath",
".",
"Join",
"(",
"s",
".",
"path",
",",
"filepath",
".",
"Clean",
"(",
"name",
")",
")",
"\n",
"out",
".",
"Debug",
"(",
"ctx",
",",
"\"fs.Delete(%s) - %s\"",
",",
"name",
",",
"path",
")",
"\n",
"if",
"err",
":=",
"os",
".",
"Remove",
"(",
"path",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"s",
".",
"removeEmptyParentDirectories",
"(",
"path",
")",
"\n",
"}"
] | // Delete removes the named entity | [
"Delete",
"removes",
"the",
"named",
"entity"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/storage/fs/store.go#L55-L64 | train |
gopasspw/gopass | pkg/backend/storage/fs/store.go | removeEmptyParentDirectories | func (s *Store) removeEmptyParentDirectories(path string) error {
parent := filepath.Dir(path)
if relpath, err := filepath.Rel(s.path, parent); err != nil {
return err
} else if strings.HasPrefix(relpath, ".") {
return nil
}
err := os.Remove(parent)
switch {
case err == nil:
return s.removeEmptyParentDirectories(parent)
case err.(*os.PathError).Err == syscall.ENOTEMPTY:
// ignore when directory is non-empty
return nil
default:
return err
}
} | go | func (s *Store) removeEmptyParentDirectories(path string) error {
parent := filepath.Dir(path)
if relpath, err := filepath.Rel(s.path, parent); err != nil {
return err
} else if strings.HasPrefix(relpath, ".") {
return nil
}
err := os.Remove(parent)
switch {
case err == nil:
return s.removeEmptyParentDirectories(parent)
case err.(*os.PathError).Err == syscall.ENOTEMPTY:
// ignore when directory is non-empty
return nil
default:
return err
}
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"removeEmptyParentDirectories",
"(",
"path",
"string",
")",
"error",
"{",
"parent",
":=",
"filepath",
".",
"Dir",
"(",
"path",
")",
"\n",
"if",
"relpath",
",",
"err",
":=",
"filepath",
".",
"Rel",
"(",
"s",
".",
"path",
",",
"parent",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"else",
"if",
"strings",
".",
"HasPrefix",
"(",
"relpath",
",",
"\".\"",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"err",
":=",
"os",
".",
"Remove",
"(",
"parent",
")",
"\n",
"switch",
"{",
"case",
"err",
"==",
"nil",
":",
"return",
"s",
".",
"removeEmptyParentDirectories",
"(",
"parent",
")",
"\n",
"case",
"err",
".",
"(",
"*",
"os",
".",
"PathError",
")",
".",
"Err",
"==",
"syscall",
".",
"ENOTEMPTY",
":",
"return",
"nil",
"\n",
"default",
":",
"return",
"err",
"\n",
"}",
"\n",
"}"
] | // Deletes all empty parent directories up to the store root | [
"Deletes",
"all",
"empty",
"parent",
"directories",
"up",
"to",
"the",
"store",
"root"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/storage/fs/store.go#L67-L86 | train |
gopasspw/gopass | pkg/backend/storage/fs/store.go | Exists | func (s *Store) Exists(ctx context.Context, name string) bool {
path := filepath.Join(s.path, filepath.Clean(name))
out.Debug(ctx, "fs.Exists(%s) - %s", name, path)
return fsutil.IsFile(path)
} | go | func (s *Store) Exists(ctx context.Context, name string) bool {
path := filepath.Join(s.path, filepath.Clean(name))
out.Debug(ctx, "fs.Exists(%s) - %s", name, path)
return fsutil.IsFile(path)
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"Exists",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
"string",
")",
"bool",
"{",
"path",
":=",
"filepath",
".",
"Join",
"(",
"s",
".",
"path",
",",
"filepath",
".",
"Clean",
"(",
"name",
")",
")",
"\n",
"out",
".",
"Debug",
"(",
"ctx",
",",
"\"fs.Exists(%s) - %s\"",
",",
"name",
",",
"path",
")",
"\n",
"return",
"fsutil",
".",
"IsFile",
"(",
"path",
")",
"\n",
"}"
] | // Exists checks if the named entity exists | [
"Exists",
"checks",
"if",
"the",
"named",
"entity",
"exists"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/storage/fs/store.go#L89-L93 | train |
gopasspw/gopass | pkg/backend/storage/fs/store.go | List | func (s *Store) List(ctx context.Context, prefix string) ([]string, error) {
prefix = strings.TrimPrefix(prefix, "/")
out.Debug(ctx, "fs.List(%s)", prefix)
files := make([]string, 0, 100)
if err := filepath.Walk(s.path, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() && strings.HasPrefix(info.Name(), ".") && path != s.path {
return filepath.SkipDir
}
if info.IsDir() {
return nil
}
if path == s.path {
return nil
}
name := strings.TrimPrefix(path, s.path+string(filepath.Separator))
if !strings.HasPrefix(name, prefix) {
return nil
}
files = append(files, name)
return nil
}); err != nil {
return nil, err
}
sort.Strings(files)
return files, nil
} | go | func (s *Store) List(ctx context.Context, prefix string) ([]string, error) {
prefix = strings.TrimPrefix(prefix, "/")
out.Debug(ctx, "fs.List(%s)", prefix)
files := make([]string, 0, 100)
if err := filepath.Walk(s.path, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() && strings.HasPrefix(info.Name(), ".") && path != s.path {
return filepath.SkipDir
}
if info.IsDir() {
return nil
}
if path == s.path {
return nil
}
name := strings.TrimPrefix(path, s.path+string(filepath.Separator))
if !strings.HasPrefix(name, prefix) {
return nil
}
files = append(files, name)
return nil
}); err != nil {
return nil, err
}
sort.Strings(files)
return files, nil
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"List",
"(",
"ctx",
"context",
".",
"Context",
",",
"prefix",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"prefix",
"=",
"strings",
".",
"TrimPrefix",
"(",
"prefix",
",",
"\"/\"",
")",
"\n",
"out",
".",
"Debug",
"(",
"ctx",
",",
"\"fs.List(%s)\"",
",",
"prefix",
")",
"\n",
"files",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"100",
")",
"\n",
"if",
"err",
":=",
"filepath",
".",
"Walk",
"(",
"s",
".",
"path",
",",
"func",
"(",
"path",
"string",
",",
"info",
"os",
".",
"FileInfo",
",",
"err",
"error",
")",
"error",
"{",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"info",
".",
"IsDir",
"(",
")",
"&&",
"strings",
".",
"HasPrefix",
"(",
"info",
".",
"Name",
"(",
")",
",",
"\".\"",
")",
"&&",
"path",
"!=",
"s",
".",
"path",
"{",
"return",
"filepath",
".",
"SkipDir",
"\n",
"}",
"\n",
"if",
"info",
".",
"IsDir",
"(",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"path",
"==",
"s",
".",
"path",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"name",
":=",
"strings",
".",
"TrimPrefix",
"(",
"path",
",",
"s",
".",
"path",
"+",
"string",
"(",
"filepath",
".",
"Separator",
")",
")",
"\n",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"name",
",",
"prefix",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"files",
"=",
"append",
"(",
"files",
",",
"name",
")",
"\n",
"return",
"nil",
"\n",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"files",
")",
"\n",
"return",
"files",
",",
"nil",
"\n",
"}"
] | // List returns a list of all entities | [
"List",
"returns",
"a",
"list",
"of",
"all",
"entities"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/storage/fs/store.go#L96-L124 | train |
gopasspw/gopass | pkg/backend/storage/fs/store.go | IsDir | func (s *Store) IsDir(ctx context.Context, name string) bool {
path := filepath.Join(s.path, filepath.Clean(name))
isDir := fsutil.IsDir(path)
out.Debug(ctx, "fs.Isdir(%s) - %s -> %t", name, path, isDir)
return isDir
} | go | func (s *Store) IsDir(ctx context.Context, name string) bool {
path := filepath.Join(s.path, filepath.Clean(name))
isDir := fsutil.IsDir(path)
out.Debug(ctx, "fs.Isdir(%s) - %s -> %t", name, path, isDir)
return isDir
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"IsDir",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
"string",
")",
"bool",
"{",
"path",
":=",
"filepath",
".",
"Join",
"(",
"s",
".",
"path",
",",
"filepath",
".",
"Clean",
"(",
"name",
")",
")",
"\n",
"isDir",
":=",
"fsutil",
".",
"IsDir",
"(",
"path",
")",
"\n",
"out",
".",
"Debug",
"(",
"ctx",
",",
"\"fs.Isdir(%s) - %s -> %t\"",
",",
"name",
",",
"path",
",",
"isDir",
")",
"\n",
"return",
"isDir",
"\n",
"}"
] | // IsDir returns true if the named entity is a directory | [
"IsDir",
"returns",
"true",
"if",
"the",
"named",
"entity",
"is",
"a",
"directory"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/storage/fs/store.go#L127-L132 | train |
gopasspw/gopass | pkg/backend/storage/fs/store.go | Prune | func (s *Store) Prune(ctx context.Context, prefix string) error {
path := filepath.Join(s.path, filepath.Clean(prefix))
out.Debug(ctx, "fs.Prune(%s) - %s", prefix, path)
return os.RemoveAll(path)
} | go | func (s *Store) Prune(ctx context.Context, prefix string) error {
path := filepath.Join(s.path, filepath.Clean(prefix))
out.Debug(ctx, "fs.Prune(%s) - %s", prefix, path)
return os.RemoveAll(path)
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"Prune",
"(",
"ctx",
"context",
".",
"Context",
",",
"prefix",
"string",
")",
"error",
"{",
"path",
":=",
"filepath",
".",
"Join",
"(",
"s",
".",
"path",
",",
"filepath",
".",
"Clean",
"(",
"prefix",
")",
")",
"\n",
"out",
".",
"Debug",
"(",
"ctx",
",",
"\"fs.Prune(%s) - %s\"",
",",
"prefix",
",",
"path",
")",
"\n",
"return",
"os",
".",
"RemoveAll",
"(",
"path",
")",
"\n",
"}"
] | // Prune removes a named directory | [
"Prune",
"removes",
"a",
"named",
"directory"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/storage/fs/store.go#L135-L139 | train |
gopasspw/gopass | pkg/agent/agent.go | New | func New(dir string) *Agent {
a := &Agent{
socket: filepath.Join(dir, ".gopass-agent.sock"),
cache: &cache{
ttl: time.Hour,
maxTTL: 24 * time.Hour,
},
pinentry: func() (piner, error) {
return pinentry.New()
},
}
mux := http.NewServeMux()
mux.HandleFunc("/ping", a.servePing)
mux.HandleFunc("/passphrase", a.servePassphrase)
mux.HandleFunc("/cache/remove", a.serveRemove)
mux.HandleFunc("/cache/purge", a.servePurge)
a.server = &http.Server{
Handler: mux,
}
return a
} | go | func New(dir string) *Agent {
a := &Agent{
socket: filepath.Join(dir, ".gopass-agent.sock"),
cache: &cache{
ttl: time.Hour,
maxTTL: 24 * time.Hour,
},
pinentry: func() (piner, error) {
return pinentry.New()
},
}
mux := http.NewServeMux()
mux.HandleFunc("/ping", a.servePing)
mux.HandleFunc("/passphrase", a.servePassphrase)
mux.HandleFunc("/cache/remove", a.serveRemove)
mux.HandleFunc("/cache/purge", a.servePurge)
a.server = &http.Server{
Handler: mux,
}
return a
} | [
"func",
"New",
"(",
"dir",
"string",
")",
"*",
"Agent",
"{",
"a",
":=",
"&",
"Agent",
"{",
"socket",
":",
"filepath",
".",
"Join",
"(",
"dir",
",",
"\".gopass-agent.sock\"",
")",
",",
"cache",
":",
"&",
"cache",
"{",
"ttl",
":",
"time",
".",
"Hour",
",",
"maxTTL",
":",
"24",
"*",
"time",
".",
"Hour",
",",
"}",
",",
"pinentry",
":",
"func",
"(",
")",
"(",
"piner",
",",
"error",
")",
"{",
"return",
"pinentry",
".",
"New",
"(",
")",
"\n",
"}",
",",
"}",
"\n",
"mux",
":=",
"http",
".",
"NewServeMux",
"(",
")",
"\n",
"mux",
".",
"HandleFunc",
"(",
"\"/ping\"",
",",
"a",
".",
"servePing",
")",
"\n",
"mux",
".",
"HandleFunc",
"(",
"\"/passphrase\"",
",",
"a",
".",
"servePassphrase",
")",
"\n",
"mux",
".",
"HandleFunc",
"(",
"\"/cache/remove\"",
",",
"a",
".",
"serveRemove",
")",
"\n",
"mux",
".",
"HandleFunc",
"(",
"\"/cache/purge\"",
",",
"a",
".",
"servePurge",
")",
"\n",
"a",
".",
"server",
"=",
"&",
"http",
".",
"Server",
"{",
"Handler",
":",
"mux",
",",
"}",
"\n",
"return",
"a",
"\n",
"}"
] | // New creates a new agent | [
"New",
"creates",
"a",
"new",
"agent"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/agent/agent.go#L38-L58 | train |
gopasspw/gopass | pkg/agent/agent.go | ListenAndServe | func (a *Agent) ListenAndServe(ctx context.Context) error {
out.Debug(ctx, "Trying to listen on %s", a.socket)
lis, err := net.Listen("unix", a.socket)
if err == nil {
return a.server.Serve(lis)
}
out.Debug(ctx, "Failed to listen on %s: %s", a.socket, err)
if err := client.New(filepath.Dir(a.socket)).Ping(ctx); err == nil {
return fmt.Errorf("agent already running")
}
if err := os.Remove(a.socket); err != nil {
return errors.Wrapf(err, "failed to remove old agent socket %s: %s", a.socket, err)
}
out.Debug(ctx, "Trying to listen on %s after removing old socket", a.socket)
lis, err = net.Listen("unix", a.socket)
if err != nil {
return errors.Wrapf(err, "failed to listen on %s after cleanup: %s", a.socket, err)
}
return a.server.Serve(lis)
} | go | func (a *Agent) ListenAndServe(ctx context.Context) error {
out.Debug(ctx, "Trying to listen on %s", a.socket)
lis, err := net.Listen("unix", a.socket)
if err == nil {
return a.server.Serve(lis)
}
out.Debug(ctx, "Failed to listen on %s: %s", a.socket, err)
if err := client.New(filepath.Dir(a.socket)).Ping(ctx); err == nil {
return fmt.Errorf("agent already running")
}
if err := os.Remove(a.socket); err != nil {
return errors.Wrapf(err, "failed to remove old agent socket %s: %s", a.socket, err)
}
out.Debug(ctx, "Trying to listen on %s after removing old socket", a.socket)
lis, err = net.Listen("unix", a.socket)
if err != nil {
return errors.Wrapf(err, "failed to listen on %s after cleanup: %s", a.socket, err)
}
return a.server.Serve(lis)
} | [
"func",
"(",
"a",
"*",
"Agent",
")",
"ListenAndServe",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"out",
".",
"Debug",
"(",
"ctx",
",",
"\"Trying to listen on %s\"",
",",
"a",
".",
"socket",
")",
"\n",
"lis",
",",
"err",
":=",
"net",
".",
"Listen",
"(",
"\"unix\"",
",",
"a",
".",
"socket",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"a",
".",
"server",
".",
"Serve",
"(",
"lis",
")",
"\n",
"}",
"\n",
"out",
".",
"Debug",
"(",
"ctx",
",",
"\"Failed to listen on %s: %s\"",
",",
"a",
".",
"socket",
",",
"err",
")",
"\n",
"if",
"err",
":=",
"client",
".",
"New",
"(",
"filepath",
".",
"Dir",
"(",
"a",
".",
"socket",
")",
")",
".",
"Ping",
"(",
"ctx",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"agent already running\"",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"os",
".",
"Remove",
"(",
"a",
".",
"socket",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"failed to remove old agent socket %s: %s\"",
",",
"a",
".",
"socket",
",",
"err",
")",
"\n",
"}",
"\n",
"out",
".",
"Debug",
"(",
"ctx",
",",
"\"Trying to listen on %s after removing old socket\"",
",",
"a",
".",
"socket",
")",
"\n",
"lis",
",",
"err",
"=",
"net",
".",
"Listen",
"(",
"\"unix\"",
",",
"a",
".",
"socket",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"failed to listen on %s after cleanup: %s\"",
",",
"a",
".",
"socket",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"a",
".",
"server",
".",
"Serve",
"(",
"lis",
")",
"\n",
"}"
] | // ListenAndServe starts listening and blocks | [
"ListenAndServe",
"starts",
"listening",
"and",
"blocks"
] | fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4 | https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/agent/agent.go#L69-L89 | train |
golang/oauth2 | internal/token.go | lookupAuthStyle | func lookupAuthStyle(tokenURL string) (style AuthStyle, ok bool) {
authStyleCache.Lock()
defer authStyleCache.Unlock()
style, ok = authStyleCache.m[tokenURL]
return
} | go | func lookupAuthStyle(tokenURL string) (style AuthStyle, ok bool) {
authStyleCache.Lock()
defer authStyleCache.Unlock()
style, ok = authStyleCache.m[tokenURL]
return
} | [
"func",
"lookupAuthStyle",
"(",
"tokenURL",
"string",
")",
"(",
"style",
"AuthStyle",
",",
"ok",
"bool",
")",
"{",
"authStyleCache",
".",
"Lock",
"(",
")",
"\n",
"defer",
"authStyleCache",
".",
"Unlock",
"(",
")",
"\n",
"style",
",",
"ok",
"=",
"authStyleCache",
".",
"m",
"[",
"tokenURL",
"]",
"\n",
"return",
"\n",
"}"
] | // lookupAuthStyle reports which auth style we last used with tokenURL
// when calling RetrieveToken and whether we have ever done so. | [
"lookupAuthStyle",
"reports",
"which",
"auth",
"style",
"we",
"last",
"used",
"with",
"tokenURL",
"when",
"calling",
"RetrieveToken",
"and",
"whether",
"we",
"have",
"ever",
"done",
"so",
"."
] | 9f3314589c9a9136388751d9adae6b0ed400978a | https://github.com/golang/oauth2/blob/9f3314589c9a9136388751d9adae6b0ed400978a/internal/token.go#L134-L139 | train |
golang/oauth2 | internal/token.go | setAuthStyle | func setAuthStyle(tokenURL string, v AuthStyle) {
authStyleCache.Lock()
defer authStyleCache.Unlock()
if authStyleCache.m == nil {
authStyleCache.m = make(map[string]AuthStyle)
}
authStyleCache.m[tokenURL] = v
} | go | func setAuthStyle(tokenURL string, v AuthStyle) {
authStyleCache.Lock()
defer authStyleCache.Unlock()
if authStyleCache.m == nil {
authStyleCache.m = make(map[string]AuthStyle)
}
authStyleCache.m[tokenURL] = v
} | [
"func",
"setAuthStyle",
"(",
"tokenURL",
"string",
",",
"v",
"AuthStyle",
")",
"{",
"authStyleCache",
".",
"Lock",
"(",
")",
"\n",
"defer",
"authStyleCache",
".",
"Unlock",
"(",
")",
"\n",
"if",
"authStyleCache",
".",
"m",
"==",
"nil",
"{",
"authStyleCache",
".",
"m",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"AuthStyle",
")",
"\n",
"}",
"\n",
"authStyleCache",
".",
"m",
"[",
"tokenURL",
"]",
"=",
"v",
"\n",
"}"
] | // setAuthStyle adds an entry to authStyleCache, documented above. | [
"setAuthStyle",
"adds",
"an",
"entry",
"to",
"authStyleCache",
"documented",
"above",
"."
] | 9f3314589c9a9136388751d9adae6b0ed400978a | https://github.com/golang/oauth2/blob/9f3314589c9a9136388751d9adae6b0ed400978a/internal/token.go#L142-L149 | train |
golang/oauth2 | hipchat/hipchat.go | ServerEndpoint | func ServerEndpoint(host string) oauth2.Endpoint {
return oauth2.Endpoint{
AuthURL: "https://" + host + "/users/authorize",
TokenURL: "https://" + host + "/v2/oauth/token",
}
} | go | func ServerEndpoint(host string) oauth2.Endpoint {
return oauth2.Endpoint{
AuthURL: "https://" + host + "/users/authorize",
TokenURL: "https://" + host + "/v2/oauth/token",
}
} | [
"func",
"ServerEndpoint",
"(",
"host",
"string",
")",
"oauth2",
".",
"Endpoint",
"{",
"return",
"oauth2",
".",
"Endpoint",
"{",
"AuthURL",
":",
"\"https://\"",
"+",
"host",
"+",
"\"/users/authorize\"",
",",
"TokenURL",
":",
"\"https://\"",
"+",
"host",
"+",
"\"/v2/oauth/token\"",
",",
"}",
"\n",
"}"
] | // ServerEndpoint returns a new oauth2.Endpoint for a HipChat Server instance
// running on the given domain or host. | [
"ServerEndpoint",
"returns",
"a",
"new",
"oauth2",
".",
"Endpoint",
"for",
"a",
"HipChat",
"Server",
"instance",
"running",
"on",
"the",
"given",
"domain",
"or",
"host",
"."
] | 9f3314589c9a9136388751d9adae6b0ed400978a | https://github.com/golang/oauth2/blob/9f3314589c9a9136388751d9adae6b0ed400978a/hipchat/hipchat.go#L24-L29 | train |
golang/oauth2 | clientcredentials/clientcredentials.go | Token | func (c *Config) Token(ctx context.Context) (*oauth2.Token, error) {
return c.TokenSource(ctx).Token()
} | go | func (c *Config) Token(ctx context.Context) (*oauth2.Token, error) {
return c.TokenSource(ctx).Token()
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"Token",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"*",
"oauth2",
".",
"Token",
",",
"error",
")",
"{",
"return",
"c",
".",
"TokenSource",
"(",
"ctx",
")",
".",
"Token",
"(",
")",
"\n",
"}"
] | // Token uses client credentials to retrieve a token.
//
// The provided context optionally controls which HTTP client is used. See the oauth2.HTTPClient variable. | [
"Token",
"uses",
"client",
"credentials",
"to",
"retrieve",
"a",
"token",
".",
"The",
"provided",
"context",
"optionally",
"controls",
"which",
"HTTP",
"client",
"is",
"used",
".",
"See",
"the",
"oauth2",
".",
"HTTPClient",
"variable",
"."
] | 9f3314589c9a9136388751d9adae6b0ed400978a | https://github.com/golang/oauth2/blob/9f3314589c9a9136388751d9adae6b0ed400978a/clientcredentials/clientcredentials.go#L55-L57 | train |
golang/oauth2 | jws/jws.go | EncodeWithSigner | func EncodeWithSigner(header *Header, c *ClaimSet, sg Signer) (string, error) {
head, err := header.encode()
if err != nil {
return "", err
}
cs, err := c.encode()
if err != nil {
return "", err
}
ss := fmt.Sprintf("%s.%s", head, cs)
sig, err := sg([]byte(ss))
if err != nil {
return "", err
}
return fmt.Sprintf("%s.%s", ss, base64.RawURLEncoding.EncodeToString(sig)), nil
} | go | func EncodeWithSigner(header *Header, c *ClaimSet, sg Signer) (string, error) {
head, err := header.encode()
if err != nil {
return "", err
}
cs, err := c.encode()
if err != nil {
return "", err
}
ss := fmt.Sprintf("%s.%s", head, cs)
sig, err := sg([]byte(ss))
if err != nil {
return "", err
}
return fmt.Sprintf("%s.%s", ss, base64.RawURLEncoding.EncodeToString(sig)), nil
} | [
"func",
"EncodeWithSigner",
"(",
"header",
"*",
"Header",
",",
"c",
"*",
"ClaimSet",
",",
"sg",
"Signer",
")",
"(",
"string",
",",
"error",
")",
"{",
"head",
",",
"err",
":=",
"header",
".",
"encode",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"\"",
",",
"err",
"\n",
"}",
"\n",
"cs",
",",
"err",
":=",
"c",
".",
"encode",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"\"",
",",
"err",
"\n",
"}",
"\n",
"ss",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"%s.%s\"",
",",
"head",
",",
"cs",
")",
"\n",
"sig",
",",
"err",
":=",
"sg",
"(",
"[",
"]",
"byte",
"(",
"ss",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"%s.%s\"",
",",
"ss",
",",
"base64",
".",
"RawURLEncoding",
".",
"EncodeToString",
"(",
"sig",
")",
")",
",",
"nil",
"\n",
"}"
] | // EncodeWithSigner encodes a header and claim set with the provided signer. | [
"EncodeWithSigner",
"encodes",
"a",
"header",
"and",
"claim",
"set",
"with",
"the",
"provided",
"signer",
"."
] | 9f3314589c9a9136388751d9adae6b0ed400978a | https://github.com/golang/oauth2/blob/9f3314589c9a9136388751d9adae6b0ed400978a/jws/jws.go#L137-L152 | train |
golang/oauth2 | jws/jws.go | Verify | func Verify(token string, key *rsa.PublicKey) error {
parts := strings.Split(token, ".")
if len(parts) != 3 {
return errors.New("jws: invalid token received, token must have 3 parts")
}
signedContent := parts[0] + "." + parts[1]
signatureString, err := base64.RawURLEncoding.DecodeString(parts[2])
if err != nil {
return err
}
h := sha256.New()
h.Write([]byte(signedContent))
return rsa.VerifyPKCS1v15(key, crypto.SHA256, h.Sum(nil), []byte(signatureString))
} | go | func Verify(token string, key *rsa.PublicKey) error {
parts := strings.Split(token, ".")
if len(parts) != 3 {
return errors.New("jws: invalid token received, token must have 3 parts")
}
signedContent := parts[0] + "." + parts[1]
signatureString, err := base64.RawURLEncoding.DecodeString(parts[2])
if err != nil {
return err
}
h := sha256.New()
h.Write([]byte(signedContent))
return rsa.VerifyPKCS1v15(key, crypto.SHA256, h.Sum(nil), []byte(signatureString))
} | [
"func",
"Verify",
"(",
"token",
"string",
",",
"key",
"*",
"rsa",
".",
"PublicKey",
")",
"error",
"{",
"parts",
":=",
"strings",
".",
"Split",
"(",
"token",
",",
"\".\"",
")",
"\n",
"if",
"len",
"(",
"parts",
")",
"!=",
"3",
"{",
"return",
"errors",
".",
"New",
"(",
"\"jws: invalid token received, token must have 3 parts\"",
")",
"\n",
"}",
"\n",
"signedContent",
":=",
"parts",
"[",
"0",
"]",
"+",
"\".\"",
"+",
"parts",
"[",
"1",
"]",
"\n",
"signatureString",
",",
"err",
":=",
"base64",
".",
"RawURLEncoding",
".",
"DecodeString",
"(",
"parts",
"[",
"2",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"h",
":=",
"sha256",
".",
"New",
"(",
")",
"\n",
"h",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"signedContent",
")",
")",
"\n",
"return",
"rsa",
".",
"VerifyPKCS1v15",
"(",
"key",
",",
"crypto",
".",
"SHA256",
",",
"h",
".",
"Sum",
"(",
"nil",
")",
",",
"[",
"]",
"byte",
"(",
"signatureString",
")",
")",
"\n",
"}"
] | // Verify tests whether the provided JWT token's signature was produced by the private key
// associated with the supplied public key. | [
"Verify",
"tests",
"whether",
"the",
"provided",
"JWT",
"token",
"s",
"signature",
"was",
"produced",
"by",
"the",
"private",
"key",
"associated",
"with",
"the",
"supplied",
"public",
"key",
"."
] | 9f3314589c9a9136388751d9adae6b0ed400978a | https://github.com/golang/oauth2/blob/9f3314589c9a9136388751d9adae6b0ed400978a/jws/jws.go#L167-L182 | train |
golang/oauth2 | jira/jira.go | sign | func sign(key string, claims *ClaimSet) (string, error) {
b, err := json.Marshal(defaultHeader)
if err != nil {
return "", err
}
header := base64.RawURLEncoding.EncodeToString(b)
jsonClaims, err := json.Marshal(claims)
if err != nil {
return "", err
}
encodedClaims := strings.TrimRight(base64.URLEncoding.EncodeToString(jsonClaims), "=")
ss := fmt.Sprintf("%s.%s", header, encodedClaims)
mac := hmac.New(sha256.New, []byte(key))
mac.Write([]byte(ss))
signature := mac.Sum(nil)
return fmt.Sprintf("%s.%s", ss, base64.RawURLEncoding.EncodeToString(signature)), nil
} | go | func sign(key string, claims *ClaimSet) (string, error) {
b, err := json.Marshal(defaultHeader)
if err != nil {
return "", err
}
header := base64.RawURLEncoding.EncodeToString(b)
jsonClaims, err := json.Marshal(claims)
if err != nil {
return "", err
}
encodedClaims := strings.TrimRight(base64.URLEncoding.EncodeToString(jsonClaims), "=")
ss := fmt.Sprintf("%s.%s", header, encodedClaims)
mac := hmac.New(sha256.New, []byte(key))
mac.Write([]byte(ss))
signature := mac.Sum(nil)
return fmt.Sprintf("%s.%s", ss, base64.RawURLEncoding.EncodeToString(signature)), nil
} | [
"func",
"sign",
"(",
"key",
"string",
",",
"claims",
"*",
"ClaimSet",
")",
"(",
"string",
",",
"error",
")",
"{",
"b",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"defaultHeader",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"\"",
",",
"err",
"\n",
"}",
"\n",
"header",
":=",
"base64",
".",
"RawURLEncoding",
".",
"EncodeToString",
"(",
"b",
")",
"\n",
"jsonClaims",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"claims",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"\"",
",",
"err",
"\n",
"}",
"\n",
"encodedClaims",
":=",
"strings",
".",
"TrimRight",
"(",
"base64",
".",
"URLEncoding",
".",
"EncodeToString",
"(",
"jsonClaims",
")",
",",
"\"=\"",
")",
"\n",
"ss",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"%s.%s\"",
",",
"header",
",",
"encodedClaims",
")",
"\n",
"mac",
":=",
"hmac",
".",
"New",
"(",
"sha256",
".",
"New",
",",
"[",
"]",
"byte",
"(",
"key",
")",
")",
"\n",
"mac",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"ss",
")",
")",
"\n",
"signature",
":=",
"mac",
".",
"Sum",
"(",
"nil",
")",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"%s.%s\"",
",",
"ss",
",",
"base64",
".",
"RawURLEncoding",
".",
"EncodeToString",
"(",
"signature",
")",
")",
",",
"nil",
"\n",
"}"
] | // Sign the claim set with the shared secret
// Result to be sent as assertion | [
"Sign",
"the",
"claim",
"set",
"with",
"the",
"shared",
"secret",
"Result",
"to",
"be",
"sent",
"as",
"assertion"
] | 9f3314589c9a9136388751d9adae6b0ed400978a | https://github.com/golang/oauth2/blob/9f3314589c9a9136388751d9adae6b0ed400978a/jira/jira.go#L147-L167 | train |
facebookarchive/grace | gracenet/net.go | activeListeners | func (n *Net) activeListeners() ([]net.Listener, error) {
n.mutex.Lock()
defer n.mutex.Unlock()
ls := make([]net.Listener, len(n.active))
copy(ls, n.active)
return ls, nil
} | go | func (n *Net) activeListeners() ([]net.Listener, error) {
n.mutex.Lock()
defer n.mutex.Unlock()
ls := make([]net.Listener, len(n.active))
copy(ls, n.active)
return ls, nil
} | [
"func",
"(",
"n",
"*",
"Net",
")",
"activeListeners",
"(",
")",
"(",
"[",
"]",
"net",
".",
"Listener",
",",
"error",
")",
"{",
"n",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"n",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"ls",
":=",
"make",
"(",
"[",
"]",
"net",
".",
"Listener",
",",
"len",
"(",
"n",
".",
"active",
")",
")",
"\n",
"copy",
"(",
"ls",
",",
"n",
".",
"active",
")",
"\n",
"return",
"ls",
",",
"nil",
"\n",
"}"
] | // activeListeners returns a snapshot copy of the active listeners. | [
"activeListeners",
"returns",
"a",
"snapshot",
"copy",
"of",
"the",
"active",
"listeners",
"."
] | 75cf19382434e82df4dd84953f566b8ad23d6e9e | https://github.com/facebookarchive/grace/blob/75cf19382434e82df4dd84953f566b8ad23d6e9e/gracenet/net.go#L172-L178 | train |
facebookarchive/grace | gracenet/net.go | StartProcess | func (n *Net) StartProcess() (int, error) {
listeners, err := n.activeListeners()
if err != nil {
return 0, err
}
// Extract the fds from the listeners.
files := make([]*os.File, len(listeners))
for i, l := range listeners {
files[i], err = l.(filer).File()
if err != nil {
return 0, err
}
defer files[i].Close()
}
// Use the original binary location. This works with symlinks such that if
// the file it points to has been changed we will use the updated symlink.
argv0, err := exec.LookPath(os.Args[0])
if err != nil {
return 0, err
}
// Pass on the environment and replace the old count key with the new one.
var env []string
for _, v := range os.Environ() {
if !strings.HasPrefix(v, envCountKeyPrefix) {
env = append(env, v)
}
}
env = append(env, fmt.Sprintf("%s%d", envCountKeyPrefix, len(listeners)))
allFiles := append([]*os.File{os.Stdin, os.Stdout, os.Stderr}, files...)
process, err := os.StartProcess(argv0, os.Args, &os.ProcAttr{
Dir: originalWD,
Env: env,
Files: allFiles,
})
if err != nil {
return 0, err
}
return process.Pid, nil
} | go | func (n *Net) StartProcess() (int, error) {
listeners, err := n.activeListeners()
if err != nil {
return 0, err
}
// Extract the fds from the listeners.
files := make([]*os.File, len(listeners))
for i, l := range listeners {
files[i], err = l.(filer).File()
if err != nil {
return 0, err
}
defer files[i].Close()
}
// Use the original binary location. This works with symlinks such that if
// the file it points to has been changed we will use the updated symlink.
argv0, err := exec.LookPath(os.Args[0])
if err != nil {
return 0, err
}
// Pass on the environment and replace the old count key with the new one.
var env []string
for _, v := range os.Environ() {
if !strings.HasPrefix(v, envCountKeyPrefix) {
env = append(env, v)
}
}
env = append(env, fmt.Sprintf("%s%d", envCountKeyPrefix, len(listeners)))
allFiles := append([]*os.File{os.Stdin, os.Stdout, os.Stderr}, files...)
process, err := os.StartProcess(argv0, os.Args, &os.ProcAttr{
Dir: originalWD,
Env: env,
Files: allFiles,
})
if err != nil {
return 0, err
}
return process.Pid, nil
} | [
"func",
"(",
"n",
"*",
"Net",
")",
"StartProcess",
"(",
")",
"(",
"int",
",",
"error",
")",
"{",
"listeners",
",",
"err",
":=",
"n",
".",
"activeListeners",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"files",
":=",
"make",
"(",
"[",
"]",
"*",
"os",
".",
"File",
",",
"len",
"(",
"listeners",
")",
")",
"\n",
"for",
"i",
",",
"l",
":=",
"range",
"listeners",
"{",
"files",
"[",
"i",
"]",
",",
"err",
"=",
"l",
".",
"(",
"filer",
")",
".",
"File",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"defer",
"files",
"[",
"i",
"]",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"argv0",
",",
"err",
":=",
"exec",
".",
"LookPath",
"(",
"os",
".",
"Args",
"[",
"0",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"var",
"env",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"os",
".",
"Environ",
"(",
")",
"{",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"v",
",",
"envCountKeyPrefix",
")",
"{",
"env",
"=",
"append",
"(",
"env",
",",
"v",
")",
"\n",
"}",
"\n",
"}",
"\n",
"env",
"=",
"append",
"(",
"env",
",",
"fmt",
".",
"Sprintf",
"(",
"\"%s%d\"",
",",
"envCountKeyPrefix",
",",
"len",
"(",
"listeners",
")",
")",
")",
"\n",
"allFiles",
":=",
"append",
"(",
"[",
"]",
"*",
"os",
".",
"File",
"{",
"os",
".",
"Stdin",
",",
"os",
".",
"Stdout",
",",
"os",
".",
"Stderr",
"}",
",",
"files",
"...",
")",
"\n",
"process",
",",
"err",
":=",
"os",
".",
"StartProcess",
"(",
"argv0",
",",
"os",
".",
"Args",
",",
"&",
"os",
".",
"ProcAttr",
"{",
"Dir",
":",
"originalWD",
",",
"Env",
":",
"env",
",",
"Files",
":",
"allFiles",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"return",
"process",
".",
"Pid",
",",
"nil",
"\n",
"}"
] | // StartProcess starts a new process passing it the active listeners. It
// doesn't fork, but starts a new process using the same environment and
// arguments as when it was originally started. This allows for a newly
// deployed binary to be started. It returns the pid of the newly started
// process when successful. | [
"StartProcess",
"starts",
"a",
"new",
"process",
"passing",
"it",
"the",
"active",
"listeners",
".",
"It",
"doesn",
"t",
"fork",
"but",
"starts",
"a",
"new",
"process",
"using",
"the",
"same",
"environment",
"and",
"arguments",
"as",
"when",
"it",
"was",
"originally",
"started",
".",
"This",
"allows",
"for",
"a",
"newly",
"deployed",
"binary",
"to",
"be",
"started",
".",
"It",
"returns",
"the",
"pid",
"of",
"the",
"newly",
"started",
"process",
"when",
"successful",
"."
] | 75cf19382434e82df4dd84953f566b8ad23d6e9e | https://github.com/facebookarchive/grace/blob/75cf19382434e82df4dd84953f566b8ad23d6e9e/gracenet/net.go#L206-L248 | train |
facebookarchive/grace | gracehttp/http.go | ServeWithOptions | func ServeWithOptions(servers []*http.Server, options ...option) error {
a := newApp(servers)
for _, opt := range options {
opt(a)
}
return a.run()
} | go | func ServeWithOptions(servers []*http.Server, options ...option) error {
a := newApp(servers)
for _, opt := range options {
opt(a)
}
return a.run()
} | [
"func",
"ServeWithOptions",
"(",
"servers",
"[",
"]",
"*",
"http",
".",
"Server",
",",
"options",
"...",
"option",
")",
"error",
"{",
"a",
":=",
"newApp",
"(",
"servers",
")",
"\n",
"for",
"_",
",",
"opt",
":=",
"range",
"options",
"{",
"opt",
"(",
"a",
")",
"\n",
"}",
"\n",
"return",
"a",
".",
"run",
"(",
")",
"\n",
"}"
] | // ServeWithOptions does the same as Serve, but takes a set of options to
// configure the app struct. | [
"ServeWithOptions",
"does",
"the",
"same",
"as",
"Serve",
"but",
"takes",
"a",
"set",
"of",
"options",
"to",
"configure",
"the",
"app",
"struct",
"."
] | 75cf19382434e82df4dd84953f566b8ad23d6e9e | https://github.com/facebookarchive/grace/blob/75cf19382434e82df4dd84953f566b8ad23d6e9e/gracehttp/http.go#L181-L187 | train |
facebookarchive/grace | gracehttp/http.go | pprintAddr | func pprintAddr(listeners []net.Listener) []byte {
var out bytes.Buffer
for i, l := range listeners {
if i != 0 {
fmt.Fprint(&out, ", ")
}
fmt.Fprint(&out, l.Addr())
}
return out.Bytes()
} | go | func pprintAddr(listeners []net.Listener) []byte {
var out bytes.Buffer
for i, l := range listeners {
if i != 0 {
fmt.Fprint(&out, ", ")
}
fmt.Fprint(&out, l.Addr())
}
return out.Bytes()
} | [
"func",
"pprintAddr",
"(",
"listeners",
"[",
"]",
"net",
".",
"Listener",
")",
"[",
"]",
"byte",
"{",
"var",
"out",
"bytes",
".",
"Buffer",
"\n",
"for",
"i",
",",
"l",
":=",
"range",
"listeners",
"{",
"if",
"i",
"!=",
"0",
"{",
"fmt",
".",
"Fprint",
"(",
"&",
"out",
",",
"\", \"",
")",
"\n",
"}",
"\n",
"fmt",
".",
"Fprint",
"(",
"&",
"out",
",",
"l",
".",
"Addr",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"out",
".",
"Bytes",
"(",
")",
"\n",
"}"
] | // Used for pretty printing addresses. | [
"Used",
"for",
"pretty",
"printing",
"addresses",
"."
] | 75cf19382434e82df4dd84953f566b8ad23d6e9e | https://github.com/facebookarchive/grace/blob/75cf19382434e82df4dd84953f566b8ad23d6e9e/gracehttp/http.go#L206-L215 | train |
google/btree | btree.go | freeNode | func (f *FreeList) freeNode(n *node) (out bool) {
f.mu.Lock()
if len(f.freelist) < cap(f.freelist) {
f.freelist = append(f.freelist, n)
out = true
}
f.mu.Unlock()
return
} | go | func (f *FreeList) freeNode(n *node) (out bool) {
f.mu.Lock()
if len(f.freelist) < cap(f.freelist) {
f.freelist = append(f.freelist, n)
out = true
}
f.mu.Unlock()
return
} | [
"func",
"(",
"f",
"*",
"FreeList",
")",
"freeNode",
"(",
"n",
"*",
"node",
")",
"(",
"out",
"bool",
")",
"{",
"f",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"if",
"len",
"(",
"f",
".",
"freelist",
")",
"<",
"cap",
"(",
"f",
".",
"freelist",
")",
"{",
"f",
".",
"freelist",
"=",
"append",
"(",
"f",
".",
"freelist",
",",
"n",
")",
"\n",
"out",
"=",
"true",
"\n",
"}",
"\n",
"f",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"\n",
"}"
] | // freeNode adds the given node to the list, returning true if it was added
// and false if it was discarded. | [
"freeNode",
"adds",
"the",
"given",
"node",
"to",
"the",
"list",
"returning",
"true",
"if",
"it",
"was",
"added",
"and",
"false",
"if",
"it",
"was",
"discarded",
"."
] | 20236160a414454a9c64b6c8829381c6f4bddcaa | https://github.com/google/btree/blob/20236160a414454a9c64b6c8829381c6f4bddcaa/btree.go#L108-L116 | train |
google/btree | btree.go | NewWithFreeList | func NewWithFreeList(degree int, f *FreeList) *BTree {
if degree <= 1 {
panic("bad degree")
}
return &BTree{
degree: degree,
cow: ©OnWriteContext{freelist: f},
}
} | go | func NewWithFreeList(degree int, f *FreeList) *BTree {
if degree <= 1 {
panic("bad degree")
}
return &BTree{
degree: degree,
cow: ©OnWriteContext{freelist: f},
}
} | [
"func",
"NewWithFreeList",
"(",
"degree",
"int",
",",
"f",
"*",
"FreeList",
")",
"*",
"BTree",
"{",
"if",
"degree",
"<=",
"1",
"{",
"panic",
"(",
"\"bad degree\"",
")",
"\n",
"}",
"\n",
"return",
"&",
"BTree",
"{",
"degree",
":",
"degree",
",",
"cow",
":",
"&",
"copyOnWriteContext",
"{",
"freelist",
":",
"f",
"}",
",",
"}",
"\n",
"}"
] | // NewWithFreeList creates a new B-Tree that uses the given node free list. | [
"NewWithFreeList",
"creates",
"a",
"new",
"B",
"-",
"Tree",
"that",
"uses",
"the",
"given",
"node",
"free",
"list",
"."
] | 20236160a414454a9c64b6c8829381c6f4bddcaa | https://github.com/google/btree/blob/20236160a414454a9c64b6c8829381c6f4bddcaa/btree.go#L132-L140 | train |
google/btree | btree.go | truncate | func (s *items) truncate(index int) {
var toClear items
*s, toClear = (*s)[:index], (*s)[index:]
for len(toClear) > 0 {
toClear = toClear[copy(toClear, nilItems):]
}
} | go | func (s *items) truncate(index int) {
var toClear items
*s, toClear = (*s)[:index], (*s)[index:]
for len(toClear) > 0 {
toClear = toClear[copy(toClear, nilItems):]
}
} | [
"func",
"(",
"s",
"*",
"items",
")",
"truncate",
"(",
"index",
"int",
")",
"{",
"var",
"toClear",
"items",
"\n",
"*",
"s",
",",
"toClear",
"=",
"(",
"*",
"s",
")",
"[",
":",
"index",
"]",
",",
"(",
"*",
"s",
")",
"[",
"index",
":",
"]",
"\n",
"for",
"len",
"(",
"toClear",
")",
">",
"0",
"{",
"toClear",
"=",
"toClear",
"[",
"copy",
"(",
"toClear",
",",
"nilItems",
")",
":",
"]",
"\n",
"}",
"\n",
"}"
] | // truncate truncates this instance at index so that it contains only the
// first index items. index must be less than or equal to length. | [
"truncate",
"truncates",
"this",
"instance",
"at",
"index",
"so",
"that",
"it",
"contains",
"only",
"the",
"first",
"index",
"items",
".",
"index",
"must",
"be",
"less",
"than",
"or",
"equal",
"to",
"length",
"."
] | 20236160a414454a9c64b6c8829381c6f4bddcaa | https://github.com/google/btree/blob/20236160a414454a9c64b6c8829381c6f4bddcaa/btree.go#L176-L182 | train |
google/btree | btree.go | find | func (s items) find(item Item) (index int, found bool) {
i := sort.Search(len(s), func(i int) bool {
return item.Less(s[i])
})
if i > 0 && !s[i-1].Less(item) {
return i - 1, true
}
return i, false
} | go | func (s items) find(item Item) (index int, found bool) {
i := sort.Search(len(s), func(i int) bool {
return item.Less(s[i])
})
if i > 0 && !s[i-1].Less(item) {
return i - 1, true
}
return i, false
} | [
"func",
"(",
"s",
"items",
")",
"find",
"(",
"item",
"Item",
")",
"(",
"index",
"int",
",",
"found",
"bool",
")",
"{",
"i",
":=",
"sort",
".",
"Search",
"(",
"len",
"(",
"s",
")",
",",
"func",
"(",
"i",
"int",
")",
"bool",
"{",
"return",
"item",
".",
"Less",
"(",
"s",
"[",
"i",
"]",
")",
"\n",
"}",
")",
"\n",
"if",
"i",
">",
"0",
"&&",
"!",
"s",
"[",
"i",
"-",
"1",
"]",
".",
"Less",
"(",
"item",
")",
"{",
"return",
"i",
"-",
"1",
",",
"true",
"\n",
"}",
"\n",
"return",
"i",
",",
"false",
"\n",
"}"
] | // find returns the index where the given item should be inserted into this
// list. 'found' is true if the item already exists in the list at the given
// index. | [
"find",
"returns",
"the",
"index",
"where",
"the",
"given",
"item",
"should",
"be",
"inserted",
"into",
"this",
"list",
".",
"found",
"is",
"true",
"if",
"the",
"item",
"already",
"exists",
"in",
"the",
"list",
"at",
"the",
"given",
"index",
"."
] | 20236160a414454a9c64b6c8829381c6f4bddcaa | https://github.com/google/btree/blob/20236160a414454a9c64b6c8829381c6f4bddcaa/btree.go#L187-L195 | train |
google/btree | btree.go | truncate | func (s *children) truncate(index int) {
var toClear children
*s, toClear = (*s)[:index], (*s)[index:]
for len(toClear) > 0 {
toClear = toClear[copy(toClear, nilChildren):]
}
} | go | func (s *children) truncate(index int) {
var toClear children
*s, toClear = (*s)[:index], (*s)[index:]
for len(toClear) > 0 {
toClear = toClear[copy(toClear, nilChildren):]
}
} | [
"func",
"(",
"s",
"*",
"children",
")",
"truncate",
"(",
"index",
"int",
")",
"{",
"var",
"toClear",
"children",
"\n",
"*",
"s",
",",
"toClear",
"=",
"(",
"*",
"s",
")",
"[",
":",
"index",
"]",
",",
"(",
"*",
"s",
")",
"[",
"index",
":",
"]",
"\n",
"for",
"len",
"(",
"toClear",
")",
">",
"0",
"{",
"toClear",
"=",
"toClear",
"[",
"copy",
"(",
"toClear",
",",
"nilChildren",
")",
":",
"]",
"\n",
"}",
"\n",
"}"
] | // truncate truncates this instance at index so that it contains only the
// first index children. index must be less than or equal to length. | [
"truncate",
"truncates",
"this",
"instance",
"at",
"index",
"so",
"that",
"it",
"contains",
"only",
"the",
"first",
"index",
"children",
".",
"index",
"must",
"be",
"less",
"than",
"or",
"equal",
"to",
"length",
"."
] | 20236160a414454a9c64b6c8829381c6f4bddcaa | https://github.com/google/btree/blob/20236160a414454a9c64b6c8829381c6f4bddcaa/btree.go#L231-L237 | train |
google/btree | btree.go | maybeSplitChild | func (n *node) maybeSplitChild(i, maxItems int) bool {
if len(n.children[i].items) < maxItems {
return false
}
first := n.mutableChild(i)
item, second := first.split(maxItems / 2)
n.items.insertAt(i, item)
n.children.insertAt(i+1, second)
return true
} | go | func (n *node) maybeSplitChild(i, maxItems int) bool {
if len(n.children[i].items) < maxItems {
return false
}
first := n.mutableChild(i)
item, second := first.split(maxItems / 2)
n.items.insertAt(i, item)
n.children.insertAt(i+1, second)
return true
} | [
"func",
"(",
"n",
"*",
"node",
")",
"maybeSplitChild",
"(",
"i",
",",
"maxItems",
"int",
")",
"bool",
"{",
"if",
"len",
"(",
"n",
".",
"children",
"[",
"i",
"]",
".",
"items",
")",
"<",
"maxItems",
"{",
"return",
"false",
"\n",
"}",
"\n",
"first",
":=",
"n",
".",
"mutableChild",
"(",
"i",
")",
"\n",
"item",
",",
"second",
":=",
"first",
".",
"split",
"(",
"maxItems",
"/",
"2",
")",
"\n",
"n",
".",
"items",
".",
"insertAt",
"(",
"i",
",",
"item",
")",
"\n",
"n",
".",
"children",
".",
"insertAt",
"(",
"i",
"+",
"1",
",",
"second",
")",
"\n",
"return",
"true",
"\n",
"}"
] | // maybeSplitChild checks if a child should be split, and if so splits it.
// Returns whether or not a split occurred. | [
"maybeSplitChild",
"checks",
"if",
"a",
"child",
"should",
"be",
"split",
"and",
"if",
"so",
"splits",
"it",
".",
"Returns",
"whether",
"or",
"not",
"a",
"split",
"occurred",
"."
] | 20236160a414454a9c64b6c8829381c6f4bddcaa | https://github.com/google/btree/blob/20236160a414454a9c64b6c8829381c6f4bddcaa/btree.go#L294-L303 | train |
google/btree | btree.go | get | func (n *node) get(key Item) Item {
i, found := n.items.find(key)
if found {
return n.items[i]
} else if len(n.children) > 0 {
return n.children[i].get(key)
}
return nil
} | go | func (n *node) get(key Item) Item {
i, found := n.items.find(key)
if found {
return n.items[i]
} else if len(n.children) > 0 {
return n.children[i].get(key)
}
return nil
} | [
"func",
"(",
"n",
"*",
"node",
")",
"get",
"(",
"key",
"Item",
")",
"Item",
"{",
"i",
",",
"found",
":=",
"n",
".",
"items",
".",
"find",
"(",
"key",
")",
"\n",
"if",
"found",
"{",
"return",
"n",
".",
"items",
"[",
"i",
"]",
"\n",
"}",
"else",
"if",
"len",
"(",
"n",
".",
"children",
")",
">",
"0",
"{",
"return",
"n",
".",
"children",
"[",
"i",
"]",
".",
"get",
"(",
"key",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // get finds the given key in the subtree and returns it. | [
"get",
"finds",
"the",
"given",
"key",
"in",
"the",
"subtree",
"and",
"returns",
"it",
"."
] | 20236160a414454a9c64b6c8829381c6f4bddcaa | https://github.com/google/btree/blob/20236160a414454a9c64b6c8829381c6f4bddcaa/btree.go#L336-L344 | train |
google/btree | btree.go | min | func min(n *node) Item {
if n == nil {
return nil
}
for len(n.children) > 0 {
n = n.children[0]
}
if len(n.items) == 0 {
return nil
}
return n.items[0]
} | go | func min(n *node) Item {
if n == nil {
return nil
}
for len(n.children) > 0 {
n = n.children[0]
}
if len(n.items) == 0 {
return nil
}
return n.items[0]
} | [
"func",
"min",
"(",
"n",
"*",
"node",
")",
"Item",
"{",
"if",
"n",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"for",
"len",
"(",
"n",
".",
"children",
")",
">",
"0",
"{",
"n",
"=",
"n",
".",
"children",
"[",
"0",
"]",
"\n",
"}",
"\n",
"if",
"len",
"(",
"n",
".",
"items",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"n",
".",
"items",
"[",
"0",
"]",
"\n",
"}"
] | // min returns the first item in the subtree. | [
"min",
"returns",
"the",
"first",
"item",
"in",
"the",
"subtree",
"."
] | 20236160a414454a9c64b6c8829381c6f4bddcaa | https://github.com/google/btree/blob/20236160a414454a9c64b6c8829381c6f4bddcaa/btree.go#L347-L358 | train |
google/btree | btree.go | max | func max(n *node) Item {
if n == nil {
return nil
}
for len(n.children) > 0 {
n = n.children[len(n.children)-1]
}
if len(n.items) == 0 {
return nil
}
return n.items[len(n.items)-1]
} | go | func max(n *node) Item {
if n == nil {
return nil
}
for len(n.children) > 0 {
n = n.children[len(n.children)-1]
}
if len(n.items) == 0 {
return nil
}
return n.items[len(n.items)-1]
} | [
"func",
"max",
"(",
"n",
"*",
"node",
")",
"Item",
"{",
"if",
"n",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"for",
"len",
"(",
"n",
".",
"children",
")",
">",
"0",
"{",
"n",
"=",
"n",
".",
"children",
"[",
"len",
"(",
"n",
".",
"children",
")",
"-",
"1",
"]",
"\n",
"}",
"\n",
"if",
"len",
"(",
"n",
".",
"items",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"n",
".",
"items",
"[",
"len",
"(",
"n",
".",
"items",
")",
"-",
"1",
"]",
"\n",
"}"
] | // max returns the last item in the subtree. | [
"max",
"returns",
"the",
"last",
"item",
"in",
"the",
"subtree",
"."
] | 20236160a414454a9c64b6c8829381c6f4bddcaa | https://github.com/google/btree/blob/20236160a414454a9c64b6c8829381c6f4bddcaa/btree.go#L361-L372 | train |
google/btree | btree.go | remove | func (n *node) remove(item Item, minItems int, typ toRemove) Item {
var i int
var found bool
switch typ {
case removeMax:
if len(n.children) == 0 {
return n.items.pop()
}
i = len(n.items)
case removeMin:
if len(n.children) == 0 {
return n.items.removeAt(0)
}
i = 0
case removeItem:
i, found = n.items.find(item)
if len(n.children) == 0 {
if found {
return n.items.removeAt(i)
}
return nil
}
default:
panic("invalid type")
}
// If we get to here, we have children.
if len(n.children[i].items) <= minItems {
return n.growChildAndRemove(i, item, minItems, typ)
}
child := n.mutableChild(i)
// Either we had enough items to begin with, or we've done some
// merging/stealing, because we've got enough now and we're ready to return
// stuff.
if found {
// The item exists at index 'i', and the child we've selected can give us a
// predecessor, since if we've gotten here it's got > minItems items in it.
out := n.items[i]
// We use our special-case 'remove' call with typ=maxItem to pull the
// predecessor of item i (the rightmost leaf of our immediate left child)
// and set it into where we pulled the item from.
n.items[i] = child.remove(nil, minItems, removeMax)
return out
}
// Final recursive call. Once we're here, we know that the item isn't in this
// node and that the child is big enough to remove from.
return child.remove(item, minItems, typ)
} | go | func (n *node) remove(item Item, minItems int, typ toRemove) Item {
var i int
var found bool
switch typ {
case removeMax:
if len(n.children) == 0 {
return n.items.pop()
}
i = len(n.items)
case removeMin:
if len(n.children) == 0 {
return n.items.removeAt(0)
}
i = 0
case removeItem:
i, found = n.items.find(item)
if len(n.children) == 0 {
if found {
return n.items.removeAt(i)
}
return nil
}
default:
panic("invalid type")
}
// If we get to here, we have children.
if len(n.children[i].items) <= minItems {
return n.growChildAndRemove(i, item, minItems, typ)
}
child := n.mutableChild(i)
// Either we had enough items to begin with, or we've done some
// merging/stealing, because we've got enough now and we're ready to return
// stuff.
if found {
// The item exists at index 'i', and the child we've selected can give us a
// predecessor, since if we've gotten here it's got > minItems items in it.
out := n.items[i]
// We use our special-case 'remove' call with typ=maxItem to pull the
// predecessor of item i (the rightmost leaf of our immediate left child)
// and set it into where we pulled the item from.
n.items[i] = child.remove(nil, minItems, removeMax)
return out
}
// Final recursive call. Once we're here, we know that the item isn't in this
// node and that the child is big enough to remove from.
return child.remove(item, minItems, typ)
} | [
"func",
"(",
"n",
"*",
"node",
")",
"remove",
"(",
"item",
"Item",
",",
"minItems",
"int",
",",
"typ",
"toRemove",
")",
"Item",
"{",
"var",
"i",
"int",
"\n",
"var",
"found",
"bool",
"\n",
"switch",
"typ",
"{",
"case",
"removeMax",
":",
"if",
"len",
"(",
"n",
".",
"children",
")",
"==",
"0",
"{",
"return",
"n",
".",
"items",
".",
"pop",
"(",
")",
"\n",
"}",
"\n",
"i",
"=",
"len",
"(",
"n",
".",
"items",
")",
"\n",
"case",
"removeMin",
":",
"if",
"len",
"(",
"n",
".",
"children",
")",
"==",
"0",
"{",
"return",
"n",
".",
"items",
".",
"removeAt",
"(",
"0",
")",
"\n",
"}",
"\n",
"i",
"=",
"0",
"\n",
"case",
"removeItem",
":",
"i",
",",
"found",
"=",
"n",
".",
"items",
".",
"find",
"(",
"item",
")",
"\n",
"if",
"len",
"(",
"n",
".",
"children",
")",
"==",
"0",
"{",
"if",
"found",
"{",
"return",
"n",
".",
"items",
".",
"removeAt",
"(",
"i",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"default",
":",
"panic",
"(",
"\"invalid type\"",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"n",
".",
"children",
"[",
"i",
"]",
".",
"items",
")",
"<=",
"minItems",
"{",
"return",
"n",
".",
"growChildAndRemove",
"(",
"i",
",",
"item",
",",
"minItems",
",",
"typ",
")",
"\n",
"}",
"\n",
"child",
":=",
"n",
".",
"mutableChild",
"(",
"i",
")",
"\n",
"if",
"found",
"{",
"out",
":=",
"n",
".",
"items",
"[",
"i",
"]",
"\n",
"n",
".",
"items",
"[",
"i",
"]",
"=",
"child",
".",
"remove",
"(",
"nil",
",",
"minItems",
",",
"removeMax",
")",
"\n",
"return",
"out",
"\n",
"}",
"\n",
"return",
"child",
".",
"remove",
"(",
"item",
",",
"minItems",
",",
"typ",
")",
"\n",
"}"
] | // remove removes an item from the subtree rooted at this node. | [
"remove",
"removes",
"an",
"item",
"from",
"the",
"subtree",
"rooted",
"at",
"this",
"node",
"."
] | 20236160a414454a9c64b6c8829381c6f4bddcaa | https://github.com/google/btree/blob/20236160a414454a9c64b6c8829381c6f4bddcaa/btree.go#L384-L430 | train |
google/btree | btree.go | Delete | func (t *BTree) Delete(item Item) Item {
return t.deleteItem(item, removeItem)
} | go | func (t *BTree) Delete(item Item) Item {
return t.deleteItem(item, removeItem)
} | [
"func",
"(",
"t",
"*",
"BTree",
")",
"Delete",
"(",
"item",
"Item",
")",
"Item",
"{",
"return",
"t",
".",
"deleteItem",
"(",
"item",
",",
"removeItem",
")",
"\n",
"}"
] | // Delete removes an item equal to the passed in item from the tree, returning
// it. If no such item exists, returns nil. | [
"Delete",
"removes",
"an",
"item",
"equal",
"to",
"the",
"passed",
"in",
"item",
"from",
"the",
"tree",
"returning",
"it",
".",
"If",
"no",
"such",
"item",
"exists",
"returns",
"nil",
"."
] | 20236160a414454a9c64b6c8829381c6f4bddcaa | https://github.com/google/btree/blob/20236160a414454a9c64b6c8829381c6f4bddcaa/btree.go#L711-L713 | train |
google/btree | btree.go | AscendRange | func (t *BTree) AscendRange(greaterOrEqual, lessThan Item, iterator ItemIterator) {
if t.root == nil {
return
}
t.root.iterate(ascend, greaterOrEqual, lessThan, true, false, iterator)
} | go | func (t *BTree) AscendRange(greaterOrEqual, lessThan Item, iterator ItemIterator) {
if t.root == nil {
return
}
t.root.iterate(ascend, greaterOrEqual, lessThan, true, false, iterator)
} | [
"func",
"(",
"t",
"*",
"BTree",
")",
"AscendRange",
"(",
"greaterOrEqual",
",",
"lessThan",
"Item",
",",
"iterator",
"ItemIterator",
")",
"{",
"if",
"t",
".",
"root",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"t",
".",
"root",
".",
"iterate",
"(",
"ascend",
",",
"greaterOrEqual",
",",
"lessThan",
",",
"true",
",",
"false",
",",
"iterator",
")",
"\n",
"}"
] | // AscendRange calls the iterator for every value in the tree within the range
// [greaterOrEqual, lessThan), until iterator returns false. | [
"AscendRange",
"calls",
"the",
"iterator",
"for",
"every",
"value",
"in",
"the",
"tree",
"within",
"the",
"range",
"[",
"greaterOrEqual",
"lessThan",
")",
"until",
"iterator",
"returns",
"false",
"."
] | 20236160a414454a9c64b6c8829381c6f4bddcaa | https://github.com/google/btree/blob/20236160a414454a9c64b6c8829381c6f4bddcaa/btree.go#L746-L751 | train |
google/btree | btree.go | AscendLessThan | func (t *BTree) AscendLessThan(pivot Item, iterator ItemIterator) {
if t.root == nil {
return
}
t.root.iterate(ascend, nil, pivot, false, false, iterator)
} | go | func (t *BTree) AscendLessThan(pivot Item, iterator ItemIterator) {
if t.root == nil {
return
}
t.root.iterate(ascend, nil, pivot, false, false, iterator)
} | [
"func",
"(",
"t",
"*",
"BTree",
")",
"AscendLessThan",
"(",
"pivot",
"Item",
",",
"iterator",
"ItemIterator",
")",
"{",
"if",
"t",
".",
"root",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"t",
".",
"root",
".",
"iterate",
"(",
"ascend",
",",
"nil",
",",
"pivot",
",",
"false",
",",
"false",
",",
"iterator",
")",
"\n",
"}"
] | // AscendLessThan calls the iterator for every value in the tree within the range
// [first, pivot), until iterator returns false. | [
"AscendLessThan",
"calls",
"the",
"iterator",
"for",
"every",
"value",
"in",
"the",
"tree",
"within",
"the",
"range",
"[",
"first",
"pivot",
")",
"until",
"iterator",
"returns",
"false",
"."
] | 20236160a414454a9c64b6c8829381c6f4bddcaa | https://github.com/google/btree/blob/20236160a414454a9c64b6c8829381c6f4bddcaa/btree.go#L755-L760 | train |
google/btree | btree.go | DescendRange | func (t *BTree) DescendRange(lessOrEqual, greaterThan Item, iterator ItemIterator) {
if t.root == nil {
return
}
t.root.iterate(descend, lessOrEqual, greaterThan, true, false, iterator)
} | go | func (t *BTree) DescendRange(lessOrEqual, greaterThan Item, iterator ItemIterator) {
if t.root == nil {
return
}
t.root.iterate(descend, lessOrEqual, greaterThan, true, false, iterator)
} | [
"func",
"(",
"t",
"*",
"BTree",
")",
"DescendRange",
"(",
"lessOrEqual",
",",
"greaterThan",
"Item",
",",
"iterator",
"ItemIterator",
")",
"{",
"if",
"t",
".",
"root",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"t",
".",
"root",
".",
"iterate",
"(",
"descend",
",",
"lessOrEqual",
",",
"greaterThan",
",",
"true",
",",
"false",
",",
"iterator",
")",
"\n",
"}"
] | // DescendRange calls the iterator for every value in the tree within the range
// [lessOrEqual, greaterThan), until iterator returns false. | [
"DescendRange",
"calls",
"the",
"iterator",
"for",
"every",
"value",
"in",
"the",
"tree",
"within",
"the",
"range",
"[",
"lessOrEqual",
"greaterThan",
")",
"until",
"iterator",
"returns",
"false",
"."
] | 20236160a414454a9c64b6c8829381c6f4bddcaa | https://github.com/google/btree/blob/20236160a414454a9c64b6c8829381c6f4bddcaa/btree.go#L782-L787 | train |
google/btree | btree.go | DescendGreaterThan | func (t *BTree) DescendGreaterThan(pivot Item, iterator ItemIterator) {
if t.root == nil {
return
}
t.root.iterate(descend, nil, pivot, false, false, iterator)
} | go | func (t *BTree) DescendGreaterThan(pivot Item, iterator ItemIterator) {
if t.root == nil {
return
}
t.root.iterate(descend, nil, pivot, false, false, iterator)
} | [
"func",
"(",
"t",
"*",
"BTree",
")",
"DescendGreaterThan",
"(",
"pivot",
"Item",
",",
"iterator",
"ItemIterator",
")",
"{",
"if",
"t",
".",
"root",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"t",
".",
"root",
".",
"iterate",
"(",
"descend",
",",
"nil",
",",
"pivot",
",",
"false",
",",
"false",
",",
"iterator",
")",
"\n",
"}"
] | // DescendGreaterThan calls the iterator for every value in the tree within
// the range (pivot, last], until iterator returns false. | [
"DescendGreaterThan",
"calls",
"the",
"iterator",
"for",
"every",
"value",
"in",
"the",
"tree",
"within",
"the",
"range",
"(",
"pivot",
"last",
"]",
"until",
"iterator",
"returns",
"false",
"."
] | 20236160a414454a9c64b6c8829381c6f4bddcaa | https://github.com/google/btree/blob/20236160a414454a9c64b6c8829381c6f4bddcaa/btree.go#L800-L805 | train |
google/btree | btree.go | Get | func (t *BTree) Get(key Item) Item {
if t.root == nil {
return nil
}
return t.root.get(key)
} | go | func (t *BTree) Get(key Item) Item {
if t.root == nil {
return nil
}
return t.root.get(key)
} | [
"func",
"(",
"t",
"*",
"BTree",
")",
"Get",
"(",
"key",
"Item",
")",
"Item",
"{",
"if",
"t",
".",
"root",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"t",
".",
"root",
".",
"get",
"(",
"key",
")",
"\n",
"}"
] | // Get looks for the key item in the tree, returning it. It returns nil if
// unable to find that item. | [
"Get",
"looks",
"for",
"the",
"key",
"item",
"in",
"the",
"tree",
"returning",
"it",
".",
"It",
"returns",
"nil",
"if",
"unable",
"to",
"find",
"that",
"item",
"."
] | 20236160a414454a9c64b6c8829381c6f4bddcaa | https://github.com/google/btree/blob/20236160a414454a9c64b6c8829381c6f4bddcaa/btree.go#L818-L823 | train |
google/btree | btree.go | Has | func (t *BTree) Has(key Item) bool {
return t.Get(key) != nil
} | go | func (t *BTree) Has(key Item) bool {
return t.Get(key) != nil
} | [
"func",
"(",
"t",
"*",
"BTree",
")",
"Has",
"(",
"key",
"Item",
")",
"bool",
"{",
"return",
"t",
".",
"Get",
"(",
"key",
")",
"!=",
"nil",
"\n",
"}"
] | // Has returns true if the given key is in the tree. | [
"Has",
"returns",
"true",
"if",
"the",
"given",
"key",
"is",
"in",
"the",
"tree",
"."
] | 20236160a414454a9c64b6c8829381c6f4bddcaa | https://github.com/google/btree/blob/20236160a414454a9c64b6c8829381c6f4bddcaa/btree.go#L836-L838 | train |
google/btree | btree.go | reset | func (n *node) reset(c *copyOnWriteContext) bool {
for _, child := range n.children {
if !child.reset(c) {
return false
}
}
return c.freeNode(n) != ftFreelistFull
} | go | func (n *node) reset(c *copyOnWriteContext) bool {
for _, child := range n.children {
if !child.reset(c) {
return false
}
}
return c.freeNode(n) != ftFreelistFull
} | [
"func",
"(",
"n",
"*",
"node",
")",
"reset",
"(",
"c",
"*",
"copyOnWriteContext",
")",
"bool",
"{",
"for",
"_",
",",
"child",
":=",
"range",
"n",
".",
"children",
"{",
"if",
"!",
"child",
".",
"reset",
"(",
"c",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"c",
".",
"freeNode",
"(",
"n",
")",
"!=",
"ftFreelistFull",
"\n",
"}"
] | // reset returns a subtree to the freelist. It breaks out immediately if the
// freelist is full, since the only benefit of iterating is to fill that
// freelist up. Returns true if parent reset call should continue. | [
"reset",
"returns",
"a",
"subtree",
"to",
"the",
"freelist",
".",
"It",
"breaks",
"out",
"immediately",
"if",
"the",
"freelist",
"is",
"full",
"since",
"the",
"only",
"benefit",
"of",
"iterating",
"is",
"to",
"fill",
"that",
"freelist",
"up",
".",
"Returns",
"true",
"if",
"parent",
"reset",
"call",
"should",
"continue",
"."
] | 20236160a414454a9c64b6c8829381c6f4bddcaa | https://github.com/google/btree/blob/20236160a414454a9c64b6c8829381c6f4bddcaa/btree.go#L875-L882 | train |
kshvakov/clickhouse | lib/column/ip.go | Scan | func (ip *IP) Scan(value interface{}) (err error) {
switch v := value.(type) {
case []byte:
if len(v) == 4 || len(v) == 16 {
*ip = IP(v)
} else {
err = errInvalidScanValue
}
case string:
if len(v) == 4 || len(v) == 16 {
*ip = IP([]byte(v))
} else {
err = errInvalidScanValue
}
default:
err = errInvalidScanType
}
return
} | go | func (ip *IP) Scan(value interface{}) (err error) {
switch v := value.(type) {
case []byte:
if len(v) == 4 || len(v) == 16 {
*ip = IP(v)
} else {
err = errInvalidScanValue
}
case string:
if len(v) == 4 || len(v) == 16 {
*ip = IP([]byte(v))
} else {
err = errInvalidScanValue
}
default:
err = errInvalidScanType
}
return
} | [
"func",
"(",
"ip",
"*",
"IP",
")",
"Scan",
"(",
"value",
"interface",
"{",
"}",
")",
"(",
"err",
"error",
")",
"{",
"switch",
"v",
":=",
"value",
".",
"(",
"type",
")",
"{",
"case",
"[",
"]",
"byte",
":",
"if",
"len",
"(",
"v",
")",
"==",
"4",
"||",
"len",
"(",
"v",
")",
"==",
"16",
"{",
"*",
"ip",
"=",
"IP",
"(",
"v",
")",
"\n",
"}",
"else",
"{",
"err",
"=",
"errInvalidScanValue",
"\n",
"}",
"\n",
"case",
"string",
":",
"if",
"len",
"(",
"v",
")",
"==",
"4",
"||",
"len",
"(",
"v",
")",
"==",
"16",
"{",
"*",
"ip",
"=",
"IP",
"(",
"[",
"]",
"byte",
"(",
"v",
")",
")",
"\n",
"}",
"else",
"{",
"err",
"=",
"errInvalidScanValue",
"\n",
"}",
"\n",
"default",
":",
"err",
"=",
"errInvalidScanType",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // Scan implements the driver.Valuer interface, json field interface | [
"Scan",
"implements",
"the",
"driver",
".",
"Valuer",
"interface",
"json",
"field",
"interface"
] | 04847609e9ba2f114bdd435bc78e6c816a4ef5c1 | https://github.com/kshvakov/clickhouse/blob/04847609e9ba2f114bdd435bc78e6c816a4ef5c1/lib/column/ip.go#L50-L68 | train |
kshvakov/clickhouse | lib/cityhash102/cityhash.go | hashLen17to32 | func hashLen17to32(s []byte, length uint32) uint64 {
var a = fetch64(s) * k1
var b = fetch64(s[8:])
var c = fetch64(s[length-8:]) * k2
var d = fetch64(s[length-16:]) * k0
return hashLen16(rotate64(a-b, 43)+rotate64(c, 30)+d,
a+rotate64(b^k3, 20)-c+uint64(length))
} | go | func hashLen17to32(s []byte, length uint32) uint64 {
var a = fetch64(s) * k1
var b = fetch64(s[8:])
var c = fetch64(s[length-8:]) * k2
var d = fetch64(s[length-16:]) * k0
return hashLen16(rotate64(a-b, 43)+rotate64(c, 30)+d,
a+rotate64(b^k3, 20)-c+uint64(length))
} | [
"func",
"hashLen17to32",
"(",
"s",
"[",
"]",
"byte",
",",
"length",
"uint32",
")",
"uint64",
"{",
"var",
"a",
"=",
"fetch64",
"(",
"s",
")",
"*",
"k1",
"\n",
"var",
"b",
"=",
"fetch64",
"(",
"s",
"[",
"8",
":",
"]",
")",
"\n",
"var",
"c",
"=",
"fetch64",
"(",
"s",
"[",
"length",
"-",
"8",
":",
"]",
")",
"*",
"k2",
"\n",
"var",
"d",
"=",
"fetch64",
"(",
"s",
"[",
"length",
"-",
"16",
":",
"]",
")",
"*",
"k0",
"\n",
"return",
"hashLen16",
"(",
"rotate64",
"(",
"a",
"-",
"b",
",",
"43",
")",
"+",
"rotate64",
"(",
"c",
",",
"30",
")",
"+",
"d",
",",
"a",
"+",
"rotate64",
"(",
"b",
"^",
"k3",
",",
"20",
")",
"-",
"c",
"+",
"uint64",
"(",
"length",
")",
")",
"\n",
"}"
] | // This probably works well for 16-byte strings as well, but it may be overkill | [
"This",
"probably",
"works",
"well",
"for",
"16",
"-",
"byte",
"strings",
"as",
"well",
"but",
"it",
"may",
"be",
"overkill"
] | 04847609e9ba2f114bdd435bc78e6c816a4ef5c1 | https://github.com/kshvakov/clickhouse/blob/04847609e9ba2f114bdd435bc78e6c816a4ef5c1/lib/cityhash102/cityhash.go#L151-L159 | train |
kshvakov/clickhouse | lib/binary/compress_writer.go | NewCompressWriter | func NewCompressWriter(w io.Writer) *compressWriter {
p := &compressWriter{writer: w}
p.data = make([]byte, BlockMaxSize, BlockMaxSize)
zlen := lz4.CompressBound(BlockMaxSize) + HeaderSize
p.zdata = make([]byte, zlen, zlen)
return p
} | go | func NewCompressWriter(w io.Writer) *compressWriter {
p := &compressWriter{writer: w}
p.data = make([]byte, BlockMaxSize, BlockMaxSize)
zlen := lz4.CompressBound(BlockMaxSize) + HeaderSize
p.zdata = make([]byte, zlen, zlen)
return p
} | [
"func",
"NewCompressWriter",
"(",
"w",
"io",
".",
"Writer",
")",
"*",
"compressWriter",
"{",
"p",
":=",
"&",
"compressWriter",
"{",
"writer",
":",
"w",
"}",
"\n",
"p",
".",
"data",
"=",
"make",
"(",
"[",
"]",
"byte",
",",
"BlockMaxSize",
",",
"BlockMaxSize",
")",
"\n",
"zlen",
":=",
"lz4",
".",
"CompressBound",
"(",
"BlockMaxSize",
")",
"+",
"HeaderSize",
"\n",
"p",
".",
"zdata",
"=",
"make",
"(",
"[",
"]",
"byte",
",",
"zlen",
",",
"zlen",
")",
"\n",
"return",
"p",
"\n",
"}"
] | // NewCompressWriter wrap the io.Writer | [
"NewCompressWriter",
"wrap",
"the",
"io",
".",
"Writer"
] | 04847609e9ba2f114bdd435bc78e6c816a4ef5c1 | https://github.com/kshvakov/clickhouse/blob/04847609e9ba2f114bdd435bc78e6c816a4ef5c1/lib/binary/compress_writer.go#L24-L31 | train |
kshvakov/clickhouse | lib/column/uuid.go | xtob | func xtob(x1, x2 byte) (byte, bool) {
b1 := xvalues[x1]
b2 := xvalues[x2]
return (b1 << 4) | b2, b1 != 255 && b2 != 255
} | go | func xtob(x1, x2 byte) (byte, bool) {
b1 := xvalues[x1]
b2 := xvalues[x2]
return (b1 << 4) | b2, b1 != 255 && b2 != 255
} | [
"func",
"xtob",
"(",
"x1",
",",
"x2",
"byte",
")",
"(",
"byte",
",",
"bool",
")",
"{",
"b1",
":=",
"xvalues",
"[",
"x1",
"]",
"\n",
"b2",
":=",
"xvalues",
"[",
"x2",
"]",
"\n",
"return",
"(",
"b1",
"<<",
"4",
")",
"|",
"b2",
",",
"b1",
"!=",
"255",
"&&",
"b2",
"!=",
"255",
"\n",
"}"
] | // xtob converts hex characters x1 and x2 into a byte. | [
"xtob",
"converts",
"hex",
"characters",
"x1",
"and",
"x2",
"into",
"a",
"byte",
"."
] | 04847609e9ba2f114bdd435bc78e6c816a4ef5c1 | https://github.com/kshvakov/clickhouse/blob/04847609e9ba2f114bdd435bc78e6c816a4ef5c1/lib/column/uuid.go#L126-L130 | train |
kshvakov/clickhouse | word_matcher.go | newMatcher | func newMatcher(needle string) *wordMatcher {
return &wordMatcher{word: []rune(strings.ToUpper(needle)),
position: 0}
} | go | func newMatcher(needle string) *wordMatcher {
return &wordMatcher{word: []rune(strings.ToUpper(needle)),
position: 0}
} | [
"func",
"newMatcher",
"(",
"needle",
"string",
")",
"*",
"wordMatcher",
"{",
"return",
"&",
"wordMatcher",
"{",
"word",
":",
"[",
"]",
"rune",
"(",
"strings",
".",
"ToUpper",
"(",
"needle",
")",
")",
",",
"position",
":",
"0",
"}",
"\n",
"}"
] | // newMatcher returns matcher for word needle | [
"newMatcher",
"returns",
"matcher",
"for",
"word",
"needle"
] | 04847609e9ba2f114bdd435bc78e6c816a4ef5c1 | https://github.com/kshvakov/clickhouse/blob/04847609e9ba2f114bdd435bc78e6c816a4ef5c1/word_matcher.go#L15-L18 | train |
kshvakov/clickhouse | lib/binary/compress_reader.go | NewCompressReader | func NewCompressReader(r io.Reader) *compressReader {
p := &compressReader{
reader: r,
header: make([]byte, HeaderSize),
}
p.data = make([]byte, BlockMaxSize, BlockMaxSize)
zlen := lz4.CompressBound(BlockMaxSize) + HeaderSize
p.zdata = make([]byte, zlen, zlen)
p.pos = len(p.data)
return p
} | go | func NewCompressReader(r io.Reader) *compressReader {
p := &compressReader{
reader: r,
header: make([]byte, HeaderSize),
}
p.data = make([]byte, BlockMaxSize, BlockMaxSize)
zlen := lz4.CompressBound(BlockMaxSize) + HeaderSize
p.zdata = make([]byte, zlen, zlen)
p.pos = len(p.data)
return p
} | [
"func",
"NewCompressReader",
"(",
"r",
"io",
".",
"Reader",
")",
"*",
"compressReader",
"{",
"p",
":=",
"&",
"compressReader",
"{",
"reader",
":",
"r",
",",
"header",
":",
"make",
"(",
"[",
"]",
"byte",
",",
"HeaderSize",
")",
",",
"}",
"\n",
"p",
".",
"data",
"=",
"make",
"(",
"[",
"]",
"byte",
",",
"BlockMaxSize",
",",
"BlockMaxSize",
")",
"\n",
"zlen",
":=",
"lz4",
".",
"CompressBound",
"(",
"BlockMaxSize",
")",
"+",
"HeaderSize",
"\n",
"p",
".",
"zdata",
"=",
"make",
"(",
"[",
"]",
"byte",
",",
"zlen",
",",
"zlen",
")",
"\n",
"p",
".",
"pos",
"=",
"len",
"(",
"p",
".",
"data",
")",
"\n",
"return",
"p",
"\n",
"}"
] | // NewCompressReader wrap the io.Reader | [
"NewCompressReader",
"wrap",
"the",
"io",
".",
"Reader"
] | 04847609e9ba2f114bdd435bc78e6c816a4ef5c1 | https://github.com/kshvakov/clickhouse/blob/04847609e9ba2f114bdd435bc78e6c816a4ef5c1/lib/binary/compress_reader.go#L26-L38 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.