You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

54 lines
1.9 KiB

  1. import os
  2. import click
  3. import frappe
  4. from frappe.utils.redis_queue import RedisQueue
  5. from frappe.installer import update_site_config
  6. @click.command('create-rq-users')
  7. @click.option('--set-admin-password', is_flag=True, default=False, help='Set new Redis admin(default user) password')
  8. @click.option('--use-rq-auth', is_flag=True, default=False, help='Enable Redis authentication for sites')
  9. def create_rq_users(set_admin_password=False, use_rq_auth=False):
  10. """Create Redis Queue users and add to acl and app configs.
  11. acl config file will be used by redis server while starting the server
  12. and app config is used by app while connecting to redis server.
  13. """
  14. acl_file_path = os.path.abspath('../config/redis_queue.acl')
  15. with frappe.init_site():
  16. acl_list, user_credentials = RedisQueue.gen_acl_list(
  17. set_admin_password=set_admin_password)
  18. with open(acl_file_path, 'w') as f:
  19. f.writelines([acl+'\n' for acl in acl_list])
  20. sites_path = os.getcwd()
  21. common_site_config_path = os.path.join(sites_path, 'common_site_config.json')
  22. update_site_config("rq_username", user_credentials['bench'][0], validate=False,
  23. site_config_path=common_site_config_path)
  24. update_site_config("rq_password", user_credentials['bench'][1], validate=False,
  25. site_config_path=common_site_config_path)
  26. update_site_config("use_rq_auth", use_rq_auth, validate=False,
  27. site_config_path=common_site_config_path)
  28. click.secho('* ACL and site configs are updated with new user credentials. '
  29. 'Please restart Redis Queue server to enable namespaces.',
  30. fg='green')
  31. if set_admin_password:
  32. env_key = 'RQ_ADMIN_PASWORD'
  33. click.secho('* Redis admin password is successfully set up. '
  34. 'Include below line in .bashrc file for system to use',
  35. fg='green')
  36. click.secho(f"`export {env_key}={user_credentials['default'][1]}`")
  37. click.secho('NOTE: Please save the admin password as you '
  38. 'can not access redis server without the password',
  39. fg='yellow')
  40. commands = [
  41. create_rq_users
  42. ]