Skip to content

Commit eecaacd

Browse files
committed
Revert "Merge branch 'main' into restructure-new"
This reverts commit c7052d6, reversing changes made to 995d509.
1 parent c7052d6 commit eecaacd

File tree

160 files changed

+2310
-7857
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

160 files changed

+2310
-7857
lines changed

.github/workflows/contrib.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
steps:
3737
- name: cla
3838
if: (github.event.comment.body == 'recheck' || github.event.comment.body == 'I have read the CLA Document and I hereby sign the CLA') || github.event_name == 'pull_request_target'
39-
uses: contributor-assistant/github-action@v2.6.1
39+
uses: contributor-assistant/github-action@v2.6.0
4040
env:
4141
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4242
# the below token should have repo scope and must be manually added by you in the repository's secret

Makefile

-8
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,6 @@ gen: \
488488
agent/proto/agent.pb.go \
489489
provisionersdk/proto/provisioner.pb.go \
490490
provisionerd/proto/provisionerd.pb.go \
491-
vpn/vpn.pb.go \
492491
coderd/database/dump.sql \
493492
$(DB_GEN_FILES) \
494493
site/src/api/typesGenerated.ts \
@@ -518,7 +517,6 @@ gen/mark-fresh:
518517
agent/proto/agent.pb.go \
519518
provisionersdk/proto/provisioner.pb.go \
520519
provisionerd/proto/provisionerd.pb.go \
521-
vpn/vpn.pb.go \
522520
coderd/database/dump.sql \
523521
$(DB_GEN_FILES) \
524522
site/src/api/typesGenerated.ts \
@@ -602,12 +600,6 @@ provisionerd/proto/provisionerd.pb.go: provisionerd/proto/provisionerd.proto
602600
--go-drpc_opt=paths=source_relative \
603601
./provisionerd/proto/provisionerd.proto
604602

605-
vpn/vpn.pb.go: vpn/vpn.proto
606-
protoc \
607-
--go_out=. \
608-
--go_opt=paths=source_relative \
609-
./vpn/vpn.proto
610-
611603
site/src/api/typesGenerated.ts: $(wildcard scripts/apitypings/*) $(shell find ./codersdk $(FIND_EXCLUSIONS) -type f -name '*.go')
612604
go run ./scripts/apitypings/ > $@
613605
./scripts/pnpm_install.sh

buildinfo/buildinfo.go

-8
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ var (
2424
// Updated by buildinfo_slim.go on start.
2525
slim bool
2626

27-
// Updated by buildinfo_site.go on start.
28-
site bool
29-
3027
// Injected with ldflags at build, see scripts/build_go.sh
3128
tag string
3229
agpl string // either "true" or "false", ldflags does not support bools
@@ -98,11 +95,6 @@ func IsSlim() bool {
9895
return slim
9996
}
10097

101-
// HasSite returns true if the frontend is embedded in the build.
102-
func HasSite() bool {
103-
return site
104-
}
105-
10698
// IsAGPL returns true if this is an AGPL build.
10799
func IsAGPL() bool {
108100
return strings.Contains(agpl, "t")

buildinfo/buildinfo_site.go

-7
This file was deleted.

cli/notifications_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func createOpts(t *testing.T) *coderdtest.Options {
2020
t.Helper()
2121

2222
dt := coderdtest.DeploymentValues(t)
23+
dt.Experiments = []string{string(codersdk.ExperimentNotifications)}
2324
return &coderdtest.Options{
2425
DeploymentValues: dt,
2526
}

cli/root.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ func (r *RootCmd) Command(subcommands []*serpent.Command) (*serpent.Command, err
411411
{
412412
Flag: varNoOpen,
413413
Env: "CODER_NO_OPEN",
414-
Description: "Suppress opening the browser when logging in, or starting the server.",
414+
Description: "Suppress opening the browser after logging in.",
415415
Value: serpent.BoolOf(&r.noOpen),
416416
Hidden: true,
417417
Group: globalGroup,

cli/server.go

+53-48
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,15 @@ import (
5656

5757
"cdr.dev/slog"
5858
"cdr.dev/slog/sloggers/sloghuman"
59+
"github.com/coder/coder/v2/coderd/entitlements"
60+
"github.com/coder/coder/v2/coderd/notifications/reports"
61+
"github.com/coder/coder/v2/coderd/runtimeconfig"
5962
"github.com/coder/pretty"
6063
"github.com/coder/quartz"
6164
"github.com/coder/retry"
6265
"github.com/coder/serpent"
6366
"github.com/coder/wgtunnel/tunnelsdk"
6467

65-
"github.com/coder/coder/v2/coderd/entitlements"
66-
"github.com/coder/coder/v2/coderd/notifications/reports"
67-
"github.com/coder/coder/v2/coderd/runtimeconfig"
68-
6968
"github.com/coder/coder/v2/buildinfo"
7069
"github.com/coder/coder/v2/cli/clilog"
7170
"github.com/coder/coder/v2/cli/cliui"
@@ -493,12 +492,7 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
493492
BorderForeground(lipgloss.Color("12")).
494493
Render(fmt.Sprintf("View the Web UI:\n%s",
495494
pretty.Sprint(cliui.DefaultStyles.Hyperlink, accessURL))))
496-
if buildinfo.HasSite() {
497-
err = openURL(inv, accessURL)
498-
if err == nil {
499-
cliui.Infof(inv.Stdout, "Opening local browser... You can disable this by passing --no-open.\n")
500-
}
501-
}
495+
_ = openURL(inv, accessURL)
502496

503497
// Used for zero-trust instance identity with Google Cloud.
504498
googleTokenValidator, err := idtoken.NewValidator(ctx, option.WithoutAuthentication())
@@ -685,6 +679,10 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
685679
options.OIDCConfig = oc
686680
}
687681

682+
experiments := coderd.ReadExperiments(
683+
options.Logger, options.DeploymentValues.Experiments.Value(),
684+
)
685+
688686
// We'll read from this channel in the select below that tracks shutdown. If it remains
689687
// nil, that case of the select will just never fire, but it's important not to have a
690688
// "bare" read on this channel.
@@ -948,33 +946,6 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
948946
return xerrors.Errorf("write config url: %w", err)
949947
}
950948

951-
// Manage notifications.
952-
cfg := options.DeploymentValues.Notifications
953-
metrics := notifications.NewMetrics(options.PrometheusRegistry)
954-
helpers := templateHelpers(options)
955-
956-
// The enqueuer is responsible for enqueueing notifications to the given store.
957-
enqueuer, err := notifications.NewStoreEnqueuer(cfg, options.Database, helpers, logger.Named("notifications.enqueuer"), quartz.NewReal())
958-
if err != nil {
959-
return xerrors.Errorf("failed to instantiate notification store enqueuer: %w", err)
960-
}
961-
options.NotificationsEnqueuer = enqueuer
962-
963-
// The notification manager is responsible for:
964-
// - creating notifiers and managing their lifecycles (notifiers are responsible for dequeueing/sending notifications)
965-
// - keeping the store updated with status updates
966-
notificationsManager, err := notifications.NewManager(cfg, options.Database, helpers, metrics, logger.Named("notifications.manager"))
967-
if err != nil {
968-
return xerrors.Errorf("failed to instantiate notification manager: %w", err)
969-
}
970-
971-
// nolint:gocritic // TODO: create own role.
972-
notificationsManager.Run(dbauthz.AsSystemRestricted(ctx))
973-
974-
// Run report generator to distribute periodic reports.
975-
notificationReportGenerator := reports.NewReportGenerator(ctx, logger.Named("notifications.report_generator"), options.Database, options.NotificationsEnqueuer, quartz.NewReal())
976-
defer notificationReportGenerator.Close()
977-
978949
// Since errCh only has one buffered slot, all routines
979950
// sending on it must be wrapped in a select/default to
980951
// avoid leaving dangling goroutines waiting for the
@@ -1031,6 +1002,38 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
10311002
options.WorkspaceUsageTracker = tracker
10321003
defer tracker.Close()
10331004

1005+
// Manage notifications.
1006+
var (
1007+
notificationsManager *notifications.Manager
1008+
)
1009+
if experiments.Enabled(codersdk.ExperimentNotifications) {
1010+
cfg := options.DeploymentValues.Notifications
1011+
metrics := notifications.NewMetrics(options.PrometheusRegistry)
1012+
helpers := templateHelpers(options)
1013+
1014+
// The enqueuer is responsible for enqueueing notifications to the given store.
1015+
enqueuer, err := notifications.NewStoreEnqueuer(cfg, options.Database, helpers, logger.Named("notifications.enqueuer"), quartz.NewReal())
1016+
if err != nil {
1017+
return xerrors.Errorf("failed to instantiate notification store enqueuer: %w", err)
1018+
}
1019+
options.NotificationsEnqueuer = enqueuer
1020+
1021+
// The notification manager is responsible for:
1022+
// - creating notifiers and managing their lifecycles (notifiers are responsible for dequeueing/sending notifications)
1023+
// - keeping the store updated with status updates
1024+
notificationsManager, err = notifications.NewManager(cfg, options.Database, helpers, metrics, logger.Named("notifications.manager"))
1025+
if err != nil {
1026+
return xerrors.Errorf("failed to instantiate notification manager: %w", err)
1027+
}
1028+
1029+
// nolint:gocritic // TODO: create own role.
1030+
notificationsManager.Run(dbauthz.AsSystemRestricted(ctx))
1031+
1032+
// Run report generator to distribute periodic reports.
1033+
notificationReportGenerator := reports.NewReportGenerator(ctx, logger.Named("notifications.report_generator"), options.Database, options.NotificationsEnqueuer, quartz.NewReal())
1034+
defer notificationReportGenerator.Close()
1035+
}
1036+
10341037
// Wrap the server in middleware that redirects to the access URL if
10351038
// the request is not to a local IP.
10361039
var handler http.Handler = coderAPI.RootHandler
@@ -1150,17 +1153,19 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
11501153
// Cancel any remaining in-flight requests.
11511154
shutdownConns()
11521155

1153-
// Stop the notification manager, which will cause any buffered updates to the store to be flushed.
1154-
// If the Stop() call times out, messages that were sent but not reflected as such in the store will have
1155-
// their leases expire after a period of time and will be re-queued for sending.
1156-
// See CODER_NOTIFICATIONS_LEASE_PERIOD.
1157-
cliui.Info(inv.Stdout, "Shutting down notifications manager..."+"\n")
1158-
err = shutdownWithTimeout(notificationsManager.Stop, 5*time.Second)
1159-
if err != nil {
1160-
cliui.Warnf(inv.Stderr, "Notifications manager shutdown took longer than 5s, "+
1161-
"this may result in duplicate notifications being sent: %s\n", err)
1162-
} else {
1163-
cliui.Info(inv.Stdout, "Gracefully shut down notifications manager\n")
1156+
if notificationsManager != nil {
1157+
// Stop the notification manager, which will cause any buffered updates to the store to be flushed.
1158+
// If the Stop() call times out, messages that were sent but not reflected as such in the store will have
1159+
// their leases expire after a period of time and will be re-queued for sending.
1160+
// See CODER_NOTIFICATIONS_LEASE_PERIOD.
1161+
cliui.Info(inv.Stdout, "Shutting down notifications manager..."+"\n")
1162+
err = shutdownWithTimeout(notificationsManager.Stop, 5*time.Second)
1163+
if err != nil {
1164+
cliui.Warnf(inv.Stderr, "Notifications manager shutdown took longer than 5s, "+
1165+
"this may result in duplicate notifications being sent: %s\n", err)
1166+
} else {
1167+
cliui.Info(inv.Stdout, "Gracefully shut down notifications manager\n")
1168+
}
11641169
}
11651170

11661171
// Shut down provisioners before waiting for WebSockets

cli/testdata/coder_tokens_create_--help.golden

-4
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,5 @@ OPTIONS:
1212
-n, --name string, $CODER_TOKEN_NAME
1313
Specify a human-readable name.
1414

15-
-u, --user string, $CODER_TOKEN_USER
16-
Specify the user to create the token for (Only works if logged in user
17-
is admin).
18-
1915
———
2016
Run `coder --help` for a list of global options.

cli/tokens.go

+1-13
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ func (r *RootCmd) createToken() *serpent.Command {
4848
var (
4949
tokenLifetime time.Duration
5050
name string
51-
user string
5251
)
5352
client := new(codersdk.Client)
5453
cmd := &serpent.Command{
@@ -59,11 +58,7 @@ func (r *RootCmd) createToken() *serpent.Command {
5958
r.InitClient(client),
6059
),
6160
Handler: func(inv *serpent.Invocation) error {
62-
userID := codersdk.Me
63-
if user != "" {
64-
userID = user
65-
}
66-
res, err := client.CreateToken(inv.Context(), userID, codersdk.CreateTokenRequest{
61+
res, err := client.CreateToken(inv.Context(), codersdk.Me, codersdk.CreateTokenRequest{
6762
Lifetime: tokenLifetime,
6863
TokenName: name,
6964
})
@@ -92,13 +87,6 @@ func (r *RootCmd) createToken() *serpent.Command {
9287
Description: "Specify a human-readable name.",
9388
Value: serpent.StringOf(&name),
9489
},
95-
{
96-
Flag: "user",
97-
FlagShorthand: "u",
98-
Env: "CODER_TOKEN_USER",
99-
Description: "Specify the user to create the token for (Only works if logged in user is admin).",
100-
Value: serpent.StringOf(&user),
101-
},
10290
}
10391

10492
return cmd

cli/tokens_test.go

+1-46
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,13 @@ import (
1717
func TestTokens(t *testing.T) {
1818
t.Parallel()
1919
client := coderdtest.New(t, nil)
20-
adminUser := coderdtest.CreateFirstUser(t, client)
21-
22-
secondUserClient, secondUser := coderdtest.CreateAnotherUser(t, client, adminUser.OrganizationID)
23-
_, thirdUser := coderdtest.CreateAnotherUser(t, client, adminUser.OrganizationID)
20+
_ = coderdtest.CreateFirstUser(t, client)
2421

2522
ctx, cancelFunc := context.WithTimeout(context.Background(), testutil.WaitLong)
2623
defer cancelFunc()
2724

2825
// helpful empty response
2926
inv, root := clitest.New(t, "tokens", "ls")
30-
//nolint:gocritic // This should be run as the owner user.
3127
clitest.SetupConfig(t, client, root)
3228
buf := new(bytes.Buffer)
3329
inv.Stdout = buf
@@ -46,19 +42,6 @@ func TestTokens(t *testing.T) {
4642
require.NotEmpty(t, res)
4743
id := res[:10]
4844

49-
// Test creating a token for second user from first user's (admin) session
50-
inv, root = clitest.New(t, "tokens", "create", "--name", "token-two", "--user", secondUser.ID.String())
51-
clitest.SetupConfig(t, client, root)
52-
buf = new(bytes.Buffer)
53-
inv.Stdout = buf
54-
err = inv.WithContext(ctx).Run()
55-
// Test should succeed in creating token for second user
56-
require.NoError(t, err)
57-
res = buf.String()
58-
require.NotEmpty(t, res)
59-
secondTokenID := res[:10]
60-
61-
// Test listing tokens from the first user's (admin) session
6245
inv, root = clitest.New(t, "tokens", "ls")
6346
clitest.SetupConfig(t, client, root)
6447
buf = new(bytes.Buffer)
@@ -67,39 +50,11 @@ func TestTokens(t *testing.T) {
6750
require.NoError(t, err)
6851
res = buf.String()
6952
require.NotEmpty(t, res)
70-
// Result should only contain the token created for the admin user
7153
require.Contains(t, res, "ID")
7254
require.Contains(t, res, "EXPIRES AT")
7355
require.Contains(t, res, "CREATED AT")
7456
require.Contains(t, res, "LAST USED")
7557
require.Contains(t, res, id)
76-
// Result should not contain the token created for the second user
77-
require.NotContains(t, res, secondTokenID)
78-
79-
// Test listing tokens from the second user's session
80-
inv, root = clitest.New(t, "tokens", "ls")
81-
clitest.SetupConfig(t, secondUserClient, root)
82-
buf = new(bytes.Buffer)
83-
inv.Stdout = buf
84-
err = inv.WithContext(ctx).Run()
85-
require.NoError(t, err)
86-
res = buf.String()
87-
require.NotEmpty(t, res)
88-
require.Contains(t, res, "ID")
89-
require.Contains(t, res, "EXPIRES AT")
90-
require.Contains(t, res, "CREATED AT")
91-
require.Contains(t, res, "LAST USED")
92-
// Result should contain the token created for the second user
93-
require.Contains(t, res, secondTokenID)
94-
95-
// Test creating a token for third user from second user's (non-admin) session
96-
inv, root = clitest.New(t, "tokens", "create", "--name", "token-two", "--user", thirdUser.ID.String())
97-
clitest.SetupConfig(t, secondUserClient, root)
98-
buf = new(bytes.Buffer)
99-
inv.Stdout = buf
100-
err = inv.WithContext(ctx).Run()
101-
// User (non-admin) should not be able to create a token for another user
102-
require.Error(t, err)
10358

10459
inv, root = clitest.New(t, "tokens", "ls", "--output=json")
10560
clitest.SetupConfig(t, client, root)

0 commit comments

Comments
 (0)