Acehaidrey commented on a change in pull request #18916:
URL: https://github.com/apache/airflow/pull/18916#discussion_r733334616



##########
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:
       Hey @uranusjr when I try this I get it breaking.
   But looking at documentation I think you just need to change 
`exporting_roles` and `f`. `json.dump(exporting_roles, f, **kwargs)`. 
   
   ```def dump(obj, fp, *, skipkeys=False,...)```
   




-- 
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]


Reply via email to