Cli export / import roles including permissions#36347
Conversation
|
LGTM as an approach. My proposal will be to replace the whole Role if it is already defined with the new one coming from the. import. I wonder if we should backwards compatibility and add |
potiuk
left a comment
There was a problem hiding this comment.
LGTM but I would look for other's opinions?
|
I've just tested on my installation and it works ! There is only a little aesthetic inaccuracy as you can see form the it says 38 roles, actually they are only 4 roles but the permissions associated have multiplied them. I looked at the code and I think we have the same problem also in the import phase. |
Good chance to make a PR and fix it @gbonazzoli |
|
Unfortunately I'm not a developer and I'm not able to make the PR (git commands and count distinct "name" attribute in the Python list are among the things that I do not know how to write). Anyway, If I was a developer I should print out:
|
Sounds like a cool - REALLY SMALL - issue to start to learn being developer. It's not as hard. And that one looks like super easy fix. |
|
And BTW, if you don't want to - then I suggest you create an issue - then we can mark it as good-first-issue and make it ready for someone to pick it up. Comment in PR is not really actionable and will just gone forgotten if there is no issue. |
|
By looking at this PR again, the json format changes, is not it a breaking change? If some users use the CI command |
|
To fix the test: #36558 |
The observation we had is that we should treat it as bugfix. Roles export/import without permissions is kinda useless, so it's rather unlikely anyone would use it. |
|
Sounds good :) |
|
#36580 created with the title: Cli export / import roles including permissions Part 2 (refinement) |
closes: #36128
This PR contains both an updated
airflow roles exportandairflow roles importcli command, according to the above mentioned issue.The export command now exports resources and actions by default in the following structure:
When a role has no permissions the values for the respective keys are set to empty Strings.
This way the import function can later easily distinguish if the imported role needs permissions to be set or not
@potiuk I originally mentioned that we could use the
-pflag to say whether we want to export names and permissions or just the names. However the function already uses the-pflag (--pretty) thus I believe this will not work. That's why the function currently also exports permissions by default.Previously the
-pflag sorted the list of names in alphabetical order and set the indent to 4 . However with the function now returning a list of dictionaries, I disabled the sorting if-pis set, because in this case the order of the keys would be switched.The
airflow roles importcommands expect the json to be in the same structure as the exported one. In it I have reused the__roles_add_or_remove_permissionswhich was already contained in the file and handles the logic for adding permissions.to pass args to __roles_add_or_remove_permissions from the imported json, I used Namespace from argparse. argparse is already a dependency of airflow.
In the beginning, I remove all roles that are already contained within the db from the json. By this I can ensure that only new roles are being added. Due to the structure of the json, role names are contained multiple time with different resources, thus I need to check for each dictionary, whether the role has been already added and thus I only need to add the permissions within this dictionary or a new role needs to be created.
Unit tests have been added to test the new functions.
^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named
{pr_number}.significant.rstor{issue_number}.significant.rst, in newsfragments.