Page MenuHomeDevCentral

No OneTemporary

diff --git a/tools/nasqueron-reports/Dockerfile b/tools/nasqueron-reports/Dockerfile
new file mode 100644
index 0000000..e960edf
--- /dev/null
+++ b/tools/nasqueron-reports/Dockerfile
@@ -0,0 +1,41 @@
+# -------------------------------------------------------------
+# Nasqueron Reports :: Docker image
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# License: BSD-2-Clause
+# -------------------------------------------------------------
+
+# -------------------------------------------------------------
+# Build Python package
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+FROM debian:trixie AS build
+
+COPY . /app
+WORKDIR /app
+RUN apt-get update && apt install -y python3-pip python3-build git && \
+ git clone https://devcentral.nasqueron.org/source/reports.git /usr/src/reports && \
+ python3 -m build
+
+# -------------------------------------------------------------
+# Final image
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+FROM debian:trixie AS runner
+
+COPY --from=build /app/dist/nasqueron_reports-0.1.0-py3-none-any.whl /app/
+COPY --from=build /usr/src/reports/sql /usr/share/nasqueron-reports/sql
+COPY conf/reports.yaml /etc/reports.yaml
+
+RUN apt-get update && \
+ apt install -y python3-pip locales --no-install-recommends && \
+ rm -r /var/lib/apt/lists/* && \
+ sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
+ echo 'LANG="en_US.UTF-8"' > /etc/default/locale && \
+ dpkg-reconfigure --frontend=noninteractive locales && \
+ update-locale LANG=en_US.UTF-8 && \
+ pip install /app/nasqueron_reports-0.1.0-py3-none-any.whl --break-system-packages
+
+WORKDIR /app
+ENV LANG=en_US.UTF-8
+CMD ["run-report"]
diff --git a/tools/nasqueron-reports/conf/reports.yaml b/tools/nasqueron-reports/conf/reports.yaml
index 48928e2..da9360e 100644
--- a/tools/nasqueron-reports/conf/reports.yaml
+++ b/tools/nasqueron-reports/conf/reports.yaml
@@ -1,23 +1,48 @@
# -------------------------------------------------------------
# Reports configuration
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Project: Nasqueron
# -------------------------------------------------------------
services:
+ acquisitariat:
+ connector: MySQL
+ hostname: mysql
+ credentials:
+ driver: env
+ variables:
+ username: DB_USERNAME
+ password: DB_PASSWORD
+
db-B:
connector: MariaDB
hostname: db-B-001
- credentials: ops/secrets/dbserver/cluster-B/users/rhyne-wyse
+ credentials:
+ driver: vault
+ secret: ops/secrets/dbserver/cluster-B/users/rhyne-wyse
reports:
agora-operations-grimoire-older-pages:
path: sql/db-B/agora/operations-grimoire-older-pages.sql
service: db-B
format: mediawiki
format_options:
# Mapping between query columns and table headings
cols:
page_link: Article
age: Age (days)
+
+ devcentral-tokens-language-models:
+ path: sql/acquisitariat/devcentral/tokens-language-models.sql
+ service: acquisitariat
+
+ format: mediawiki
+ format_options:
+ # Mapping between query columns and table headings
+ cols:
+ revision: Revision
+ title: Commit title
+ date: Date
+ userName: Author
+ repository: Repository
diff --git a/tools/nasqueron-reports/src/nasqueron_reports/config.py b/tools/nasqueron-reports/src/nasqueron_reports/config.py
index 56a6541..980b1de 100644
--- a/tools/nasqueron-reports/src/nasqueron_reports/config.py
+++ b/tools/nasqueron-reports/src/nasqueron_reports/config.py
@@ -1,111 +1,110 @@
# -------------------------------------------------------------
# Nasqueron Reports :: Config
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Project: Nasqueron
# Description: Reports configuration
# License: BSD-2-Clause
# -------------------------------------------------------------
import os
import yaml
-from nasqueron_reports.credentials import vault
+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"
]
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")
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"]:
- secret_path = report_config["service_options"]["credentials"]
- credentials = vault.fetch_credentials(secret_path)
+ credentials = resolve_credentials(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/__init__.py b/tools/nasqueron-reports/src/nasqueron_reports/credentials/__init__.py
index 9c4bc8e..92fc6b2 100644
--- a/tools/nasqueron-reports/src/nasqueron_reports/credentials/__init__.py
+++ b/tools/nasqueron-reports/src/nasqueron_reports/credentials/__init__.py
@@ -1,8 +1,9 @@
# -------------------------------------------------------------
# Nasqueron Reports :: Credentials
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Project: Nasqueron
# License: BSD-2-Clause
# -------------------------------------------------------------
+from .credentials import resolve_credentials
from . import vault
diff --git a/tools/nasqueron-reports/src/nasqueron_reports/credentials/credentials.py b/tools/nasqueron-reports/src/nasqueron_reports/credentials/credentials.py
new file mode 100644
index 0000000..fe1df8c
--- /dev/null
+++ b/tools/nasqueron-reports/src/nasqueron_reports/credentials/credentials.py
@@ -0,0 +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()}

File Metadata

Mime Type
text/x-diff
Expires
Sun, Oct 12, 05:23 (20 h, 40 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3065148
Default Alt Text
(8 KB)

Event Timeline