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



##########
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:
+        json.dump(exporting_roles, f, **kwargs)

Review comment:
       Better to explicitly add `encoding="utf8"` to `open`; the `json` module 
always uses `"utf8"`, but this is _not_ always the default encoding used by 
`open` (it depends on the operating system setup).
   
   (Another option is to pass `ensure_ascii=True`; maybe this should be a CLI 
option as well.)




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