-
Notifications
You must be signed in to change notification settings - Fork 96
Crawler: support for object ownership #2774
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
Conversation
This involves wiring up all the crawlers to have a workspace client, needed to locate the workspace administrator when an owner for the object cannot be found.
Iterable[User]: The active workspace administrators, if any. | ||
""" | ||
all_users = ws.users.list(attributes="id,active,userName,roles") | ||
return (user for user in all_users if user.active and _has_role(user, "workspace_admin")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we have that role and it's no longer the admins
group membership?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this was just a guess while I figured out how it's supposed to be done. (And indeed, it now uses membership of the admins
workspace group.)
found. | ||
""" | ||
first_user = functools.partial(min, default=None, key=lambda user: user.name) | ||
return first_user(find_workspace_admins(ws)) or first_user(find_account_admins(ws)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't forget to sort, because each invocation first user will be different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…ace and account users.
…if a user directly associated with the resource cannot be located.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rewrite assert "@" in ownership.owner_of(grant_record)
to check for concrete usernames as much as possible, as these tests don't test enough - e.g. hiding the problem
# Verify ownership is as expected. | ||
ownership = ClusterOwnership(runtime_ctx.administrator_locator) | ||
assert ownership.owner_of(cluster_record_with_owner) == ws.current_user.me().user_name | ||
assert "@" in ownership.owner_of(cluster_record_without_owner) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exact user name match is preferred
def test_pipeline_ownership(ws, runtime_ctx, make_pipeline, inventory_schema, sql_backend) -> None: | ||
"""Verify the ownership can be determined for crawled pipelines.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def test_pipeline_ownership(ws, runtime_ctx, make_pipeline, inventory_schema, sql_backend) -> None: | |
"""Verify the ownership can be determined for crawled pipelines.""" | |
def test_verify_ownership_determined_for_crawled_pipelines(ws, runtime_ctx, make_pipeline, inventory_schema, sql_backend) -> None: |
|
||
# Verify ownership can be made. | ||
ownership = GrantOwnership(runtime_ctx.administrator_locator) | ||
assert "@" in ownership.owner_of(grant_record) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rewrite assert "@" in ownership.owner_of(grant_record)
to check for concrete usernames as much as possible, as these tests don't test enough - e.g. hiding the problem
For some reason deleting the owner of a cluster doesn't clear the creator field, even though the documentation says it should. Instead we just check that the creator is actually returned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
## Changes This updates an integration test to more thoroughly verify that we can locate the user-name of an administrator. ### Linked issues Follows: #2774 ### Tests - updated integration test
Changes
As part of #2761 we need to have a way for determining the user responsible for some of our inventory types. This PR updates the crawler framework so that:
Linked issues
Progresses #2761.
Functionality
A component for locating an administrator user.
Ownership information for the following inventory types:
ClusterInfo
DirectFsAccess
(stubbed)Grant
JobInfo
PipelineInfo
PolicyInfo
Table
TableMigrationStatus
UDF
Tests