From c6f7ef4b84b25bf8c35e3b0755d2e973a072ebd5 Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Tue, 1 Nov 2022 11:20:57 -0500 Subject: op-mode: T4791: decamelize raw output of 'show_*' before normalization --- python/vyos/opmode.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/vyos/opmode.py b/python/vyos/opmode.py index 727e118a8..2e896c8e6 100644 --- a/python/vyos/opmode.py +++ b/python/vyos/opmode.py @@ -16,6 +16,7 @@ import re import sys import typing +from humps import decamelize class Error(Exception): @@ -200,6 +201,7 @@ def run(module): if not args["raw"]: return res else: + res = decamelize(res) res = _normalize_field_names(res) from json import dumps return dumps(res, indent=4) -- cgit v1.2.3 From 702fc62726723136c46e0c116504b4e6ff7d38ca Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Tue, 1 Nov 2022 13:36:01 -0500 Subject: op-mode: T4791: add python3-pyhumps as build dep for op-mode nosetest Using humps.decamelize in vyos.opmode requires python3-pyhumps to be a build dependency for the nosetest test_op_mode.py. --- debian/control | 1 + 1 file changed, 1 insertion(+) diff --git a/debian/control b/debian/control index cf766a825..d7cd5b688 100644 --- a/debian/control +++ b/debian/control @@ -25,6 +25,7 @@ Build-Depends: python3-setuptools, python3-sphinx, python3-xmltodict, + python3-pyhumps, quilt, whois Standards-Version: 3.9.6 -- cgit v1.2.3 From db0791238c9cccaf73aac61844a6c0293c513a54 Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Tue, 1 Nov 2022 11:21:05 -0500 Subject: graphql: T4791: decamelize/normalize result of op-mode queries --- src/services/api/graphql/libs/op_mode.py | 6 ++++++ src/services/api/graphql/session/session.py | 3 +++ 2 files changed, 9 insertions(+) diff --git a/src/services/api/graphql/libs/op_mode.py b/src/services/api/graphql/libs/op_mode.py index da2bcdb5b..97a26520e 100644 --- a/src/services/api/graphql/libs/op_mode.py +++ b/src/services/api/graphql/libs/op_mode.py @@ -17,8 +17,11 @@ import os import re import typing import importlib.util +from typing import Union +from humps import decamelize from vyos.defaults import directories +from vyos.opmode import _normalize_field_names def load_as_module(name: str, path: str): spec = importlib.util.spec_from_file_location(name, path) @@ -98,3 +101,6 @@ def map_type_name(type_name: type, optional: bool = False) -> str: # scalar 'Generic' is defined in schema.graphql return 'Generic' + +def normalize_output(result: Union[dict, list]) -> Union[dict, list]: + return _normalize_field_names(decamelize(result)) diff --git a/src/services/api/graphql/session/session.py b/src/services/api/graphql/session/session.py index c2c1db1df..0b77b1433 100644 --- a/src/services/api/graphql/session/session.py +++ b/src/services/api/graphql/session/session.py @@ -25,6 +25,7 @@ from vyos.template import render from vyos.opmode import Error as OpModeError from api.graphql.libs.op_mode import load_op_mode_as_module, split_compound_op_mode_name +from api.graphql.libs.op_mode import normalize_output op_mode_include_file = os.path.join(directories['data'], 'op-mode-standardized.json') @@ -149,6 +150,8 @@ class Session: except OpModeError as e: raise e + res = normalize_output(res) + return res def gen_op_mutation(self): -- cgit v1.2.3