From 7f3e7146c868d546637f0cbd14c718d482970a20 Mon Sep 17 00:00:00 2001 From: aalsabag <43807484+aalsabag@users.noreply.github.com> Date: Sat, 4 Nov 2023 05:54:10 -0500 Subject: [PATCH] =?UTF-8?q?adding=20feature=20to=20allow=20for=20override?= =?UTF-8?q?=20of=20the=20default=20rekor=20domain=20on=20s=E2=80=A6=20(#67?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * adding feature to allow for override of the default rekor domain on startup of the UI Signed-off-by: Ahmed Alsabag * adding comment to explain the use of the NEXT_PUBLIC prefix Signed-off-by: Ahmed Alsabag * fixing formatting and spacing issues Signed-off-by: Ahmed Alsabag --------- Signed-off-by: Ahmed Alsabag --- README.md | 9 +++++++++ src/modules/api/context.tsx | 10 ++++++++++ src/modules/components/Settings.tsx | 11 ++++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 28fe10b..2e50e4f 100644 --- a/README.md +++ b/README.md @@ -17,3 +17,12 @@ Open [http://localhost:3000](http://localhost:3000) with your browser to see the ## Deploy The app is based on [Next.JS](https://nextjs.org/) and is automatically built & deployed to GitHub Pages when pushing to the `main` branch. + +## Internal Server Configuration + +This app supports overriding of the default rekor server instance for those running private instances of the the sigstore stack. +Create a `.env.local` file at the root and include in it this environment variable + +```properties +NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN=https://privaterekor.sigstore.dev +``` diff --git a/src/modules/api/context.tsx b/src/modules/api/context.tsx index e849fd6..2401043 100644 --- a/src/modules/api/context.tsx +++ b/src/modules/api/context.tsx @@ -24,6 +24,16 @@ export const RekorClientProvider: FunctionComponent> = ({ const [baseUrl, setBaseUrl] = useState(); const context: RekorClientContext = useMemo(() => { + /* + Using the Next.js framework, the NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN env variable requires + a NEXT_PUBLIC_* prefix to make the value of the variable accessible to the browser. + Variables missing this prefix are only accessible in the Node.js environment. + https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables + */ + if (baseUrl === undefined && process.env.NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN) { + setBaseUrl(process.env.NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN); + } + return { client: new RekorClient({ BASE: baseUrl }), baseUrl, diff --git a/src/modules/components/Settings.tsx b/src/modules/components/Settings.tsx index 05642df..347105c 100644 --- a/src/modules/components/Settings.tsx +++ b/src/modules/components/Settings.tsx @@ -30,6 +30,13 @@ export function Settings({ }, []); const onSave = useCallback(() => { + if ( + localBaseUrl === undefined && + process.env.NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN + ) { + setLocalBaseUrl(process.env.NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN); + } + setBaseUrl(localBaseUrl); onClose(); }, [localBaseUrl, setBaseUrl, onClose]); @@ -49,7 +56,9 @@ export function Settings({ Override rekor endpoint