Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding feature to allow for override of the default rekor domain on s… #67

Merged
merged 3 commits into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,11 @@ 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this would be for private instances, it feels like we should not use PUBLIC in the variable name?

Copy link
Contributor Author

@aalsabag aalsabag Nov 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! I think however this might be a requirement defined by Next.js. Otherwise the variable would not be available for use in the browser.

Non-NEXT_PUBLIC_ environment variables are only available in the Node.js environment, meaning they aren't accessible to the browser (the client runs in a different environment).
In order to make the value of an environment variable accessible in the browser, Next.js can "inline" a value, at build time, into the js bundle that is delivered to the client, replacing all references to process.env.[variable] with a hard-coded value. To tell it to do this, you just have to prefix the variable with NEXT_PUBLIC_. For example: NEXT_PUBLIC_ANALYTICS_ID=abcdefghijk

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps it's worth adding some additional comments in the tsx files to denote the purpose? It's pretty confusing, though now I see it wasn't intended

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps it's worth adding some additional comments in the tsx files to denote the purpose? It's pretty confusing, though now I see it wasn't intended

I'm on it sir!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment in the context.tsx file. Let me know if that's sufficient

```
4 changes: 4 additions & 0 deletions src/modules/api/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export const RekorClientProvider: FunctionComponent<PropsWithChildren<{}>> = ({
const [baseUrl, setBaseUrl] = useState<string>();

const context: RekorClientContext = useMemo(() => {
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
6 changes: 5 additions & 1 deletion src/modules/components/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ 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 +53,7 @@ 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