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

"pastebin" SDK Example #379

Closed
michaelquigley opened this issue Jul 26, 2023 · 2 comments
Closed

"pastebin" SDK Example #379

michaelquigley opened this issue Jul 26, 2023 · 2 comments
Assignees
Labels
feature New feature description spike Spikes
Milestone

Comments

@michaelquigley
Copy link
Collaborator

michaelquigley commented Jul 26, 2023

Build a simple "pastebin" example application for use in an SDK tutorial (should also be useful in the real world).

Got Ken to describe a strawman application as he would like to see it:

The pastebin command is for sharing hunks of text privately without leaving the terminal. Each bin works like a stack: last in, first out. You can share between people or your own devices and all you need is the share token of the pastebin.

The pastebin has two built in personalities that allow it to assume you're either copying or pasting, i.e., pushing or popping. The personalities can be invoked by executing a symlink with the same name as the personality, or by renaming the pastebin command itself. If the pastebin command is not invoked as either personality then it's necessary to provide a command-line parameter that specifies which direction the bytes should flow: pastebin copy (push) or pastebin paste (pop).

To put a hunk in the bin (push it on the stack) you can pipe the bytes to pastebin's standard input or by providing a file path as an argument, i.e., these are equivalent: pastebin copy < ./in-stuff.txt or cat ./in-stuff.txt | pastebin copy or pastebin copy ./in-stuff.txt or copyto ./in-stuff.txt.

The input includes all lines and is terminated by EOF. The input just-a-bunch-of-bytes and so it tolerates null-separated lines and may contain non-printable characters.

When a hunk is pushed on the stack without specifying the unique id of the stack (the share token), the output includes the share token the recipient will use to remove the top hunk from the bin (pop it off the stack).

To receive a shared hunk the pastebin paste or pastefrom command is used. The presence of the share token as a positional parameter invokes the paste mode, e.g., pastebin paste abc123456 > ./out-stuff.txt or pastefrom abc123456 ./out-stuff.txt.

The default behavior is to send the bytes from the topmost hunk to standard output, so the bytes are printed to the tty if it is not redirected to a pager or file. Alternatively, the presence of a second positional parameter that is a file path may be used to only write the bytes to that file.

You can push multiple hunks onto the same stack by specifying the share token that was provisioned when the first hunk was pushed, or by specifying multiple input files. Standard input can only be used to push a single, EOF-terminated hunk, e.g.,

  • create a new pastebin with two hunks: copyto ./in-stuff.txt ./in-stuff2.txt
  • push another hunk onto an existing pastebin: copyto abc123456 ./in-stuff2.txt
@michaelquigley michaelquigley self-assigned this Jul 26, 2023
@michaelquigley michaelquigley added spike Spikes feature New feature description labels Jul 26, 2023
@michaelquigley michaelquigley added this to the v0.4 milestone Jul 26, 2023
@michaelquigley
Copy link
Collaborator Author

Consider using a persistent share token to refer to the instance of a pastebin "channel". A PASTEBIN_TOKEN environment variable on both ends could make working with the wormhole pretty ergonomic.

@michaelquigley
Copy link
Collaborator Author

The goal will be to get the minimum viable version of this up and running for illustrating how the new SDK approach works. We'll figure out how to curate it into the zrok ecosystem longer term after the example is working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature description spike Spikes
Projects
Development

No branches or pull requests

1 participant