Lint: plugin.common
This commit is contained in:
parent
b01baf44ad
commit
94662df00a
@ -1,49 +1,43 @@
|
||||
# from box import Box
|
||||
import textwrap
|
||||
from pprint import pprint
|
||||
import glob
|
||||
from pathlib import Path
|
||||
from jinja2 import Template
|
||||
import yaml
|
||||
import json
|
||||
"""Common libraries for plugins"""
|
||||
|
||||
import logging
|
||||
from kheops.utils import schema_validate
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
from kheops.utils import schema_validate
|
||||
import copy
|
||||
|
||||
# Candidate Classes
|
||||
# =============================
|
||||
class Candidate:
|
||||
engine = None
|
||||
found = False
|
||||
data = None
|
||||
run = None
|
||||
scope = None
|
||||
key = None
|
||||
|
||||
def __init__(self, run):
|
||||
self.run = copy.deepcopy(run)
|
||||
|
||||
def __repr__(self):
|
||||
return f"{self.__dict__}"
|
||||
|
||||
def _report_data(self, data=None):
|
||||
default_data = {
|
||||
# "rule": self.config,
|
||||
"value": self.engine._plugin_value,
|
||||
"data": self.data,
|
||||
}
|
||||
data = data or default_data
|
||||
d = json.dumps(data, indent=2) # , sort_keys=True, )
|
||||
return d
|
||||
# class Candidate:
|
||||
# engine = None
|
||||
# found = False
|
||||
# data = None
|
||||
# run = None
|
||||
# scope = None
|
||||
# key = None
|
||||
#
|
||||
# def __init__(self, run):
|
||||
# self.run = copy.deepcopy(run)
|
||||
#
|
||||
# def __repr__(self):
|
||||
# return f"{self.__dict__}"
|
||||
#
|
||||
# def _report_data(self, data=None):
|
||||
# default_data = {
|
||||
# # "rule": self.config,
|
||||
# "value": self.engine._plugin_value,
|
||||
# "data": self.data,
|
||||
# }
|
||||
# data = data or default_data
|
||||
# data = json.dumps(data, indent=2) # , sort_keys=True, )
|
||||
# return data
|
||||
|
||||
|
||||
# Generic Classes
|
||||
# =============================
|
||||
class PluginClass:
|
||||
"""Generic plugin class"""
|
||||
|
||||
_plugin_type = "none"
|
||||
_plugin_value = None
|
||||
|
||||
@ -52,7 +46,6 @@ class PluginClass:
|
||||
_schema_props_plugin = {
|
||||
"engine": {
|
||||
"type": "string",
|
||||
# TODO: Fix this ug
|
||||
"default": "jerakia",
|
||||
},
|
||||
"value": {},
|
||||
@ -81,6 +74,8 @@ class PluginClass:
|
||||
|
||||
|
||||
class PluginBackendClass(PluginClass):
|
||||
"""Backend plugin class"""
|
||||
|
||||
_plugin_type = "backend"
|
||||
|
||||
def _init(self):
|
||||
@ -88,6 +83,8 @@ class PluginBackendClass(PluginClass):
|
||||
|
||||
|
||||
class PluginStrategyClass(PluginClass):
|
||||
"""Strategy plugin class"""
|
||||
|
||||
_plugin_type = "strategy"
|
||||
|
||||
def _init(self):
|
||||
@ -95,6 +92,8 @@ class PluginStrategyClass(PluginClass):
|
||||
|
||||
|
||||
class PluginEngineClass(PluginClass):
|
||||
"""Engine plugin class"""
|
||||
|
||||
_plugin_type = "engine"
|
||||
|
||||
_schema_props_default = {
|
||||
@ -132,20 +131,22 @@ class PluginEngineClass(PluginClass):
|
||||
|
||||
# Public Methods
|
||||
# =====================
|
||||
def dump(self):
|
||||
def dump(self) -> dict:
|
||||
"""Dump plugin configuration"""
|
||||
|
||||
ret = {
|
||||
"config": self.config,
|
||||
}
|
||||
return ret
|
||||
|
||||
def lookup_candidates(self, key=None, scope=None):
|
||||
raise Exception(f"Module does not implement this method :(")
|
||||
def lookup_candidates(self, key=None, scope=None) -> list:
|
||||
"""Placeholder to return candidates"""
|
||||
raise Exception("Module does not implement this method :(")
|
||||
# It must always return a list of `Candidate` instances
|
||||
return []
|
||||
|
||||
def _example(self):
|
||||
print(f"Module does not implement this method :(")
|
||||
return None
|
||||
# def _example(self):
|
||||
# print(f"Module does not implement this method :(")
|
||||
# return None
|
||||
|
||||
|
||||
# File plugins Extensions
|
||||
@ -153,6 +154,7 @@ class PluginEngineClass(PluginClass):
|
||||
|
||||
|
||||
class PluginFileGlob:
|
||||
"""Provide glob functionnality"""
|
||||
|
||||
_schema_props_glob = {
|
||||
"glob": {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user