-
Notifications
You must be signed in to change notification settings - Fork 27
Allow an optional static bearer token when using dev server #983
Conversation
🚀 Deployed Preview: http://konveyor-forklift-ui-pr-983-preview.surge.sh ✨ Compare with current main branch: http://konveyor-forklift-ui-preview.surge.sh |
pkg/web/src/app/client/helpers.ts
Outdated
@@ -203,7 +203,7 @@ export const checkIfResourceExists = async ( | |||
export const useClientInstance = (): KubeClient.ClusterClient => { | |||
const { currentUser } = useNetworkContext(); | |||
const user = { | |||
access_token: currentUser?.access_token || '', | |||
access_token: currentUser?.access_token || window['_meta']?.clusterBearerToken || '', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of directly referencing window['_meta']
, the properties from the meta.json file should be added to the IMetaVars
type here and fallback defaults for each should be added to the exported META
variable here. Then this file can import { META } from '@app/common/constants';
and you can use META.clusterBearerToken
here.
That way we get strong types for these (useful for editor autocomplete and avoiding typos) and don't need the ?.
and the || ''
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, alternatively you could use an environment variable for this. the meta.json file is generated by the operator and generally used for things that also apply to prod but can be overridden in dev. If it's an environment variable it could be overridden on the command line if necessary. I honestly can't remember exactly why we did both (@ibolton336 may remember), and the distinction has probably been broken, but just so you're aware of both:
To define a new environment variable you add it to the IEnvVars
type here, use import { ENV } from '@app/common/constants';
(defined here), and make sure to add it to the list on the server here so it gets bundled up and sent to the client.
Both these META
and ENV
mechanisms could probably be combined and/or replaced, they were hacks that stuck around... but the strong types are useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 👍, I like the environment variable approach better then the meta file for a token parameter,
changed the code to use the ENV, and added the type as recomended/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we document env vars someware ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added documentation to README.md file
177ec6b
to
307c04b
Compare
2a37d23
to
7f3c09c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect! Thanks
Agh sorry, looks like I caused a merge conflict by merging #984 |
7f3c09c
to
37f741a
Compare
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
@mturley np :-), rebased |
When running on dev environment, sometimes it's useful to allow to provide static bearer token.
For example if running the UI with minikube[1]
In my use case I start minishift with a dev user that has some bearer token, and then run
with this patch the dev server command will look something like:
[1] https://github.com/konveyor/forklift-console-plugin/blob/main/scripts/configure-minikube.sh