Skip to content

Commit

Permalink
adding feature to allow for override of the default rekor domain on s… (
Browse files Browse the repository at this point in the history
#67)

* adding feature to allow for override of the default rekor domain on startup of the UI

Signed-off-by: Ahmed Alsabag <ahmed.alsabag@gmail.com>

* adding comment to explain the use of the NEXT_PUBLIC prefix

Signed-off-by: Ahmed Alsabag <ahmed.alsabag@gmail.com>

* fixing formatting and spacing issues

Signed-off-by: Ahmed Alsabag <ahmed.alsabag@gmail.com>

---------

Signed-off-by: Ahmed Alsabag <ahmed.alsabag@gmail.com>
  • Loading branch information
aalsabag authored Nov 4, 2023
1 parent a0976a1 commit 7f3e714
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
10 changes: 10 additions & 0 deletions src/modules/api/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ export const RekorClientProvider: FunctionComponent<PropsWithChildren<{}>> = ({
const [baseUrl, setBaseUrl] = useState<string>();

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,
Expand Down
11 changes: 10 additions & 1 deletion src/modules/components/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -49,7 +56,9 @@ export function Settings({
<Typography variant="overline">Override rekor endpoint</Typography>
<TextField
value={localBaseUrl ?? ""}
placeholder="https://rekor.sigstore.dev"
placeholder={
baseUrl === undefined ? "https://rekor.sigstore.dev" : baseUrl
}
onChange={handleChangeBaseUrl}
fullWidth
/>
Expand Down

0 comments on commit 7f3e714

Please sign in to comment.