Skip to content

Commit bb83071

Browse files
authored
chore: override codersdk.SessionTokenCookie in develop.sh (#18991)
Updates `develop.sh`, `coder-dev.sh` and `build_go.sh` to conditionally override `codersdk.SessionTokenCookie` for usage in nested development scenario.
1 parent f41275e commit bb83071

File tree

7 files changed

+35
-10
lines changed

7 files changed

+35
-10
lines changed

codersdk/client.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ import (
2929
// These cookies are Coder-specific. If a new one is added or changed, the name
3030
// shouldn't be likely to conflict with any user-application set cookies.
3131
// Be sure to strip additional cookies in httpapi.StripCoderCookies!
32+
// SessionTokenCookie represents the name of the cookie or query parameter the API key is stored in.
33+
// NOTE: This is declared as a var so that we can override it in `develop.sh` if required.
34+
var SessionTokenCookie = "coder_session_token"
35+
3236
const (
33-
// SessionTokenCookie represents the name of the cookie or query parameter the API key is stored in.
34-
SessionTokenCookie = "coder_session_token"
3537
// SessionTokenHeader is the custom header to use for authentication.
3638
SessionTokenHeader = "Coder-Session-Token"
3739
// OAuth2StateCookie is the name of the cookie that stores the oauth2 state.

scripts/build_go.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ boringcrypto=${CODER_BUILD_BORINGCRYPTO:-0}
4949
dylib=0
5050
windows_resources="${CODER_WINDOWS_RESOURCES:-0}"
5151
debug=0
52+
develop_in_coder="${DEVELOP_IN_CODER:-0}"
5253

5354
bin_ident="com.coder.cli"
5455

@@ -149,6 +150,13 @@ if [[ "$debug" == 0 ]]; then
149150
ldflags+=(-s -w)
150151
fi
151152

153+
if [[ "$develop_in_coder" == 1 ]]; then
154+
echo "INFO : Overriding codersdk.SessionTokenCookie as we are developing inside a Coder workspace."
155+
ldflags+=(
156+
-X "'github.com/coder/coder/v2/codersdk.SessionTokenCookie=dev_coder_session_token'"
157+
)
158+
fi
159+
152160
# We use ts_omit_aws here because on Linux it prevents Tailscale from importing
153161
# github.com/aws/aws-sdk-go-v2/aws, which adds 7 MB to the binary.
154162
TS_EXTRA_SMALL="ts_omit_aws,ts_omit_bird,ts_omit_tap,ts_omit_kube"

scripts/coder-dev.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ source "${SCRIPT_DIR}/lib.sh"
1010

1111
GOOS="$(go env GOOS)"
1212
GOARCH="$(go env GOARCH)"
13+
CODER_AGENT_URL="${CODER_AGENT_URL:-}"
14+
DEVELOP_IN_CODER="${DEVELOP_IN_CODER:-0}"
1315
DEBUG_DELVE="${DEBUG_DELVE:-0}"
1416
BINARY_TYPE=coder-slim
1517
if [[ ${1:-} == server ]]; then
@@ -35,16 +37,20 @@ CODER_DEV_DIR="$(realpath ./.coderv2)"
3537
CODER_DELVE_DEBUG_BIN=$(realpath "./build/coder_debug_${GOOS}_${GOARCH}")
3638
popd
3739

40+
if [ -n "${CODER_AGENT_URL}" ]; then
41+
DEVELOP_IN_CODER=1
42+
fi
43+
3844
case $BINARY_TYPE in
3945
coder-slim)
4046
# Ensure the coder slim binary is always up-to-date with local
4147
# changes, this simplifies usage of this script for development.
4248
# NOTE: we send all output of `make` to /dev/null so that we do not break
4349
# scripts that read the output of this command.
4450
if [[ -t 1 ]]; then
45-
make -j "${RELATIVE_BINARY_PATH}"
51+
DEVELOP_IN_CODER="${DEVELOP_IN_CODER}" make -j "${RELATIVE_BINARY_PATH}"
4652
else
47-
make -j "${RELATIVE_BINARY_PATH}" >/dev/null 2>&1
53+
DEVELOP_IN_CODER="${DEVELOP_IN_CODER}" make -j "${RELATIVE_BINARY_PATH}" >/dev/null 2>&1
4854
fi
4955
;;
5056
coder)

scripts/develop.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ source "${SCRIPT_DIR}/lib.sh"
1414
set -euo pipefail
1515

1616
CODER_DEV_ACCESS_URL="${CODER_DEV_ACCESS_URL:-http://127.0.0.1:3000}"
17+
DEVELOP_IN_CODER="${DEVELOP_IN_CODER:-0}"
1718
debug=0
1819
DEFAULT_PASSWORD="SomeSecurePassword!"
1920
password="${CODER_DEV_ADMIN_PASSWORD:-${DEFAULT_PASSWORD}}"
@@ -66,6 +67,10 @@ if [ "${CODER_BUILD_AGPL:-0}" -gt "0" ] && [ "${multi_org}" -gt "0" ]; then
6667
echo '== ERROR: cannot use both multi-organizations and APGL build.' && exit 1
6768
fi
6869

70+
if [ -n "${CODER_AGENT_URL}" ]; then
71+
DEVELOP_IN_CODER=1
72+
fi
73+
6974
# Preflight checks: ensure we have our required dependencies, and make sure nothing is listening on port 3000 or 8080
7075
dependencies curl git go make pnpm
7176
curl --fail http://127.0.0.1:3000 >/dev/null 2>&1 && echo '== ERROR: something is listening on port 3000. Kill it and re-run this script.' && exit 1
@@ -75,7 +80,7 @@ curl --fail http://127.0.0.1:8080 >/dev/null 2>&1 && echo '== ERROR: something i
7580
# node_modules if necessary.
7681
GOOS="$(go env GOOS)"
7782
GOARCH="$(go env GOARCH)"
78-
make -j "build/coder_${GOOS}_${GOARCH}"
83+
DEVELOP_IN_CODER="${DEVELOP_IN_CODER}" make -j "build/coder_${GOOS}_${GOARCH}"
7984

8085
# Use the coder dev shim so we don't overwrite the user's existing Coder config.
8186
CODER_DEV_SHIM="${PROJECT_ROOT}/scripts/coder-dev.sh"
@@ -150,7 +155,7 @@ fatal() {
150155
trap 'fatal "Script encountered an error"' ERR
151156

152157
cdroot
153-
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 "$@"
158+
DEBUG_DELVE="${debug}" DEVELOP_IN_CODER="${DEVELOP_IN_CODER}" 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 "$@"
154159

155160
echo '== Waiting for Coder to become ready'
156161
# Start the timeout in the background so interrupting this script

site/src/api/api.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ const getMissingParameters = (
107107
return missingParameters;
108108
};
109109

110+
/**
111+
* Originally from codersdk/client.go.
112+
* The below declaration is required to stop Knip from complaining.
113+
* @public
114+
*/
115+
export const SessionTokenCookie = "coder_session_token";
116+
110117
/**
111118
* @param agentId
112119
* @returns {OneWayWebSocket} A OneWayWebSocket that emits Server-Sent Events.

site/src/api/typesGenerated.ts

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/vite.config.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export default defineConfig({
116116
secure: process.env.NODE_ENV === "production",
117117
},
118118
},
119-
allowedHosts: [".coder"],
119+
allowedHosts: [".coder", ".dev.coder.com"],
120120
},
121121
resolve: {
122122
alias: {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy