"""
-SUMMARY
+summary
------------------------------------------------------
-Utility for one-step dynamic cnfvar configuration.
+Module for one-step dynamic cnfvar configuration using minimal templates.
-.. note:: DEPRECATED! Please do not extend this or add new uses of this module,
- use :py:mod:`pyi2ncommon.arnied_api` or :py:mod:`pyi2ncommon.cnfvar`
- instead!
+.. codeauthor:: Intra2net
-Copyright: Intra2net AG
-
-CONTENTS
-------------------------------------------------------
-Contains general as well as specialized versions of some of the main
-configurations performed by our tests.
-
-INTERFACE
+interface
------------------------------------------------------
"""
import logging
# custom imports
-from . import arnied_wrapper as aw
-from .arnied_wrapper import Delete, Update, Add, Child, batch_update_cnf, build_cnf
-from .cnfline import build_cnfvar, build_group, build_intraclient
-from .cnfline import build_nic, build_provider, build_user
+from .model import Cnf, CnfList
+
+
+log = logging.getLogger('pyi2ncommon.cnfvar.templates')
-log = logging.getLogger('pyi2ncommon.mk_config')
###############################################################################
# MINOR CONFIGURATION
###############################################################################
-def simple(varname, data, filename):
+def simple(varname, data, instance=0):
"""
- Generate and save a single-variable configuration file.
+ Generate a minimal simple cnf variable in terms of required and validated attributes.
:param str varname: cnf variable name
- :param str data: cnf variable data
- :param str filename: config name
- :returns: generated config filename
- :rtype: str
+ :param str data: cnf variable value
+ :param int instance: cnf variable instance number
+ :returns: generated cnf variable
+ :rtype: :py:class:`Cnf`
"""
- log.info("Create single-variable configuration file")
- tmp = build_cnfvar.BuildCnfVar(name=varname, data=data)
- [filename] = aw.prep_config_paths([filename], aw.DUMP_CONFIG_DIR)
- logging.info("Saving simple configuration to %s", filename)
- tmp.save(filename)
- return filename
+ log.info(f"Generating a simple {varname} cnfvar")
+ return Cnf(varname, value=data, instance=instance)
-def user(username="admin", instance=1, suffix="host"):
+def user(username, password, instance=-1):
"""
- Generate and save a user configuration file.
+ Generate a minimal user cnf variable in terms of required and validated attributes.
- :param str username: username for the user variable
- :param int instance: instance number (for multiple users, -1 for next available)
- :param str suffix: optional suffix to use for config identification
- :returns: generated config filename
- :rtype: str
+ :param str username: username for the user
+ :param str password: password for the user
+ :param int instance: instance number for the user
+ :returns: generated cnf variable
+ :rtype: :py:class:`Cnf`
"""
- log.info("Create arnied user configuration")
- user_obj = batch_update_cnf(
- build_user.BuildUser(data=username, instance=instance, line_no=1),
- [(Update, ("USER_FULLNAME", 0, username)),
- (Update, ("USER_GROUP_MEMBER_REF", 0, "1")),
- (Add, ("USER_GROUP_MEMBER_REF", 1, "2")),
- (Delete, "USER_WEBMAIL_MESSAGES_PER_PAGE"),
- (Delete, "USER_LOCALE"),
- (Delete, "USER_TRASH_DELETEDAYS"),
- (Delete, "USER_WEBMAIL_SIGNATURE")])
- user_cnf = "user-%d-%s.cnf" % (time.time(), suffix)
- [user_cnf] = aw.prep_config_paths([user_cnf], aw.DUMP_CONFIG_DIR)
- logging.info("Saving user configuration to %s", user_cnf)
- user_obj.save(user_cnf)
+ log.info(f"Generating a minimal user {username} cnfvar")
+ user_cnf = Cnf("user", value=username, instance=instance)
+ user_cnf.add_children(
+ ("user_fullname", username.capitalize()),
+ ("user_group_member_ref", 2),
+ ("user_password", password))
return user_cnf