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

feat(client/keys): add support for importing hex key using standard input #21829

Merged
merged 3 commits into from
Sep 20, 2024

Conversation

zakir-code
Copy link
Contributor

@zakir-code zakir-code commented Sep 20, 2024

Description

Closes: #XXXX


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • New Features

    • Support for importing hex keys using standard input in the key management module.
  • Bug Fixes

    • Improved handling of command arguments for hex key import, allowing for optional input.
  • Tests

    • Added a new test case to validate reading hex keys from standard input, enhancing test coverage.

Copy link
Contributor

coderabbitai bot commented Sep 20, 2024

Walkthrough

Walkthrough

The changes introduce a new feature in the Cosmos SDK's client/keys module that allows users to import a hex key via standard input. The ImportKeyCommand and ImportKeyHexCommand functions have been updated to facilitate this new functionality, including adjustments to command arguments and variable naming. Additionally, the testing framework has been enhanced to support reading hex keys from standard input, streamlining the setup and cleanup processes for tests.

Changes

File Change Summary
CHANGELOG.md Added an entry detailing the new feature for importing hex keys using standard input in the client/keys module.
client/keys/import.go Modified ImportKeyCommand and ImportKeyHexCommand to read hex keys from standard input, updated argument handling, and changed variable names for clarity.
client/keys/import_test.go Simplified test setup and cleanup, added a new test case for reading hex keys from standard input, and adjusted command arguments based on input method.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    -- I pushed a fix in commit <commit_id>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added C:CLI C:Keys Keybase, KMS and HSMs labels Sep 20, 2024
@zakir-code zakir-code marked this pull request as ready for review September 20, 2024 08:49
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range and nitpick comments (3)
CHANGELOG.md (3)

Line range hint 1-4: Suggestion: Add a title and description at the top of the changelog

Consider adding a brief title and description at the very top of the changelog explaining what this document is, and how users can make the most of the information here. This can help new users quickly understand the purpose and structure of the changelog.


Line range hint 310-310: Typo: "begin" should be "begin block"

- (x/upgrade) [#12603](https://github.com/cosmos/cosmos-sdk/pull/12603) feat: Move AppModule.BeginBlock and AppModule.EndBlock to extension interfaces

Here "begin" should be expanded to "begin block" to match "end block" and be more descriptive.


Line range hint 407-407: Unclear breaking change description

- [#9879](https://github.com/cosmos/cosmos-sdk/pull/9879) Modify ABCI Queries to use `abci.QueryRequest` Height field if it is non-zero, otherwise continue using context height.

The breaking change description here is quite unclear. It doesn't explain what queries were impacted, what the previous behavior was, and why the new behavior might break existing clients.

Consider expanding this with more context, such as:

- [#9879](https://github.com/cosmos/cosmos-sdk/pull/9879) ABCI Queries should use the `Height` field of `abci.RequestQuery` if it is non-zero. 
Previously, the context height was used in all cases. Clients relying on the old behavior of using context height when the `Height` field is set 
will need to be updated.

This provides more details on what changed, what the previous behavior was, and how clients might be impacted and need to adapt.

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d6364b8 and 20ebcee.

Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • client/keys/import.go (3 hunks)
  • client/keys/import_test.go (5 hunks)
Additional context used
Path-based instructions (3)
CHANGELOG.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

client/keys/import.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

client/keys/import_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

Additional comments not posted (7)
client/keys/import.go (2)

Line range hint 37-47: LGTM!

The changes in the ImportKeyCommand function are well-structured and improve code readability:

  • Reading the file contents into a variable named armor is more descriptive than the previous name bz.
  • Using string(armor) instead of string(bz) in the ImportPrivKey call is consistent with the variable name change.

The logic flow remains clear and concise.


Line range hint 54-78: Great work on enhancing the ImportKeyHexCommand function!

The updates to the command usage and argument handling logic improve the user experience:

  • Changing Args: cobra.ExactArgs(2) to Args: cobra.RangeArgs(1, 2) allows for flexibility in providing the hex key.
  • The conditional logic for handling the second argument is well-structured and handles both cases effectively.
  • Prompting the user for input when the second argument is not provided is a nice touch.
  • Using the name variable instead of args[0] in the ImportPrivKeyHex call improves code readability.

The changes are logically sound and enhance the functionality of the command.

client/keys/import_test.go (2)

85-88: LGTM!

The changes simplify the setup and cleanup of the temporary keybase directory for each test case. Using os.MkdirAll directly without checking for existence first is a cleaner approach. Applying the cleanup function consistently with t.Cleanup ensures proper removal of the directory after each test case.


135-141: Excellent addition of the new test case and cleanup improvements!

The new test case for reading the hex key from standard input enhances the flexibility and coverage of the test suite. The use of the stdInput flag to conditionally set the command arguments is a clean approach.

Also, applying the cleanup function consistently with t.Cleanup for removing the temporary keybase directory is a good improvement.

Also applies to: 152-155, 166-173

CHANGELOG.md (3)

49-49: The new --output flag for tx CLI commands is a useful addition

Allowing JSON output for tx CLI commands with the new --output flag will make it easier to integrate the CLI with scripts and tools that consume JSON. Nice improvement!


Line range hint 8-46: The v0.46.0 release notes are quite thorough

The release notes for v0.46.0 are very comprehensive, covering breaking changes, new features, bug fixes and improvements across many areas of the SDK. Excellent work on putting together such detailed release notes - this will really help users understand all the changes in this release and how to upgrade.

Some additional suggestions to consider:

  • Adding a high-level summary at the top of the major themes or focus areas for this release
  • Providing links to documentation or other resources with more details on some of the major changes
  • Including any steps or guidance for upgrading from the previous major version (v0.45.x)

But overall, the level of detail and organization here is great!


Line range hint 8-11: Verify if the security fix for non-Cosmos Hub chains is still relevant

This changelog entry mentions an important security fix for non-Cosmos Hub chains running Stargate versions of the SDK. However, it's not clear if this is still an issue that operators need to be aware of when upgrading to v0.46.0.

To verify, we can search the codebase for the original issue and fix to see if it's still present in v0.46.0:

If the searches don't turn up the original issue and affected version logic, we can likely remove this item as it's no longer relevant. If they are still present, the entry should be updated to clearly state if this remains an issue in v0.46.0.

Copy link
Contributor

@JulianToledano JulianToledano left a comment

Choose a reason for hiding this comment

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

Nice one!!

@tac0turtle tac0turtle added this pull request to the merge queue Sep 20, 2024
Merged via the queue into cosmos:main with commit 8d248f0 Sep 20, 2024
74 checks passed
@zakir-code zakir-code deleted the zakir/keys-import branch September 20, 2024 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants