From a05866e5301934f61a3c83550f91926e03bfc7b0 Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Mon, 29 Nov 2021 16:02:12 -0600 Subject: 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. --- src/services/api/graphql/recipes/session.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/services/api/graphql/recipes/session.py') 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 -- cgit v1.2.3