Skip to content

Commit 05838f1

Browse files
committed
Improve IAM policy title abbreviation to prevent duplicates
- Enhance title_abbrev generation by appending source context (e.g. "from AWS Account Management") - Add test coverage for the updated title abbreviation logic - Add test resources for IAMPolicyGrammar configuration This reduces duplicate title abbreviations that occur when multiple policies have similar names.
1 parent 0e096a7 commit 05838f1

6 files changed

Lines changed: 81 additions & 6 deletions

File tree

aws_doc_sdk_examples_tools/agent/bin/main.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,8 @@
2525

2626

2727
def format_duration(seconds: float) -> str:
28-
"""Format duration in seconds to hours:minutes:seconds format."""
2928
td = timedelta(seconds=seconds)
30-
hours, remainder = divmod(td.total_seconds(), 3600)
31-
minutes, seconds = divmod(remainder, 60)
32-
return f"{int(hours):02d}:{int(minutes):02d}:{int(seconds):02d}"
29+
return str(td).zfill(8)
3330

3431

3532
@app.command()

aws_doc_sdk_examples_tools/agent/process_ailly_files.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ def parse_ailly_file(
8181
if key in result:
8282
result[key] = f"{prefix}{result[key]}"
8383

84-
result["title_abbrev"] = result["title"]
8584
result["id"] = Path(file_path).name.split(".md.ailly.md")[0]
8685
result["_source_file"] = file_path
8786

aws_doc_sdk_examples_tools/agent/update_doc_gen.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
logging.basicConfig(level=logging.INFO)
99
logger = logging.getLogger(__name__)
1010

11+
IAM_LANGUAGE = "IAMPolicyGrammar"
12+
1113

1214
def examples_from_updates(updates_path: Path) -> Iterable[Example]:
1315
"""
@@ -44,7 +46,9 @@ def update_examples(doc_gen: DocGen, examples: Iterable[Example]) -> None:
4446
for example in examples:
4547
if doc_gen_example := doc_gen.examples.get(example.id):
4648
doc_gen_example.title = example.title
47-
doc_gen_example.title_abbrev = example.title_abbrev
49+
# This reduces the number of duplicate title_abbrev that occur due to similar policies
50+
source = doc_gen_example.languages[IAM_LANGUAGE].versions[0].source.title
51+
doc_gen_example.title_abbrev = f"{example.title_abbrev} (from {source})"
4852
doc_gen_example.synopsis = example.synopsis
4953
else:
5054
logger.warning(f"Could not find example with id: {example.id}")
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import pytest
2+
from pathlib import Path
3+
4+
from aws_doc_sdk_examples_tools.doc_gen import DocGen
5+
from aws_doc_sdk_examples_tools.metadata import Example
6+
from aws_doc_sdk_examples_tools.agent.update_doc_gen import update_examples
7+
8+
9+
@pytest.fixture
10+
def doc_gen_tributary():
11+
"""
12+
Fixture that returns a DocGen instance using the doc_gen_tributary_test as root.
13+
"""
14+
tributary_root = (
15+
Path(__file__).parent.parent / "test_resources" / "doc_gen_tributary_test"
16+
)
17+
doc_gen = DocGen.from_root(tributary_root)
18+
doc_gen.collect_snippets()
19+
return doc_gen
20+
21+
22+
def smoke_test_doc_gen(doc_gen_tributary: DocGen):
23+
assert isinstance(doc_gen_tributary, DocGen)
24+
25+
26+
def test_update_examples_title_abbrev(doc_gen_tributary: DocGen):
27+
"""Test that title_abbrev is updated correctly with service_main suffix."""
28+
# Create an example with a title_abbrev to update
29+
update_example = Example(
30+
id="iam_policies_example",
31+
file=None,
32+
languages={},
33+
title_abbrev="Updated Title Abbrev",
34+
)
35+
36+
# Update the examples
37+
update_examples(doc_gen_tributary, [update_example])
38+
39+
# Verify title_abbrev was updated with the service_main suffix
40+
updated_example = doc_gen_tributary.examples["iam_policies_example"]
41+
assert updated_example.title_abbrev == "Updated Title Abbrev (from AWS Account Management)"

aws_doc_sdk_examples_tools/test_resources/doc_gen_tributary_test/.doc_gen/config/sdks.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,16 @@ IAMPolicy:
1111
name: "&SAZR;"
1212
link_template: "SomeTemplate"
1313
guide: "&guide-iam-user;"
14+
IAMPolicyGrammar:
15+
property: json
16+
syntax: json
17+
sdk:
18+
1:
19+
long: "IAM policy"
20+
short: "IAM policy"
21+
guide: "IAM/latest/UserGuide/introduction.html"
22+
api_ref:
23+
uid: "IAMPolicy"
24+
name: "&SAZR;"
25+
link_template: "SomeTemplate"
26+
guide: "&guide-iam-user;"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
iam_policies_example:
2+
category: IAMPolicy
3+
languages:
4+
IAMPolicyGrammar:
5+
versions:
6+
- authors:
7+
- alias: amazonian@amazon.com
8+
name: Sir Peccy
9+
excerpts:
10+
- description: test
11+
owner: AWS/Documentation/Accounts Management Docs
12+
sdk_version: 1
13+
source:
14+
title: AWS Account Management
15+
url: https://code.amazon.com/packages/AccountControlApiDoc
16+
services:
17+
iam: {}
18+
synopsis: This identity-based policy allows the attached identity to retrieve the
19+
billing alternate contact information for a specific account within an organization.
20+
title: Allow retrieval of a specific alternate contact type for an account
21+
title_abbrev: Allow retrieval of a specific alternate contact type for an account

0 commit comments

Comments
 (0)