diff options
author | John Estabrook <jestabro@vyos.io> | 2021-11-29 16:02:12 -0600 |
---|---|---|
committer | John Estabrook <jestabro@vyos.io> | 2021-11-30 10:43:43 -0600 |
commit | aae53dad4a02ca5b7591ff07059c0b99190aee7e (patch) | |
tree | 11b2063502a40e9b56e8f0fbb24c5d0bf27883f7 /src/services/api/graphql/recipes | |
parent | a17f8caf10a3e19f52f41e45ab3f28d12f460858 (diff) | |
download | vyos-1x-aae53dad4a02ca5b7591ff07059c0b99190aee7e.tar.gz vyos-1x-aae53dad4a02ca5b7591ff07059c0b99190aee7e.zip |
graphql: T3993: add config session show_config
Note that one can also use the mutation Show, with path
["configuration", "json", "pretty"]; that command will obscure passwords
and keys, and we may want to disallow this version.
(cherry picked from commit a05866e5301934f61a3c83550f91926e03bfc7b0)
Diffstat (limited to 'src/services/api/graphql/recipes')
-rw-r--r-- | src/services/api/graphql/recipes/session.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/services/api/graphql/recipes/session.py b/src/services/api/graphql/recipes/session.py index c6c3209c0..f8c072b39 100644 --- a/src/services/api/graphql/recipes/session.py +++ b/src/services/api/graphql/recipes/session.py @@ -1,6 +1,10 @@ +import json + from ariadne import convert_camel_case_to_snake + import vyos.defaults from vyos.config import Config +from vyos.configtree import ConfigTree from vyos.template import render class Session(object): @@ -43,6 +47,21 @@ class Session(object): session.delete(path) session.commit() + def show_config(self): + session = self._session + data = self._data + out = '' + + try: + out = session.show_config(data['path']) + if data.get('config_format', '') == 'json': + config_tree = vyos.configtree.ConfigTree(out) + out = json.loads(config_tree.to_json()) + except Exception as error: + raise error + + return out + def save(self): session = self._session data = self._data |