Description
Specification
Standard unix commands include things like cp
, mv
and ls
.
This allows users to interact with secret vaults as if they were real filesystems. (And they sort of are).
Imagine (IN ORDER OF PRIORITY):
# these 2 might be merged into 1 command just `write` is sufficient
pk secrets read vault1:/a/b
pk secrets write v1:/abc
pk secrets cat vault1:/a/b
pk secrets touch vault1:/a/b
pk secrets ls vault1
pk secrets mkdir vault1:/c
pk secrets rm vault1:/a/b
pk secrets mv vault1:/a/b vault1:/a/c
pk secrets cp vault1:/a/b vault1:/a/c
pk secrets ln vault1:/a/b vault1:/d/e
# this one is special
pk secrets env
# this one is also special
pk secrets ed vault1:/a/b
# these are less important
pk secrets head vault1:/a/b
pk secrets tail vault1:/a/b
pk secrets find vault1
pk secrets grep vault1:/a/b
pk secrets sed vault1:/a/b
I believe some of these commands were already implemented before in the old PK codebase. You have things like pk secrets create
and pk secrets delete
.
»» ~/Projects/js-polykey/src/bin/secrets
♖ tree . (client-refactoring) pts/5 14:47:05
.
├── create.ts
├── delete.ts
├── dir.ts
├── edit.ts
├── env.ts
├── get.ts
├── index.ts
├── list.ts
├── mkdir.ts
├── rename.ts
└── update.ts
0 directories, 11 files
I believe there's a problem with doing this. We are reinventing the wheel, and we'll never cover all the commands that Unix already has.
This has the benefit of reusing context that developers already know and remember when interacting with a Unix shell.
But how do we do this without having to rewrite all the code? Luckily it seems someone has already done this.
See: https://github.com/shelljs/shelljs
It has implemented all the major Unix shell commands in raw JS.
The only problem that their command source code currently directly imports the native Node fs:
If we would want to use the shelljs
library, we would need to globally mock the fs as described here: shelljs/shelljs#747 (comment)
However that may be dangerous if that leaks into other places of the FS.
There is another alternative: https://github.com/dthree/cash. The difference between the 2 are: https://github.com/dthree/cash#doesnt-shelljs-do-this However I think it's even less integratable compared to shelljs
.
So it seems we would need to "extract" the command code from shelljs
and place it into PK directly and thus enable us to change the fs
object to our Vault EFS.
Note that we do not need all shell commands, just the major ones that relate to files, and doesn't change cwd context since we don't use that. Nothing that changes permissions is relevant to us. Process control is also not relevant.
One major difference is that our commands will have to traverse both vault filesystems and the real filesystem. For example pk secrets mv vault1:/a ./a
which has to take a file from a vault to the real fs. The functionality to achieve this will also end up being used to do commands between vaults. Because the efs.mv
won't work between EFS instances anyway.
Additional context
- Exposing different interfaces for use of secrets within polykey Polykey#55 - Oldest issue talking about the different interfaces PK was meant to have
- Secret editor on the CLI Polykey#78 - With regards to the
pk secrets ed
command - The
pk secrets env
command for meeting Development Environment Usecase #31 - Thepk secrets env
command is similar concept here replicating the Unix commandenv
- Pseudo file systems interface Polykey#169 - Mounting a vault as fs also sort of does this, but it is more difficult to do
- File Descriptor Interface Polykey#170 - Some discussion about file descriptor interface for PK, relevant to the
pk secrets cat
command and composition of PK to other commands
Sub issues
- Implement
secrets write
command #242 - Implement
secrets cat
command #243 - Implement
secrets touch
command #244 - Implement
secrets ls
command #245 - Implement
secrets mkdir
command #246 - Implement
secrets rm
command #247 - Implement
secrets mv
command #248 - Implement
secrets cp
command #249 - Implement utility that generates a file tree from a path pattern Polykey#767
- Implement a file tree serialiser/de-serialiser Polykey#768
Tasks
- ...
- ...
- ...