owner and group could be a variable

This commit is contained in:
Emmanuel Garette 2022-01-26 13:01:40 +01:00
parent 4c011ee551
commit fbc5f9374e
24 changed files with 392 additions and 2 deletions

View File

@ -69,7 +69,9 @@
<!ATTLIST file source CDATA #IMPLIED> <!ATTLIST file source CDATA #IMPLIED>
<!ATTLIST file mode CDATA #IMPLIED> <!ATTLIST file mode CDATA #IMPLIED>
<!ATTLIST file owner CDATA #IMPLIED> <!ATTLIST file owner CDATA #IMPLIED>
<!ATTLIST file owner_type (unix_user|variable) "unix_user">
<!ATTLIST file group CDATA #IMPLIED> <!ATTLIST file group CDATA #IMPLIED>
<!ATTLIST file group_type (unix_user|variable) "unix_user">
<!ATTLIST file filelist CDATA #IMPLIED> <!ATTLIST file filelist CDATA #IMPLIED>
<!ATTLIST file redefine (True|False) "False"> <!ATTLIST file redefine (True|False) "False">
<!ATTLIST file engine (none|creole|jinja2|creole_legacy) #IMPLIED> <!ATTLIST file engine (none|creole|jinja2|creole_legacy) #IMPLIED>

View File

@ -55,9 +55,12 @@ log = logging.getLogger(__name__)
log.addHandler(logging.NullHandler()) log.addHandler(logging.NullHandler())
INFORMATIONS = {'files': ['source', 'mode', 'owner', 'group', 'engine', 'included'], INFORMATIONS = {'files': ['source', 'mode', 'engine', 'included'],
'overrides': ['name', 'source', 'engine'], 'overrides': ['name', 'source', 'engine'],
} }
DEFAULT = {'files': ['owner', 'group'],
'overrides': [],
}
class RougailLeaderIndex: class RougailLeaderIndex:
@ -196,7 +199,10 @@ class RougailExtra:
return self._suboption.items() return self._suboption.items()
def __str__(self): def __str__(self):
return f'<extra object with: {self._suboption}>' suboptions = {}
for key, value in self._suboption.items():
suboptions[key] = str(value)
return f'<extra object with: {suboptions}>'
class RougailBaseTemplate: class RougailBaseTemplate:
@ -377,6 +383,7 @@ class RougailBaseTemplate:
type_ = await fills.option.name() type_ = await fills.option.name()
for fill_obj in await fills.list('all'): for fill_obj in await fills.list('all'):
fill = await fill_obj.value.dict() fill = await fill_obj.value.dict()
self.get_default(type_, fill, fill_obj)
await self.get_informations(type_, fill, fill_obj) await self.get_informations(type_, fill, fill_obj)
if 'included' in fill: if 'included' in fill:
if (fill['included'] == 'no' and included is True) or \ if (fill['included'] == 'no' and included is True) or \
@ -407,6 +414,19 @@ class RougailBaseTemplate:
if ori_dir is not None: if ori_dir is not None:
chdir(ori_dir) chdir(ori_dir)
def get_default(self,
type_: str,
dico: dict,
obj: 'Option',
) -> None:
for key in DEFAULT.get(type_, []):
default_key = f'default_{type_}_{key}'
if default_key in RougailConfig:
default_value = RougailConfig[default_key]
else:
default_value = undefined
dico[key] = dico.get(key, default_value)
async def get_informations(self, async def get_informations(self,
type_: str, type_: str,
dico: dict, dico: dict,
@ -516,6 +536,10 @@ class RougailBaseTemplate:
value = await option.value.get() value = await option.value.get()
variables[await option.option.name()] = value variables[await option.option.name()] = value
if isinstance(is_service_namespace, str) and is_service_namespace + 's' in INFORMATIONS: if isinstance(is_service_namespace, str) and is_service_namespace + 's' in INFORMATIONS:
self.get_default(is_service_namespace + 's',
variables,
optiondescription,
)
await self.get_informations(is_service_namespace + 's', await self.get_informations(is_service_namespace + 's',
variables, variables,
optiondescription, optiondescription,

View File

@ -0,0 +1,16 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail version="0.10">
<services>
<service name="test">
<file owner="nobody" group="nobody">/etc/file</file>
<file owner="nobody" group="nobody" engine="jinja2">/etc/file2</file>
</service>
</services>
<variables>
<family name="general">
<variable name="mode_conteneur_actif" type="string" description="Description">
<value>non</value>
</variable>
</family>
</variables>
</rougail>

View File

@ -0,0 +1,46 @@
{
"rougail.general.mode_conteneur_actif": {
"owner": "default",
"value": "non"
},
"services.test.files.file.group": {
"owner": "default",
"value": "nobody"
},
"services.test.files.file.name": {
"owner": "default",
"value": "/etc/file"
},
"services.test.files.file.owner": {
"owner": "default",
"value": "nobody"
},
"services.test.files.file.activate": {
"owner": "default",
"value": true
},
"services.test.files.file2.group": {
"owner": "default",
"value": "nobody"
},
"services.test.files.file2.name": {
"owner": "default",
"value": "/etc/file2"
},
"services.test.files.file2.owner": {
"owner": "default",
"value": "nobody"
},
"services.test.files.file2.activate": {
"owner": "default",
"value": true
},
"services.test.activate": {
"owner": "default",
"value": true
},
"services.test.manage": {
"owner": "default",
"value": true
}
}

View File

@ -0,0 +1,13 @@
{
"rougail.general.mode_conteneur_actif": "non",
"services.test.files.file.group": "nobody",
"services.test.files.file.name": "/etc/file",
"services.test.files.file.owner": "nobody",
"services.test.files.file.activate": true,
"services.test.files.file2.group": "nobody",
"services.test.files.file2.name": "/etc/file2",
"services.test.files.file2.owner": "nobody",
"services.test.files.file2.activate": true,
"services.test.activate": true,
"services.test.manage": true
}

View File

@ -0,0 +1,46 @@
{
"rougail.general.mode_conteneur_actif": {
"owner": "default",
"value": "non"
},
"services.test.files.file.group": {
"owner": "default",
"value": "nobody"
},
"services.test.files.file.name": {
"owner": "default",
"value": "/etc/file"
},
"services.test.files.file.owner": {
"owner": "default",
"value": "nobody"
},
"services.test.files.file.activate": {
"owner": "default",
"value": true
},
"services.test.files.file2.group": {
"owner": "default",
"value": "nobody"
},
"services.test.files.file2.name": {
"owner": "default",
"value": "/etc/file2"
},
"services.test.files.file2.owner": {
"owner": "default",
"value": "nobody"
},
"services.test.files.file2.activate": {
"owner": "default",
"value": true
},
"services.test.activate": {
"owner": "default",
"value": true
},
"services.test.manage": {
"owner": "default",
"value": true
}
}

View File

@ -0,0 +1,2 @@
non
non

View File

@ -0,0 +1,2 @@
non
non

View File

@ -0,0 +1,2 @@
C /etc/file 0644 nobody nobody - /usr/local/lib/etc/file
C /etc/file2 0644 nobody nobody - /usr/local/lib/etc/file2

View File

@ -0,0 +1,38 @@
from importlib.machinery import SourceFileLoader as _SourceFileLoader
from importlib.util import spec_from_loader as _spec_from_loader, module_from_spec as _module_from_spec
class func:
pass
_loader = _SourceFileLoader('func', 'tests/dictionaries/../eosfunc/test.py')
_spec = _spec_from_loader(_loader.name, _loader)
_func = _module_from_spec(_spec)
_loader.exec_module(_func)
for function in dir(_func):
if function.startswith('_'):
continue
setattr(func, function, getattr(_func, function))
try:
from tiramisu3 import *
except:
from tiramisu import *
option_3 = StrOption(name="mode_conteneur_actif", doc="Description", default="non", properties=frozenset({"mandatory", "normal"}))
option_2 = OptionDescription(name="general", doc="general", children=[option_3], properties=frozenset({"normal"}))
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2])
option_8 = UsernameOption(name="group", doc="group", default="nobody")
option_9 = FilenameOption(name="name", doc="name", default="/etc/file")
option_10 = UsernameOption(name="owner", doc="owner", default="nobody")
option_11 = BoolOption(name="activate", doc="activate", default=True)
option_7 = OptionDescription(name="file", doc="file", children=[option_8, option_9, option_10, option_11])
option_7.impl_set_information('source', "file")
option_13 = UsernameOption(name="group", doc="group", default="nobody")
option_14 = FilenameOption(name="name", doc="name", default="/etc/file2")
option_15 = UsernameOption(name="owner", doc="owner", default="nobody")
option_16 = BoolOption(name="activate", doc="activate", default=True)
option_12 = OptionDescription(name="file2", doc="file2", children=[option_13, option_14, option_15, option_16])
option_12.impl_set_information('engine', "jinja2")
option_12.impl_set_information('source', "file2")
option_6 = OptionDescription(name="files", doc="files", children=[option_7, option_12])
option_17 = BoolOption(name="activate", doc="activate", default=True)
option_18 = BoolOption(name="manage", doc="manage", default=True)
option_5 = OptionDescription(name="test", doc="test", children=[option_6, option_17, option_18])
option_4 = OptionDescription(name="services", doc="services", children=[option_5], properties=frozenset({"hidden"}))
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1, option_4])

