diff options
author | John Estabrook <jestabro@vyos.io> | 2023-02-06 12:48:59 -0600 |
---|---|---|
committer | John Estabrook <jestabro@vyos.io> | 2023-02-06 12:48:59 -0600 |
commit | 1f71a4f9d733e5f24b1f1648f68787dc2c5cef09 (patch) | |
tree | 62d984ce09b96423726ff328654f3fbbb47b7887 /src | |
parent | 2622902ac76bc1c3356bb722f63e931119f3eb04 (diff) | |
download | vyos-1x-1f71a4f9d733e5f24b1f1648f68787dc2c5cef09.tar.gz vyos-1x-1f71a4f9d733e5f24b1f1648f68787dc2c5cef09.zip |
graphql: T4979: add query show_user_info
Diffstat (limited to 'src')
-rw-r--r-- | src/services/api/graphql/generate/config_session_function.py | 6 | ||||
-rw-r--r-- | src/services/api/graphql/session/session.py | 27 |
2 files changed, 32 insertions, 1 deletions
diff --git a/src/services/api/graphql/generate/config_session_function.py b/src/services/api/graphql/generate/config_session_function.py index fc0dd7a87..20fc7cc1d 100644 --- a/src/services/api/graphql/generate/config_session_function.py +++ b/src/services/api/graphql/generate/config_session_function.py @@ -8,8 +8,12 @@ def show_config(path: list[str], configFormat: typing.Optional[str]): def show(path: list[str]): pass +def show_user_info(user: str): + pass + queries = {'show_config': show_config, - 'show': show} + 'show': show, + 'show_user_info': show_user_info} def save_config_file(fileName: typing.Optional[str]): pass diff --git a/src/services/api/graphql/session/session.py b/src/services/api/graphql/session/session.py index 0b77b1433..b2aef9bd9 100644 --- a/src/services/api/graphql/session/session.py +++ b/src/services/api/graphql/session/session.py @@ -46,6 +46,17 @@ class Session: except Exception: self._op_mode_list = None + @staticmethod + def _get_config_dict(path=[], effective=False, key_mangling=None, + get_first_key=False, no_multi_convert=False, + no_tag_node_value_mangle=False): + config = Config() + return config.get_config_dict(path=path, effective=effective, + key_mangling=key_mangling, + get_first_key=get_first_key, + no_multi_convert=no_multi_convert, + no_tag_node_value_mangle=no_tag_node_value_mangle) + def show_config(self): session = self._session data = self._data @@ -116,6 +127,22 @@ class Session: return res + def show_user_info(self): + session = self._session + data = self._data + + user_info = {} + user = data['user'] + try: + info = self._get_config_dict(['system', 'login', 'user', user, + 'full-name']) + user_info['user'] = user + user_info['full_name'] = info.get('full-name', '') + except Exception as error: + raise error + + return user_info + def system_status(self): import api.graphql.session.composite.system_status as system_status |