owner and group could be a variable
This commit is contained in:
parent
4c011ee551
commit
fbc5f9374e
@ -69,7 +69,9 @@
|
||||
<!ATTLIST file source CDATA #IMPLIED>
|
||||
<!ATTLIST file mode CDATA #IMPLIED>
|
||||
<!ATTLIST file owner CDATA #IMPLIED>
|
||||
<!ATTLIST file owner_type (unix_user|variable) "unix_user">
|
||||
<!ATTLIST file group CDATA #IMPLIED>
|
||||
<!ATTLIST file group_type (unix_user|variable) "unix_user">
|
||||
<!ATTLIST file filelist CDATA #IMPLIED>
|
||||
<!ATTLIST file redefine (True|False) "False">
|
||||
<!ATTLIST file engine (none|creole|jinja2|creole_legacy) #IMPLIED>
|
||||
|
@ -55,9 +55,12 @@ log = logging.getLogger(__name__)
|
||||
log.addHandler(logging.NullHandler())
|
||||
|
||||
|
||||
INFORMATIONS = {'files': ['source', 'mode', 'owner', 'group', 'engine', 'included'],
|
||||
INFORMATIONS = {'files': ['source', 'mode', 'engine', 'included'],
|
||||
'overrides': ['name', 'source', 'engine'],
|
||||
}
|
||||
DEFAULT = {'files': ['owner', 'group'],
|
||||
'overrides': [],
|
||||
}
|
||||
|
||||
|
||||
class RougailLeaderIndex:
|
||||
@ -196,7 +199,10 @@ class RougailExtra:
|
||||
return self._suboption.items()
|
||||
|
||||
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:
|
||||
@ -377,6 +383,7 @@ class RougailBaseTemplate:
|
||||
type_ = await fills.option.name()
|
||||
for fill_obj in await fills.list('all'):
|
||||
fill = await fill_obj.value.dict()
|
||||
self.get_default(type_, fill, fill_obj)
|
||||
await self.get_informations(type_, fill, fill_obj)
|
||||
if 'included' in fill:
|
||||
if (fill['included'] == 'no' and included is True) or \
|
||||
@ -407,6 +414,19 @@ class RougailBaseTemplate:
|
||||
if ori_dir is not None:
|
||||
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,
|
||||
type_: str,
|
||||
dico: dict,
|
||||
@ -516,6 +536,10 @@ class RougailBaseTemplate:
|
||||
value = await option.value.get()
|
||||
variables[await option.option.name()] = value
|
||||
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',
|
||||
variables,
|
||||
optiondescription,
|
||||
|
16
tests/dictionaries/01base_file_owner/00-base.xml
Normal file
16
tests/dictionaries/01base_file_owner/00-base.xml
Normal 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>
|
0
tests/dictionaries/01base_file_owner/__init__.py
Normal file
0
tests/dictionaries/01base_file_owner/__init__.py
Normal file
46
tests/dictionaries/01base_file_owner/makedict/after.json
Normal file
46
tests/dictionaries/01base_file_owner/makedict/after.json
Normal 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
|
||||
}
|
||||
}
|
13
tests/dictionaries/01base_file_owner/makedict/base.json
Normal file
13
tests/dictionaries/01base_file_owner/makedict/base.json
Normal 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
|
||||
}
|
46
tests/dictionaries/01base_file_owner/makedict/before.json
Normal file
46
tests/dictionaries/01base_file_owner/makedict/before.json
Normal 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
|
||||
}
|
||||
}
|
2
tests/dictionaries/01base_file_owner/result/etc/file
Normal file
2
tests/dictionaries/01base_file_owner/result/etc/file
Normal file
@ -0,0 +1,2 @@
|
||||
non
|
||||
non
|
2
tests/dictionaries/01base_file_owner/result/etc/file2
Normal file
2
tests/dictionaries/01base_file_owner/result/etc/file2
Normal file
@ -0,0 +1,2 @@
|
||||
non
|
||||
non
|
@ -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
|
38
tests/dictionaries/01base_file_owner/tiramisu/base.py
Normal file
38
tests/dictionaries/01base_file_owner/tiramisu/base.py
Normal 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])
|
2
tests/dictionaries/01base_file_owner/tmpl/file
Normal file
2
tests/dictionaries/01base_file_owner/tmpl/file
Normal file
@ -0,0 +1,2 @@
|
||||
%%mode_conteneur_actif
|
||||
%%rougail.general.mode_conteneur_actif
|
2
tests/dictionaries/01base_file_owner/tmpl/file2
Normal file
2
tests/dictionaries/01base_file_owner/tmpl/file2
Normal file
@ -0,0 +1,2 @@
|
||||
{{ mode_conteneur_actif }}
|
||||
{{ rougail.general.mode_conteneur_actif }}
|
22
tests/dictionaries/01base_file_owner_variable/00-base.xml
Normal file
22
tests/dictionaries/01base_file_owner_variable/00-base.xml
Normal 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>
|
@ -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
|
||||
}
|
||||
}
|
@ -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
|
||||
}
|
@ -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
|
||||
}
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
non
|
||||
non
|
@ -0,0 +1,2 @@
|
||||
non
|
||||
non
|
@ -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
|
@ -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])
|
2
tests/dictionaries/01base_file_owner_variable/tmpl/file
Normal file
2
tests/dictionaries/01base_file_owner_variable/tmpl/file
Normal file
@ -0,0 +1,2 @@
|
||||
%%mode_conteneur_actif
|
||||
%%rougail.general.mode_conteneur_actif
|
2
tests/dictionaries/01base_file_owner_variable/tmpl/file2
Normal file
2
tests/dictionaries/01base_file_owner_variable/tmpl/file2
Normal file
@ -0,0 +1,2 @@
|
||||
{{ mode_conteneur_actif }}
|
||||
{{ rougail.general.mode_conteneur_actif }}
|
Loading…
Reference in New Issue
Block a user