View File

@ -0,0 +1,2 @@
%%mode_conteneur_actif
%%rougail.general.mode_conteneur_actif

View File

@ -0,0 +1,2 @@
{{ mode_conteneur_actif }}
{{ rougail.general.mode_conteneur_actif }}

View File

@ -0,0 +1,22 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail version="0.10">
<services>
<service name="test">
<file owner_type='variable' owner="owner" group_type='variable' group="group">/etc/file</file>
<file owner_type='variable' owner="owner" group_type='variable' group="group" engine="jinja2">/etc/file2</file>
</service>
</services>
<variables>
<family name="general">
<variable name="mode_conteneur_actif" type="string" description="Description">
<value>non</value>
</variable>
<variable name="owner" type="unix_user">
<value>nobody</value>
</variable>
<variable name="group" type="unix_user">
<value>nobody</value>
</variable>
</family>
</variables>
</rougail>

View File

@ -0,0 +1,54 @@
{
"rougail.general.mode_conteneur_actif": {
"owner": "default",
"value": "non"
},
"rougail.general.owner": {
"owner": "default",
"value": "nobody"
},
"rougail.general.group": {
"owner": "default",
"value": "nobody"
},
"services.test.files.file.group": {
"owner": "default",
"value": "nobody"
},
"services.test.files.file.name": {
"owner": "default",
"value": "/etc/file"
},
"services.test.files.file.owner": {
"owner": "default",
"value": "nobody"
},
"services.test.files.file.activate": {
"owner": "default",
"value": true
},
"services.test.files.file2.group": {
"owner": "default",
"value": "nobody"
},
"services.test.files.file2.name": {
"owner": "default",
"value": "/etc/file2"
},
"services.test.files.file2.owner": {
"owner": "default",
"value": "nobody"
},
"services.test.files.file2.activate": {
"owner": "default",
"value": true
},
"services.test.activate": {
"owner": "default",
"value": true
},
"services.test.manage": {
"owner": "default",
"value": true
}
}

View File

@ -0,0 +1,15 @@
{
"rougail.general.mode_conteneur_actif": "non",
"rougail.general.owner": "nobody",
"rougail.general.group": "nobody",
"services.test.files.file.group": "nobody",
"services.test.files.file.name": "/etc/file",
"services.test.files.file.owner": "nobody",
"services.test.files.file.activate": true,
"services.test.files.file2.group": "nobody",
"services.test.files.file2.name": "/etc/file2",
"services.test.files.file2.owner": "nobody",
"services.test.files.file2.activate": true,
"services.test.activate": true,
"services.test.manage": true
}

View File

