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

Output for ockam project ticket is improved and information is not opaque #7478

Open
nazmulidris opened this issue Jan 29, 2024 · 2 comments

Comments

@nazmulidris
Copy link
Contributor

Current behavior

When you run ockam enroll and then run ockam project ticket you get the following output displayed to stdout:

✔ Created enrollment ticket. You can use it to enroll another machine using: ockam project enroll
7b226f6e655f74696d655f636f6465223a226336653736343166366631626462346161396635386431306537356635626...646d696e222c2273636f7065223a225370616365227d5d7d7d

After the first line (which is output to stderr), the long string (which is base 64 encoded JSON) is output to stdout. This can be redirected to a file as well (ockam project ticket > ticket.txt). Or saved to an environment variable (TICKET=$(ockam project ticket)), for later use by ockam ticket enroll.

Desired behavior

In addition to displaying the HEX string to stdout (using opts.terminal.stdout().plain()), also display the JSON blob to stderr (using opts.terminal.write_line()).

Here's an example of how this is used.

opts.terminal.write_line(/* json output */)?;
  • This ensures that the display of the JSON blob is visible to the end user (since it is output to stderr).
    • Piping to file and saving to env var still works, since opts.terminal.write_line() takes care of not polluting stdout.
  • The HEX string is actually output to stdout, so that it can be redirected to a file, or saved to a file, or saved to an env var. So ockam project ticket > ticket.txt or TICKET=$(ockam project ticket) will still work.

The opts.terminal.write_line() function does nothing when it detects that the terminal is not interactive. And this prevents this output from ending up in an env var or file (via redirect).

Bonus behavior

The ockam enroll command copies a one-time code that is generated to the clipboard. Here's the code for this.

Use the same mechanism to copy the HEX string when ockam project ticket is run and the base 64 encoded string is displayed to stdout:

  • Display the normal base64 output to stdout.
  • Also copy it to the clipboard (and let the user know that it is copied to the clipboard, if that succeeded). You can follow the example in ockam enroll to do this.

Here's the code to implement the ockam project ticket command: https://github.com/build-trust/ockam/blob/develop/implementations/rust/ockam/ockam_command/src/project/ticket.rs#L97

@nazmulidris nazmulidris changed the title Output for ockam project ticket is improved and information is not opaque Output for ockam project ticket is improved and information is not opaque Jan 29, 2024
@devanbenz
Copy link

Can I take on this ticket?

@nazmulidris
Copy link
Contributor Author

@devanbenz That's awesome, this is all yours. Please let us know if you have any questions as you explore. You can also ask questions on the contributors discord https://discord.ockam.io

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants