Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(okta): adds ingest_groups_users config parameter #12371

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions metadata-ingestion/src/datahub/ingestion/source/identity/okta.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from collections import defaultdict
from dataclasses import dataclass, field
from time import sleep
from typing import Dict, Iterable, List, Optional, Union
from typing import Dict, Iterable, List, Optional, Set, Union

import nest_asyncio
from okta.client import Client as OktaClient
Expand Down Expand Up @@ -76,6 +76,10 @@
default=True,
description="Whether group membership should be ingested into DataHub. ingest_groups must be True if this is True.",
)
ingest_groups_users: bool = Field(
default=True,
description="This option is useful only when `ingest_users` is set to False and `ingest_group_membership` to True. As effect, only the users which belongs to the selected groups will be ingested.",
)

# Optional: Customize the mapping to DataHub Username from an attribute appearing in the Okta User
# profile. Reference: https://developer.okta.com/docs/reference/api/users/
Expand Down Expand Up @@ -343,6 +347,7 @@
aspect=StatusClass(removed=False),
).as_workunit()

okta_users: Set[User] = set()

Check warning on line 350 in metadata-ingestion/src/datahub/ingestion/source/identity/okta.py

View check run for this annotation

Codecov / codecov/patch

metadata-ingestion/src/datahub/ingestion/source/identity/okta.py#L350

Added line #L350 was not covered by tests
# Step 2: Populate GroupMembership Aspects for CorpUsers
datahub_corp_user_urn_to_group_membership: Dict[
str, GroupMembershipClass
Expand Down Expand Up @@ -371,14 +376,20 @@
self.report.report_failure("okta_user_mapping", error_str)
continue

if self.config.ingest_groups_users:
okta_users.add(okta_user)

Check warning on line 380 in metadata-ingestion/src/datahub/ingestion/source/identity/okta.py

View check run for this annotation

Codecov / codecov/patch

metadata-ingestion/src/datahub/ingestion/source/identity/okta.py#L379-L380

Added lines #L379 - L380 were not covered by tests

# Update the GroupMembership aspect for this group member.
datahub_corp_user_urn_to_group_membership[
datahub_corp_user_urn
].groups.append(datahub_corp_group_urn)

# Step 3: Produce MetadataWorkUnits for CorpUsers.
if self.config.ingest_users:
okta_users = self._get_okta_users(event_loop)
# we can just throw away collected okta users so far and fetch them all
okta_users = set(self._get_okta_users(event_loop))

Check warning on line 390 in metadata-ingestion/src/datahub/ingestion/source/identity/okta.py

View check run for this annotation

Codecov / codecov/patch

metadata-ingestion/src/datahub/ingestion/source/identity/okta.py#L390

Added line #L390 was not covered by tests

if okta_users:

Check warning on line 392 in metadata-ingestion/src/datahub/ingestion/source/identity/okta.py

View check run for this annotation

Codecov / codecov/patch

metadata-ingestion/src/datahub/ingestion/source/identity/okta.py#L392

Added line #L392 was not covered by tests
filtered_okta_users = filter(self._filter_okta_user, okta_users)
datahub_corp_user_snapshots = self._map_okta_users(filtered_okta_users)
for user_count, datahub_corp_user_snapshot in enumerate(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
[
{
"proposedSnapshot": {
"com.linkedin.pegasus2avro.metadata.snapshot.CorpGroupSnapshot": {
"urn": "urn:li:corpGroup:All%20Employees",
"aspects": [
{
"com.linkedin.pegasus2avro.identity.CorpGroupInfo": {
"displayName": "All Employees",
"admins": [],
"members": [],
"groups": [],
"description": "All Employees in the Test Company."
}
}
]
}
},
"systemMetadata": {
"lastObserved": 1586847600000,
"runId": "test-okta-usage",
"lastRunId": "no-run-id-provided"
}
},
{
"entityType": "corpGroup",
"entityUrn": "urn:li:corpGroup:All%20Employees",
"changeType": "UPSERT",
"aspectName": "origin",
"aspect": {
"json": {
"type": "EXTERNAL",
"externalType": "OKTA"
}
},
"systemMetadata": {
"lastObserved": 1586847600000,
"runId": "test-okta-usage",
"lastRunId": "no-run-id-provided"
}
},
{
"entityType": "corpGroup",
"entityUrn": "urn:li:corpGroup:All%20Employees",
"changeType": "UPSERT",
"aspectName": "status",
"aspect": {
"json": {
"removed": false
}
},
"systemMetadata": {
"lastObserved": 1586847600000,
"runId": "test-okta-usage",
"lastRunId": "no-run-id-provided"
}
},
{
"proposedSnapshot": {
"com.linkedin.pegasus2avro.metadata.snapshot.CorpGroupSnapshot": {
"urn": "urn:li:corpGroup:Engineering",
"aspects": [
{
"com.linkedin.pegasus2avro.identity.CorpGroupInfo": {
"displayName": "Engineering",
"admins": [],
"members": [],
"groups": [],
"description": "Engineering team!"
}
}
]
}
},
"systemMetadata": {
"lastObserved": 1586847600000,
"runId": "test-okta-usage",
"lastRunId": "no-run-id-provided"
}
},
{
"entityType": "corpGroup",
"entityUrn": "urn:li:corpGroup:Engineering",
"changeType": "UPSERT",
"aspectName": "origin",
"aspect": {
"json": {
"type": "EXTERNAL",
"externalType": "OKTA"
}
},
"systemMetadata": {
"lastObserved": 1586847600000,
"runId": "test-okta-usage",
"lastRunId": "no-run-id-provided"
}
},
{
"entityType": "corpGroup",
"entityUrn": "urn:li:corpGroup:Engineering",
"changeType": "UPSERT",
"aspectName": "status",
"aspect": {
"json": {
"removed": false
}
},
"systemMetadata": {
"lastObserved": 1586847600000,
"runId": "test-okta-usage",
"lastRunId": "no-run-id-provided"
}
},
{
"proposedSnapshot": {
"com.linkedin.pegasus2avro.metadata.snapshot.CorpUserSnapshot": {
"urn": "urn:li:corpuser:mary.jane",
"aspects": [
{
"com.linkedin.pegasus2avro.identity.CorpUserInfo": {
"customProperties": {},
"active": true,
"displayName": "Mary Jane",
"email": "mary.jane@test.com",
"title": "Software Engineer",
"departmentName": "Engineering",
"firstName": "Mary",
"lastName": "Jane",
"fullName": "Mary Jane",
"countryCode": "us"
}
},
{
"com.linkedin.pegasus2avro.identity.GroupMembership": {
"groups": [
"urn:li:corpGroup:All%20Employees",
"urn:li:corpGroup:All%20Employees",
"urn:li:corpGroup:Engineering",
"urn:li:corpGroup:Engineering"
]
}
}
]
}
},
"systemMetadata": {
"lastObserved": 1586847600000,
"runId": "test-okta-usage",
"lastRunId": "no-run-id-provided"
}
},
{
"entityType": "corpuser",
"entityUrn": "urn:li:corpuser:mary.jane",
"changeType": "UPSERT",
"aspectName": "origin",
"aspect": {
"json": {
"type": "EXTERNAL",
"externalType": "OKTA"
}
},
"systemMetadata": {
"lastObserved": 1586847600000,
"runId": "test-okta-usage",
"lastRunId": "no-run-id-provided"
}
},
{
"entityType": "corpuser",
"entityUrn": "urn:li:corpuser:mary.jane",
"changeType": "UPSERT",
"aspectName": "status",
"aspect": {
"json": {
"removed": false
}
},
"systemMetadata": {
"lastObserved": 1586847600000,
"runId": "test-okta-usage",
"lastRunId": "no-run-id-provided"
}
},
{
"proposedSnapshot": {
"com.linkedin.pegasus2avro.metadata.snapshot.CorpUserSnapshot": {
"urn": "urn:li:corpuser:john.doe",
"aspects": [
{
"com.linkedin.pegasus2avro.identity.CorpUserInfo": {
"customProperties": {},
"active": true,
"displayName": "JDoe",
"email": "john.doe@test.com",
"firstName": "John",
"lastName": "Doe",
"fullName": "John Doe"
}
},
{
"com.linkedin.pegasus2avro.identity.GroupMembership": {
"groups": [
"urn:li:corpGroup:All%20Employees",
"urn:li:corpGroup:Engineering"
]
}
}
]
}
},
"systemMetadata": {
"lastObserved": 1586847600000,
"runId": "test-okta-usage",
"lastRunId": "no-run-id-provided"
}
},
{
"entityType": "corpuser",
"entityUrn": "urn:li:corpuser:john.doe",
"changeType": "UPSERT",
"aspectName": "origin",
"aspect": {
"json": {
"type": "EXTERNAL",
"externalType": "OKTA"
}
},
"systemMetadata": {
"lastObserved": 1586847600000,
"runId": "test-okta-usage",
"lastRunId": "no-run-id-provided"
}
},
{
"entityType": "corpuser",
"entityUrn": "urn:li:corpuser:john.doe",
"changeType": "UPSERT",
"aspectName": "status",
"aspect": {
"json": {
"removed": false
}
},
"systemMetadata": {
"lastObserved": 1586847600000,
"runId": "test-okta-usage",
"lastRunId": "no-run-id-provided"
}
}
]
26 changes: 26 additions & 0 deletions metadata-ingestion/tests/integration/okta/test_okta.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,32 @@ def test_okta_source_default_configs(pytestconfig, mock_datahub_graph, tmp_path)
)


@freeze_time(FROZEN_TIME)
def test_okta_source_ingest_groups_users(pytestconfig, mock_datahub_graph, tmp_path):
test_resources_dir: pathlib.Path = pytestconfig.rootpath / "tests/integration/okta"

output_file_path = f"{tmp_path}/okta_mces_ingest_groups_users.json"

new_recipe = default_recipe(output_file_path)
new_recipe["source"]["config"]["ingest_users"] = False
new_recipe["source"]["config"]["ingest_groups"] = True
new_recipe["source"]["config"]["ingest_groups_users"] = True

run_ingest(
mock_datahub_graph=mock_datahub_graph,
mocked_functions_reference=partial(
_init_mock_okta_client, test_resources_dir=test_resources_dir
),
recipe=new_recipe,
)

mce_helpers.check_golden_file(
pytestconfig,
output_path=output_file_path,
golden_path=f"{test_resources_dir}/okta_mces_golden_ingest_groups_users.json",
)


@freeze_time(FROZEN_TIME)
def test_okta_source_ingestion_disabled(pytestconfig, mock_datahub_graph, tmp_path):
test_resources_dir: pathlib.Path = pytestconfig.rootpath / "tests/integration/okta"
Expand Down
Loading