Compare commits
12 Commits
pkg/dev/ri
...
fcd137ae6f
Author | SHA1 | Date | |
---|---|---|---|
fcd137ae6f | |||
b6c5dccf17 | |||
9423cdef8d | |||
ef43b197a1 | |||
fc5a13152b | |||
94b6563d8f | |||
617ef55dd3 | |||
88c2c168ac | |||
8c5a2bb702 | |||
09cd0a4e4c | |||
92846052b1 | |||
3085bf67d6 |
@ -5,7 +5,7 @@ CREATE TABLE RisottoLog(
|
||||
URI VARCHAR(255),
|
||||
URIS VARCHAR(255),
|
||||
UserLogin VARCHAR(100) NOT NULL,
|
||||
Level VARCHAR(10) NOT NULL,
|
||||
Status INTEGER NOT NULL,
|
||||
Kwargs JSON,
|
||||
Returns JSON,
|
||||
StartDate timestamp DEFAULT current_timestamp,
|
||||
|
@ -65,6 +65,18 @@ if 'CELERYRISOTTO_DB_USER' in environ:
|
||||
CELERYRISOTTO_DB_USER = environ['CELERYRISOTTO_DB_USER']
|
||||
else:
|
||||
CELERYRISOTTO_DB_USER = config.get('CELERYRISOTTO_DB_USER', None)
|
||||
if 'LEMUR_DB_NAME' in environ:
|
||||
LEMUR_DB_NAME = environ['LEMUR_DB_NAME']
|
||||
else:
|
||||
LEMUR_DB_NAME = config.get('LEMUR_DB_NAME', None)
|
||||
if 'LEMUR_DB_PASSWORD' in environ:
|
||||
LEMUR_DB_PASSWORD = environ['LEMUR_DB_PASSWORD']
|
||||
else:
|
||||
LEMUR_DB_PASSWORD = config.get('LEMUR_DB_PASSWORD', None)
|
||||
if 'LEMUR_DB_USER' in environ:
|
||||
LEMUR_DB_USER = environ['LEMUR_DB_USER']
|
||||
else:
|
||||
LEMUR_DB_USER = config.get('LEMUR_DB_USER', None)
|
||||
if 'DB_ADDRESS' in environ:
|
||||
DB_ADDRESS = environ['DB_ADDRESS']
|
||||
else:
|
||||
@ -115,6 +127,11 @@ if 'PASSWORD_URL' in environ:
|
||||
PASSWORD_URL = environ['PASSWORD_URL']
|
||||
else:
|
||||
PASSWORD_URL = config.get('PASSWORD_URL', 'https://localhost:8001/')
|
||||
|
||||
if 'PASSWORD_LENGTH' in environ:
|
||||
PASSWORD_LENGTH = int(environ['PASSWORD_LENGTH'])
|
||||
else:
|
||||
PASSWORD_LENGTH = int(config.get('PASSWORD_LENGTH', 20))
|
||||
if 'PKI_ADMIN_PASSWORD' in environ:
|
||||
PKI_ADMIN_PASSWORD = environ['PKI_ADMIN_PASSWORD']
|
||||
else:
|
||||
@ -136,7 +153,8 @@ def dsn_factory(database, user, password, address=DB_ADDRESS):
|
||||
|
||||
_config = {'database': {'dsn': dsn_factory(RISOTTO_DB_NAME, RISOTTO_DB_USER, RISOTTO_DB_PASSWORD),
|
||||
'tiramisu_dsn': dsn_factory(TIRAMISU_DB_NAME, TIRAMISU_DB_USER, TIRAMISU_DB_PASSWORD),
|
||||
'celery_dsn': dsn_factory(CELERYRISOTTO_DB_NAME, CELERYRISOTTO_DB_USER, CELERYRISOTTO_DB_PASSWORD)
|
||||
'celery_dsn': dsn_factory(CELERYRISOTTO_DB_NAME, CELERYRISOTTO_DB_USER, CELERYRISOTTO_DB_PASSWORD),
|
||||
'lemur_dns': dsn_factory(LEMUR_DB_NAME, LEMUR_DB_USER, LEMUR_DB_PASSWORD),
|
||||
},
|
||||
'http_server': {'port': RISOTTO_PORT,
|
||||
'default_user': DEFAULT_USER,
|
||||
@ -155,6 +173,7 @@ _config = {'database': {'dsn': dsn_factory(RISOTTO_DB_NAME, RISOTTO_DB_USER, RIS
|
||||
'admin_password': PASSWORD_ADMIN_PASSWORD,
|
||||
'device_identifier': PASSWORD_DEVICE_IDENTIFIER,
|
||||
'service_url': PASSWORD_URL,
|
||||
'length': PASSWORD_LENGTH,
|
||||
},
|
||||
'pki': {'admin_password': PKI_ADMIN_PASSWORD,
|
||||
'owner': PKI_ADMIN_EMAIL,
|
||||
|
@ -65,8 +65,7 @@ class Controller:
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
async def check_role(self,
|
||||
uri: str,
|
||||
async def check_role(uri: str,
|
||||
username: str,
|
||||
**kwargs: dict,
|
||||
) -> None:
|
||||
@ -309,6 +308,7 @@ except:
|
||||
await config_std.property.read_only()
|
||||
|
||||
# copy informations from 'to deploy' configuration to configuration
|
||||
await config.information.importation(await config_std.information.exportation())
|
||||
await config.value.importation(await config_std.value.exportation())
|
||||
await config.permissive.importation(await config_std.permissive.exportation())
|
||||
await config.property.importation(await config_std.property.exportation())
|
||||
|
@ -42,14 +42,21 @@ class CallDispatcher:
|
||||
for ret in returns:
|
||||
async with await Config(response, display_name=lambda self, dyn_name, suffix: self.impl_getname()) as config:
|
||||
await config.property.read_write()
|
||||
key = None
|
||||
try:
|
||||
for key, value in ret.items():
|
||||
await config.option(key).value.set(value)
|
||||
except AttributeError:
|
||||
except AttributeError as err:
|
||||
if key is not None:
|
||||
err = _(f'function {module_name}.{function_name} return the unknown parameter "{key}" for the uri "{risotto_context.version}.{risotto_context.message}"')
|
||||
else:
|
||||
err = _(f'function {module_name}.{function_name} return unconsistency data "{err}" for the uri "{risotto_context.version}.{risotto_context.message}"')
|
||||
raise CallError(err)
|
||||
except ValueError as err:
|
||||
if key is not None:
|
||||
err = _(f'function {module_name}.{function_name} return the invalid parameter "{key}" for the uri "{risotto_context.version}.{risotto_context.message}": {err}')
|
||||
else:
|
||||
err = _(f'function {module_name}.{function_name} return unconsistency error for the uri "{risotto_context.version}.{risotto_context.message}": {err}')
|
||||
raise CallError(err)
|
||||
await config.property.read_only()
|
||||
mandatories = await config.value.mandatory()
|
||||
@ -468,6 +475,8 @@ class Dispatcher(register.RegisterDispatcher,
|
||||
)
|
||||
# notification
|
||||
if function_obj.get('notification'):
|
||||
if returns is None:
|
||||
raise Exception(_(f'function "{function_obj["full_module_name"]}.{function_obj["function"].__name__}" must returns something for {function_obj["notification"]}!'))
|
||||
notif_version, notif_message = function_obj['notification'].split('.', 1)
|
||||
if not isinstance(returns, list):
|
||||
send_returns = [returns]
|
||||
|
@ -23,9 +23,13 @@ extra_statics = {}
|
||||
|
||||
def create_context(request):
|
||||
risotto_context = Context()
|
||||
risotto_context.username = request.match_info.get('username',
|
||||
get_config()['http_server']['default_user'],
|
||||
)
|
||||
if 'username' in dict(request.match_info):
|
||||
username = request.match_info['username']
|
||||
elif 'username' in request.headers:
|
||||
username = request.headers['username']
|
||||
else:
|
||||
username = get_config()['http_server']['default_user']
|
||||
risotto_context.username = username
|
||||
return risotto_context
|
||||
|
||||
|
||||
|
@ -11,6 +11,9 @@ from .config import get_config
|
||||
database_lock = Lock()
|
||||
|
||||
|
||||
LEVELS = ['Error', 'Info', 'Success', 'Started', 'Failure']
|
||||
|
||||
|
||||
class Logger:
|
||||
""" An object to manager log
|
||||
"""
|
||||
@ -39,9 +42,9 @@ class Logger:
|
||||
) -> None:
|
||||
uri = self._get_last_uri(risotto_context)
|
||||
uris = " ".join(risotto_context.paths)
|
||||
insert = 'INSERT INTO RisottoLog(Msg, URI, URIS, UserLogin, Level'
|
||||
insert = 'INSERT INTO RisottoLog(Msg, URI, URIS, UserLogin, Status'
|
||||
values = 'VALUES($1,$2,$3,$4,$5'
|
||||
args = [msg, uri, uris, risotto_context.username, level]
|
||||
args = [msg, uri, uris, risotto_context.username, LEVELS.index(level)]
|
||||
if kwargs:
|
||||
insert += ', Kwargs'
|
||||
values += ',$6'
|
||||
@ -67,40 +70,6 @@ class Logger:
|
||||
except UndefinedTableError as err:
|
||||
raise Exception(_(f'cannot access to database ({err}), was the database really created?'))
|
||||
|
||||
async def query(self,
|
||||
risotto_context: Context,
|
||||
context_id: int,
|
||||
uri: Optional[str],
|
||||
) -> list:
|
||||
sql = '''SELECT Msg as msg, URI as uri_name, URIS as uris, UserLogin as user_login, Level as level, Kwargs as kwargs, Returns as returns, StartDate as start_date, StopDate as stop_date
|
||||
FROM RisottoLog
|
||||
WHERE UserLogin = $1 AND (LogId = $2 OR ContextId = $2)
|
||||
'''
|
||||
args = [sql, risotto_context.username, context_id]
|
||||
if uri is not None:
|
||||
sql += ' AND URI = $3'
|
||||
args.append(uri)
|
||||
ret = []
|
||||
async with database_lock:
|
||||
connection = await self.get_connection(risotto_context)
|
||||
for row in await connection.fetch(*args):
|
||||
d = {}
|
||||
for key, value in row.items():
|
||||
if key in ['kwargs', 'returns']:
|
||||
if isinstance(value, dict):
|
||||
pass
|
||||
elif not value:
|
||||
value = {}
|
||||
else:
|
||||
value = loads(value)
|
||||
if key == 'uris':
|
||||
value = value.split(' ')
|
||||
elif key in ['start_date', 'stop_date']:
|
||||
value = str(value)
|
||||
d[key] = value
|
||||
ret.append(d)
|
||||
return ret
|
||||
|
||||
def _get_last_uri(self,
|
||||
risotto_context: Context,
|
||||
) -> str:
|
||||
@ -171,7 +140,7 @@ class Logger:
|
||||
print(_(f'{risotto_context.username}: START{context}:{paths_msg}: {msg}'))
|
||||
await self.insert(msg,
|
||||
risotto_context,
|
||||
'Start',
|
||||
'Started',
|
||||
arguments,
|
||||
start=True,
|
||||
)
|
||||
@ -185,11 +154,11 @@ class Logger:
|
||||
print(_(f'{risotto_context.username}: SUCCESS({risotto_context.context_id}):{paths_msg}'))
|
||||
sql = """UPDATE RisottoLog
|
||||
SET StopDate = $2,
|
||||
Level = 'SUCCESS'
|
||||
Status = $3
|
||||
"""
|
||||
args = [datetime.now()]
|
||||
args = [datetime.now(), LEVELS.index('Success')]
|
||||
if returns:
|
||||
sql += """, Returns = $3
|
||||
sql += """, Returns = $4
|
||||
"""
|
||||
args.append(dumps(returns))
|
||||
sql += """WHERE LogId = $1
|
||||
@ -214,7 +183,7 @@ class Logger:
|
||||
print(_(f'{risotto_context.username}: FAILED({risotto_context.context_id}):{paths_msg}: {err}'))
|
||||
sql = """UPDATE RisottoLog
|
||||
SET StopDate = $2,
|
||||
Level = 'FAILED',
|
||||
Status = $4,
|
||||
Msg = $3
|
||||
WHERE LogId = $1
|
||||
"""
|
||||
@ -223,7 +192,8 @@ class Logger:
|
||||
await connection.execute(sql,
|
||||
risotto_context.start_id,
|
||||
datetime.now(),
|
||||
err,
|
||||
err[:254],
|
||||
LEVELS.index('Failure'),
|
||||
)
|
||||
|
||||
async def info(self,
|
||||
|
@ -313,6 +313,7 @@ class CustomParam:
|
||||
'string': 'String',
|
||||
'number': 'Number',
|
||||
'object': 'Dict',
|
||||
'any': 'Any',
|
||||
'array': 'Array',
|
||||
'file': 'File',
|
||||
'float': 'Float'}
|
||||
@ -448,6 +449,7 @@ def _get_option(name,
|
||||
'reverse_condition': ParamValue(True)}),
|
||||
calc_value_property_help))
|
||||
|
||||
props.append('notunique')
|
||||
description = arg.description.strip().rstrip()
|
||||
kwargs = {'name': name,
|
||||
'doc': _get_description(description, name),
|
||||
@ -523,6 +525,7 @@ def _parse_responses(message_def,
|
||||
'Number': IntOption,
|
||||
'Boolean': BoolOption,
|
||||
'Dict': DictOption,
|
||||
'Any': AnyOption,
|
||||
'Float': FloatOption,
|
||||
# FIXME
|
||||
'File': StrOption}.get(type_)
|
||||
@ -530,8 +533,9 @@ def _parse_responses(message_def,
|
||||
raise Exception(f'unknown param type {obj.type} in responses of message {message_def.message}')
|
||||
if hasattr(obj, 'default'):
|
||||
kwargs['default'] = obj.default
|
||||
kwargs['properties'] = ('notunique',)
|
||||
else:
|
||||
kwargs['properties'] = ('mandatory',)
|
||||
kwargs['properties'] = ('mandatory', 'notunique')
|
||||
options.append(option(**kwargs))
|
||||
od = OptionDescription(uri,
|
||||
message_def.response.description,
|
||||
@ -600,7 +604,7 @@ def get_messages(current_module_names,
|
||||
select_option = ChoiceOption('message',
|
||||
'Nom du message.',
|
||||
tuple(messages),
|
||||
properties=frozenset(['mandatory', 'positional']))
|
||||
properties=frozenset(['mandatory', 'positional', 'notunique']))
|
||||
for uri in messages:
|
||||
message_def = get_message(uri,
|
||||
current_module_names,
|
||||
|
@ -107,6 +107,7 @@ class RegisterDispatcher:
|
||||
version = obj['version']
|
||||
if version not in self.messages:
|
||||
self.messages[version] = {}
|
||||
obj['message'] = tiramisu_message
|
||||
self.messages[version][tiramisu_message] = obj
|
||||
|
||||
def get_function_args(self,
|
||||
|
@ -23,5 +23,5 @@ def tiramisu_display_name(kls,
|
||||
if suffix:
|
||||
doc += suffix
|
||||
if name != doc:
|
||||
name += f' ({doc})'
|
||||
name += f'" "{doc}'
|
||||
return name
|
||||
|
Reference in New Issue
Block a user