Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow formatted data when using -field and -format together. #3987

Merged
merged 2 commits into from
Feb 15, 2018

Conversation

jefferai
Copy link
Member

As a special case, allows "data" to be passed in to get the entire data
struct output.

As a special case, allows "data" to be passed in to get the entire data
struct output.
vishalnayak
vishalnayak previously approved these changes Feb 15, 2018
Copy link
Member

@vishalnayak vishalnayak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this. The output looks neat! LGTM!

@vishalnayak
Copy link
Member

@jefferai

payload.json
{
        "data": {
                "foo": "bar",
                "bar": ["foo", "bar"],
                "baz": {
                        "bar": "baz"
                }
        }
}

vault write secret/foo [email protected]
vault read -format json -field raw secret/foo

Has a different output before and after the fix.

@jefferai
Copy link
Member Author

I'm aware of that edge case but there's no real way to solve it. The only thing to do might be to see if the map has a data key and if so use that instead. Either way in one case or the other it won't work, it's just a matter of which will be more common. And of course in advanced usage like that people can just hit the API directly.

@jefferai
Copy link
Member Author

Actually what you are seeing above is a different thing. When you use [email protected] what gets sent up to Vault is the string output of the file, json-encoded. So when you use -format=json -field=raw, now, it correctly fetches that one field, which is a string, and outputs it in a JSON-compatible way, which is its existing form. So this is actually correct behavior now.

What you can/should do there is simply not specify format=json so that the raw output is used for the field. This causes the shell to interpret the newlines, which produces the output you want. Since -format wasn't actually used with -field in prior version, simply not specifying format=json just falls back to previous behavior.

@jefferai
Copy link
Member Author

Also note that if you send @payload.json directly as the value in the CLI, since you're not assigning it as a value for the key raw (which is always string=string in the CLI), then it goes up as a struct, not a string, and -format=json with -field do the right thing. So basically this is just allowing less garbage :-)

@vishalnayak
Copy link
Member

@jefferai Yep. Had tested the sending of @payload.json directly and had verified that the behavior was proper. I also had tested the behavior which the reporting user was using as a workaround. I agree that the behavior we notice is right (since we are encoding the value as a string). So, all good.

@jefferai jefferai merged commit b24cf9a into master Feb 15, 2018
@jefferai jefferai deleted the field-and-format branch February 15, 2018 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants