From 7612b8f8345fe2af068d1f906aa50fcee723459f Mon Sep 17 00:00:00 2001 From: mtamadonDHSE Date: Wed, 10 May 2023 11:53:03 +0200 Subject: [PATCH 1/4] Add textbox template type --- grafana_dashboards/schema/template/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grafana_dashboards/schema/template/base.py b/grafana_dashboards/schema/template/base.py index 0eb83f2..2111e5e 100644 --- a/grafana_dashboards/schema/template/base.py +++ b/grafana_dashboards/schema/template/base.py @@ -66,7 +66,7 @@ def __init__(self): self.base = { v.Required("name"): v.All(str, v.Length(min=1)), v.Required("type"): v.Any( - "query", "interval", "custom", "datasource", "adhoc", "constant" + "query", "interval", "custom", "datasource", "adhoc", "constant", "textbox" ), v.Optional("description"): v.All(str), } From 129ad2433d7e3f786f83460f6d06045d5d5e3814 Mon Sep 17 00:00:00 2001 From: mtamadonDHSE Date: Wed, 10 May 2023 12:10:14 +0200 Subject: [PATCH 2/4] add the schema and validations --- .../schema/template/__init__.py | 3 ++ grafana_dashboards/schema/template/textbox.py | 29 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 grafana_dashboards/schema/template/textbox.py diff --git a/grafana_dashboards/schema/template/__init__.py b/grafana_dashboards/schema/template/__init__.py index 08b35e3..f2cc51a 100644 --- a/grafana_dashboards/schema/template/__init__.py +++ b/grafana_dashboards/schema/template/__init__.py @@ -20,6 +20,7 @@ from grafana_dashboards.schema.template.datasource import Datasource from grafana_dashboards.schema.template.interval import Interval from grafana_dashboards.schema.template.query import Query +from grafana_dashboards.schema.template.textbox import Textbox class Template(object): @@ -52,6 +53,8 @@ def f(data): schema = Datasource().get_schema() if template["type"] == "adhoc": schema = Adhoc().get_schema() + if template["type"] == "textbox": + schema = Textbox().get_schema() res["list"].append(schema(template)) diff --git a/grafana_dashboards/schema/template/textbox.py b/grafana_dashboards/schema/template/textbox.py new file mode 100644 index 0000000..40ae514 --- /dev/null +++ b/grafana_dashboards/schema/template/textbox.py @@ -0,0 +1,29 @@ +# Copyright 2018 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import voluptuous as v + +from grafana_dashboards.schema.template.base import Base + + +class Textbox(Base): + def get_schema(self): + query = { + v.Optional("hide"): v.All(int, v.Range(min=0, max=2)), + v.Optional("label", default=""): v.All(str), + v.Optional("name"): v.All(str), + v.Optional("query"): v.All(str), + } + query.update(self.base) + return v.Schema(query) From 0ed02c8d6874b8a1521ca1ad00fd543920765333 Mon Sep 17 00:00:00 2001 From: mtamadonDHSE Date: Wed, 10 May 2023 13:01:33 +0200 Subject: [PATCH 3/4] change copyright --- grafana_dashboards/schema/template/textbox.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grafana_dashboards/schema/template/textbox.py b/grafana_dashboards/schema/template/textbox.py index 40ae514..eae7ca8 100644 --- a/grafana_dashboards/schema/template/textbox.py +++ b/grafana_dashboards/schema/template/textbox.py @@ -1,4 +1,4 @@ -# Copyright 2018 Red Hat, Inc. +# Copyright 2018 Delivery Hero SE. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. From 190fb5f2edd009a214085585b7dc67edba7891b1 Mon Sep 17 00:00:00 2001 From: mtamadonDHSE Date: Wed, 10 May 2023 13:04:15 +0200 Subject: [PATCH 4/4] reformat --- grafana_dashboards/schema/template/base.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/grafana_dashboards/schema/template/base.py b/grafana_dashboards/schema/template/base.py index 2111e5e..6e5d819 100644 --- a/grafana_dashboards/schema/template/base.py +++ b/grafana_dashboards/schema/template/base.py @@ -66,7 +66,13 @@ def __init__(self): self.base = { v.Required("name"): v.All(str, v.Length(min=1)), v.Required("type"): v.Any( - "query", "interval", "custom", "datasource", "adhoc", "constant", "textbox" + "query", + "interval", + "custom", + "datasource", + "adhoc", + "constant", + "textbox", ), v.Optional("description"): v.All(str), }