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: tedge cert create-csr should use cloud profile's CN #3316

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

rina23q
Copy link
Member

@rina23q rina23q commented Jan 6, 2025

Proposed changes

tedge cert create-csr <cloud> --profile <profile> should use the CN of the corresponding device certificate/private key if --device-id is not provided.

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

#3315

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA (in all commits with git commit -s)
  • I ran cargo fmt as mentioned in CODING_GUIDELINES
  • I used cargo clippy 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

Copy link

codecov bot commented Jan 6, 2025

Codecov Report

Attention: Patch coverage is 0% with 16 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/core/tedge/src/cli/certificate/cli.rs 0.00% 16 Missing ⚠️
Additional details and impacted files

📢 Thoughts on this report? Let us know!

Copy link
Contributor

github-actions bot commented Jan 6, 2025

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
552 0 2 552 100 1h29m53.552837999s

@rina23q rina23q temporarily deployed to Test Pull Request January 6, 2025 16:37 — with GitHub Actions Inactive
@@ -97,7 +97,12 @@ impl BuildCommand for TEdgeCertCli {
let cloud: Option<Cloud> = cloud.map(<_>::try_into).transpose()?;

// Use the current device id if no id is provided
let id = id.unwrap_or(get_device_id_from_cloud(&config, &cloud)?);
let id = if let Some(id) = id {
Copy link
Member Author

@rina23q rina23q Jan 6, 2025

Choose a reason for hiding this comment

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

At first, I wrote this line as below.

let id = id.unwrap_or(get_device_id_from_cloud(&config, &cloud)?);

However, it causes a problem when certificate doesn't exist but the id has Some() sinceunwrap_or() evaluates the default always regardless of id is Some or None.

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed, and unwrap_or_else, makes it so you can't use ? from within the closure, which is a bit of a pain.

@rina23q rina23q force-pushed the fix/3315/cert-create-csr-should-use-cloud-profile-cn branch from f9bab9b to 5f6a6f2 Compare January 6, 2025 17:26
@rina23q rina23q temporarily deployed to Test Pull Request January 6, 2025 17:27 — with GitHub Actions Inactive
@@ -97,7 +97,12 @@ impl BuildCommand for TEdgeCertCli {
let cloud: Option<Cloud> = cloud.map(<_>::try_into).transpose()?;

// Use the current device id if no id is provided
let id = id.unwrap_or(get_device_id_from_cloud(&config, &cloud)?);
let id = if let Some(id) = id {
Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed, and unwrap_or_else, makes it so you can't use ? from within the closure, which is a bit of a pain.

Copy link
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

@@ -186,3 +191,17 @@ pub enum UploadCertCli {
profile: Option<ProfileName>,
},
}

fn get_device_id_from_cloud(
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
fn get_device_id_from_cloud(
fn get_device_id_from_config(

Since it's not always the id from a cloud profile but could be the main device.id as well.

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.

3 participants