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

JSON format #4

Closed
AnatomicJC opened this issue Jan 26, 2022 · 11 comments · Fixed by #20
Closed

JSON format #4

AnatomicJC opened this issue Jan 26, 2022 · 11 comments · Fixed by #20
Assignees
Labels
enhancement New feature or request

Comments

@AnatomicJC
Copy link

Hi !

thanks for this awesome tool ! Do you plan to propose json format as output ? It will be easier to parse.

Thanks 😽

@speatzle
Copy link
Collaborator

Hi,
i have investigated JSON output in the past and there are a these considerations:

  1. Errors won't be in JSON due to cobra.
  2. For what sub-commands would JSON output be useful? I can only see JSON output being useful for list, get and maybe create what about the rest of the sub-commands? To 'properly' support JSON output all sub-commands 'should' be able to output JSON, but that would be allot of work that will probably be unused.

I'm not sure if i want to implement the JSON output with these 'compromises'.
What do you think?

@AnatomicJC
Copy link
Author

Hi and sorry for this late reply.

Usually, I use jq to parse API calls outputs to filter results. That's why I wondered if it should easy to implement, but it seems it is not :/

As an example, I created a docker image for go-passbolt-cli, and added some wrappers to easily fetch what I want.

As an example, to get a password per resource name and username, I use this wrapper:

#!/bin/sh

if [ "$#" -ne 2 ]; then
    echo "Illegal number of parameters"
    echo "Usage: get-password name username"
    exit 1
fi

NAME="${1}"
USERNAME="${2}"

ID="$(passbolt list resource --column ID --column Name --column Username \
  | grep "${NAME}" | grep "${USERNAME}" | head -n1 | awk '{print $1}')"

passbolt get resource --id ${ID} | grep Password | sed 's/^Password: //g'

I totally understand it can be a non-trivial task and you can close this issue. I already played a bit with golang, and I quickly switched back to python to manipulate json. It was easier for me 😆

@speatzle
Copy link
Collaborator

speatzle commented Feb 2, 2022

Hi,

i think JSON output is useful in allot of cases as using jq is much easier than combining grep, awk, sed, head and friends to parse Output.

For the Issues With adding JSON output:

  1. The Errors can't be in JSON due to cobra but errors always set the Exitcode to 1 so if this is properly documented i think that is ok since Scripts can very easily check the Exitcode.

  2. After thinking about it, i believe it would be fine to only support JSON output on list, get and create sub-commands since the other commands are usually only used manually and not by Scripts.

As such i think the few hours of effort implementing this would be well spent since it makes such a big difference with ease of parsing and the Issues can be properly worked around.

@speatzle speatzle reopened this Feb 2, 2022
@speatzle speatzle self-assigned this Feb 2, 2022
@speatzle speatzle added the enhancement New feature or request label Feb 2, 2022
@nourcy
Copy link
Member

nourcy commented Mar 10, 2022

Hi,
I would be also interested for list and get!
Are you planning to work on it in the coming weeks?

Cheers

@speatzle
Copy link
Collaborator

Yes, i am planning to get around to it SoonTM.

@AlexandreMarcq
Copy link

@speatzle I can try to help you on that, is there any setup I should do before trying anything ?

@speatzle
Copy link
Collaborator

@AlexandreMarcq you just need to clone the repository and have a Passbolt Instance.
When implementing this you basically just add a flag to cmd/list.go, cmd/get.go and cmd/create.go called --json which then marshals the existing go-passbolt structs to JSON (those structs already have the correct JSON tags)

@schustersv
Copy link

Any news on the PR? Being able to produce easily parsable json output would be really welcome.

@speatzle
Copy link
Collaborator

speatzle commented Dec 9, 2022

Since there hasn't been any activity on the PR in a long time by @AlexandreMarcq ill see if I can fix it up and merge it soon

@speatzle
Copy link
Collaborator

This got Implemented by #20.
will make a New Release soon.

@speatzle
Copy link
Collaborator

Released in v0.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants