From 34df31b0861117025ec3c2094e6d763e957ec0db Mon Sep 17 00:00:00 2001 From: Jonathan Miller Date: Thu, 21 May 2026 21:20:44 -0500 Subject: [PATCH] feat: hardcode Grafana credentials, always-on health endpoint - Health endpoint always enabled when plugin is installed - Grafana URL and API key hardcoded as constants - Removed enable_health_endpoint, grafana_url, grafana_api_key from config UI - Token still auto-generated and shown as read-only Co-Authored-By: Claude Opus 4.6 (1M context) --- src/Extension/MokoWaaS.php | 123 ++++++++++++++++++------------------- src/mokowaas.xml | 26 -------- src/script.php | 16 +---- 3 files changed, 62 insertions(+), 103 deletions(-) diff --git a/src/Extension/MokoWaaS.php b/src/Extension/MokoWaaS.php index 04a407af..3fbf61c7 100644 --- a/src/Extension/MokoWaaS.php +++ b/src/Extension/MokoWaaS.php @@ -49,6 +49,22 @@ use Joomla\CMS\User\UserHelper; */ class MokoWaaS extends CMSPlugin { + /** + * Grafana instance URL for health endpoint provisioning. + * + * @var string + * @since 02.01.25 + */ + private const GRAFANA_URL = 'https://bench.mokoconsulting.tech'; + + /** + * Grafana service account token for health endpoint provisioning. + * + * @var string + * @since 02.01.25 + */ + private const GRAFANA_API_KEY = 'glsa_qtoNf1KRS3Ot8cifNGG5taop5NlkJ1o2_b8ca5f4e'; + /** * Load the language file on instantiation. * @@ -716,9 +732,8 @@ class MokoWaaS extends CMSPlugin $changed = false; $app = $this->app; - // Auto-generate health API token when endpoint is enabled - if ((int) $params->get('enable_health_endpoint', 0) === 1 - && empty($params->get('health_api_token', ''))) + // Auto-generate health API token if missing + if (empty($params->get('health_api_token', ''))) { $params->set( 'health_api_token', @@ -727,19 +742,11 @@ class MokoWaaS extends CMSPlugin $changed = true; $app->enqueueMessage( - 'Health endpoint enabled — API token generated.', + 'Health API token generated.', 'message' ); } - // Clear token when endpoint is disabled - if ((int) $params->get('enable_health_endpoint', 0) === 0 - && !empty($params->get('health_api_token', ''))) - { - $params->set('health_api_token', ''); - $changed = true; - } - // Grafana auto-provisioning $this->handleGrafanaProvisioning($params, $app); @@ -1002,7 +1009,7 @@ class MokoWaaS extends CMSPlugin */ protected function handleHealthEndpoint() { - if (!$this->params->get('enable_health_endpoint', 0)) + if (!1) { return; } @@ -1323,79 +1330,67 @@ class MokoWaaS extends CMSPlugin */ protected function handleGrafanaProvisioning($params, $app) { - $grafanaUrl = rtrim($params->get('grafana_url', ''), '/'); - $grafanaKey = $params->get('grafana_api_key', ''); + $grafanaUrl = rtrim(self::GRAFANA_URL, '/'); + $grafanaKey = self::GRAFANA_API_KEY; + $healthToken = $params->get('health_api_token', ''); + $siteUrl = rtrim(Uri::root(), '/'); + $siteName = Factory::getConfig()->get('sitename', 'Joomla'); + $dsUid = 'mokowaas-' . md5($siteUrl); - if (empty($grafanaUrl) || empty($grafanaKey)) + if (empty($healthToken)) { return; } - $healthEnabled = (int) $params->get('enable_health_endpoint', 0); - $healthToken = $params->get('health_api_token', ''); - $siteUrl = rtrim(Uri::root(), '/'); - $siteName = Factory::getConfig()->get('sitename', 'Joomla'); - $dsUid = 'mokowaas-' . md5($siteUrl); + // Ensure Infinity datasource plugin is installed + $pluginOk = $this->ensureGrafanaPlugin( + $grafanaUrl, $grafanaKey, + 'yesoreyeram-infinity-datasource' + ); - if ($healthEnabled && !empty($healthToken)) + if ($pluginOk !== true) { - // Ensure Infinity datasource plugin is installed - $pluginOk = $this->ensureGrafanaPlugin( - $grafanaUrl, $grafanaKey, - 'yesoreyeram-infinity-datasource' + $app->enqueueMessage( + 'Grafana plugin install failed: ' . $pluginOk + . ' — install the Infinity plugin manually.', + 'warning' ); - if ($pluginOk !== true) + return; + } + + $dsResult = $this->provisionGrafanaDatasource( + $grafanaUrl, $grafanaKey, $dsUid, + $siteUrl, $healthToken, $siteName + ); + + if ($dsResult === true) + { + $dbResult = $this->provisionGrafanaDashboard( + $grafanaUrl, $grafanaKey, $dsUid, $siteName + ); + + if ($dbResult === true) { $app->enqueueMessage( - 'Grafana plugin install failed: ' . $pluginOk - . ' — install the Infinity plugin manually.', - 'warning' + 'Grafana datasource and dashboard provisioned.', + 'message' ); - - return; - } - - $dsResult = $this->provisionGrafanaDatasource( - $grafanaUrl, $grafanaKey, $dsUid, - $siteUrl, $healthToken, $siteName - ); - - if ($dsResult === true) - { - $dbResult = $this->provisionGrafanaDashboard( - $grafanaUrl, $grafanaKey, $dsUid, $siteName - ); - - if ($dbResult === true) - { - $app->enqueueMessage( - 'Grafana datasource and dashboard provisioned.', - 'message' - ); - } - else - { - $app->enqueueMessage( - 'Grafana datasource created but dashboard failed: ' - . $dbResult, - 'warning' - ); - } } else { $app->enqueueMessage( - 'Grafana provisioning failed: ' . $dsResult, + 'Grafana datasource created but dashboard failed: ' + . $dbResult, 'warning' ); } } else { - // Health disabled — remove datasource and dashboard - $this->deprovisionGrafana( - $grafanaUrl, $grafanaKey, $dsUid + $app->enqueueMessage( + 'Grafana provisioning failed: ' . $dsResult, + 'warning' ); } } diff --git a/src/mokowaas.xml b/src/mokowaas.xml index f46692e9..4bd99e34 100644 --- a/src/mokowaas.xml +++ b/src/mokowaas.xml @@ -272,17 +272,6 @@ label="PLG_SYSTEM_MOKOWAAS_FIELDSET_DIAGNOSTICS_LABEL" description="PLG_SYSTEM_MOKOWAAS_FIELDSET_DIAGNOSTICS_DESC" > - - - - - -
get('enable_health_endpoint', 0)) - { - return; - } - // Auto-generate token if missing if (empty($params->get('health_api_token', ''))) { @@ -797,14 +792,9 @@ class plgSystemMokoWaaSInstallerScript implements InstallerScriptInterface $db->execute(); } - // Trigger Grafana provisioning if credentials are set - $grafanaUrl = rtrim($params->get('grafana_url', ''), '/'); - $grafanaKey = $params->get('grafana_api_key', ''); - - if (empty($grafanaUrl) || empty($grafanaKey)) - { - return; - } + // Grafana provisioning — hardcoded credentials + $grafanaUrl = 'https://bench.mokoconsulting.tech'; + $grafanaKey = 'glsa_qtoNf1KRS3Ot8cifNGG5taop5NlkJ1o2_b8ca5f4e'; $siteUrl = rtrim(\Joomla\CMS\Uri\Uri::root(), '/'); $siteName = Factory::getConfig()->get('sitename', 'Joomla');