Skip to content

Commit

Permalink
Support configuration object to create_user and make it work locally.
Browse files Browse the repository at this point in the history
  • Loading branch information
albu-diku committed Feb 28, 2025
1 parent 187b17c commit 6be64f6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
31 changes: 27 additions & 4 deletions envhelp/makeconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@
import os
import sys

sys.path.append(os.path.realpath(
os.path.join(os.path.dirname(__file__), "..")))
_SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
_LOCAL_MIG_BASE = os.path.normpath(os.path.join(_SCRIPT_DIR, ".."))

sys.path.append(_LOCAL_MIG_BASE)

from mig.shared.install import MIG_BASE, generate_confs

Check warning on line 41 in envhelp/makeconfig.py

View workflow job for this annotation

GitHub Actions / Style Check Python with Lint

module level import not at top of file

_LOCAL_MIG_BASE = os.path.normpath(
os.path.join(os.path.dirname(__file__), ".."))
_LOCAL_ENVHELP_OUTPUT_DIR = os.path.join(_LOCAL_MIG_BASE, "envhelp/output")
_MAKECONFIG_ALLOWED = ["local", "test"]
_USERADM_PATH_KEYS = ('user_cache', 'user_db_home', 'user_home',
'user_settings', 'mrsl_files_dir', 'resource_pending')


def _at(sequence, index=-1, default=None):
Expand All @@ -52,6 +54,18 @@ def _at(sequence, index=-1, default=None):
return default


def _ensure_dirs_needed_for_userdb(configuration):
"""Provision the basic directories needed for the operation of the
userdb deriving paths from the supplied configuration object."""

for config_key in _USERADM_PATH_KEYS:
dir_path = getattr(configuration, config_key)[0:-1]
try:
os.makedirs(dir_path)
except OSError as exc:
pass


def write_testconfig(env_name, is_docker=False):
is_predefined = env_name == 'test'
confs_name = '%sconfs' % (env_name,)
Expand Down Expand Up @@ -84,6 +98,15 @@ def write_testconfig(env_name, is_docker=False):

generate_confs(_LOCAL_ENVHELP_OUTPUT_DIR, **overrides)

# now that a valid configuration was written, we need to ensure a handful
# of essential state directories are available for basic userdb operation
from mig.shared.conf import get_configuration_object
written_config_file = os.path.join(
overrides['destination'], 'MiGserver.conf')
written_configuration = get_configuration_object(
written_config_file, skip_log=True, disable_auth_log=True)
_ensure_dirs_needed_for_userdb(written_configuration)

confs_destination = ''.join(
[overrides['destination'], overrides['destination_suffix']])
print('wrote configuration for "%s" env into: %s' %
Expand Down
4 changes: 2 additions & 2 deletions mig/server/createuser.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ def usage(name='createuser.py'):
if verbose:
print('using user dict: %s' % user_dict)
try:
create_user(user_dict, conf_path, db_path, force, verbose, ask_renew,
default_renew, verify_peer=peer_pattern,
create_user(user_dict, configuration, db_path, force, verbose,
ask_renew, default_renew, verify_peer=peer_pattern,
peer_expire_slack=slack_secs, ask_change_pw=ask_change_pw)
if configuration.site_enable_gdp:
(success_here, msg) = ensure_gdp_user(configuration,
Expand Down
6 changes: 5 additions & 1 deletion mig/shared/useradm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,9 @@ def create_user(user, conf_path, db_path, force=False, verbose=False,
format as a first step.
"""

if conf_path:
if isinstance(conf_path, Configuration):
configuration = conf_path
elif conf_path:
if isinstance(conf_path, basestring):

# has been checked for accessibility above...
Expand All @@ -1037,7 +1039,9 @@ def create_user(user, conf_path, db_path, force=False, verbose=False,
configuration = conf_path
else:
configuration = get_configuration_object()

_logger = configuration.logger

if db_path == keyword_auto:
db_path = default_db_path(configuration)

Expand Down

0 comments on commit 6be64f6

Please sign in to comment.