chore: override codersdk.SessionTokenCookie in develop.sh#18991
Conversation
| }, | ||
| }, | ||
| allowedHosts: [".coder"], | ||
| allowedHosts: [".coder", ".dev.coder.com"], |
There was a problem hiding this comment.
review: also updated allowedHosts for dev URLs.
|
|
||
| cdroot | ||
| DEBUG_DELVE="${debug}" start_cmd API "" "${CODER_DEV_SHIM}" server --http-address 0.0.0.0:3000 --swagger-enable --access-url "${CODER_DEV_ACCESS_URL}" --dangerous-allow-cors-requests=true --enable-terraform-debug-mode "$@" | ||
| DEBUG_DELVE="${debug}" CODER_DEV_SESSION_TOKEN_COOKIE_PREFIX="${CODER_DEV_SESSION_TOKEN_COOKIE_PREFIX}" start_cmd API "" "${CODER_DEV_SHIM}" server --http-address 0.0.0.0:3000 --swagger-enable --access-url "${CODER_DEV_ACCESS_URL}" --dangerous-allow-cors-requests=true --enable-terraform-debug-mode "$@" |
There was a problem hiding this comment.
review: I'm setting the prefix to dev_ by default in develop.sh.
| func GetSessionTokenCookie() string { | ||
| if buildinfo.IsDev() { | ||
| if pfx, found := os.LookupEnv("CODER_DEV_SESSION_TOKEN_COOKIE_PREFIX"); found && pfx != "" { | ||
| return pfx + "_" + SessionTokenCookie | ||
| } | ||
| } | ||
| return SessionTokenCookie | ||
| } |
There was a problem hiding this comment.
Should SessionTokenCookie just be a var? And a function updates the var?
At the very least, SessionTokenCookie should probably not be exported. Just this function
There was a problem hiding this comment.
Yeah I was thinking of doing that but didn't want to make a breaking API change.
But you got me thinking... what do we do for buildinfo.tag?
If I change SessionTokenCookie to a var we can just do the -ldflags -X trick and not have to change anything else :)
|
woooooooooo!!!! |
| // From codersdk/client.go | ||
| export const SessionTokenCookie = "coder_session_token"; | ||
|
|
There was a problem hiding this comment.
This isn't intentional; I need to figure out how to keep this around.
@Emyrk think it's possible to modify this behaviour in apitypings?
There was a problem hiding this comment.
For now I'm manually vendoring this into api.ts.
| if [[ "$develop_in_coder" == 1 ]]; then | ||
| echo "INFO : Overriding codersdk.SessionTokenCookie as we are developing inside a Coder workspace." | ||
| ldflags+=( | ||
| -X "'github.com/coder/coder/v2/codersdk.SessionTokenCookie=dev_coder_session_token'" | ||
| ) | ||
| fi |
There was a problem hiding this comment.
I decided to try this way instead. It's a little more involved but requires less code changes in codersdk. I can remove the echo message if it's annoying.
| /** | ||
| * Originally from codersdk/client.go. | ||
| * The below declaration is required to stop Knip from complaining. | ||
| * @public | ||
| */ | ||
| export const SessionTokenCookie = "coder_session_token"; |
| CODER_DELVE_DEBUG_BIN=$(realpath "./build/coder_debug_${GOOS}_${GOARCH}") | ||
| popd | ||
|
|
||
| if [ -n "${CODER_AGENT_URL}" ]; then |
There was a problem hiding this comment.
We could also check if CODER=true. That's what I do in my dotfiles.
There was a problem hiding this comment.
I forgot about that one!
There was a problem hiding this comment.
Should also maybe be "${CODER_AGENT_URL:-}" in case the env var is not set, on account of the set -u.
There was a problem hiding this comment.
I did that here above (L13) but missed it in develop.sh. Will push a separate PR 👍
There was a problem hiding this comment.
Oh right oops! I got lost in what script I was looking at lol
Enables viewing the Coder UI proxied by Coder.
Exposes an environment variable
CODER_DEV_SESSION_TOKEN_COOKIE_PREFIXwhich allows adding a prefix to the name of the session token cookie. This only works for development builds.EDIT: I tried an alternative implementation instead using
-ldflags -Xthat removes the need for most changes in codersdk.