@ -0,0 +1,54 @@
{
"rougail.general.mode_conteneur_actif": {
"owner": "default",
"value": "non"
},
"rougail.general.owner": {
"owner": "default",
"value": "nobody"
},
"rougail.general.group": {
"owner": "default",
"value": "nobody"
},
"services.test.files.file.group": {
"owner": "default",
"value": "nobody"
},
"services.test.files.file.name": {
"owner": "default",
"value": "/etc/file"
},
"services.test.files.file.owner": {
"owner": "default",
"value": "nobody"
},
"services.test.files.file.activate": {
"owner": "default",
"value": true
},
"services.test.files.file2.group": {
"owner": "default",
"value": "nobody"
},
"services.test.files.file2.name": {
"owner": "default",
"value": "/etc/file2"
},
"services.test.files.file2.owner": {
"owner": "default",
"value": "nobody"
},
"services.test.files.file2.activate": {
"owner": "default",
"value": true
},
"services.test.activate": {
"owner": "default",
"value": true
},
"services.test.manage": {
"owner": "default",
"value": true
}
}

View File

@ -0,0 +1,2 @@
non
non

View File

@ -0,0 +1,2 @@
non
non

View File

@ -0,0 +1,2 @@
C /etc/file 0644 nobody nobody - /usr/local/lib/etc/file
C /etc/file2 0644 nobody nobody - /usr/local/lib/etc/file2

View File

@ -0,0 +1,40 @@
from importlib.machinery import SourceFileLoader as _SourceFileLoader
from importlib.util import spec_from_loader as _spec_from_loader, module_from_spec as _module_from_spec
class func:
pass
_loader = _SourceFileLoader('func', 'tests/dictionaries/../eosfunc/test.py')
_spec = _spec_from_loader(_loader.name, _loader)
_func = _module_from_spec(_spec)
_loader.exec_module(_func)
for function in dir(_func):
if function.startswith('_'):
continue
setattr(func, function, getattr(_func, function))
try:
from tiramisu3 import *
except:
from tiramisu import *
option_3 = StrOption(name="mode_conteneur_actif", doc="Description", default="non", properties=frozenset({"mandatory", "normal"}))
option_4 = UsernameOption(name="owner", doc="owner", default="nobody", properties=frozenset({"mandatory", "normal"}))
option_5 = UsernameOption(name="group", doc="group", default="nobody", properties=frozenset({"mandatory", "normal"}))
option_2 = OptionDescription(name="general", doc="general", children=[option_3, option_4, option_5], properties=frozenset({"normal"}))
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2])
option_10 = SymLinkOption(name="group", opt=option_5)
option_11 = FilenameOption(name="name", doc="name", default="/etc/file")
option_12 = SymLinkOption(name="owner", opt=option_4)
option_13 = BoolOption(name="activate", doc="activate", default=True)
option_9 = OptionDescription(name="file", doc="file", children=[option_10, option_11, option_12, option_13])
option_9.impl_set_information('source', "file")
option_15 = SymLinkOption(name="group", opt=option_5)
option_16 = FilenameOption(name="name", doc="name", default="/etc/file2")
option_17 = SymLinkOption(name="owner", opt=option_4)
option_18 = BoolOption(name="activate", doc="activate", default=True)
option_14 = OptionDescription(name="file2", doc="file2", children=[option_15, option_16, option_17, option_18])
option_14.impl_set_information('engine', "jinja2")
option_14.impl_set_information('source', "file2")
option_8 = OptionDescription(name="files", doc="files", children=[option_9, option_14])
option_19 = BoolOption(name="activate", doc="activate", default=True)
option_20 = BoolOption(name="manage", doc="manage", default=True)
option_7 = OptionDescription(name="test", doc="test", children=[option_8, option_19, option_20])
option_6 = OptionDescription(name="services", doc="services", children=[option_7], properties=frozenset({"hidden"}))
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1, option_6])

View File

@ -0,0 +1,2 @@
%%mode_conteneur_actif
%%rougail.general.mode_conteneur_actif

View File

@ -0,0 +1,2 @@
{{ mode_conteneur_actif }}
{{ rougail.general.mode_conteneur_actif }}