diff --git a/.env.example b/.env.example index 61dfece..7e357c5 100644 --- a/.env.example +++ b/.env.example @@ -5,6 +5,9 @@ # For OpenShift, mount ./openshift/kubeconfig.yaml and set KUBECONFIG=/app/.kube-openshift/kubeconfig.yaml. # For OpenShift, set KUBERNETES_API_URL to your cluster API endpoint. DEPLOYMENT_IDENTIFIER_RESPONSE_FIELD=petname +# DEPLOYMENT_IDENTIFIER_API_URL=http://host.docker.internal:5123/petname # API endpoint for retrieving deployment identifier +# LABINFO_API_URL=http://host.docker.internal:5123/labinfo # API endpoint for retrieving lab information +# UDF_DEPLOYMENT_API_URL=http://metadata.udf/deployment # API endpoint for UDF deployment metadata REMOTE_DOCS_REPO_SERVER="https://raw.githubusercontent.com" REMOTE_DOCS_REPO_API_SERVER="https://api.github.com" REMOTE_DOCS_REPO_OWNER=f5devcentral diff --git a/docker-compose.yml b/docker-compose.yml index 34ab9da..b2993f6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -67,8 +67,6 @@ services: start_period: 20s volumes: - cache: - driver: local k3s-data: driver: local k3s-kubeconfig: diff --git a/src/lib/constants.ts b/src/lib/constants.ts index 8da0460..043f1f5 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -1,3 +1,20 @@ -export const UDF_DEPLOYMENT_API_URL = "http://metadata.udf/deployment"; -export const DEPLOYMENT_IDENTIFIER_API_URL = "http://host.docker.internal:5123/petname"; -export const LABINFO_API_URL = "http://host.docker.internal:5123/labinfo"; +/** + * Returns the UDF deployment API URL from environment or default. + */ +export function getUdfDeploymentApiUrl(): string { + return process.env.UDF_DEPLOYMENT_API_URL || "http://metadata.udf/deployment"; +} + +/** + * Returns the deployment identifier API URL from environment or default. + */ +export function getDeploymentIdentifierApiUrl(): string { + return process.env.DEPLOYMENT_IDENTIFIER_API_URL || "http://host.docker.internal:5123/petname"; +} + +/** + * Returns the LabInfo API URL from environment or default. + */ +export function getLabInfoApiUrl(): string { + return process.env.LABINFO_API_URL || "http://host.docker.internal:5123/labinfo"; +} diff --git a/src/lib/deployment-identifier-action.ts b/src/lib/deployment-identifier-action.ts index a517f4a..73f888f 100644 --- a/src/lib/deployment-identifier-action.ts +++ b/src/lib/deployment-identifier-action.ts @@ -1,6 +1,6 @@ "use server"; -import { DEPLOYMENT_IDENTIFIER_API_URL } from "./constants"; +import { getDeploymentIdentifierApiUrl } from "./constants"; import { DeploymentIdentifier } from "./types"; function getDeploymentIdentifierResponseField(): string { @@ -9,10 +9,11 @@ function getDeploymentIdentifierResponseField(): string { export async function fetchDeploymentIdentifierServer(): Promise { try { - const response = await fetch(DEPLOYMENT_IDENTIFIER_API_URL, { cache: "no-store" }); + const deploymentIdentifierApiUrl = getDeploymentIdentifierApiUrl(); + const response = await fetch(deploymentIdentifierApiUrl, { cache: "no-store" }); if (!response.ok) { throw new Error( - `Failed to retrieve deployment identifier from ${DEPLOYMENT_IDENTIFIER_API_URL}` + `Failed to retrieve deployment identifier from ${getDeploymentIdentifierApiUrl()}` ); } diff --git a/src/lib/udf-action.ts b/src/lib/udf-action.ts index 6a6ccd6..3660a39 100644 --- a/src/lib/udf-action.ts +++ b/src/lib/udf-action.ts @@ -1,6 +1,6 @@ "use server"; -import { LABINFO_API_URL, UDF_DEPLOYMENT_API_URL } from "./constants"; +import { getLabInfoApiUrl, getUdfDeploymentApiUrl } from "./constants"; import { findValueByKey } from "./object-utils"; async function fetchInfo(url: string, variableName: string): Promise { @@ -18,11 +18,11 @@ async function fetchInfo(url: string, variableName: string): Promis } export async function fetchLabInfoServer(variableName: string): Promise { - return await fetchInfo(LABINFO_API_URL, variableName); + return await fetchInfo(getLabInfoApiUrl(), variableName); } export async function fetchUDFInfoServer(variableName: string): Promise { - return await fetchInfo(UDF_DEPLOYMENT_API_URL, variableName); + return await fetchInfo(getUdfDeploymentApiUrl(), variableName); } export async function fetchUdfComponentWebShellServer(componentName: string | null = null): Promise { @@ -31,7 +31,7 @@ export async function fetchUdfComponentWebShellServer(componentName: string | nu return null; } - const response = await fetch(UDF_DEPLOYMENT_API_URL, { mode: "cors" }); + const response = await fetch(getUdfDeploymentApiUrl(), { mode: "cors" }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`);