Skip to content

pass Get unmarshaling error #120

@yashasolutions

Description

@yashasolutions

for a given entry with pass:

$ pass show dummy
plop

The given code is stumbling upon some unmarshall issue:

func Execute() {
	fmt.Println(Pass("", "dummy"))
}

func Pass(prefix string,key string) string {
	ring, err := keyring.Open(keyring.Config{
		ServiceName: "example",
		PassCmd: "pass",
		AllowedBackends: []keyring.BackendType{"pass"},
		PassDir: "~/.password-store",
		PassPrefix: prefix,
	})
	if err != nil {
		panic(err)
	}

	i, err := ring.Get(key)

	if err != nil {
		panic(err)
	}

	return string(i.Data)
}

So ring.Get(key) is failing with the following error:

panic: invalid character 'p' looking for beginning of value

From what I could gather, in the Get function - I have annoted value I get some delve debugging.

func (k *passKeyring) Get(key string) (Item, error) {
	if !k.itemExists(key) {
		return Item{}, ErrKeyNotFound
	}

	name := filepath.Join(k.prefix, key)

	// this is working
	cmd := k.pass("show", name)

	output, err := cmd.Output()
	// output value is "plop\n" 	

	if err != nil {
		return Item{}, err
	}

	var decoded Item
	err = json.Unmarshal(output, &decoded)
        // this is failing
        // in json.Unmarshal -> err := checkValid(data, &d.scan) 
        // is msg: "invalid character 'p' looking for beginning of value",

	return decoded, err
}

I am not sure what is the issue, nor why it needs to be unmarshalled, pass is not returning no json, just a string.

Am I missing something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions