From c95aab3ca3feefb0648954e742f6fc02e4c0e989 Mon Sep 17 00:00:00 2001 From: Chris Farhood Date: Wed, 11 Feb 2026 13:35:35 -0500 Subject: [PATCH] feat: add full URL support for custom Polaris dashboards - Add isFullUrl() helper to detect full vs proxy URLs - Support both K8s proxy URLs and direct HTTP/HTTPS URLs - Use fetch() for full URLs, ApiProxy for K8s proxy URLs - Improve error messages with context-specific guidance - Update settings with examples for both URL types - Version bump to 0.2.3 Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude Co-Authored-By: Happy --- artifacthub-pkg.yml | 6 ++-- package.json | 2 +- src/api/polaris.ts | 52 ++++++++++++++++++++++++------ src/components/PolarisSettings.tsx | 33 +++++++++++-------- 4 files changed, 66 insertions(+), 27 deletions(-) diff --git a/artifacthub-pkg.yml b/artifacthub-pkg.yml index 856b253..30e9338 100644 --- a/artifacthub-pkg.yml +++ b/artifacthub-pkg.yml @@ -1,4 +1,4 @@ -version: 0.2.2 +version: 0.2.3 name: headlamp-polaris-plugin displayName: Polaris createdAt: "2026-02-05T19:00:00Z" @@ -28,7 +28,7 @@ maintainers: - name: cpfarhood email: "chris@farhood.org" annotations: - headlamp/plugin/archive-url: "https://github.com/cpfarhood/headlamp-polaris-plugin/releases/download/v0.2.2/headlamp-polaris-plugin-0.2.2.tar.gz" + headlamp/plugin/archive-url: "https://github.com/cpfarhood/headlamp-polaris-plugin/releases/download/v0.2.3/headlamp-polaris-plugin-0.2.3.tar.gz" headlamp/plugin/version-compat: ">=0.26" - headlamp/plugin/archive-checksum: sha256:22400516eed9645e463873e7a5ab6c2dab8bfa8fca8a51bb51b0475079ca8c83 + headlamp/plugin/archive-checksum: sha256:0000000000000000000000000000000000000000000000000000000000000000 headlamp/plugin/distro-compat: in-cluster diff --git a/package.json b/package.json index c35033d..2c1fabd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "headlamp-polaris-plugin", - "version": "0.2.2", + "version": "0.2.3", "description": "Headlamp plugin for Fairwinds Polaris audit results", "scripts": { "start": "headlamp-plugin start", diff --git a/src/api/polaris.ts b/src/api/polaris.ts index ad8bbb1..6271414 100644 --- a/src/api/polaris.ts +++ b/src/api/polaris.ts @@ -178,6 +178,10 @@ function getPolarisApiPath(): string { return baseUrl.endsWith('/') ? `${baseUrl}results.json` : `${baseUrl}/results.json`; } +function isFullUrl(url: string): boolean { + return url.startsWith('http://') || url.startsWith('https://'); +} + interface PolarisDataState { data: AuditData | null; loading: boolean; @@ -195,7 +199,21 @@ export function usePolarisData(refreshIntervalSeconds: number): PolarisDataState async function fetchData() { try { - const result: AuditData = await ApiProxy.request(getPolarisApiPath()); + const apiPath = getPolarisApiPath(); + let result: AuditData; + + if (isFullUrl(apiPath)) { + // Direct fetch for full URLs + const response = await fetch(apiPath); + if (!response.ok) { + throw new Error(`HTTP ${response.status}: ${response.statusText}`); + } + result = await response.json(); + } else { + // Kubernetes proxy for relative URLs + result = await ApiProxy.request(apiPath); + } + if (!cancelled) { setData(result); setError(null); @@ -203,17 +221,31 @@ export function usePolarisData(refreshIntervalSeconds: number): PolarisDataState } } catch (err: unknown) { if (cancelled) return; + const apiPath = getPolarisApiPath(); const status = (err as { status?: number }).status; - if (status === 403) { - setError( - 'Access denied (403). Check that your RBAC permissions allow proxying to the Polaris service.' - ); - } else if (status === 404 || status === 503) { - setError( - 'Polaris dashboard not reachable. Ensure Polaris is installed in the polaris namespace.' - ); + + if (isFullUrl(apiPath)) { + // Full URL errors + if (status === 403) { + setError('Access denied (403). Check authentication and CORS configuration.'); + } else if (status === 404) { + setError('Polaris dashboard not found (404). Verify the URL is correct.'); + } else { + setError(`Failed to fetch from ${apiPath}: ${String(err)}`); + } } else { - setError(`Failed to fetch Polaris data: ${String(err)}`); + // Kubernetes proxy errors + if (status === 403) { + setError( + 'Access denied (403). Check that your RBAC permissions allow proxying to the Polaris service.' + ); + } else if (status === 404 || status === 503) { + setError( + 'Polaris dashboard not reachable. Ensure Polaris is installed in the configured namespace.' + ); + } else { + setError(`Failed to fetch Polaris data: ${String(err)}`); + } } setLoading(false); } diff --git a/src/components/PolarisSettings.tsx b/src/components/PolarisSettings.tsx index c7e3fd2..85413ef 100644 --- a/src/components/PolarisSettings.tsx +++ b/src/components/PolarisSettings.tsx @@ -43,19 +43,26 @@ export default function PolarisSettings(props: PluginSettingsProps) { { name: 'Dashboard URL', value: ( - +
+ +
+ Examples:
+ • K8s proxy: /api/v1/namespaces/polaris/services/polaris-dashboard:80/proxy/
+ • Full URL: https://my-polaris.example.com +
+
), }, ]}