Acehaidrey commented on a change in pull request #18916:
URL: https://github.com/apache/airflow/pull/18916#discussion_r733335608
##########
File path: airflow/cli/commands/role_command.py
##########
@@ -42,3 +45,46 @@ def roles_create(args):
for role_name in args.role:
appbuilder.sm.add_role(role_name)
print(f"Added {len(args.role)} role(s)")
+
+
+@suppress_logs_and_warning
+def roles_export(args):
+ """
+ Exports all the rules from the data base to a file.
+ Note, this function does not export the permissions associated for each
role.
+ Strictly, it exports the role names into the passed role json file.
+ """
+ appbuilder = cached_app().appbuilder
+ roles = appbuilder.sm.get_all_roles()
+ exporting_roles = [role.name for role in roles if role.name not in
EXISTING_ROLES]
+ filename = os.path.expanduser(args.file)
+ kwargs = {} if not args.pformat else {'sort_keys': True, 'indent': 4}
+ with open(filename, 'w') as f:
+ f.write(json.dumps(exporting_roles, **kwargs))
Review comment:
I'm making the update and the merging the changes to have just a single
call to this. Thanks for this suggestion btw! Doing one last test locally to
confirm.
And btw I also updated to add the option to format the output to the json
file. Thank you for that suggestion too.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]