_id stringlengths 2 7 | title stringlengths 1 118 | partition stringclasses 3
values | text stringlengths 52 85.5k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q28900 | findSelection | train | func (s *Action) findSelection(ctx context.Context, c *cli.Context, choices []string, needle string, cb showFunc) error {
sort.Strings(choices)
act, sel := cui.GetSelection(ctx, "Found secrets - Please select an entry", "<↑/↓> to change the selection, <→> to show, <←> to copy, <s> to sync, <e> to edit, <ESC> to quit"... | go | {
"resource": ""
} |
q28901 | QRCode | train | func QRCode(content string) (string, error) {
q, err := qrcode.New(content, qrcode.Medium)
if err != nil {
return "", err
}
buf := bytes.Buffer{}
i := q.Image(0)
b := i.Bounds()
for x := b.Min.X; x < b.Max.X; x++ {
for y := b.Min.Y; y < b.Max.Y; y++ {
col := i.At(x, y)
if sameColor(col, q.ForegroundCol... | go | {
"resource": ""
} |
q28902 | GetContext | train | func (r *Store) GetContext(ctx context.Context, name string) (store.Secret, context.Context, error) {
// forward to substore
ctx, store, name := r.getStore(ctx, name)
sec, err := store.Get(ctx, name)
return sec, ctx, err
} | go | {
"resource": ""
} |
q28903 | New | train | func New(name string) *Folder {
f := newFolder(name)
f.Root = true
return f
} | go | {
"resource": ""
} |
q28904 | IsUpdateable | train | func IsUpdateable(ctx context.Context) error {
fn, err := executable(ctx)
if err != nil {
return err
}
out.Debug(ctx, "isUpdateable - File: %s", fn)
// check if this is a test binary
if strings.HasSuffix(filepath.Base(fn), ".test") {
return nil
}
// check if we want to force updateability
if uf := os.Gete... | go | {
"resource": ""
} |
q28905 | Homedir | train | func Homedir() string {
if hd := os.Getenv("GOPASS_HOMEDIR"); hd != "" {
return hd
}
hd, err := homedir.Dir()
if err != nil {
if debug {
fmt.Printf("[DEBUG] Failed to get homedir: %s\n", err)
}
return ""
}
return hd
} | go | {
"resource": ""
} |
q28906 | configLocations | train | func configLocations() []string {
l := []string{}
if cf := os.Getenv("GOPASS_CONFIG"); cf != "" {
l = append(l, cf)
}
if xch := os.Getenv("XDG_CONFIG_HOME"); xch != "" {
l = append(l, filepath.Join(xch, "gopass", "config.yml"))
}
l = append(l, filepath.Join(Homedir(), ".config", "gopass", "config.yml"))
l = ... | go | {
"resource": ""
} |
q28907 | Render | train | func Render(browser, wrapperPath, binPath string, global bool) ([]byte, []byte, error) {
mf, err := getManifestContent(browser, wrapperPath)
if err != nil {
return nil, nil, err
}
if binPath == "" {
binPath = gopassPath(global)
}
wrap, err := getWrapperContent(binPath)
if err != nil {
return nil, nil, err... | go | {
"resource": ""
} |
q28908 | GitInit | train | func (r *Store) GitInit(ctx context.Context, name, userName, userEmail string) error {
ctx, store, _ := r.getStore(ctx, name)
return store.GitInit(ctx, userName, userEmail)
} | go | {
"resource": ""
} |
q28909 | GitInitConfig | train | func (r *Store) GitInitConfig(ctx context.Context, name, userName, userEmail string) error {
ctx, store, _ := r.getStore(ctx, name)
return store.RCS().InitConfig(ctx, userName, userEmail)
} | go | {
"resource": ""
} |
q28910 | GitVersion | train | func (r *Store) GitVersion(ctx context.Context) semver.Version {
return r.store.RCS().Version(ctx)
} | go | {
"resource": ""
} |
q28911 | GitAddRemote | train | func (r *Store) GitAddRemote(ctx context.Context, name, remote, url string) error {
ctx, store, _ := r.getStore(ctx, name)
return store.RCS().AddRemote(ctx, remote, url)
} | go | {
"resource": ""
} |
q28912 | GitRemoveRemote | train | func (r *Store) GitRemoveRemote(ctx context.Context, name, remote string) error {
ctx, store, _ := r.getStore(ctx, name)
return store.RCS().RemoveRemote(ctx, remote)
} | go | {
"resource": ""
} |
q28913 | GitPull | train | func (r *Store) GitPull(ctx context.Context, name, origin, remote string) error {
ctx, store, _ := r.getStore(ctx, name)
return store.RCS().Pull(ctx, origin, remote)
} | go | {
"resource": ""
} |
q28914 | GitPush | train | func (r *Store) GitPush(ctx context.Context, name, origin, remote string) error {
ctx, store, _ := r.getStore(ctx, name)
return store.RCS().Push(ctx, origin, remote)
} | go | {
"resource": ""
} |
q28915 | ListRevisions | train | func (r *Store) ListRevisions(ctx context.Context, name string) ([]backend.Revision, error) {
ctx, store, name := r.getStore(ctx, name)
return store.ListRevisions(ctx, name)
} | go | {
"resource": ""
} |
q28916 | GetRevision | train | func (r *Store) GetRevision(ctx context.Context, name, revision string) (store.Secret, error) {
ctx, store, name := r.getStore(ctx, name)
return store.GetRevision(ctx, name, revision)
} | go | {
"resource": ""
} |
q28917 | Init | train | func (l loader) Init(ctx context.Context, path, username, email string) (backend.RCS, error) {
return Init(ctx, path)
} | go | {
"resource": ""
} |
q28918 | Insert | train | func (s *Action) Insert(ctx context.Context, c *cli.Context) error {
echo := c.Bool("echo")
multiline := c.Bool("multiline")
force := c.Bool("force")
append := c.Bool("append")
args, kvps := parseArgs(c)
name := args.Get(0)
key := args.Get(1)
if name == "" {
return ExitError(ctx, ExitNoName, nil, "Usage: %s... | go | {
"resource": ""
} |
q28919 | Load | train | func Load() *Config {
for _, l := range configLocations() {
if debug {
fmt.Printf("[DEBUG] Trying to load config from %s\n", l)
}
cfg, err := load(l)
if err == ErrConfigNotFound {
continue
}
if err != nil {
panic(err)
}
_ = cfg.checkDefaults()
if debug {
fmt.Printf("[DEBUG] Loaded config ... | go | {
"resource": ""
} |
q28920 | Save | train | func (c *Config) Save() error {
if err := c.checkDefaults(); err != nil {
return err
}
buf, err := yaml.Marshal(c)
if err != nil {
return errors.Wrapf(err, "failed to marshal YAML")
}
cfgLoc := configLocation()
cfgDir := filepath.Dir(cfgLoc)
if !fsutil.IsDir(cfgDir) {
if err := os.MkdirAll(cfgDir, 0700)... | go | {
"resource": ""
} |
q28921 | Delete | train | func (s *Action) Delete(ctx context.Context, c *cli.Context) error {
force := c.Bool("force")
recursive := c.Bool("recursive")
name := c.Args().First()
if name == "" {
return ExitError(ctx, ExitUsage, nil, "Usage: %s rm name", s.Name)
}
if !recursive && s.Store.IsDir(ctx, name) {
return ExitError(ctx, ExitU... | go | {
"resource": ""
} |
q28922 | deleteKeyFromYAML | train | func (s *Action) deleteKeyFromYAML(ctx context.Context, name, key string) error {
sec, err := s.Store.Get(ctx, name)
if err != nil {
return ExitError(ctx, ExitIO, err, "Can not delete key '%s' from '%s': %s", key, name, err)
}
if err := sec.DeleteKey(key); err != nil {
return ExitError(ctx, ExitIO, err, "Can no... | go | {
"resource": ""
} |
q28923 | Open | train | func Open(path string) (*Git, error) {
r, err := git.PlainOpen(path)
if err != nil {
return nil, err
}
w, err := r.Worktree()
if err != nil {
return nil, err
}
return &Git{
path: path,
repo: r,
wt: w,
}, nil
} | go | {
"resource": ""
} |
q28924 | Clone | train | func Clone(ctx context.Context, repo, path string) (*Git, error) {
r, err := git.PlainCloneContext(ctx, path, false, &git.CloneOptions{
URL: repo,
Progress: Stdout,
})
if err != nil {
return nil, err
}
w, err := r.Worktree()
if err != nil {
return nil, err
}
return &Git{
path: path,
repo: r,
... | go | {
"resource": ""
} |
q28925 | Init | train | func Init(ctx context.Context, path string) (*Git, error) {
g := &Git{
path: path,
}
if !g.IsInitialized() {
r, err := git.PlainInit(path, false)
if err != nil {
return nil, errors.Wrapf(err, "Failed to initialize git: %s", err)
}
g.repo = r
wt, err := g.repo.Worktree()
if err != nil {
return ni... | go | {
"resource": ""
} |
q28926 | IsInitialized | train | func (g *Git) IsInitialized() bool {
_, err := git.PlainOpen(g.path)
return err == nil
} | go | {
"resource": ""
} |
q28927 | Add | train | func (g *Git) Add(ctx context.Context, files ...string) error {
if len(files) < 1 || (len(files) == 1 && files[0] == g.path) {
return g.addAll()
}
for _, file := range files {
if strings.HasPrefix(file, g.path) {
file = strings.TrimPrefix(file, g.path+string(filepath.Separator))
}
_, err := g.wt.Add(file)... | go | {
"resource": ""
} |
q28928 | HasStagedChanges | train | func (g *Git) HasStagedChanges(ctx context.Context) bool {
st, err := g.wt.Status()
if err != nil {
out.Error(ctx, "Error: Unable to get status: %s", err)
return false
}
return !st.IsClean()
} | go | {
"resource": ""
} |
q28929 | Commit | train | func (g *Git) Commit(ctx context.Context, msg string) error {
if !g.HasStagedChanges(ctx) {
return store.ErrGitNothingToCommit
}
_, err := g.wt.Commit(msg, &git.CommitOptions{
All: true,
Author: &object.Signature{
Name: os.Getenv("GIT_AUTHOR_NAME"),
Email: os.Getenv("GIT_AUTHOR_EMAIL"),
When: time.... | go | {
"resource": ""
} |
q28930 | PushPull | train | func (g *Git) PushPull(ctx context.Context, op, remote, branch string) error {
if err := g.Pull(ctx, remote, branch); err != nil {
if op == "pull" {
return err
}
out.Yellow(ctx, "Failed to pull before git push: %s", err)
}
if op == "pull" {
return nil
}
return g.Push(ctx, remote, branch)
} | go | {
"resource": ""
} |
q28931 | Pull | train | func (g *Git) Pull(ctx context.Context, remote, branch string) error {
if !g.IsInitialized() {
return store.ErrGitNotInit
}
if remote == "" {
remote = "origin"
}
if branch == "" {
branch = "master"
}
cfg, err := g.repo.Config()
if err != nil {
return errors.Wrapf(err, "Failed to get git config: %s", e... | go | {
"resource": ""
} |
q28932 | Push | train | func (g *Git) Push(ctx context.Context, remote, branch string) error {
if !g.IsInitialized() {
return store.ErrGitNotInit
}
if remote == "" {
remote = "origin"
}
cfg, err := g.repo.Config()
if err != nil {
return errors.Wrapf(err, "Failed to get git config: %s", err)
}
if _, found := cfg.Remotes[remote]... | go | {
"resource": ""
} |
q28933 | Cmd | train | func (g *Git) Cmd(context.Context, string, ...string) error {
return fmt.Errorf("not supported")
} | go | {
"resource": ""
} |
q28934 | Crypto | train | func (r *Store) Crypto(ctx context.Context, name string) backend.Crypto {
_, sub, _ := r.getStore(ctx, name)
if !sub.Valid() {
out.Debug(ctx, "Sub-Store not found for %s. Returning nil crypto backend", name)
return nil
}
return sub.Crypto()
} | go | {
"resource": ""
} |
q28935 | Audit | train | func (s *Action) Audit(ctx context.Context, c *cli.Context) error {
filter := c.Args().First()
ctx = s.Store.WithConfig(ctx, filter)
out.Print(ctx, "Auditing passwords for common flaws ...")
t, err := s.Store.Tree(ctx)
if err != nil {
return ExitError(ctx, ExitList, err, "failed to get store tree: %s", err)
}... | go | {
"resource": ""
} |
q28936 | New | train | func New(ctx context.Context, cfg Config) (*GPG, error) {
// ensure created files don't have group or world perms set
// this setting should be inherited by sub-processes
umask(cfg.Umask)
// make sure GPG_TTY is set (if possible)
if gt := os.Getenv("GPG_TTY"); gt == "" {
if t := tty(); t != "" {
_ = os.Seten... | go | {
"resource": ""
} |
q28937 | RecipientIDs | train | func (g *GPG) RecipientIDs(ctx context.Context, buf []byte) ([]string, error) {
_ = os.Setenv("LANGUAGE", "C")
recp := make([]string, 0, 5)
args := []string{"--batch", "--list-only", "--list-packets", "--no-default-keyring", "--secret-keyring", "/dev/null"}
cmd := exec.CommandContext(ctx, g.binary, args...)
cmd.S... | go | {
"resource": ""
} |
q28938 | Decrypt | train | func (g *GPG) Decrypt(ctx context.Context, ciphertext []byte) ([]byte, error) {
args := append(g.args, "--decrypt")
cmd := exec.CommandContext(ctx, g.binary, args...)
cmd.Stdin = bytes.NewReader(ciphertext)
cmd.Stderr = os.Stderr
out.Debug(ctx, "gpg.Decrypt: %s %+v", cmd.Path, cmd.Args)
return cmd.Output()
} | go | {
"resource": ""
} |
q28939 | Calculate | train | func Calculate(ctx context.Context, name string, sec store.Secret) (twofactor.OTP, string, error) {
otpURL := ""
// check body
for _, line := range strings.Split(sec.Body(), "\n") {
if strings.HasPrefix(line, "otpauth://") {
otpURL = line
break
}
}
if otpURL != "" {
return twofactor.FromURL(otpURL)
}
... | go | {
"resource": ""
} |
q28940 | WriteQRFile | train | func WriteQRFile(ctx context.Context, otp twofactor.OTP, label, file string) error {
var qr []byte
var err error
switch otp.Type() {
case twofactor.OATH_HOTP:
hotp := otp.(*twofactor.HOTP)
qr, err = hotp.QR(label)
case twofactor.OATH_TOTP:
totp := otp.(*twofactor.TOTP)
qr, err = totp.QR(label)
default:
... | go | {
"resource": ""
} |
q28941 | ListRecipients | train | func (r *Store) ListRecipients(ctx context.Context, store string) []string {
ctx, sub, _ := r.getStore(ctx, store)
return sub.Recipients(ctx)
} | go | {
"resource": ""
} |
q28942 | RemoveRecipient | train | func (r *Store) RemoveRecipient(ctx context.Context, store, rec string) error {
ctx, sub, _ := r.getStore(ctx, store)
return sub.RemoveRecipient(ctx, rec)
} | go | {
"resource": ""
} |
q28943 | ImportMissingPublicKeys | train | func (r *Store) ImportMissingPublicKeys(ctx context.Context) error {
for alias, sub := range r.mounts {
ctx := r.cfg.Mounts[alias].WithContext(ctx)
if err := sub.ImportMissingPublicKeys(ctx); err != nil {
out.Error(ctx, "[%s] Failed to import missing public keys: %s", alias, err)
}
}
return r.store.ImportM... | go | {
"resource": ""
} |
q28944 | RecipientsTree | train | func (r *Store) RecipientsTree(ctx context.Context, pretty bool) (tree.Tree, error) {
root := simple.New("gopass")
for _, recp := range r.store.Recipients(ctx) {
if err := r.addRecipient(ctx, "", root, recp, pretty); err != nil {
color.Yellow("Failed to add recipient to tree %s: %s", recp, err)
}
}
mps := ... | go | {
"resource": ""
} |
q28945 | gpgHome | train | func gpgHome(ctx context.Context) string {
if gh := os.Getenv("GNUPGHOME"); gh != "" {
return gh
}
hd, err := homedir.Dir()
if err != nil {
out.Debug(ctx, "Failed to get homedir: %s", err)
return ""
}
return filepath.Join(hd, ".gnupg")
} | go | {
"resource": ""
} |
q28946 | WithFsckCheck | train | func WithFsckCheck(ctx context.Context, check bool) context.Context {
return context.WithValue(ctx, ctxKeyFsckCheck, check)
} | go | {
"resource": ""
} |
q28947 | HasFsckCheck | train | func HasFsckCheck(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyFsckCheck).(bool)
return ok
} | go | {
"resource": ""
} |
q28948 | IsFsckCheck | train | func IsFsckCheck(ctx context.Context) bool {
bv, ok := ctx.Value(ctxKeyFsckCheck).(bool)
if !ok {
return false
}
return bv
} | go | {
"resource": ""
} |
q28949 | WithFsckForce | train | func WithFsckForce(ctx context.Context, force bool) context.Context {
return context.WithValue(ctx, ctxKeyFsckForce, force)
} | go | {
"resource": ""
} |
q28950 | HasFsckForce | train | func HasFsckForce(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyFsckForce).(bool)
return ok
} | go | {
"resource": ""
} |
q28951 | IsFsckForce | train | func IsFsckForce(ctx context.Context) bool {
bv, ok := ctx.Value(ctxKeyFsckForce).(bool)
if !ok {
return false
}
return bv
} | go | {
"resource": ""
} |
q28952 | WithAutoSync | train | func WithAutoSync(ctx context.Context, sync bool) context.Context {
return context.WithValue(ctx, ctxKeyAutoSync, sync)
} | go | {
"resource": ""
} |
q28953 | HasAutoSync | train | func HasAutoSync(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyAutoSync).(bool)
return ok
} | go | {
"resource": ""
} |
q28954 | IsAutoSync | train | func IsAutoSync(ctx context.Context) bool {
bv, ok := ctx.Value(ctxKeyAutoSync).(bool)
if !ok {
return true
}
return bv
} | go | {
"resource": ""
} |
q28955 | HasReason | train | func HasReason(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyReason).(string)
return ok
} | go | {
"resource": ""
} |
q28956 | GetReason | train | func GetReason(ctx context.Context) string {
sv, ok := ctx.Value(ctxKeyReason).(string)
if !ok {
return ""
}
return sv
} | go | {
"resource": ""
} |
q28957 | WithImportFunc | train | func WithImportFunc(ctx context.Context, imf store.ImportCallback) context.Context {
return context.WithValue(ctx, ctxKeyImportFunc, imf)
} | go | {
"resource": ""
} |
q28958 | HasImportFunc | train | func HasImportFunc(ctx context.Context) bool {
imf, ok := ctx.Value(ctxKeyImportFunc).(store.ImportCallback)
return ok && imf != nil
} | go | {
"resource": ""
} |
q28959 | WithRecipientFunc | train | func WithRecipientFunc(ctx context.Context, imf store.RecipientCallback) context.Context {
return context.WithValue(ctx, ctxKeyRecipientFunc, imf)
} | go | {
"resource": ""
} |
q28960 | HasRecipientFunc | train | func HasRecipientFunc(ctx context.Context) bool {
imf, ok := ctx.Value(ctxKeyRecipientFunc).(store.RecipientCallback)
return ok && imf != nil
} | go | {
"resource": ""
} |
q28961 | WithFsckFunc | train | func WithFsckFunc(ctx context.Context, imf store.FsckCallback) context.Context {
return context.WithValue(ctx, ctxKeyFsckFunc, imf)
} | go | {
"resource": ""
} |
q28962 | HasFsckFunc | train | func HasFsckFunc(ctx context.Context) bool {
imf, ok := ctx.Value(ctxKeyFsckFunc).(store.FsckCallback)
return ok && imf != nil
} | go | {
"resource": ""
} |
q28963 | WithCheckRecipients | train | func WithCheckRecipients(ctx context.Context, cr bool) context.Context {
return context.WithValue(ctx, ctxKeyCheckRecipients, cr)
} | go | {
"resource": ""
} |
q28964 | HasCheckRecipients | train | func HasCheckRecipients(ctx context.Context) bool {
_, ok := ctx.Value(ctxKeyCheckRecipients).(bool)
return ok
} | go | {
"resource": ""
} |
q28965 | New | train | func New(ctx context.Context, prefix string) (*File, error) {
td, err := ioutil.TempDir(tempdirBase(), prefix)
if err != nil {
return nil, err
}
tf := &File{
dir: td,
dbg: ctxutil.IsDebug(ctx),
}
if err := tf.mount(ctx); err != nil {
_ = os.RemoveAll(tf.dir)
return nil, err
}
fn := filepath.Join(tf... | go | {
"resource": ""
} |
q28966 | Name | train | func (t *File) Name() string {
if t.fh == nil {
return ""
}
return t.fh.Name()
} | go | {
"resource": ""
} |
q28967 | Write | train | func (t *File) Write(p []byte) (int, error) {
if t.fh == nil {
return 0, errors.Errorf("not initialized")
}
return t.fh.Write(p)
} | go | {
"resource": ""
} |
q28968 | Close | train | func (t *File) Close() error {
if t.fh == nil {
return nil
}
return t.fh.Close()
} | go | {
"resource": ""
} |
q28969 | Remove | train | func (t *File) Remove(ctx context.Context) error {
_ = t.Close()
if err := t.unmount(ctx); err != nil {
return errors.Errorf("Failed to unmount %s from %s: %s", t.dev, t.dir, err)
}
if t.dir == "" {
return nil
}
return os.RemoveAll(t.dir)
} | go | {
"resource": ""
} |
q28970 | GetRegistryPath | train | func GetRegistryPath(browser string) (string, error) {
path, found := registryPaths[browser]
if !found {
return "", fmt.Errorf("browser %s on %s is currently not supported", browser, runtime.GOOS)
}
return path, nil
} | go | {
"resource": ""
} |
q28971 | Fsck | train | func (s *Store) Fsck(ctx context.Context, path string) error {
ctx = out.AddPrefix(ctx, "["+s.alias+"] ")
out.Debug(ctx, "Fsck(%s)", path)
// first let the storage backend check itself
if err := s.storage.Fsck(ctx); err != nil {
return errors.Wrapf(err, "storage backend found errors: %s", err)
}
pcb := ctxuti... | go | {
"resource": ""
} |
q28972 | WithContext | train | func (c StoreConfig) WithContext(ctx context.Context) context.Context {
if !ctxutil.HasAskForMore(ctx) {
ctx = ctxutil.WithAskForMore(ctx, c.AskForMore)
}
if !ctxutil.HasAutoClip(ctx) {
ctx = ctxutil.WithAutoClip(ctx, c.AutoClip)
}
if !c.AutoImport {
ctx = sub.WithImportFunc(ctx, nil)
}
if !sub.HasAutoSync... | go | {
"resource": ""
} |
q28973 | ValidBrowser | train | func ValidBrowser(name string) bool {
_, found := manifestPath[runtime.GOOS][name]
return found
} | go | {
"resource": ""
} |
q28974 | Path | train | func Path(browser, libpath string, globalInstall bool) (string, error) {
location, err := getLocation(browser, libpath, globalInstall)
if err != nil {
return "", err
}
expanded, err := homedir.Expand(location)
if err != nil {
return "", err
}
return filepath.Join(expanded, Name+".json"), nil
} | go | {
"resource": ""
} |
q28975 | getLocation | train | func getLocation(browser, libpath string, globalInstall bool) (string, error) {
if globalInstall {
return getGlobalLocation(browser, libpath)
}
pm, found := manifestPath[runtime.GOOS]
if !found {
return "", fmt.Errorf("platform %s is currently not supported", runtime.GOOS)
}
path, found := pm[browser]
if !f... | go | {
"resource": ""
} |
q28976 | Path | train | func (r *Store) Path() string {
if r.url == nil {
return ""
}
return r.url.Path
} | go | {
"resource": ""
} |
q28977 | URL | train | func (r *Store) URL() string {
if r.url == nil {
return ""
}
return r.url.String()
} | go | {
"resource": ""
} |
q28978 | Storage | train | func (r *Store) Storage(ctx context.Context, name string) backend.Storage {
_, sub, _ := r.getStore(ctx, name)
if sub == nil || !sub.Valid() {
return nil
}
return sub.Storage()
} | go | {
"resource": ""
} |
q28979 | New | train | func New(host, prefix, datacenter, token string) (*Store, error) {
if !strings.HasSuffix(prefix, "/") {
prefix += "/"
}
if strings.HasPrefix(prefix, "/") {
prefix = strings.TrimPrefix(prefix, "/")
}
client, err := api.NewClient(&api.Config{
Address: host,
Datacenter: datacenter,
Token: token,
})... | go | {
"resource": ""
} |
q28980 | Get | train | func (s *Store) Get(ctx context.Context, name string) ([]byte, error) {
name = s.prefix + name
out.Debug(ctx, "consul.Get(%s)", name)
p, _, err := s.api.KV().Get(name, nil)
if err != nil {
return nil, err
}
if p == nil || p.Value == nil {
return nil, nil
}
return p.Value, nil
} | go | {
"resource": ""
} |
q28981 | Set | train | func (s *Store) Set(ctx context.Context, name string, value []byte) error {
name = s.prefix + name
out.Debug(ctx, "consul.Set(%s)", name)
p := &api.KVPair{
Key: name,
Value: value,
}
_, err := s.api.KV().Put(p, nil)
return err
} | go | {
"resource": ""
} |
q28982 | Exists | train | func (s *Store) Exists(ctx context.Context, name string) bool {
out.Debug(ctx, "consul.Exists(%s)", name)
v, err := s.Get(ctx, name)
if err == nil && v != nil {
return true
}
return false
} | go | {
"resource": ""
} |
q28983 | List | train | func (s *Store) List(ctx context.Context, _ string) ([]string, error) {
prefix := s.prefix
out.Debug(ctx, "consul.List(%s)", prefix)
pairs, _, err := s.api.KV().List(prefix, nil)
if err != nil {
return nil, err
}
res := make([]string, len(pairs))
for _, kvp := range pairs {
res = append(res, strings.TrimPref... | go | {
"resource": ""
} |
q28984 | IsDir | train | func (s *Store) IsDir(ctx context.Context, name string) bool {
name = s.prefix + name
out.Debug(ctx, "consul.IsDir(%s)", name)
count := 0
ls, err := s.List(ctx, name)
if err != nil {
return false
}
for _, e := range ls {
if strings.HasPrefix(e, name) {
count++
}
}
return count > 1
} | go | {
"resource": ""
} |
q28985 | Prune | train | func (s *Store) Prune(ctx context.Context, prefix string) error {
prefix = s.prefix + prefix
out.Debug(ctx, "consul.Prune(%s)", prefix)
return s.Delete(ctx, prefix)
} | go | {
"resource": ""
} |
q28986 | Version | train | func (s *Store) Version(context.Context) semver.Version {
return semver.Version{Major: 1}
} | go | {
"resource": ""
} |
q28987 | Fsck | train | func (s *Store) Fsck(ctx context.Context) error {
pcb := ctxutil.GetProgressCallback(ctx)
entries, err := s.List(ctx, "")
if err != nil {
return err
}
dirs := make(map[string]struct{}, len(entries))
for _, entry := range entries {
pcb()
out.Debug(ctx, "file.Fsck() - Checking %s", entry)
filename := file... | go | {
"resource": ""
} |
q28988 | StoreConfig | train | func (c *Pre182StoreConfig) StoreConfig() *StoreConfig {
sc := &StoreConfig{
AskForMore: c.AskForMore,
AutoClip: c.AutoClip,
AutoImport: c.AutoImport,
AutoSync: c.AutoSync,
CheckRecpHash: c.CheckRecpHash,
ClipTimeout: c.ClipTimeout,
Concurrency: c.Concurrency,
EditRecipients:... | go | {
"resource": ""
} |
q28989 | New | train | func New(password, body string) *Secret {
return &Secret{
password: password,
body: body,
}
} | go | {
"resource": ""
} |
q28990 | Parse | train | func Parse(buf []byte) (*Secret, error) {
s := &Secret{}
lines := bytes.SplitN(buf, []byte("\n"), 2)
if len(lines) > 0 {
s.password = string(bytes.TrimSpace(lines[0]))
}
if len(lines) > 1 {
s.body = string(bytes.TrimSpace(lines[1]))
}
if err := s.decode(); err != nil {
return s, err
}
return s, nil
} | go | {
"resource": ""
} |
q28991 | Bytes | train | func (s *Secret) Bytes() ([]byte, error) {
buf := &bytes.Buffer{}
_, _ = buf.WriteString(s.password)
if s.body != "" {
_, _ = buf.WriteString("\n")
_, _ = buf.WriteString(s.body)
}
return buf.Bytes(), nil
} | go | {
"resource": ""
} |
q28992 | String | train | func (s *Secret) String() string {
var buf strings.Builder
_, _ = buf.WriteString(s.password)
if s.body != "" {
_, _ = buf.WriteString("\n")
_, _ = buf.WriteString(s.body)
}
return buf.String()
} | go | {
"resource": ""
} |
q28993 | Password | train | func (s *Secret) Password() string {
s.Lock()
defer s.Unlock()
return s.password
} | go | {
"resource": ""
} |
q28994 | Body | train | func (s *Secret) Body() string {
s.Lock()
defer s.Unlock()
return s.body
} | go | {
"resource": ""
} |
q28995 | Data | train | func (s *Secret) Data() map[string]interface{} {
s.Lock()
defer s.Unlock()
return s.data
} | go | {
"resource": ""
} |
q28996 | SetBody | train | func (s *Secret) SetBody(b string) error {
s.Lock()
defer s.Unlock()
s.body = b
s.data = nil
err := s.decode()
return err
} | go | {
"resource": ""
} |
q28997 | Equal | train | func (s *Secret) Equal(other store.Secret) bool {
if s == nil && (other == nil || reflect.ValueOf(other).IsNil()) {
return true
}
if s == nil || other == nil || reflect.ValueOf(other).IsNil() {
return false
}
s.Lock()
defer s.Unlock()
if s.password != other.Password() {
return false
}
if s.body != oth... | go | {
"resource": ""
} |
q28998 | RandomLength | train | func RandomLength(length int, lang string) (string, error) {
return RandomLengthDelim(length, " ", lang)
} | go | {
"resource": ""
} |
q28999 | RandomLengthDelim | train | func RandomLengthDelim(length int, delim, lang string) (string, error) {
g := xkcdpwgen.NewGenerator()
g.SetNumWords(length)
g.SetDelimiter(delim)
g.SetCapitalize(delim == "")
if err := g.UseLangWordlist(lang); err != nil {
return "", err
}
return string(g.GeneratePassword()), nil
} | go | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.