summaryrefslogtreecommitdiff
path: root/src/services/api/graphql/recipes/session.py
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2021-11-29 16:02:12 -0600
committerJohn Estabrook <jestabro@vyos.io>2021-11-30 10:07:44 -0600
commita05866e5301934f61a3c83550f91926e03bfc7b0 (patch)
tree81fdbce6a96091bf058e4058c4b9ebe043eb5ffc /src/services/api/graphql/recipes/session.py
parent1f926e1b1fe7d82113be55916a55ca7e3cceac76 (diff)
downloadvyos-1x-a05866e5301934f61a3c83550f91926e03bfc7b0.tar.gz
vyos-1x-a05866e5301934f61a3c83550f91926e03bfc7b0.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.
Diffstat (limited to 'src/services/api/graphql/recipes/session.py')
-rw-r--r--src/services/api/graphql/recipes/session.py19
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