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

Polykey-CLI: Polykey Secrets Edit command not working as expected on Mac Os #187

Closed
CryptoTotalWar opened this issue May 26, 2024 · 3 comments
Assignees
Labels
bug Something isn't working r&d:polykey:core activity 1 Secret Vault Sharing and Secret History Management

Comments

@CryptoTotalWar
Copy link

Describe the bug

Encountering issues with the polykey secrets edit command that suggest problems with permissions and directory handling. The command fails with either a permissions error or a complaint about an existing directory.

To Reproduce

To Reproduce

Steps to reproduce the behavior:

  1. Execute the command to edit a secret:

    polykey secrets edit my-vault-tutorial-1:API_ACCESS_KEY

    Error received:

    Error: EEXIST: file already exists, mkdir '/Users/rulerpablo/Matrix_ai/my_asciinema_recordings/pksecret'
    
  2. Attempt to edit another secret:

    polykey secrets edit my-new-vault:old_api_secret

    Error received:

    Error: command-argument value 'Old-API-Secret' is invalid for argument 'secretPath'. Old-API-Secret is not of the format <vaultName>:<directoryPath>
    

Expected behavior

The polykey secrets edit command should open the secret in the default editor without errors, allowing for modifications. There should be no permission issues or erroneous directory existence errors.

Platform (please complete the following information)

  • Device: [Mac]
  • OS: [Mac OS]
  • PK Version [1.2.3-alpha.4]

Additional context

Notify maintainers

@tegefaulkes

@CryptoTotalWar CryptoTotalWar added the bug Something isn't working label May 26, 2024
Copy link

linear bot commented May 26, 2024

@CMCDragonkai
Copy link
Member

While the edit command isn't exactly correctly designed.

I suspect:

Error: EEXIST: file already exists, mkdir '/Users/rulerpablo/Matrix_ai/my_asciinema_recordings/pksecret'

Has more to do with your ascinnema situation than anything to do with PK.

@CryptoTotalWar
Copy link
Author

Resolution and Documentation Update

Issue Resolution

We identified that the polykey secrets edit command was failing due to an unset default editor in the system environment. This issue was resolved by setting nano as the default editor in the .zshrc configuration file. After making this update, the command executed successfully without permissions errors or directory handling issues.

Steps Taken

  1. Confirmed that the EDITOR environment variable was not set by running:
    echo $EDITOR
  2. Set nano as the default editor:
    export EDITOR=nano
  3. Added the export command to the .zshrc file to make the change permanent:
    echo 'export EDITOR="nano"' >> ~/.zshrc
  4. Reloaded the .zshrc to apply the changes:
    source ~/.zshrc

Certainly! Continuing from where we left off, here's how to describe the process within Nano and confirming the changes:

Detailed Steps and Terminal Output (Continued)

  1. Editing the Secret in Nano:

    • Upon executing the polykey secrets edit my-new-vault:old_api_secret command, nano opened the file containing the secret.
    • In nano, I edited the text to update the API secret. After making the changes, I exited nano by pressing CTRL+X, confirmed saving the changes by pressing Y, and then pressed Enter to finalize the save.
  2. Terminal Processing After Exiting Nano:

    • After exiting nano, the terminal briefly processed the changes, taking about half a second to complete.
  3. Verifying the Edit:

    • To ensure the edit was successful, I ran:
      polykey secrets get my-new-vault:old_api_secret
    • The output confirmed the successful edit with the new content of the secret:
      This is an outdated API Secret... not anymore!!
      

Required Documentation Update

Setting a Default Text Editor for Polykey Commands

To use the polykey secrets edit command effectively, which allows for direct editing of secrets within your vault, setting a default text editor is mandatory. This setup is crucial for ensuring that the command functions correctly across all supported platforms. Below is a step-by-step guide to configure nano as the default editor, which can be adapted for other editors like vim based on your preference.

  1. Edit Your Shell Configuration File:
    Access your shell's configuration file (.bashrc for Bash or .zshrc for Zsh) using a text editor. For simplicity, we are using nano here:

    nano ~/.bashrc  # Or ~/.zshrc for Zsh users
  2. Configure the Default Editor:
    Append the following line to your configuration file to set nano as the default editor:

    export EDITOR='nano'
  3. Save and Exit:
    Save the changes and exit the editor. In nano, press CTRL+X to exit, hit Y to confirm the changes, and Enter to close the editor.

  4. Activate the Changes:
    Ensure the new settings take effect by sourcing the updated configuration file:

    source ~/.bashrc  # Or ~/.zshrc if you're using Zsh

Using the polykey secrets edit Command

Once your default editor is set, you can begin editing secrets directly within Polykey:

  • Edit a Secret: Use the polykey secrets edit command to open the secret in your default text editor. For example:

    polykey secrets edit my-vault:my-secret

    This command opens the secret's content in nano, allowing you to make necessary edits.

  • Save and Exit the Editor: After editing, save your changes and exit the editor.

  • Verify Changes: To ensure your edits were saved correctly, retrieve the updated secret using:

    polykey secrets get my-vault:my-secret

    This will display the updated content of the secret in the terminal, confirming that your changes have been successfully applied.

This setup and subsequent steps are essential for ensuring a smooth operation of the polykey secrets edit command, making it a necessary configuration for all Polykey users on macOS, Linux, and Windows systems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working r&d:polykey:core activity 1 Secret Vault Sharing and Secret History Management
Development

No branches or pull requests

3 participants