[amg] Fix year duration calculation for service-account token create (#10181) - #10195
[amg] Fix year duration calculation for service-account token create (#10181)#10195Nithin (nithin42) wants to merge 13 commits into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
Pull request overview
This PR updates the amg (Azure Managed Grafana) CLI extension to correct year-based TTL parsing for service-account token creation, preventing invalid/overflowed expirations when users pass values like --time-to-live 10y.
Changes:
- Fixes the
"y"duration unit conversion from an incorrect 30× multiplier to a correct 365-day year in_convert_duration_to_seconds. - Adds a regression test covering duration conversions for all supported units.
- Bumps the extension version to
3.0.1and adds a changelog entry; fixes a small help-text typo.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/amg/azext_amg/custom.py | Corrects year-to-seconds conversion used for secondsToLive when creating service-account tokens. |
| src/amg/azext_amg/tests/latest/test_amg_scenario.py | Adds coverage for duration parsing across all supported units, including y. |
| src/amg/azext_amg/_params.py | Fixes a typo in the --time-to-live help text. |
| src/amg/setup.py | Bumps the amg extension version to 3.0.1. |
| src/amg/HISTORY.rst | Adds a 3.0.1 changelog entry describing the fix. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
amg |
|
Ethan Yang (@necusjz) any updates ? |
|
lgtm. and im honored to have the review from @ABZhang0 who is the owner from service team. |
|
Hi Alan Zhang (@alanbzhang) 👋 Whenever you have a moment, looking forward to your review! Thanks again Ethan Yang (@necusjz) for the LGTM approval! |
|
LGTM, thanks for the fix! |
|
Thank you Alan Zhang (@alanbzhang) for the review! Ethan Yang (@necusjz) please let me know if any other changes are needed from my end whenever you get a chance. |
|
/azp run |
|
Azure Pipelines: Successfully started running 2 pipeline(s). |
|
Ethan Yang (@necusjz) Pushed a quick PEP8 style cleanup commit for |
|
/azp run |
|
Azure Pipelines: Successfully started running 2 pipeline(s). |
566cc1b to
469cbb4
Compare
|
/azp run |
|
Azure Pipelines: Successfully started running 2 pipeline(s). |
|
Hi Ethan Yang (@necusjz), Yong Zhang (@yonzhan) & Alan Zhang (@alanbzhang) All required static checks, linters ( Local unit test execution for Please let me know if everything is good on your end or if any further steps are needed before merging. Thank you! |
|
Nithin (@nithin42) unfortunately, the ci is still failling. you can reproduce it by kindly reminder, it's better add amg extension to dev mode (azdev extension add amg) before you start to develop it. |
…ttest.TestCase) class
469cbb4 to
b1864c9
Compare
|
Thank you for the tip and doc link!
All linters (azdev style, azdev linter), breaking change checks, and unit tests are passing 100% green. Ready for /azp run whenever you get a chance. Thanks! |
|
/azp run |
|
Azure Pipelines: Successfully started running 2 pipeline(s). |
…on in migrate scenario test
|
/azp run |
|
Azure Pipelines: Successfully started running 2 pipeline(s). |
|
Hi Ethan Yang (@necusjz), Yong Zhang (@yonzhan) & Alan Zhang (@alanbzhang), Cleaned up the branch to keep the PR diff strictly focused on the issue:
Ready for |
|
/azp run |
|
Azure Pipelines: Successfully started running 2 pipeline(s). |
|
Hi Ethan Yang (@necusjz), Yong Zhang (@yonzhan) & Alan Zhang (@alanbzhang), Traced and fixed the
Pushed commit |
|
/azp run |
|
Azure Pipelines: Successfully started running 2 pipeline(s). |
|
Hi Ethan Yang (@necusjz), Yong Zhang (@yonzhan) & Alan Zhang (@alanbzhang), Here is a summary of the updates completed in this PR: 1. Core Fix (#10181) & Unit Tests
2. Track-2 SDK Serialization Compatibility
3. Cassette Alignment
4. Status
Thank you so much Ethan Yang (@necusjz), Yong Zhang (@yonzhan), and Alan Zhang (@alanbzhang) for your time, valuable feedback, and guidance throughout this PR. I really appreciate the opportunity to contribute to the Azure CLI community! |
🤖 PR Validation — ️✔️ All clear
Description
Fixes #10181.
This PR fixes a duration calculation bug in the Azure Managed Grafana (
amg) extension when creating service account tokens with the year unit (e.g.,--time-to-live 10y).Problem & Cause
In
src/amg/azext_amg/custom.py, theunit_to_secondsdictionary mapped"y"to3600 * 24 * 30 * 365. Because of the duplicate30multiplier, 1 year was calculated as 30 years (315,360,000seconds). Passing10yevaluated to 300 years, causing Grafana's nanosecond timestamp calculation to overflow into the past (year 1741), producing an already-expired token.Fix Details
"y"inunit_to_secondsfrom3600 * 24 * 30 * 365to3600 * 24 * 365(31,536,000seconds/year)._params.py("fr"->"for").test_duration_conversionunit test covering all duration units (s,m,h,d,w,M,y).amgextension version to3.0.1insetup.pyand updatedHISTORY.rst.Testing
Ran unit test suite validating duration conversion logic for all supported units (
s,m,h,d,w,M,y).