add setting prefix (name of the module)

This commit is contained in:
Emmanuel Garette 2020-02-26 19:22:59 +01:00
parent 5ac9ec72f8
commit 2655e03172
14 changed files with 188 additions and 179 deletions

View File

@ -1,32 +1,31 @@
MESSAGE_ROOT_PATH = 'messages'
INTERNAL_USER = 'internal'
CONFIGURATION_DIR = 'configurations'
TEMPLATE_DIR = 'templates'
TMP_DIR = 'tmp'
DEFAULT_USER = 'Anonymous'
DEFAULT_DSN = 'postgres:///risotto?host=/var/run/postgresql/&user=risotto'
DEFAULT_TIRAMISU_DSN = 'postgres:///tiramisu?host=/var/run/postgresql/&user=tiramisu'
from os import environ
from pathlib import PurePosixPath
CURRENT_PATH = PurePosixPath(__file__)
CONFIGURATION_DIR = 'configurations'
TMP_DIR = 'tmp'
DEFAULT_USER = environ.get('DEFAULT_USER', 'Anonymous')
DEFAULT_DSN = environ.get('RISOTTO_DSN', 'postgres:///risotto?host=/var/run/postgresql/&user=risotto')
DEFAULT_TIRAMISU_DSN = environ.get('DEFAULT_TIRAMISU_DSN', 'postgres:///tiramisu?host=/var/run/postgresql/&user=tiramisu')
MESSAGE_PATH = environ.get('MESSAGE_PATH', '/root/risotto-message/messages')
MODULE_NAME = environ.get('MODULE_NAME', 'test')
def get_config():
return {'database': {'dsn': environ.get('RISOTTO_DSN', DEFAULT_DSN),
'tiramisu_dsn': environ.get('RISOTTO_TIRAMISU_DSN', DEFAULT_TIRAMISU_DSN),
return {'database': {'dsn': DEFAULT_DSN,
'tiramisu_dsn': DEFAULT_TIRAMISU_DSN,
},
'http_server': {'port': 8080,
#'default_user': "gnunux"},
'default_user': DEFAULT_USER},
'global': {'message_root_path': CURRENT_PATH.parents[2] / 'messages',
'global': {'message_root_path': MESSAGE_PATH,
'debug': True,
'internal_user': 'internal',
'check_role': True,
'admin_user': DEFAULT_USER},
'admin_user': DEFAULT_USER,
'module_name': MODULE_NAME,
'version': 'v1'},
'source': {'root_path': '/srv/seed'},
'cache': {'root_path': '/var/cache/risotto'},
'servermodel': {'internal_source': 'internal',
'internal_distribution': 'last',
'internal_release_name': 'none'},
}

View File

@ -102,7 +102,8 @@ async def api(request, risotto_context):
WHERE RoleURI.URIId = URI.URIId
'''
uris = [uri['uriname'] for uri in await connection.fetch(sql)]
async with await Config(get_messages(load_shortarg=True, uris=uris)[1]) as config:
async with await Config(get_messages(load_shortarg=True,
uris=uris)[1]) as config:
await config.property.read_write()
tiramisu = await config.option.dict(remotable='none')
return tiramisu

View File

@ -12,7 +12,9 @@ from os.path import isfile
from ..config import get_config
from ..utils import _
MESSAGE_ROOT_PATH = get_config().get('global').get('message_root_path')
MESSAGE_ROOT_PATH = get_config()['global']['message_root_path']
MODULE_NAME = get_config()['global']['module_name']
CUSTOMTYPES = {}
groups.addgroup('message')
@ -56,18 +58,21 @@ class MessageDefinition:
self.errors = []
self.related = []
self.response = None
self.uri = message
# loads yaml information into object
for key, value in raw_def.items():
if key == 'uri':
raise Exception('uri in not allowed in message')
if isinstance(value, str):
value = value.strip()
if key == 'pattern':
if value not in ['rpc', 'event', 'error']:
if value not in ['rpc', 'event']:
raise Exception(_('unknown pattern {}').format(value))
elif key == 'parameters':
if 'type' in value and isinstance(value['type'], str):
# should be a customtype
value = customtypes[value['type']].properties
value = CUSTOMTYPES[value['type']].properties
else:
value = _parse_parameters(value)
elif key == 'response':
@ -81,8 +86,6 @@ class MessageDefinition:
getattr(self, key)
except AttributeError:
raise Exception(_('mandatory key not set {} message').format(key))
if self.uri != message:
raise Exception(_(f'yaml file name "{message}.yml" does not match uri "{self.uri}"'))
class ParameterDefinition:
@ -110,11 +113,11 @@ class ParameterDefinition:
tvalue = value[2:]
else:
tvalue = value
if tvalue in customtypes:
if tvalue in CUSTOMTYPES:
if value.startswith('[]'):
value = '[]{}'.format(customtypes[tvalue].type)
value = '[]{}'.format(CUSTOMTYPES[tvalue].type)
else:
value = customtypes[value].type
value = CUSTOMTYPES[value].type
else:
self._valid_type(value)
#self._valid_type(value)
@ -133,6 +136,7 @@ class ParameterDefinition:
elif typ not in ['Boolean', 'String', 'Number', 'File', 'Dict', 'Any']:
raise Exception(_('unknown parameter type: {}').format(typ))
class ResponseDefinition:
"""
An ResponseDefinition is a representation of a response in the Zephir application messaging context
@ -158,13 +162,13 @@ class ResponseDefinition:
self.multi = True
else:
tvalue = value
if tvalue in customtypes:
self.parameters = customtypes[tvalue].properties
self.required = customtypes[tvalue].required
if tvalue in CUSTOMTYPES:
self.parameters = CUSTOMTYPES[tvalue].properties
self.required = CUSTOMTYPES[tvalue].required
if value.startswith('[]'):
value = '[]{}'.format(customtypes[tvalue].type)
value = '[]{}'.format(CUSTOMTYPES[tvalue].type)
else:
value = customtypes[value].type
value = CUSTOMTYPES[value].type
else:
self._valid_type(value)
setattr(self, key, value)
@ -209,14 +213,17 @@ def _parse_parameters(raw_defs):
return parameters
def parse_definition(filecontent: bytes, message: str):
def parse_definition(filecontent: bytes,
message: str):
return MessageDefinition(load(filecontent, Loader=SafeLoader), message)
def is_message_defined(uri):
version, message = split_message_uri(uri)
path = get_message_file_path(version, message)
return isfile(path)
def get_message(uri):
load_customtypes()
try:
@ -231,23 +238,30 @@ def get_message(uri):
traceback.print_exc()
raise Exception(_('cannot parse message {}: {}').format(uri, str(err)))
def split_message_uri(uri):
return uri.split('.', 1)
def get_message_file_path(version, message):
return join(MESSAGE_ROOT_PATH, version, 'messages', message + '.yml')
module_name, filename = message.split('.', 1)
if module_name != MODULE_NAME:
raise Exception(f'should only load message for {MODULE_NAME}, not {message}')
return join(MESSAGE_ROOT_PATH, version, MODULE_NAME, 'messages', filename + '.yml')
def list_messages(uris):
messages = listdir(MESSAGE_ROOT_PATH)
messages.sort()
for version in messages:
for message in listdir(join(MESSAGE_ROOT_PATH, version, 'messages')):
versions = listdir(join(MESSAGE_ROOT_PATH))
versions.sort()
for version in versions:
for message in listdir(join(MESSAGE_ROOT_PATH, version, MODULE_NAME, 'messages')):
if message.endswith('.yml'):
uri = version + '.' + message.rsplit('.', 1)[0]
uri = version + '.' + MODULE_NAME + '.' + message.rsplit('.', 1)[0]
if uris is not None and uri not in uris:
continue
yield uri
class CustomParam:
__slots__ = ('name',
'type',
@ -358,25 +372,24 @@ class CustomType:
return self.title
customtypes = {}
def load_customtypes():
if not customtypes:
if not CUSTOMTYPES:
versions = listdir(MESSAGE_ROOT_PATH)
versions.sort()
for version in versions:
for message in listdir(join(MESSAGE_ROOT_PATH, version, 'types')):
for message in listdir(join(MESSAGE_ROOT_PATH, version, MODULE_NAME, 'types')):
if message.endswith('.yml'):
path = join(MESSAGE_ROOT_PATH, version, 'types', message)
path = join(MESSAGE_ROOT_PATH, version, MODULE_NAME, 'types', message)
message = message.rsplit('.', 1)[0]
with open(path, "r") as message_file:
try:
ret = CustomType(load(message_file, Loader=SafeLoader))
customtypes[ret.getname()] = ret
CUSTOMTYPES[ret.getname()] = ret
except Exception as err:
import traceback
traceback.print_exc()
raise Exception('{} for {}'.format(err, message))
for customtype in customtypes.values():
for customtype in CUSTOMTYPES.values():
properties = {}
for key, value in customtype.properties.items():
type_ = value.type
@ -384,10 +397,10 @@ def load_customtypes():
ttype_ = type_[2:]
else:
ttype_ = type_
if ttype_ in customtypes:
if ttype_ in CUSTOMTYPES:
if type_.startswith('[]'):
raise Exception(_('cannot have []CustomType'))
properties[key] = customtypes[ttype_]
properties[key] = CUSTOMTYPES[ttype_]
else:
properties[key] = value
customtype.properties = properties
@ -580,26 +593,18 @@ def get_messages(load_shortarg=False,
uris=None):
"""generate description from yml files
"""
optiondescriptions = OrderedDict()
optiondescriptions_name = []
optiondescriptions = {}
optiondescriptions_info = {}
needs = OrderedDict()
needs = {}
messages = list(list_messages(uris))
messages.sort()
for message_name in messages:
message_def = get_message(message_name)
if message_def.pattern not in ['rpc', 'event']:
continue
optiondescriptions_name.append(message_def.uri)
optiondescriptions_name.sort()
optiondescriptions_name = [message_name.split('.', 1)[1] for message_name in messages]
select_option = ChoiceOption('message',
'Nom du message.',
tuple(optiondescriptions_name),
properties=frozenset(['mandatory', 'positional']))
for message_name in messages:
message_def = get_message(message_name)
if message_def.pattern not in ['rpc', 'event']:
continue
optiondescriptions_info[message_def.uri] = {'pattern': message_def.pattern}
if message_def.pattern == 'rpc':
optiondescriptions_info[message_def.uri]['response'] = _parse_responses(message_def,

View File

@ -8,7 +8,7 @@ from .utils import _
from .error import RegistrationError
from .message import get_messages
from .context import Context
from .config import INTERNAL_USER, get_config
from .config import get_config
from .logger import log
@ -39,11 +39,11 @@ class RegisterDispatcher:
self.messages = {}
# load tiramisu objects
messages, self.option = get_messages()
#FIXME
version = 'v1'
version = get_config()['global']['version']
self.messages[version] = {}
for tiramisu_message, obj in messages.items():
self.messages[version][tiramisu_message] = obj
self.risotto_module = get_config()['global']['module_name']
def get_function_args(self,
function: Callable):
@ -145,6 +145,9 @@ class RegisterDispatcher:
# xxx module can only be register with v1.xxxx..... message
module_name = function.__module__.split('.')[-2]
message_namespace = message.split('.', 1)[0]
message_risotto_module, message_namespace, message_name = message.split('.', 2)
if message_risotto_module != self.risotto_module:
raise RegistrationError(_(f'cannot registered the "{message}" is not "{self.risotto_module}"'))
if self.messages[version][message]['pattern'] == 'rpc' and message_namespace != module_name:
raise RegistrationError(_(f'cannot registered the "{message}" message in module "{module_name}"'))
@ -221,6 +224,7 @@ class RegisterDispatcher:
raise RegistrationError(_(f'missing uri {missing_messages}'))
async def on_join(self):
internal_user = get_config()['global']['internal_user']
async with self.pool.acquire() as connection:
await connection.set_type_codec(
'json',
@ -231,7 +235,7 @@ class RegisterDispatcher:
async with connection.transaction():
for module_name, module in self.injected_self.items():
risotto_context = Context()
risotto_context.username = INTERNAL_USER
risotto_context.username = internal_user
risotto_context.paths.append(f'{module_name}.on_join')
risotto_context.type = None
risotto_context.connection = connection

View File

@ -21,11 +21,11 @@ class Risotto(Controller):
async def on_join(self,
risotto_context: Context) -> None:
internal_source = await self.call('v1.source.create',
internal_source = await self.call('v1.setting.source.create',
risotto_context,
source_name=self.internal_source_name,
source_url='none')
internal_release = await self.call('v1.source.release.create',
internal_release = await self.call('v1.setting.source.release.create',
risotto_context,
source_name=self.internal_source_name,
release_name=self.internal_release_name,
@ -65,14 +65,14 @@ class Risotto(Controller):
applicationservice_id,
dependency)
@register('v1.applicationservice.dependency.add')
@register('v1.setting.applicationservice.dependency.add')
async def applicationservice_dependency_add(self,
risotto_context: Context,
applicationservice_name: str,
applicationservice_dependency: str,
source_name: str,
release_distribution: str) -> Dict:
release = await self.call('v1.source.release.describe',
release = await self.call('v1.setting.source.release.describe',
risotto_context,
source_name=source_name,
release_distribution=release_distribution)
@ -92,7 +92,7 @@ class Risotto(Controller):
await self.insert_dependency(risotto_context,
as_descr['applicationservice_id'],
[dependency_descr['applicationservice_id']])
await self.publish('v1.applicationservice.updated',
await self.publish('v1.setting.applicationservice.updated',
risotto_context,
**as_descr)
await self.updated_related_applicationservice(risotto_context,
@ -111,7 +111,7 @@ class Risotto(Controller):
dependency_id = dependency['applicationservice_id']
applicationservice = await self._applicationservice_get_by_id(risotto_context,
dependency_id)
await self.publish('v1.applicationservice.updated',
await self.publish('v1.setting.applicationservice.updated',
risotto_context,
**applicationservice)
await self.updated_related_applicationservice(risotto_context,
@ -133,7 +133,7 @@ class Risotto(Controller):
dependency)
return dependencies
@register('v1.applicationservice.create')
@register('v1.setting.applicationservice.create')
async def applicationservice_create(self,
risotto_context: Context,
applicationservice_name: str,
@ -149,12 +149,12 @@ class Risotto(Controller):
applicationservice['applicationservice_dependencies'] = dependencies
return applicationservice
@register('v1.applicationservice.dataset.updated')
@register('v1.setting.applicationservice.dataset.updated')
async def applicationservice_update(self,
risotto_context: Context,
source_name: str,
release_distribution: str) -> Dict:
release = await self.call('v1.source.release.describe',
release = await self.call('v1.setting.source.release.describe',
risotto_context,
source_name=source_name,
release_distribution=release_distribution)
@ -188,7 +188,7 @@ class Risotto(Controller):
return {'retcode': 0,
'returns': _('Application Services successfully loaded')}
@register('v1.applicationservice.get_by_id')
@register('v1.setting.applicationservice.get_by_id')
async def applicationservice_get_by_id(self,
risotto_context: Context,
applicationservice_id: int) -> Dict:
@ -228,13 +228,13 @@ class Risotto(Controller):
return dict(applicationservice)
@register('v1.applicationservice.describe')
@register('v1.setting.applicationservice.describe')
async def applicationservice_describe(self,
risotto_context: Context,
applicationservice_name,
source_name,
release_distribution):
release = await self.call('v1.source.release.describe',
release = await self.call('v1.setting.source.release.describe',
risotto_context,
source_name=source_name,
release_distribution=release_distribution)

View File

@ -49,7 +49,7 @@ class Risotto(Controller):
await log.info_msg(risotto_context,
None,
'Load servermodels')
servermodels = await self.call('v1.servermodel.list',
servermodels = await self.call('v1.setting.servermodel.list',
risotto_context)
# load each servermodels
@ -179,7 +179,7 @@ class Risotto(Controller):
None,
f'Load servers')
# get all servers
servers = await self.call('v1.server.list',
servers = await self.call('v1.setting.server.list',
risotto_context)
# loads servers
for server in servers:
@ -258,7 +258,7 @@ class Risotto(Controller):
await config.property.read_only()
return config
@register('v1.server.created')
@register('v1.setting.server.created')
async def server_created(self,
risotto_context: Context,
server_id: int,
@ -273,7 +273,7 @@ class Risotto(Controller):
server_name,
server_servermodel_id)
@register('v1.server.deleted')
@register('v1.setting.server.deleted')
async def server_deleted(self,
server_id: int) -> None:
for server_type in ['server', 'server_to_deploy']:
@ -283,7 +283,7 @@ class Risotto(Controller):
await config.session.reset()
del self.server[server_id]
@register('v1.servermodel.created')
@register('v1.setting.servermodel.created')
async def servermodel_created(self,
risotto_context: Context,
servermodel_id: int,
@ -324,7 +324,7 @@ class Risotto(Controller):
await parent.config.pop(await mixconfig.session.id())
return children
@register('v1.servermodel.updated')
@register('v1.setting.servermodel.updated')
async def servermodel_updated(self,
risotto_context: Context,
servermodel_id: int,
@ -356,12 +356,12 @@ class Risotto(Controller):
else:
await self.servermodel[servermodel_id].config.add(child)
@register('v1.config.configuration.server.get')
@register('v1.setting.config.configuration.server.get')
async def get_configuration(self,
risotto_context: Context,
server_name: str,
deployed: bool) -> dict:
server = await self.call('v1.server.describe',
server = await self.call('v1.setting.server.describe',
risotto_context,
server_name=server_name)
server_id = server['server_id']
@ -394,13 +394,13 @@ class Risotto(Controller):
'deployed': deployed,
'configuration': configuration}
@register('v1.config.configuration.server.deploy')
@register('v1.setting.config.configuration.server.deploy')
async def deploy_configuration(self,
risotto_context: Context,
server_name: str) -> Dict:
"""Copy values, permissions, permissives from config 'to deploy' to active config
"""
server = await self.call('v1.server.describe',
server = await self.call('v1.setting.server.describe',
risotto_context,
server_name=server_name)
server_id = server['server_id']

View File

@ -13,7 +13,7 @@ class Risotto(Controller):
test: bool) -> None:
self.internal_source_name = get_config()['servermodel']['internal_source']
@register('v1.server.list')
@register('v1.setting.server.list')
async def server_list(self,
risotto_context: Context) -> Dict:
sql = '''
@ -23,7 +23,7 @@ class Risotto(Controller):
servers = await risotto_context.connection.fetch(sql)
return [dict(r) for r in servers]
@register('v1.server.create', 'v1.server.created')
@register('v1.setting.server.create', 'v1.setting.server.created')
async def server_create(self,
risotto_context: Context,
server_name: str,
@ -31,7 +31,7 @@ class Risotto(Controller):
servermodel_name: str,
release_distribution: str) -> Dict:
DomainnameOption('server_name', _('Server name'), server_name)
servermodel = await self.call('v1.servermodel.describe',
servermodel = await self.call('v1.setting.servermodel.describe',
risotto_context,
servermodel_name=servermodel_name,
source_name=self.internal_source_name,
@ -44,7 +44,7 @@ class Risotto(Controller):
server_name,
server_description,
servermodel['servermodel_id'])
await self.call('v1.user.role.create',
await self.call('v1.setting.user.role.create',
risotto_context,
user_login=risotto_context.username,
role_name='server_rw',
@ -55,7 +55,7 @@ class Risotto(Controller):
'server_description': server_description,
'server_servermodel_id': servermodel['servermodel_id']}
@register('v1.server.describe')
@register('v1.setting.server.describe')
async def server_describe(self,
risotto_context: Context,
server_name: str) -> Dict:

View File

@ -48,14 +48,14 @@ class Generator(Controller):
funcs.write(b'from tiramisu import valid_network_netmask, valid_ip_netmask, valid_broadcast, valid_in_network, valid_not_equal as valid_differ, valid_not_equal, calc_value\n\n')
for dependency in dependencies:
if dependency not in generate_cache['applicationservice']:
applicationservice = await self.call('v1.applicationservice.get_by_id',
applicationservice = await self.call('v1.setting.applicationservice.get_by_id',
risotto_context,
applicationservice_id=dependency)
generate_cache['applicationservice'][dependency] = (applicationservice['applicationservice_name'],
applicationservice['applicationservice_release_id'])
applicationservice_name, release_id = generate_cache['applicationservice'][dependency]
if release_id not in generate_cache['release_id']:
release = await self.call('v1.source.release.get_by_id',
release = await self.call('v1.setting.source.release.get_by_id',
risotto_context,
release_id=release_id)
generate_cache['release_id'][release_id] = (release['source_name'],

View File

@ -26,7 +26,7 @@ class Risotto(Generator):
async def on_join(self,
risotto_context: Context) -> None:
internal_release = await self.call('v1.source.release.describe',
internal_release = await self.call('v1.setting.source.release.describe',
risotto_context,
source_name=self.internal_source_name,
release_distribution=self.internal_distribution_name)
@ -53,7 +53,7 @@ class Risotto(Generator):
for servermodel_parent in servermodel_parents:
servermodel_parents_id.append(servermodel_parent['servermodel_id'])
dependencies.append(servermodel_parent['servermodel_applicationservice_id'])
applicationservice = await self.call('v1.applicationservice.create',
applicationservice = await self.call('v1.setting.applicationservice.create',
risotto_context,
applicationservice_name=as_name,
applicationservice_description=as_description,
@ -79,7 +79,7 @@ class Risotto(Generator):
# for as_release_id in dependencies.values():
# applicationservice_name, as_release_id = applicationservice_infos
# if as_release_id not in release_cache:
# release_cache[as_release_id] = await self.call('v1.source.release.get_by_id',
# release_cache[as_release_id] = await self.call('v1.setting.source.release.get_by_id',
# risotto_context,
# release_id=as_release_id)
await self.generate(risotto_context,
@ -107,7 +107,7 @@ class Risotto(Generator):
self.parse_parents(servermodels, servermodels[parent], parents)
return parents
@register('v1.applicationservice.updated')
@register('v1.setting.applicationservice.updated')
async def applicationservice_updated(self,
risotto_context: Context,
applicationservice_id):
@ -123,7 +123,7 @@ class Risotto(Generator):
servermodel_name = servermodel['servermodel_name']
servermodel_id = servermodel['servermodel_id']
release_id = servermodel['release_id']
applicationservice = await self.call('v1.applicationservice.get_by_id',
applicationservice = await self.call('v1.setting.applicationservice.get_by_id',
risotto_context,
applicationservice_id=applicationservice_id)
dependencies = applicationservice['applicationservice_dependencies']
@ -132,16 +132,16 @@ class Risotto(Generator):
servermodel_id,
dependencies,
None)
await self.publish('v1.servermodel.updated',
await self.publish('v1.setting.servermodel.updated',
risotto_context,
**servermodel)
@register('v1.servermodel.dataset.updated')
@register('v1.setting.servermodel.dataset.updated')
async def servermodel_dataset_updated(self,
risotto_context: Context,
source_name: str,
release_distribution: int):
release = await self.call('v1.source.release.describe',
release = await self.call('v1.setting.source.release.describe',
risotto_context,
source_name=source_name,
release_distribution=release_distribution)
@ -189,7 +189,7 @@ class Risotto(Generator):
# link application service with this servermodel
dependencies = []
for depend in servermodels[new_servermodel]['applicationservices']:
applicationservice = await self.call('v1.applicationservice.describe',
applicationservice = await self.call('v1.setting.applicationservice.describe',
risotto_context,
applicationservice_name=depend,
source_name=source_name,
@ -205,7 +205,7 @@ class Risotto(Generator):
dependencies,
release_id,
generate_cache)
await self.publish('v1.servermodel.created',
await self.publish('v1.setting.servermodel.created',
risotto_context,
**servermodel_ob)
except Exception as err:
@ -216,7 +216,7 @@ class Risotto(Generator):
servermodel_description['done'] = True
return {'retcode': 0, 'returns': _('Servermodels successfully loaded')}
@register('v1.servermodel.list')
@register('v1.setting.servermodel.list')
async def servermodel_list(self,
risotto_context: Context,
source_id: int):
@ -227,13 +227,13 @@ class Risotto(Generator):
servermodels = await risotto_context.connection.fetch(sql)
return [dict(r) for r in servermodels]
@register('v1.servermodel.describe')
@register('v1.setting.servermodel.describe')
async def servermodel_describe(self,
risotto_context: Context,
servermodel_name,
source_name,
release_distribution) -> Dict:
release = await self.call('v1.source.release.describe',
release = await self.call('v1.setting.source.release.describe',
risotto_context,
source_name=source_name,
release_distribution=release_distribution)
@ -261,7 +261,7 @@ class Risotto(Generator):
raise Exception(_(f'"{servermodel_name}" is not a valid name for a servermodel in source "{source_name}" and release "{release_distribution}"'))
return dict(servermodel)
@register('v1.servermodel.create', notification='v1.servermodel.created')
@register('v1.setting.servermodel.create', notification='v1.setting.servermodel.created')
async def create_servermodel(self,
risotto_context: Context,
servermodel_name: str,
@ -269,7 +269,7 @@ class Risotto(Generator):
servermodel_parents_name: List[int],
servermodel_parents_source_name: str,
servermodel_parents_release_distribution: str) -> Dict:
release = await self.call('v1.source.release.describe',
release = await self.call('v1.setting.source.release.describe',
risotto_context,
source_name=servermodel_parents_source_name,
release_distribution=servermodel_parents_release_distribution)

View File

@ -66,14 +66,14 @@ class Risotto(Controller):
'mode': session['mode'],
'debug': session['debug']}
@register('v1.session.server.start')
@register('v1.setting.session.server.start')
async def start_session_server(self,
risotto_context: Context,
server_name: str) -> Dict:
""" start a new config session for a server
"""
config_module = dispatcher.get_service('config')
server = await self.call('v1.server.describe',
server = await self.call('v1.setting.server.describe',
risotto_context,
server_name=server_name)
if not server or server['server_id'] not in config_module.server:
@ -110,14 +110,14 @@ class Risotto(Controller):
session_id,
'server')
@register('v1.session.servermodel.start')
@register('v1.setting.session.servermodel.start')
async def start_session_servermodel(self,
risotto_context: Context,
servermodel_name: str) -> Dict:
""" start a new config session for a server or a servermodel
"""
config_module = dispatcher.get_service('config')
servermodel = await self.call('v1.servermodel.describe',
servermodel = await self.call('v1.setting.servermodel.describe',
risotto_context,
servermodel_name=servermodel_name,
source_name=self.internal_source_name,
@ -156,7 +156,7 @@ class Risotto(Controller):
session_id,
'servermodel')
@register(['v1.session.server.list', 'v1.session.servermodel.list'])
@register(['v1.setting.session.server.list', 'v1.setting.session.servermodel.list'])
async def list_session_server(self,
risotto_context: Context) -> Dict:
type = risotto_context.message.rsplit('.', 2)[-2]
@ -164,7 +164,7 @@ class Risotto(Controller):
return [self.format_session(session_id, session) for session_id, session in storage.get_sessions().items()]
@register(['v1.session.server.filter', 'v1.session.servermodel.filter'])
@register(['v1.setting.session.server.filter', 'v1.setting.session.servermodel.filter'])
async def filter_session(self,
risotto_context: Context,
session_id: str,
@ -191,7 +191,7 @@ class Risotto(Controller):
session_id,
type)
@register(['v1.session.server.configure', 'v1.session.servermodel.configure'])
@register(['v1.setting.session.server.configure', 'v1.setting.session.servermodel.configure'])
async def configure_session(self,
risotto_context: Context,
session_id: str,
@ -228,7 +228,7 @@ class Risotto(Controller):
ret['index'] = index
return ret
@register(['v1.session.server.validate', 'v1.session.servermodel.validate'])
@register(['v1.setting.session.server.validate', 'v1.setting.session.servermodel.validate'])
async def validate_session(self,
risotto_context: Context,
session_id: str) -> Dict:
@ -257,7 +257,7 @@ class Risotto(Controller):
return self.format_session(session_id,
session)
@register(['v1.session.server.get', 'v1.session.servermodel.get'])
@register(['v1.setting.session.server.get', 'v1.setting.session.servermodel.get'])
async def get_session_server(self,
risotto_context: Context,
session_id: str,
@ -275,7 +275,7 @@ class Risotto(Controller):
info['content'] = content
return info
@register(['v1.session.server.stop', 'v1.session.servermodel.stop'])
@register(['v1.setting.session.server.stop', 'v1.setting.session.servermodel.stop'])
async def stop_session(self,
risotto_context: Context,
session_id: str,

View File

@ -10,7 +10,7 @@ from ...config import get_config
class Risotto(Controller):
@register('v1.source.create')
@register('v1.setting.source.create')
async def source_create(self,
risotto_context: Context,
source_name: str,
@ -43,7 +43,7 @@ class Risotto(Controller):
'source_url': source_url,
'source_id': source_id}
@register('v1.source.describe')
@register('v1.setting.source.describe')
async def source_describe(self,
risotto_context: Context,
source_name: str) -> Dict:
@ -57,7 +57,7 @@ class Risotto(Controller):
raise Exception(_(f'unknown source with name {source_name}'))
return dict(source)
@register('v1.source.list')
@register('v1.setting.source.list')
async def source_list(self,
risotto_context: Context) -> List[Dict]:
source_list = """SELECT SourceId as source_id, SourceName as source_name, SourceURL as source_url
@ -66,7 +66,7 @@ class Risotto(Controller):
result = await risotto_context.connection.fetch(source_list)
return [dict(r) for r in result]
@register('v1.source.dataset.update')
@register('v1.setting.source.dataset.update')
async def version_update(self,
risotto_context: Context,
source_id: int,
@ -81,7 +81,7 @@ class Risotto(Controller):
return {'release_id': release_id,
'release_name': release_name}
@register('v1.source.release.create')
@register('v1.setting.source.release.create')
async def source_release_create(self,
risotto_context: Context,
source_name: str,
@ -110,7 +110,7 @@ class Risotto(Controller):
source['release_distribution'] = release_distribution
return source
@register('v1.source.release.list')
@register('v1.setting.source.release.list')
async def release_list(self,
risotto_context,
source_name: str) -> Dict:
@ -121,7 +121,7 @@ class Risotto(Controller):
source_name)
return [dict(r) for r in result]
@register('v1.source.release.describe')
@register('v1.setting.source.release.describe')
async def release_describe(self,
risotto_context,
source_name: str,
@ -136,7 +136,7 @@ class Risotto(Controller):
raise Exception(_(f'unknown release distribution {release_distribution} in source {source_name}'))
return dict(result)
@register('v1.source.release.get_by_id')
@register('v1.setting.source.release.get_by_id')
async def release_get_by_id(self,
risotto_context: Context,
release_id: int) -> Dict:

View File

@ -17,12 +17,12 @@ class Risotto(Controller):
self.storage = Storage(engine='dictionary')
self.cache_root_path = join(get_config().get('cache').get('root_path'), 'servermodel')
@register('v1.template.generate')
@register('v1.setting.template.generate')
async def template_get(self,
risotto_context,
server_name: str) -> Dict:
# get informations for server
server = await self.call('v1.server.describe',
server = await self.call('v1.setting.server.describe',
risotto_context,
server_name=server_name)
server_id = server['server_id']

View File

@ -9,63 +9,63 @@ from ...utils import _
class Risotto(Controller):
async def on_join(self,
risotto_context):
for uri in ['v1.applicationservice.create',
'v1.applicationservice.dataset.updated',
'v1.applicationservice.dependency.add',
'v1.server.create',
'v1.servermodel.create',
'v1.servermodel.dataset.updated',
'v1.session.server.start',
'v1.source.create',
'v1.source.dataset.update',
'v1.source.release.create',
'v1.template.generate',
'v1.uri.role.join',
'v1.uri.role.list',
'v1.user.create',
'v1.user.delete',
'v1.user.list',
'v1.user.role.create',
'v1.config.configuration.server.get',
'v1.user.role.list']:
for uri in ['v1.setting.applicationservice.create',
'v1.setting.applicationservice.dataset.updated',
'v1.setting.applicationservice.dependency.add',
'v1.setting.server.create',
'v1.setting.servermodel.create',
'v1.setting.servermodel.dataset.updated',
'v1.setting.session.server.start',
'v1.setting.source.create',
'v1.setting.source.dataset.update',
'v1.setting.source.release.create',
'v1.setting.template.generate',
'v1.setting.uri.role.join',
'v1.setting.uri.role.list',
'v1.setting.user.create',
'v1.setting.user.delete',
'v1.setting.user.list',
'v1.setting.user.role.create',
'v1.setting.config.configuration.server.get',
'v1.setting.user.role.list']:
try:
await self._uri_role_join(risotto_context,
role_name='administrator',
uri_name=uri)
except:
pass
for uri in ['v1.applicationservice.describe',
'v1.server.describe',
'v1.server.list',
'v1.servermodel.list',
'v1.session.server.configure',
'v1.session.server.filter',
'v1.session.server.get',
'v1.session.server.list',
'v1.session.servermodel.configure',
'v1.session.servermodel.filter',
'v1.session.servermodel.get',
'v1.session.servermodel.list',
'v1.session.servermodel.start',
'v1.session.servermodel.stop',
'v1.session.servermodel.validate',
'v1.session.server.stop',
'v1.session.server.validate',
'v1.source.describe',
'v1.source.list',
'v1.source.release.list']:
for uri in ['v1.setting.applicationservice.describe',
'v1.setting.server.describe',
'v1.setting.server.list',
'v1.setting.servermodel.list',
'v1.setting.session.server.configure',
'v1.setting.session.server.filter',
'v1.setting.session.server.get',
'v1.setting.session.server.list',
'v1.setting.session.servermodel.configure',
'v1.setting.session.servermodel.filter',
'v1.setting.session.servermodel.get',
'v1.setting.session.servermodel.list',
'v1.setting.session.servermodel.start',
'v1.setting.session.servermodel.stop',
'v1.setting.session.servermodel.validate',
'v1.setting.session.server.stop',
'v1.setting.session.server.validate',
'v1.setting.source.describe',
'v1.setting.source.list',
'v1.setting.source.release.list']:
try:
await self._uri_role_join(risotto_context,
role_name='all',
uri_name=uri)
except:
pass
for uri in ['v1.server.describe',
'v1.applicationservice.dependency.add',
'v1.config.configuration.server.get',
'v1.config.configuration.server.deploy',
'v1.session.server.start',
'v1.template.generate']:
for uri in ['v1.setting.server.describe',
'v1.setting.applicationservice.dependency.add',
'v1.setting.config.configuration.server.get',
'v1.setting.config.configuration.server.deploy',
'v1.setting.session.server.start',
'v1.setting.template.generate']:
try:
await self._uri_role_join(risotto_context,
role_name='server_rw',
@ -73,7 +73,7 @@ class Risotto(Controller):
except:
pass
@register('v1.uri.role.join')
@register('v1.setting.uri.role.join')
async def uri_role_join(self,
risotto_context: Context,
role_name: str,
@ -106,7 +106,7 @@ class Risotto(Controller):
return {'role_name': role_name,
'uri_name': uri_name}
@register('v1.uri.role.list')
@register('v1.setting.uri.role.list')
async def uri_role_list(self,
risotto_context: Context) -> List[Dict]:
sql = '''

View File

@ -43,7 +43,7 @@ class Risotto(Controller):
user_login,
user_name,
user_surname)
await self.call('v1.user.role.create',
await self.call('v1.setting.user.role.create',
risotto_context,
user_login=user_login,
role_name='all')
@ -52,7 +52,7 @@ class Risotto(Controller):
'user_name': user_name,
'user_surname': user_surname}
@register('v1.user.create')
@register('v1.setting.user.create')
async def user_create(self,
risotto_context: Context,
user_login: str,
@ -63,7 +63,7 @@ class Risotto(Controller):
user_name,
user_surname)
@register('v1.user.list')
@register('v1.setting.user.list')
async def user_list(self,
risotto_context: Context) -> Dict:
sql = '''
@ -73,7 +73,7 @@ class Risotto(Controller):
users = await risotto_context.connection.fetch(sql)
return [dict(r) for r in users]
@register('v1.user.delete')
@register('v1.setting.user.delete')
async def user_delete(self,
risotto_context: Context,
user_login: str) -> Dict:
@ -138,7 +138,7 @@ class Risotto(Controller):
'role_attribute': role_attribute,
'role_attribute_value': role_attribute_value}
@register('v1.user.role.create')
@register('v1.setting.user.role.create')
async def user_role_create(self,
risotto_context: Context,
user_login: str,
@ -151,7 +151,7 @@ class Risotto(Controller):
role_attribute,
role_attribute_value)
@register('v1.user.role.list')
@register('v1.setting.user.role.list')
async def user_role_list(self,
risotto_context: Context,
user_login: Optional[str]) -> Dict:
@ -183,7 +183,7 @@ class Risotto(Controller):
return [dict(r) for r in roles]
#
# FIXME comment savoir quel role il faut supprimer ? avec attribut ou juste l'ID ?
# @register('v1.user.role.delete')
# @register('v1.setting.user.role.delete')
# async def user_role_delete(self,
# risotto_context: Context,
# user_login: str,