Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F24682637
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/tools/nasqueron-reports/src/nasqueron_reports/actions/reports.py b/tools/nasqueron-reports/src/nasqueron_reports/actions/reports.py
index 9ce8117..755dbba 100644
--- a/tools/nasqueron-reports/src/nasqueron_reports/actions/reports.py
+++ b/tools/nasqueron-reports/src/nasqueron_reports/actions/reports.py
@@ -1,67 +1,69 @@
# -------------------------------------------------------------
# Nasqueron Reports :: Actions :: Reports
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Project: Nasqueron
# Description: Generate a report
# License: BSD-2-Clause
# -------------------------------------------------------------
from nasqueron_reports import Report
from nasqueron_reports.connectors import db_mysql
from nasqueron_reports.formats import mediawiki
from nasqueron_reports.errors import *
# -------------------------------------------------------------
# Action
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def generate_report(report_config):
connector_cb, format_cb = wire(report_config)
# Fetch the data for the report
report = Report()
report.raw.headers, report.raw.rows = connector_cb(report_config)
# Format
format_options = report_config["format_options"]
report.formatted = format_cb(report.raw, format_options)
return report
# -------------------------------------------------------------
# Wiring
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CONNECTORS_MAP = {
"MariaDB": db_mysql.fetch_report,
"MySQL": db_mysql.fetch_report,
}
FORMATS_MAP = {
"mediawiki": mediawiki.to_table,
}
def wire(report_config):
if "connector" not in report_config["service_options"]:
service_name = report_config["service"]
- raise NasqueronReportConfigError(f"Service connector missing in configuration for service {service_name}")
+ raise NasqueronReportConfigError(
+ f"Service connector missing in configuration for service {service_name}"
+ )
if "format" not in report_config:
raise NasqueronReportConfigError(f"Format missing in report configuration")
report_connector = report_config["service_options"]["connector"]
if report_connector not in CONNECTORS_MAP:
raise NasqueronReportConfigError(f"Unknown connector: {report_connector}")
report_format = report_config["format"]
if report_format not in FORMATS_MAP:
raise NasqueronReportConfigError(f"Unknown format: {report_format}")
return CONNECTORS_MAP[report_connector], FORMATS_MAP[report_format]
diff --git a/tools/nasqueron-reports/src/nasqueron_reports/config.py b/tools/nasqueron-reports/src/nasqueron_reports/config.py
index 980b1de..2a60534 100644
--- a/tools/nasqueron-reports/src/nasqueron_reports/config.py
+++ b/tools/nasqueron-reports/src/nasqueron_reports/config.py
@@ -1,110 +1,114 @@
# -------------------------------------------------------------
# Nasqueron Reports :: Config
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Project: Nasqueron
# Description: Reports configuration
# License: BSD-2-Clause
# -------------------------------------------------------------
import os
import yaml
from nasqueron_reports.credentials import resolve_credentials
from nasqueron_reports.errors import NasqueronReportConfigError
# -------------------------------------------------------------
# Configuration paths
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
DEFAULT_CONFIG_PATHS = [
"conf/reports.yaml",
".reports.yaml",
"/usr/local/etc/reports.yaml",
"/etc/reports.yaml",
]
DEFAULT_SQL_PATHS = [
".",
"/usr/local/share/nasqueron-reports",
- "/usr/share/nasqueron-reports"
+ "/usr/share/nasqueron-reports",
]
def get_config_path():
for config_path in DEFAULT_CONFIG_PATHS:
if os.path.exists(config_path):
return config_path
return None
def resolve_sql_path(sql_path):
for sql_directory in DEFAULT_SQL_PATHS:
full_path = os.path.join(sql_directory, sql_path)
if os.path.exists(full_path):
return full_path
return sql_path
# -------------------------------------------------------------
# Main configuration
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_config():
config_path = get_config_path()
if not config_path:
- raise NasqueronReportConfigError("You need to create a reports.yaml config file")
+ raise NasqueronReportConfigError(
+ "You need to create a reports.yaml config file"
+ )
with open(config_path) as fd:
config = yaml.safe_load(fd)
return config
# -------------------------------------------------------------
# Report configuration
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def inject_service_config(config, report_config):
try:
service_name = report_config["service"]
except KeyError:
raise NasqueronReportConfigError(
f"Service parameter missing in report configuration"
)
try:
report_config["service_options"] = config["services"][service_name]
except KeyError:
raise NasqueronReportConfigError(
f"Service not declared in configuration: {service_name}"
)
if "credentials" in report_config["service_options"]:
- credentials = resolve_credentials(report_config["service_options"]["credentials"])
+ credentials = resolve_credentials(
+ config, report_config["service_options"]["credentials"]
+ )
else:
credentials = {}
report_config["service_options"]["credentials"] = credentials
def parse_report_config(report_name):
config = get_config()
try:
report_config = config["reports"][report_name]
except KeyError:
raise NasqueronReportConfigError(f"Report not found: {report_name}")
inject_service_config(config, report_config)
return report_config
diff --git a/tools/nasqueron-reports/src/nasqueron_reports/credentials/credentials.py b/tools/nasqueron-reports/src/nasqueron_reports/credentials/credentials.py
index fe1df8c..c45c436 100644
--- a/tools/nasqueron-reports/src/nasqueron_reports/credentials/credentials.py
+++ b/tools/nasqueron-reports/src/nasqueron_reports/credentials/credentials.py
@@ -1,38 +1,38 @@
# -------------------------------------------------------------
# Nasqueron Reports :: Credentials :: Vault
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Project: Nasqueron
# Description: Read credentials from Vault or OpenBao
# License: BSD-2-Clause
# -------------------------------------------------------------
import os
from nasqueron_reports.credentials import vault
from nasqueron_reports.errors import NasqueronReportConfigError
# -------------------------------------------------------------
# Credentials wiring
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def resolve_credentials(config):
if config["driver"] == "vault":
return vault.fetch_credentials(config["secret"])
if config["driver"] == "env":
variables = config.get("variables", {})
return read_environment(variables)
raise NasqueronReportConfigError("Credentials driver parameter is missing")
# -------------------------------------------------------------
# Environment
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def read_environment(variables):
- return {k:os.environ.get(v, "") for k, v in variables.items()}
+ return {k: os.environ.get(v, "") for k, v in variables.items()}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Mar 7, 01:39 (6 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3486648
Default Alt Text
(7 KB)
Attached To
Mode
rRPRT Nasqueron internal reports
Attached
Detach File
Event Timeline
Log In to Comment