summaryrefslogtreecommitdiff
path: root/src/services/api/graphql/session/session.py
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2023-02-26 15:21:13 -0600
committerJohn Estabrook <jestabro@vyos.io>2023-02-26 15:21:13 -0600
commit6d29c4c76b5affa64ae1b2e697984cafe5664246 (patch)
treecc1e7f8c9b572bb42271743da5e52d12ac03deff /src/services/api/graphql/session/session.py
parent40e0cb294e0377fdfe11171b35d78bd27e231df2 (diff)
downloadvyos-1x-6d29c4c76b5affa64ae1b2e697984cafe5664246.tar.gz
vyos-1x-6d29c4c76b5affa64ae1b2e697984cafe5664246.zip
graphql: T4979: add user info to token request
Diffstat (limited to 'src/services/api/graphql/session/session.py')
-rw-r--r--src/services/api/graphql/session/session.py38
1 files changed, 23 insertions, 15 deletions
diff --git a/src/services/api/graphql/session/session.py b/src/services/api/graphql/session/session.py
index b2aef9bd9..3c5a062b6 100644
--- a/src/services/api/graphql/session/session.py
+++ b/src/services/api/graphql/session/session.py
@@ -29,6 +29,28 @@ from api.graphql.libs.op_mode import normalize_output
op_mode_include_file = os.path.join(directories['data'], 'op-mode-standardized.json')
+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 get_user_info(user):
+ user_info = {}
+ info = get_config_dict(['system', 'login', 'user', user],
+ get_first_key=True)
+ if not info:
+ raise ValueError("No such user")
+
+ user_info['user'] = user
+ user_info['full_name'] = info.get('full-name', '')
+
+ return user_info
+
class Session:
"""
Wrapper for calling configsession functions based on GraphQL requests.
@@ -46,17 +68,6 @@ 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
@@ -134,10 +145,7 @@ class Session:
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', '')
+ user_info = get_user_info(user)
except Exception as error:
raise error