Skip to content

Commit cdf2524

Browse files
committed
Merge remote-tracking branch 'origin/main' into ssncferreira/cli-presets-list
2 parents 348148e + 28789d7 commit cdf2524

14 files changed

+135
-19
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/src/pages/CreateWorkspacePage/CreateWorkspacePage.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ const CreateWorkspacePage: FC = () => {
6565
});
6666
const permissionsQuery = useQuery({
6767
...checkAuthorization({
68-
checks: createWorkspaceChecks(templateQuery.data?.organization_id ?? ""),
68+
checks: createWorkspaceChecks(
69+
templateQuery.data?.organization_id ?? "",
70+
templateQuery.data?.id,
71+
),
6972
}),
7073
enabled: !!templateQuery.data,
7174
});
@@ -208,6 +211,7 @@ const CreateWorkspacePage: FC = () => {
208211
startPollingExternalAuth={startPollingExternalAuth}
209212
hasAllRequiredExternalAuth={hasAllRequiredExternalAuth}
210213
permissions={permissionsQuery.data as CreateWorkspacePermissions}
214+
canUpdateTemplate={permissionsQuery.data?.canUpdateTemplate}
211215
parameters={realizedParameters as TemplateVersionParameter[]}
212216
presets={templateVersionPresetsQuery.data ?? []}
213217
creatingWorkspace={createWorkspaceMutation.isPending}

site/src/pages/CreateWorkspacePage/CreateWorkspacePageExperimental.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ const CreateWorkspacePageExperimental: FC = () => {
7979
});
8080
const permissionsQuery = useQuery({
8181
...checkAuthorization({
82-
checks: createWorkspaceChecks(templateQuery.data?.organization_id ?? ""),
82+
checks: createWorkspaceChecks(
83+
templateQuery.data?.organization_id ?? "",
84+
templateQuery.data?.id,
85+
),
8386
}),
8487
enabled: !!templateQuery.data,
8588
});
@@ -292,6 +295,7 @@ const CreateWorkspacePageExperimental: FC = () => {
292295
owner={owner}
293296
setOwner={setOwner}
294297
autofillParameters={autofillParameters}
298+
canUpdateTemplate={permissionsQuery.data?.canUpdateTemplate}
295299
error={
296300
wsError ||
297301
createWorkspaceMutation.error ||

site/src/pages/CreateWorkspacePage/CreateWorkspacePageView.stories.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const meta: Meta<typeof CreateWorkspacePageView> = {
2828
mode: "form",
2929
permissions: {
3030
createWorkspaceForAny: true,
31+
canUpdateTemplate: false,
3132
},
3233
onCancel: action("onCancel"),
3334
},
@@ -386,3 +387,23 @@ export const ExternalAuthAllConnected: Story = {
386387
],
387388
},
388389
};
390+
391+
export const WithViewSourceButton: Story = {
392+
args: {
393+
canUpdateTemplate: true,
394+
versionId: "template-version-123",
395+
template: {
396+
...MockTemplate,
397+
organization_name: "default",
398+
name: "docker-template",
399+
},
400+
},
401+
parameters: {
402+
docs: {
403+
description: {
404+
story:
405+
"This story shows the View Source button that appears for template administrators. The button allows quick navigation to the template editor from the workspace creation page.",
406+
},
407+
},
408+
},
409+
};

site/src/pages/CreateWorkspacePage/CreateWorkspacePageView.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ import { Switch } from "components/Switch/Switch";
2727
import { UserAutocomplete } from "components/UserAutocomplete/UserAutocomplete";
2828
import { type FormikContextType, useFormik } from "formik";
2929
import type { ExternalAuthPollingState } from "hooks/useExternalAuth";
30+
import { ExternalLinkIcon } from "lucide-react";
3031
import { generateWorkspaceName } from "modules/workspaces/generateWorkspaceName";
3132
import { type FC, useCallback, useEffect, useMemo, useState } from "react";
33+
import { Link } from "react-router-dom";
3234
import {
3335
getFormHelpers,
3436
nameValidator,
@@ -67,6 +69,7 @@ interface CreateWorkspacePageViewProps {
6769
presets: TypesGen.Preset[];
6870
permissions: CreateWorkspacePermissions;
6971
creatingWorkspace: boolean;
72+
canUpdateTemplate?: boolean;
7073
onCancel: () => void;
7174
onSubmit: (
7275
req: TypesGen.CreateWorkspaceRequest,
@@ -92,6 +95,7 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
9295
presets = [],
9396
permissions,
9497
creatingWorkspace,
98+
canUpdateTemplate,
9599
onSubmit,
96100
onCancel,
97101
}) => {
@@ -218,9 +222,21 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
218222
<Margins size="medium">
219223
<PageHeader
220224
actions={
221-
<Button size="sm" variant="outline" onClick={onCancel}>
222-
Cancel
223-
</Button>
225+
<Stack direction="row" spacing={2}>
226+
{canUpdateTemplate && (
227+
<Button asChild size="sm" variant="outline">
228+
<Link
229+
to={`/templates/${template.organization_name}/${template.name}/versions/${versionId}/edit`}
230+
>
231+
<ExternalLinkIcon />
232+
View source
233+
</Link>
234+
</Button>
235+
)}
236+
<Button size="sm" variant="outline" onClick={onCancel}>
237+
Cancel
238+
</Button>
239+
</Stack>
224240
}
225241
>
226242
<Stack direction="row">

0 commit comments

Comments
 (0)