question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't parse dictionnary to create_or_update_secret method

See original GitHub issue

Briefly describe the issue:

vault_co.secrets.kv.v2.create_or_update_secret('prod/' + next(iter(server)), secret=secret) is giving me a json.decoder.JSONDecodeError however vault_co.write('secret/prod/' + next(iter(server)), data=secret) is working fine.

What did you expect to happen?

create_or_update_secret seems to not validate the dictionnary in the secret variable, although write does.

What did happen?

create_or_update_secret failed.

Please include helpful code examples so we can attempt to replicate (if applicable):

Here is the variables:

next(iter(server)) = Arthur
secret = {'IP': '192.168.1.4', 'User': 'root', 'Password': 'Pa$$w0rd'}

Here is the Stacktrace:

Traceback (most recent call last):
  File "<stdin>", line 5, in <module>
  File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/hvac/api/secrets_engines/kv_v2.py", line 124, in create_or_update_secret
    return response.json()
  File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/requests/models.py", line 897, in json
    return complexjson.loads(self.text, **kwargs)
  File "/opt/rh/rh-python36/root/usr/lib64/python3.6/json/__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "/opt/rh/rh-python36/root/usr/lib64/python3.6/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/opt/rh/rh-python36/root/usr/lib64/python3.6/json/decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

This may be not the correct way to create secrets, as the write function didn’t parse data correctly:

$ vault kv get secret/prod/Arthur
==== Data ====
Key     Value
---     -----
data    map[IP:192.168.1.4 Password:Pa$$w0rd User:root]

I expected something like:

==== Data ====
Key     Value
---     -----
IP    192.168.1.4
Password  Pa$$w0rd
User   root

This is maybe related to the create_or_update_secret issue, however I can’t find the correct way to do it in the documentation.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
drewmullencommented, Sep 18, 2019

check the version of your secret engine vault secrets list --detailed, i suspect that your problem is that the secret engine youre using is v1

0reactions
drewmullencommented, Sep 19, 2019

I think it all just depends on the version. I have a 1.2.2 container and that does get kvv2 at init

Anyways, glad you got working!

Read more comments on GitHub >

github_iconTop Results From Across the Web

AWS Secret can't be converted into key names and value pairs
The error is shown when the console cannot parse the SecretString to key value pairs. This is expected behaviour, since your top level...
Read more >
GetSecretValue - AWS Secrets Manager
Retrieves the contents of the encrypted fields SecretString or SecretBinary from the specified version of a secret, whichever contains content.
Read more >
Working with Secrets Manager in Python using Boto3
In this article we've covered how to use Python to interact with AWS Secret Manager to create, update, delete secrets using the Boto3...
Read more >
SecretsManager — Boto3 Docs 1.26.34 documentation - AWS
The Secrets Manager console stores the information as a JSON structure of key/value pairs that a Lambda rotation function can parse.
Read more >
Create a secret | Secret Manager Documentation | Google Cloud
On the Create secret page, under Name, enter a name for the secret (e.g. my-secret ). (Optional) To also add a secret version...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found