Skip to content

feat: avoid using months when displaying certificate duration#3673

Merged
reubenmiller merged 1 commit intothin-edge:mainfrom
reubenmiller:feat-certificate-duration-formatting
Jun 6, 2025
Merged

feat: avoid using months when displaying certificate duration#3673
reubenmiller merged 1 commit intothin-edge:mainfrom
reubenmiller:feat-certificate-duration-formatting

Conversation

@reubenmiller
Copy link
Copy Markdown
Contributor

@reubenmiller reubenmiller commented Jun 5, 2025

Proposed changes

Improve the certificate validity duration by only using years, days, hours, minutes and seconds (avoiding months), to align to user expectations and avoid the "days in a month" rounding errors in the total duration.

Some examples of the duration in the new format:

  • 364d 8h 42m 43s
  • 5y 219d 2h 59m
  • 2y
  • 2h 1m 3s

Background

The humantime crate uses averaged units in the conversion to a human time, so for a duration spanning months, then the remaining hours part of the duration can get skewed unexpectedly (from the users perspective).

For instance, when a certificate is renewed using the Cumulocity Certificate Authority, the new certificate has a validity of 1 year (~365 days if you ignore leap years etc.). When the user downloads a new certificate from Cumulocity, the validity of the certificate is set to 1 year, however the duration displayed is:

Status:        VALID (expires in: 11months 30days 3h 48m 54s)

Where the number of hours remaining is unexpected, as something like 23h 48m 54s would of been more expected (assuming we ignore leap years, total days in a month etc.).

The displaying of the duration in months has the potential to raise more questions, and to avoid having to explain it every time, I'd propose to change to using days as the maximum unit of measurement.

Before (current)

$ tedge cert show
Certificate:   /opt/homebrew/etc/tedge/device-certs/tedge-certificate.pem
Subject:       CN=rmi_macos, O=Thin Edge, OU=Device
Issuer:        C=United States, O=Cumulocity, CN=t9679
Status:        VALID (expires in: 11months 30days 3h 48m 54s)
Valid from:    Thu, 05 Jun 2025 15:50:24 +0000
Valid until:   Fri, 05 Jun 2026 15:50:24 +0000
Serial number: 1749138624770 (0x19740c95102)
Thumbprint:    0FC922ED665081767BC42A180B93A90CA50EAF69

After

$ tedge cert show
Certificate:   /opt/homebrew/etc/tedge/device-certs/tedge-certificate.pem
Subject:       CN=rmi_macos, O=Thin Edge, OU=Device
Issuer:        C=United States, O=Cumulocity, CN=t9679
Status:        VALID (expires in: 364d 23h 57m 43s)
Valid from:    Thu, 05 Jun 2025 15:50:24 +0000
Valid until:   Fri, 05 Jun 2026 15:50:24 +0000
Serial number: 1749138624770 (0x19740c95102)
Thumbprint:    0FC922ED665081767BC42A180B93A90CA50EAF69

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


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 temporarily deployed to Test Pull Request June 5, 2025 16:37 — with GitHub Actions Inactive
@reubenmiller reubenmiller added theme:cli Theme: cli related topics theme:certificates Theme: Device certificate topics and removed theme:cli Theme: cli related topics labels Jun 5, 2025
@codecov
Copy link
Copy Markdown

codecov bot commented Jun 5, 2025

Codecov Report

Attention: Patch coverage is 97.19626% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/core/tedge/src/cli/certificate/show.rs 97.19% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@didier-wenzek didier-wenzek left a comment

Choose a reason for hiding this comment

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

Approved

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jun 5, 2025

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
641 0 3 641 100 1h49m25.254955s

@reubenmiller reubenmiller changed the title feat: only display certificate duration in days not months feat: avoid using months when displaying certificate duration Jun 6, 2025
Copy link
Copy Markdown
Contributor

@didier-wenzek didier-wenzek left a comment

Choose a reason for hiding this comment

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

I confirm my approval after the fixup to show total years as well (i.e. 5y 219d instead of 2044d)

Signed-off-by: reubenmiller <reuben.d.miller@gmail.com>
@reubenmiller reubenmiller force-pushed the feat-certificate-duration-formatting branch from 4acd600 to 6741084 Compare June 6, 2025 08:05
@reubenmiller reubenmiller temporarily deployed to Test Pull Request June 6, 2025 08:05 — with GitHub Actions Inactive
@reubenmiller reubenmiller added this pull request to the merge queue Jun 6, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jun 6, 2025
@reubenmiller reubenmiller added this pull request to the merge queue Jun 6, 2025
Merged via the queue into thin-edge:main with commit 6b3836a Jun 6, 2025
34 checks passed
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants