Skip to content

fix: support relative path args when using tedge cert#3564

Merged
reubenmiller merged 3 commits intothin-edge:mainfrom
didier-wenzek:fix/accept_relative_path_args
Apr 17, 2025
Merged

fix: support relative path args when using tedge cert#3564
reubenmiller merged 3 commits intothin-edge:mainfrom
didier-wenzek:fix/accept_relative_path_args

Conversation

@didier-wenzek
Copy link
Copy Markdown
Contributor

@didier-wenzek didier-wenzek commented Apr 14, 2025

Proposed changes

Allow users to provide a relative path when using tedge cert sub-commands a create-csr or show.

  • Improve tedge config set to make sure no relative paths is stored in the TOML config (because used later from any working directory)
  • Improve tedge config set to store cannonalized paths when given relative paths
  • Remove from tedge cert the check that was preventing a path argument to be relative.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Improvement (general improvements like code refactoring that doesn't explicitly fix a bug or add any new functionality)
  • Documentation Update (if none of the other choices apply)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Paste Link to the issue

#3547

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA (in all commits with git commit -s. You can activate automatic signing by running just prepare-dev once)
  • I ran just format as mentioned in CODING_GUIDELINES
  • I used just check as mentioned in CODING_GUIDELINES
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

@reubenmiller reubenmiller added theme:cli Theme: cli related topics theme:certificates Theme: Device certificate topics labels Apr 14, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 14, 2025

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
615 0 3 615 100 1h52m43.334048s

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 15, 2025

Copy link
Copy Markdown
Contributor

@albinsuresh albinsuresh left a comment

Choose a reason for hiding this comment

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

Changes looked fine. But just wanted to confirm if we wanted to restrict relative paths not just from the TOML file, but also in the CLI when they are set. Will approve after this confirmation.

tedge configure MQTT client authentication
Execute Command tedge config set mqtt.client.auth.cert_file client.crt
Execute Command tedge config set mqtt.client.auth.key_file client.key
Execute Command tedge config set mqtt.client.auth.cert_file "$(pwd)/client.crt"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I thought that relative paths would still be accepted in the CLI, but its absolute form (after resolving it) would be stored in the TOML file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

tedge config set expects absolute paths and doesn't try to convert a relative path into an absolute form that would be stored in the TOML file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Here a proposal to implement this idea to normalize a path configured using tedge config set

368ec48

Copy link
Copy Markdown
Member

@rina23q rina23q left a comment

Choose a reason for hiding this comment

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

The changes really make sense. CLI accepts both absolute and relative paths while tedge config accepts only absolute.

Copy link
Copy Markdown
Contributor

@albinsuresh albinsuresh left a comment

Choose a reason for hiding this comment

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

LGTM. Just one minor remark on an error message.

Ok(AbsolutePath(path))
}
let Ok(Ok(pwd)) = std::env::current_dir().map(Utf8PathBuf::try_from) else {
return Err(InvalidAbsolutePath(path));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor:

Suggested change
return Err(InvalidAbsolutePath(path));
return Err(InvalidRelativePath(path));

Else the error message will be slightly misleading, right? As the issue is not at all with the input path but from the derived pwd.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I changed the error message to "Cannot be converted to an absolute path" but let the error type name unchanged because it makes sense for AbsolutePath::try_new to fail with InvalidAbsolutePath.

See 4134c9e

fn clean_utf8_path(path: &Utf8Path) -> Utf8PathBuf {
Utf8PathBuf::from(path_clean::clean(path.as_str()))
// unwrap is safe because clean returns an utf8 path when given an utf8 path
Utf8PathBuf::try_from(path_clean::clean(path.as_std_path())).unwrap()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm assuming that we're using path_clean::clean() instead of std::path::absolute() because our MSRV is still 1.78 and the latter is only available from 1.79.

Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
@didier-wenzek didier-wenzek force-pushed the fix/accept_relative_path_args branch from 4134c9e to 4e350e1 Compare April 17, 2025 11:52
@didier-wenzek didier-wenzek enabled auto-merge April 17, 2025 12:03
@didier-wenzek didier-wenzek added this pull request to the merge queue Apr 17, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 17, 2025
@didier-wenzek didier-wenzek added this pull request to the merge queue Apr 17, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 17, 2025
@reubenmiller reubenmiller added this pull request to the merge queue Apr 17, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 17, 2025
@didier-wenzek didier-wenzek added this pull request to the merge queue Apr 17, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 17, 2025
@reubenmiller reubenmiller added this pull request to the merge queue Apr 17, 2025
Merged via the queue into thin-edge:main with commit 1414e07 Apr 17, 2025
34 checks passed
@didier-wenzek didier-wenzek deleted the fix/accept_relative_path_args branch April 17, 2025 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

theme:certificates Theme: Device certificate topics theme:cli Theme: cli related topics

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants