Update: schema management across plugins, trailing spaces cleanup
This commit is contained in:
parent
50c7af2f58
commit
4854bb240f
@ -22,15 +22,15 @@ log = logging.getLogger(__name__)
|
||||
class App():
|
||||
|
||||
schema = {
|
||||
"$schema": 'http://json-schema.org/draft-04/schema#',
|
||||
"$schema": 'http://json-schema.org/draft-07/schema#',
|
||||
"type": "object",
|
||||
"additionalProperties": False,
|
||||
"default": {},
|
||||
"$def" :{
|
||||
'backends_items': None,
|
||||
'backends_config': None,
|
||||
'rules_items': None,
|
||||
'rules_config': None,
|
||||
'backends_items': {},
|
||||
'backends_config': {},
|
||||
'rules_items': {},
|
||||
'rules_config': {},
|
||||
},
|
||||
"patternProperties": {
|
||||
".*": {
|
||||
@ -70,12 +70,15 @@ class App():
|
||||
"tree": {
|
||||
"type": "array",
|
||||
"default": [],
|
||||
"arrayItem": { "$ref": "#/$defs/backends_items" },
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": { "$ref": "#/$defs/backends_items" },
|
||||
},
|
||||
},
|
||||
"rules": {
|
||||
"type": "array",
|
||||
"default": [],
|
||||
"arrayItem": { "$ref": "#/$defs/rules_items" },
|
||||
# "arrayItem": { "$ref": "#/$defs/rules_items" },
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -122,12 +125,9 @@ class App():
|
||||
r2 = RulesManager.get_schema(AlberoPlugins)
|
||||
|
||||
d = self.schema
|
||||
d['$def']['backends_items'] = r1
|
||||
d['$def']['rules_items'] = r2
|
||||
d['$def']['backends_config'] = None
|
||||
d['$def']['rules_config'] = None
|
||||
d['patternProperties']['.*']['properties'] ['tree']['items']['properties'] = r1
|
||||
d['patternProperties']['.*']['properties'] ['tree']['items'] = r2
|
||||
|
||||
#pprint(d)
|
||||
print(json.dumps(d, indent=2))
|
||||
|
||||
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
|
||||
import dpath.util
|
||||
|
||||
import copy
|
||||
import json
|
||||
import textwrap
|
||||
@ -47,37 +49,32 @@ class LoadPlugin():
|
||||
class Manager():
|
||||
|
||||
plugins_kind = []
|
||||
|
||||
_schema_props_default = {}
|
||||
_schema_props_default = {}
|
||||
_schema_props_default = None
|
||||
|
||||
@classmethod
|
||||
def get_schema(cls, plugins_db):
|
||||
pprint (cls.plugins_kind)
|
||||
|
||||
ret = {}
|
||||
ret3 = []
|
||||
|
||||
# Properties
|
||||
ret3 = {}
|
||||
for kind in cls.plugins_kind:
|
||||
ret[kind] = {}
|
||||
# ret[kind] = {}
|
||||
plugin_kind = getattr(plugins_db, kind)
|
||||
|
||||
for plugin_name in [i for i in dir(plugin_kind) if not i.startswith('_')]:
|
||||
plugin = getattr(plugin_kind, plugin_name)
|
||||
print (plugin.Plugin)
|
||||
#pprint (dir(plugin))
|
||||
plugin_cls = getattr(plugin, 'Plugin', None)
|
||||
if plugin_cls:
|
||||
schema_props = getattr(plugin_cls, '_schema_props_new', 'MISSING ITEM')
|
||||
if schema_props:
|
||||
ret[kind][plugin_name] = schema_props
|
||||
print (plugin_name)
|
||||
ret3.append( schema_props )
|
||||
|
||||
ret3.append( cls._schema_props_new )
|
||||
# ret[kind][plugin_name] = schema_props
|
||||
ret3.update( schema_props )
|
||||
ret3.update( cls._schema_props_new )
|
||||
|
||||
# Injection
|
||||
ret1 = cls._schema_props_default
|
||||
ret1["$def"]["items"] = ret3
|
||||
position = cls._props_position
|
||||
dpath.util.set(ret1, position, ret3)
|
||||
|
||||
return ret1
|
||||
|
||||
|
||||
@ -95,25 +92,30 @@ class BackendsManager(Manager):
|
||||
"default": 'UNSET',
|
||||
"optional": False,
|
||||
},
|
||||
#### INSERT HERE SUBSCHEMA !!!!!
|
||||
}
|
||||
|
||||
_props_position = 'oneOf/0/properties'
|
||||
_schema_props_default = {
|
||||
"$schema": 'http://json-schema.org/draft-04/schema#',
|
||||
"$schema": 'http://json-schema.org/draft-07/schema#',
|
||||
"default": "",
|
||||
"$def": {
|
||||
"items": {},
|
||||
},
|
||||
# This does not work :(
|
||||
#"$def": {
|
||||
# "props": {},
|
||||
# },
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "string",
|
||||
"default": "BLAAAAHHH"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"additionalProperties": True,
|
||||
"default": {},
|
||||
"properties": { "$ref": "#/$defs/name" },
|
||||
"title": "object",
|
||||
"properties": {},
|
||||
"description": "Object to configure a bacjend item",
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"default": "BLAAAAHHH",
|
||||
"title": "string",
|
||||
"description": "Enter a simple string configuration value for default engine",
|
||||
},
|
||||
]
|
||||
}
|
||||
@ -251,8 +253,9 @@ class RulesManager(Manager):
|
||||
},
|
||||
}
|
||||
|
||||
_props_position = 'oneOf/1/properties'
|
||||
_schema_props_default = {
|
||||
"$schema": 'http://json-schema.org/draft-04/schema#',
|
||||
"$schema": 'http://json-schema.org/draft-07/schema#',
|
||||
"default": "",
|
||||
"$def": {
|
||||
"items": {},
|
||||
@ -272,7 +275,7 @@ class RulesManager(Manager):
|
||||
}
|
||||
|
||||
OLD_rule_schema = {
|
||||
"$schema": 'http://json-schema.org/draft-04/schema#',
|
||||
"$schema": 'http://json-schema.org/draft-07/schema#',
|
||||
"type": "object",
|
||||
"additionalProperties": False,
|
||||
"properties": {
|
||||
|
||||
@ -14,38 +14,107 @@ import textwrap
|
||||
class Plugin(PluginBackendClass):
|
||||
|
||||
_plugin_name = "loop"
|
||||
_plugin_help = """
|
||||
This module helps to loop over a backend
|
||||
""",
|
||||
_schema_props_new = {
|
||||
"loop": {
|
||||
"description": _plugin_help,
|
||||
"default": None,
|
||||
"optional": True,
|
||||
"examples": [
|
||||
{
|
||||
"value": "site/{{ loop_env }}/config/{{ os }}",
|
||||
"loop": {
|
||||
"var": "loop_env",
|
||||
"data": [
|
||||
"dev",
|
||||
"preprod",
|
||||
"prod",
|
||||
],
|
||||
},
|
||||
"comment": "The module will loop three time over the value, and the variable `loop_env` will consecutely have `dev`, `preprod` and `prod` as value",
|
||||
},
|
||||
{
|
||||
"value": "site/{{ loop_env2 }}/config/{{ os }}",
|
||||
"loop": {
|
||||
"var": "loop_env2",
|
||||
"data": "my_scope_var",
|
||||
},
|
||||
"comment": "Like the previous example, but it will fetch the list from any scope variables",
|
||||
},
|
||||
{
|
||||
"loop": None,
|
||||
"comment": "Disable this module, no loop will operate",
|
||||
},
|
||||
|
||||
|
||||
# "loop": {
|
||||
# "var": "my_var",
|
||||
# },
|
||||
# },
|
||||
# "loop": {
|
||||
# "var": "my_var",
|
||||
# },
|
||||
# "example": "",
|
||||
# },
|
||||
# "loop": {
|
||||
# "var": "my_var",
|
||||
# },
|
||||
# "example": "",
|
||||
# },
|
||||
],
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "null",
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"additionalProperties": True,
|
||||
"additionalProperties": False,
|
||||
"default": {},
|
||||
"title": "Complete config",
|
||||
"description": "",
|
||||
|
||||
"properties": {
|
||||
"data": {
|
||||
"default": None,
|
||||
"optional": False,
|
||||
"title": "Module configuration",
|
||||
"description": "Data list used for iterations. It only accept lists as type. It disable the module if set to `null`.",
|
||||
"anyOf":[
|
||||
{"type": "null"},
|
||||
{"type": "string"},
|
||||
{"type": "array"},
|
||||
{
|
||||
"type": "null",
|
||||
"title": "Disable Module",
|
||||
"description": "Disable the module",
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"title": "Scope variable",
|
||||
"description": "Will look the value of the loop list from the scope. TOFIX: What if variablle does not exists?",
|
||||
},
|
||||
{
|
||||
"type": "array",
|
||||
"title": "Hardcoded list",
|
||||
"description": "Simply enter the list of value to be iterated to.",
|
||||
},
|
||||
]
|
||||
},
|
||||
"var": {
|
||||
"type": "string",
|
||||
"default": "loop_item",
|
||||
"optional": True,
|
||||
"title": "Module configuration",
|
||||
"description": "Name of the variable to be used in templating language",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"title": "Short config",
|
||||
"description": "If set to string, it will define the name of the variable to lookup into the scope.",
|
||||
},
|
||||
{
|
||||
"type": "null",
|
||||
"title": "Disable",
|
||||
"description": "If set to null, it disable the module",
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@ -149,7 +149,7 @@ class PluginEngineClass(PluginClass):
|
||||
schema = getattr(self, key)
|
||||
props.update(schema)
|
||||
self.schema = {
|
||||
"$schema": 'http://json-schema.org/draft-04/schema#',
|
||||
"$schema": 'http://json-schema.org/draft-07/schema#',
|
||||
"type": "object",
|
||||
"additionalProperties": True,
|
||||
"properties": props,
|
||||
|
||||
@ -54,7 +54,7 @@ class Plugin(PluginStrategyClass):
|
||||
}
|
||||
|
||||
default_merge_schema = {
|
||||
"$schema": 'http://json-schema.org/draft-04/schema#',
|
||||
"$schema": 'http://json-schema.org/draft-07/schema#',
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "array",
|
||||
|
||||
@ -12,6 +12,7 @@ jsonmerge = "^1.8.0"
|
||||
anyconfig = "^0.12.0"
|
||||
python-box = "^5.4.1"
|
||||
prettytable = "^3.0.0"
|
||||
dpath = "^2.0.5"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
json-schema-for-humans = "^0.40"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user