Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add updated-name wrappers for built-in FAB methods. #16077

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

Merged
merged 4 commits into from
May 29, 2021

Conversation

jhtimmins
Copy link
Contributor

This is a re-implementation of one piece of #15398, which uses the "resource" and "action" naming scheme.

The original PR has proved difficult to get reviewed and through CI, as it touches a lot of different files that change frequently. This PR introduces wrapper methods around default FAB methods, this time using the updated naming scheme.

The methods are not in use yet; the next PR will update method calls throughout Airflow to use the new methods instead of the default FAB methods.

@boring-cyborg boring-cyborg bot added the area:webserver Webserver related Issues label May 26, 2021
@jhtimmins jhtimmins requested review from ashb, jedcunningham and kaxil May 26, 2021 02:56
@jhtimmins jhtimmins force-pushed the add-fab-wrapper-functions branch from cb60630 to 6345285 Compare May 26, 2021 03:04
Copy link
Member

@jedcunningham jedcunningham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM. Minor nit, might be nice to having typing on these.

:return: Action record, if it exists
:rtype: Permission
"""
return super().find_permission(name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this super() vs self?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And should we change parameter to action_name? for consistency ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, I like to add only as much explanation as is necessary based on context. In this case it seems reasonable to infer that name refers to the name of the action being retrieved.

@@ -409,6 +474,20 @@ def has_access(self, permission, resource, user=None) -> bool:

return has_access

def _has_access(self, user, action, resource) -> bool:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "action_name" and "resource_name" should be here as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed

@@ -639,6 +750,16 @@ def sync_perm_for_dag(self, dag_id, access_control=None):
if access_control:
self._sync_dag_view_permissions(dag_resource_name, access_control)

def get_resource_permissions(self, resource):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just double-checking - resource here is different than "resource_name" (looks like - from the type).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, resource should apply to the actual object

Copy link
Member

@potiuk potiuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few consistency nits.

Would you also care to add Type annotations for parameters? That would make mypy verify types of the parameters in most cases - especially when there was action vs. action_name or resource vs. resource_name.

@jhtimmins jhtimmins force-pushed the add-fab-wrapper-functions branch from 6b815c9 to 129ebf1 Compare May 26, 2021 20:57
@jhtimmins jhtimmins requested review from potiuk and jedcunningham May 26, 2021 20:59
Comment on lines 240 to 242
Returns a resource record by name, if it exists.
:param name: Name of resource
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sphinx needs one blank line between description and params

Suggested change
Returns a resource record by name, if it exists.
:param name: Name of resource
Returns a resource record by name, if it exists.
:param name: Name of resource

airflow/www/security.py Outdated Show resolved Hide resolved
Comment on lines 258 to 262
Gets an existing action record.
:param name: name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Gets an existing action record.
:param name: name
Gets an existing action record.
:param name: name

Comment on lines 268 to 273
Gets a permission made with the given action->resource pair, if the permission already exists.
:param action_name: Name of action
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Gets a permission made with the given action->resource pair, if the permission already exists.
:param action_name: Name of action
Gets a permission made with the given action->resource pair, if the permission already exists.
:param action_name: Name of action

Comment on lines 280 to 286
Creates a permission linking an action and resource.
:param action_name: Name of existing action
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Creates a permission linking an action and resource.
:param action_name: Name of existing action
Creates a permission linking an action and resource.
:param action_name: Name of existing action

Comment on lines 594 to 603
Add an existing permission pair to a role.
:param role: The role about to get a new permission.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Add an existing permission pair to a role.
:param role: The role about to get a new permission.
Add an existing permission pair to a role.
:param role: The role about to get a new permission.

Comment on lines 606 to 616
Remove a permission pair from a role.
:param role: User role containing permissions.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Remove a permission pair from a role.
:param role: User role containing permissions.
Remove a permission pair from a role.
:param role: User role containing permissions.

Comment on lines 616 to 627
Deletes a permission action.
:param name: Name of action to delete (e.g. can_read).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Deletes a permission action.
:param name: Name of action to delete (e.g. can_read).
Deletes a permission action.
:param name: Name of action to delete (e.g. can_read).

Comment on lines 763 to 775
Retrieve permission pairs associated with a specific resource object.
:param resource: Object representing a single resource.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Retrieve permission pairs associated with a specific resource object.
:param resource: Object representing a single resource.
Retrieve permission pairs associated with a specific resource object.
:param resource: Object representing a single resource.

Comment on lines 876 to 892
then re-syncs them.
:return: None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
then re-syncs them.
:return: None
then re-syncs them.
:return: None

@jhtimmins jhtimmins force-pushed the add-fab-wrapper-functions branch from 129ebf1 to c05946a Compare May 27, 2021 01:21
@jhtimmins jhtimmins requested a review from kaxil May 27, 2021 01:25
@jhtimmins jhtimmins force-pushed the add-fab-wrapper-functions branch from 08e46ad to 1768355 Compare May 27, 2021 19:02
@jhtimmins
Copy link
Contributor Author

@potiuk can you take another look? I've added typing and either updated or explained the naming choices.

@github-actions github-actions bot added the okay to merge It's ok to merge this PR as it does not require more tests label May 27, 2021
@github-actions
Copy link

The PR is likely OK to be merged with just subset of tests for default Python and Database versions without running the full matrix of tests, because it does not modify the core of Airflow. If the committers decide that the full tests matrix is needed, they will add the label 'full tests needed'. Then you should rebase to the latest master or amend the last commit of the PR, and push it with --force-with-lease.

Copy link
Member

@potiuk potiuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the explanations. Makes sense.

@potiuk potiuk merged commit a27e930 into apache:master May 29, 2021
@jhtimmins
Copy link
Contributor Author

Thanks @potiuk. Is the failing MSSQL test related to that other PR about improving MSSQL compatibility?

@potiuk
Copy link
Member

potiuk commented May 30, 2021

Yep. We already have a fix for that. We looked for the problem for last few days and it turned out it is caused by ..... Tmpfs backing our docker engine for self-hosted runners (they are optimized for speed). Fix is coming in #16159

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:webserver Webserver related Issues okay to merge It's ok to merge this PR as it does not require more tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.