Skip to content

Commit 7eee6ad

Browse files
authored
Merge branch 'devel' into cleanup/diff-unused-param
2 parents 28c6967 + 7458f1c commit 7eee6ad

3 files changed

Lines changed: 12 additions & 19 deletions

File tree

ansible_base/lib/workload_identity/base.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,24 @@ def generate_sub_claim(cls, workload_claims: dict) -> str:
4040
"""
4141
Generate a sub claim string from workload claims using the scope's claim mapping.
4242
43-
Given a dictionary with the claims of a workload, generates a sub claim string with the following format:
44-
"job:<job_name>:organization:<organization_name>:project:<project_name>:job_template:<job_template_name>"
43+
Constructs a colon-delimited string prefixed with "workload_type:{scope_name}:" followed by
44+
the claim names and values specified by the scope's get_target_claim_names_to_sub_stubs()
45+
method. The order is determined by the subclass implementation.
4546
4647
Note: The specified claim names are included in the output sub claim value even if they
4748
are empty. Claim validation is expected to take care of doing these checks before this
4849
function is called.
4950
5051
:param workload_claims: A dictionary containing the workload claims (claim names to values)
5152
:type workload_claims: dict
52-
:return: A string containing the sub claim
53+
:return: A string containing the sub claim prefixed with workload type
5354
:rtype: str
5455
"""
5556
target_claim_names_to_sub_stubs = cls.get_target_claim_names_to_sub_stubs()
56-
return ":".join([f"{target_claim_names_to_sub_stubs[key]}:{workload_claims.get(key, '')}" for key in target_claim_names_to_sub_stubs.keys()])
57+
base_sub = [f"workload_type:{cls.name}"]
58+
base_sub.extend([f"{target_claim_names_to_sub_stubs[key]}:{workload_claims.get(key, '')}" for key in target_claim_names_to_sub_stubs.keys()])
59+
60+
return ":".join(base_sub)
5761

5862
@abstractmethod
5963
def populate_claims(self, workload_data: dict) -> dict:

ansible_base/lib/workload_identity/controller.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ def list_claims(cls) -> list[str]:
4747
@classmethod
4848
def get_target_claim_names_to_sub_stubs(cls) -> dict[str, str]:
4949
return {
50-
cls.CLAIM_JOB_NAME: "job",
5150
cls.CLAIM_ORGANIZATION_NAME: "organization",
52-
cls.CLAIM_PROJECT_NAME: "project",
5351
cls.CLAIM_JOB_TEMPLATE_NAME: "job_template",
5452
}

test_app/tests/lib/workload_identity/test_controller.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ def test_get_target_claim_names_to_sub_stubs():
4343
of claim names to their sub claim stubs.
4444
"""
4545
expected_mapping = {
46-
'aap_controller_job_name': 'job',
4746
'aap_controller_organization_name': 'organization',
48-
'aap_controller_project_name': 'project',
4947
'aap_controller_job_template_name': 'job_template',
5048
}
5149

@@ -71,28 +69,21 @@ def test_get_target_claim_names_to_sub_stubs_keys_are_valid_claims():
7169
[
7270
(
7371
{
74-
'aap_controller_job_name': 'my-job',
7572
'aap_controller_organization_name': 'my-org',
76-
'aap_controller_project_name': 'my-project',
7773
'aap_controller_job_template_name': 'my-template',
7874
},
79-
"job:my-job:organization:my-org:project:my-project:job_template:my-template",
75+
"workload_type:aap_controller_automation_job:organization:my-org:job_template:my-template",
8076
),
8177
(
8278
{
83-
'aap_controller_job_name': 'my-job',
8479
'aap_controller_organization_name': '',
85-
'aap_controller_project_name': 'my-project',
8680
'aap_controller_job_template_name': '',
8781
},
88-
"job:my-job:organization::project:my-project:job_template:",
82+
"workload_type:aap_controller_automation_job:organization::job_template:",
8983
),
9084
(
91-
{
92-
'aap_controller_job_name': 'my-job',
93-
'aap_controller_project_name': 'my-project',
94-
},
95-
"job:my-job:organization::project:my-project:job_template:",
85+
{'aap_controller_job_template_name': 'my-template'},
86+
"workload_type:aap_controller_automation_job:organization::job_template:my-template",
9687
),
9788
],
9889
)

0 commit comments

Comments
 (0)