Skip to content

Commit d5db1ad

Browse files
committed
RSPEED-2326: feat(auth): add get_org_id method to RHIdentityData
Add get_org_id() method to extract organization ID from identity data, enabling downstream access to org context for telemetry and logging. Signed-off-by: Major Hayden <major@redhat.com>
1 parent e9f0c09 commit d5db1ad

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

src/authentication/rh_identity.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ def get_username(self) -> str:
125125
return identity["user"]["username"]
126126
return identity["account_number"]
127127

128+
def get_org_id(self) -> str:
129+
"""Extract organization ID from identity data.
130+
131+
Returns:
132+
Organization ID string, or empty string if not present
133+
"""
134+
return self.identity_data["identity"].get("org_id", "")
135+
128136
def has_entitlement(self, service: str) -> bool:
129137
"""Check if user has a specific service entitlement.
130138

tests/unit/authentication/test_rh_identity.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,23 @@ def test_system_type_extraction(self, system_identity_data: dict) -> None:
129129
assert rh_identity.get_user_id() == "c87dcb4c-8af1-40dd-878e-60c744edddd0"
130130
assert rh_identity.get_username() == "123"
131131

132+
@pytest.mark.parametrize(
133+
"fixture_name", ["user_identity_data", "system_identity_data"]
134+
)
135+
def test_get_org_id(
136+
self, fixture_name: str, request: pytest.FixtureRequest
137+
) -> None:
138+
"""Test org_id extraction for both identity types."""
139+
identity_data = request.getfixturevalue(fixture_name)
140+
rh_identity = RHIdentityData(identity_data)
141+
assert rh_identity.get_org_id() == "321"
142+
143+
def test_get_org_id_missing(self, user_identity_data: dict) -> None:
144+
"""Test org_id returns empty string when not present."""
145+
user_identity_data["identity"].pop("org_id")
146+
rh_identity = RHIdentityData(user_identity_data)
147+
assert rh_identity.get_org_id() == ""
148+
132149
@pytest.mark.parametrize(
133150
"service,expected",
134151
[

0 commit comments

Comments
 (0)