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

secrets edit creates a secret if it doesn't exist #267

Merged
merged 1 commit into from
Sep 10, 2024

Conversation

aryanjassal
Copy link
Contributor

@aryanjassal aryanjassal commented Aug 26, 2024

Description

This PR tracks improving the secrets edit command to create a file in the vault if it didn't exist, otherwise edit the file contents as usual.

This iteration will focus on creating a new secret if it didn't exist at the time of editing it. Other features from the issue, including platform agnostic editor search or using RawHandler to stream file contents instead of UnaryHandler will be implemented in future iterations.

Issues Fixed

Tasks

  • 1. Create file if it doesn't exist in the vault
  • 2. Write tests for secrets edit

Final checklist

  • Domain specific tests
  • Full tests
  • Updated inline-comment documentation
  • Lint fixed
  • Squash and rebased
  • Sanity check the final build

@aryanjassal aryanjassal self-assigned this Aug 26, 2024
Copy link

linear bot commented Aug 26, 2024

@aryanjassal
Copy link
Contributor Author

aryanjassal commented Aug 26, 2024

Based on the discussion we had in #255, for rapid iteration over these commands, do I merge this PR which introduces automatic file creation, or do I keep working on it and implement the platform-specific $EDITOR commands, which would take longer and is currently blocked by me not having access to a Windows or a Mac at this moment?

@CMCDragonkai @tegefaulkes

Copy link

linear bot commented Aug 27, 2024

@tegefaulkes
Copy link
Contributor

tegefaulkes commented Aug 27, 2024

If we're keeping to the iterative style then we should merge the current fix and move editor changes to a new issue.

There's a little more work to do here however. We need to use the new secret contents serialiser to stream over the secret contents.

@aryanjassal
Copy link
Contributor Author

There's a little more work to do here however. We need to use the new secret contents serialiser to stream over the secret contents.

Oh, do you mean that we stop using vaultsSecretsGet and instead use the file contents serialiser proposed in MatrixAI/Polykey#785?

@tegefaulkes
Copy link
Contributor

Yep, we nee to use the new serialiser to get the contents but also send the changed file back.

@aryanjassal
Copy link
Contributor Author

#266 (comment)

@aryanjassal aryanjassal force-pushed the feature-unix-edit branch 2 times, most recently from b7170cc to 00f1fbe Compare September 6, 2024 07:07
@aryanjassal aryanjassal marked this pull request as ready for review September 6, 2024 07:07
Copy link
Contributor

@tegefaulkes tegefaulkes left a comment

Choose a reason for hiding this comment

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

We need to add tests to show functionality of this command. Its actually a problem that there are no tests already but understandable because its kinda hard to test interactive input. You can create a test node or bash script and use that as a psudo editor for testing. The script will do two things, return to the test the contents of the file so we can verify it, but also edit the file with the contents we provide it.

These tests are essential to check for regressions when future changes are made so we really need tests here that cover all the intended functionality of the command. There are two main cases.

  1. edit the file and check that the contents are updated. With the current code this would actually fail.
  2. Edit a new file and show that it is created with the contents.

src/secrets/CommandEdit.ts Outdated Show resolved Hide resolved
src/secrets/CommandEdit.ts Outdated Show resolved Hide resolved
src/secrets/CommandEdit.ts Outdated Show resolved Hide resolved
@aryanjassal
Copy link
Contributor Author

execSync(`$EDITOR \"${tmpFile}\"`, { stdio: 'inherit' });

Apparently when you invoke environment variables using SVARIABLE in execSync, it doesn't respect the variable value in process.env. For me, while I had set process.env.EDITOR to a script I made for testing the secrets edit command, the execSync kept opening my actual system editor.

However, logging the value of process.env.EDITOR showed me that the value was set correctly. So, when I replaced $EDITOR with process.env.EDITOR, the command started respecting the actual environment variable and using the script correctly.

It is weird, because ExecSync by default uses NodeJS.ProcessEnv for its environment variables, but for some reason, it didn't work with the tests.

@aryanjassal aryanjassal changed the title Improving usability and experience of secrets edit command secrets edit creates a secret if it doesn't exist Sep 9, 2024
Copy link
Contributor

@tegefaulkes tegefaulkes left a comment

Choose a reason for hiding this comment

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

Some small changes are we're good.

src/secrets/CommandEdit.ts Outdated Show resolved Hide resolved
src/secrets/CommandEdit.ts Outdated Show resolved Hide resolved
src/secrets/CommandEdit.ts Outdated Show resolved Hide resolved
src/secrets/CommandEdit.ts Outdated Show resolved Hide resolved
src/secrets/CommandEdit.ts Outdated Show resolved Hide resolved
feat: added tests for secrets edit

chore: fixed logic errors and added review changes
@aryanjassal aryanjassal merged commit 9f7a7e1 into staging Sep 10, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants