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

fix(cli): canonicalize keystore path #19312

Merged
merged 2 commits into from
Sep 11, 2024
Merged

fix(cli): canonicalize keystore path #19312

merged 2 commits into from
Sep 11, 2024

Conversation

amnn
Copy link
Contributor

@amnn amnn commented Sep 11, 2024

Description

Fix a bug where a relative keystore path was written out to the config upon creation when the config itself was specified at a relative path.

The fix is to canonicalize the keystore path before using it, but we need to handle multiple edge cases:

  • A wallet config created in the current working directory as a relative path (and relative paths in general).
  • A wallet config created at the very root of the filesystem (although this should never happen, the correct behaviour is not to default to the default config directory here).

Test plan

sui$ cargo build --bin sui
sui$ export SUI=~/sui/target/debug/sui
sui$ mv ~/.sui/sui_config/client.yaml{,~}
sui$ cd ~

# Create the config at the default location using a relative path
sui$ $SUI client --client.config .sui/sui_config/client.yaml gas
sui$ cd -
sui$ $SUI client gas

# Create the config at some other location, using a relative path
sui$ mkdir -p /tmp/a
sui$ cd /tmp/a
a$ $SUI client --client.config ./client.yaml gas
a$ cd -
sui$ $SUI client --client.config /tmp/a/client.yaml gas

# Create the config at some other location, using a relative path
# without a root
sui$ mkdir -p /tmp/b
sui$ cd /tmp/b
b$ $SUI client --client.config client.yaml gas
b$ cd -
sui$ $SUI client --client.config /tmp/b/client.yaml gas

Release notes

Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required.

For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates.

  • Protocol:
  • Nodes (Validators and Full nodes):
  • Indexer:
  • JSON-RPC:
  • GraphQL:
  • CLI: Fixes a bug where the CLI would write out a config with a relative path for the keystore that would only work if the CLI was subsequently called from the same directory that the config was first created in.
  • Rust SDK:
  • REST API:

## Description

Fix a bug where a relative keystore path was written out to the config
upon creation when the config itself was specified at a relative path.

The fix is to canonicalize the keystore path before using it, but we
need to handle multiple edge cases:

- A wallet config created in the current working directory as a relative
  path (and relative paths in general).
- A wallet config created at the very root of the filesystem (although
  this should never happen, the correct behaviour is not to default to
  the default config directory here).

## Test plan

```
sui$ cargo build --bin sui
sui$ export SUI=~/sui/target/debug/sui
sui$ mv ~/.sui/sui_config/client.yaml{,~}
sui$ cd ~

# Create the config at the default location using a relative path
sui$ $SUI client --client.config .sui/sui_config/client.yaml gas
sui$ cd -
sui$ $SUI client gas

# Create the config at some other location, using a relative path
sui$ mkdir -p /tmp/a
sui$ cd /tmp/a
a$ $SUI client --client.config ./client.yaml gas
a$ cd -
sui$ $SUI client --client.config /tmp/a/client.yaml gas

# Create the config at some other location, using a relative path
# without a root
sui$ mkdir -p /tmp/b
sui$ cd /tmp/b
b$ $SUI client --client.config client.yaml gas
b$ cd -
sui$ $SUI client --client.config /tmp/b/client.yaml gas
```
@amnn amnn requested review from giac-mysten, stefan-mysten and a team September 11, 2024 10:33
@amnn amnn self-assigned this Sep 11, 2024
Copy link

vercel bot commented Sep 11, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sui-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 11, 2024 10:41am
3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
multisig-toolkit ⬜️ Ignored (Inspect) Sep 11, 2024 10:41am
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview Sep 11, 2024 10:41am
sui-typescript-docs ⬜️ Ignored (Inspect) Visit Preview Sep 11, 2024 10:41am

Copy link

@giac-mysten giac-mysten left a comment

Choose a reason for hiding this comment

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

Thank you @amnn!

crates/sui/src/sui_commands.rs Outdated Show resolved Hide resolved
@amnn amnn enabled auto-merge (squash) September 11, 2024 10:42
@amnn amnn merged commit 9cd655a into main Sep 11, 2024
51 checks passed
@amnn amnn deleted the amnn/fix-config-new branch September 11, 2024 10:54
suiwombat pushed a commit that referenced this pull request Sep 16, 2024
## Description

Fix a bug where a relative keystore path was written out to the config
upon creation when the config itself was specified at a relative path.

The fix is to canonicalize the keystore path before using it, but we
need to handle multiple edge cases:

- A wallet config created in the current working directory as a relative
path (and relative paths in general).
- A wallet config created at the very root of the filesystem (although
this should never happen, the correct behaviour is not to default to the
default config directory here).

## Test plan

```
sui$ cargo build --bin sui
sui$ export SUI=~/sui/target/debug/sui
sui$ mv ~/.sui/sui_config/client.yaml{,~}
sui$ cd ~

# Create the config at the default location using a relative path
sui$ $SUI client --client.config .sui/sui_config/client.yaml gas
sui$ cd -
sui$ $SUI client gas

# Create the config at some other location, using a relative path
sui$ mkdir -p /tmp/a
sui$ cd /tmp/a
a$ $SUI client --client.config ./client.yaml gas
a$ cd -
sui$ $SUI client --client.config /tmp/a/client.yaml gas

# Create the config at some other location, using a relative path
# without a root
sui$ mkdir -p /tmp/b
sui$ cd /tmp/b
b$ $SUI client --client.config client.yaml gas
b$ cd -
sui$ $SUI client --client.config /tmp/b/client.yaml gas
```

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [x] CLI: Fixes a bug where the CLI would write out a config with a
relative path for the keystore that would only work if the CLI was
subsequently called from the same directory that the config was first
created in.
- [ ] Rust SDK:
- [ ] REST API:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants