Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f454184

Browse files
committed
Merge branch 'main' of https://github.com/coder/coder into dk/system-notifications-o11y
2 parents 00633a1 + a6d66cc commit f454184

File tree

98 files changed

+345
-375
lines changed

Some content is hidden

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

98 files changed

+345
-375
lines changed

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,7 @@ lint/ts:
448448
lint/go:
449449
./scripts/check_enterprise_imports.sh
450450
linter_ver=$(shell egrep -o 'GOLANGCI_LINT_VERSION=\S+' dogfood/Dockerfile | cut -d '=' -f 2)
451-
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v$$linter_ver
452-
golangci-lint run
451+
go run github.com/golangci/golangci-lint/cmd/golangci-lint@v$$linter_ver run
453452
.PHONY: lint/go
454453

455454
lint/examples:

agent/agentscripts/agentscripts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ func (r *Runner) run(ctx context.Context, script codersdk.WorkspaceAgentScript)
349349
"This usually means a child process was started with references to stdout or stderr. As a result, this " +
350350
"process may now have been terminated. Consider redirecting the output or using a separate " +
351351
"\"coder_script\" for the process, see " +
352-
"https://coder.com/docs/v2/latest/templates/troubleshooting#startup-script-issues for more information.",
352+
"https://coder.com/docs/templates/troubleshooting#startup-script-issues for more information.",
353353
)
354354
// Inform the user by propagating the message via log writers.
355355
_, _ = fmt.Fprintf(cmd.Stderr, "WARNING: %s. %s\n", message, details)

apiversion/apiversion.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type APIVersion struct {
2626
}
2727

2828
func (v *APIVersion) WithBackwardCompat(majs ...int) *APIVersion {
29-
v.additionalMajors = append(v.additionalMajors, majs[:]...)
29+
v.additionalMajors = append(v.additionalMajors, majs...)
3030
return v
3131
}
3232

cli/cliui/agent.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func Agent(ctx context.Context, writer io.Writer, agentID uuid.UUID, opts AgentO
116116
if agent.Status == codersdk.WorkspaceAgentTimeout {
117117
now := time.Now()
118118
sw.Log(now, codersdk.LogLevelInfo, "The workspace agent is having trouble connecting, wait for it to connect or restart your workspace.")
119-
sw.Log(now, codersdk.LogLevelInfo, troubleshootingMessage(agent, "https://coder.com/docs/v2/latest/templates#agent-connection-issues"))
119+
sw.Log(now, codersdk.LogLevelInfo, troubleshootingMessage(agent, "https://coder.com/docs/templates#agent-connection-issues"))
120120
for agent.Status == codersdk.WorkspaceAgentTimeout {
121121
if agent, err = fetch(); err != nil {
122122
return xerrors.Errorf("fetch: %w", err)
@@ -221,13 +221,13 @@ func Agent(ctx context.Context, writer io.Writer, agentID uuid.UUID, opts AgentO
221221
sw.Fail(stage, safeDuration(sw, agent.ReadyAt, agent.StartedAt))
222222
// Use zero time (omitted) to separate these from the startup logs.
223223
sw.Log(time.Time{}, codersdk.LogLevelWarn, "Warning: A startup script exited with an error and your workspace may be incomplete.")
224-
sw.Log(time.Time{}, codersdk.LogLevelWarn, troubleshootingMessage(agent, "https://coder.com/docs/v2/latest/templates/troubleshooting#startup-script-exited-with-an-error"))
224+
sw.Log(time.Time{}, codersdk.LogLevelWarn, troubleshootingMessage(agent, "https://coder.com/docs/templates/troubleshooting#startup-script-exited-with-an-error"))
225225
default:
226226
switch {
227227
case agent.LifecycleState.Starting():
228228
// Use zero time (omitted) to separate these from the startup logs.
229229
sw.Log(time.Time{}, codersdk.LogLevelWarn, "Notice: The startup scripts are still running and your workspace may be incomplete.")
230-
sw.Log(time.Time{}, codersdk.LogLevelWarn, troubleshootingMessage(agent, "https://coder.com/docs/v2/latest/templates/troubleshooting#your-workspace-may-be-incomplete"))
230+
sw.Log(time.Time{}, codersdk.LogLevelWarn, troubleshootingMessage(agent, "https://coder.com/docs/templates/troubleshooting#your-workspace-may-be-incomplete"))
231231
// Note: We don't complete or fail the stage here, it's
232232
// intentionally left open to indicate this stage didn't
233233
// complete.
@@ -249,7 +249,7 @@ func Agent(ctx context.Context, writer io.Writer, agentID uuid.UUID, opts AgentO
249249
stage := "The workspace agent lost connection"
250250
sw.Start(stage)
251251
sw.Log(time.Now(), codersdk.LogLevelWarn, "Wait for it to reconnect or restart your workspace.")
252-
sw.Log(time.Now(), codersdk.LogLevelWarn, troubleshootingMessage(agent, "https://coder.com/docs/v2/latest/templates/troubleshooting#agent-connection-issues"))
252+
sw.Log(time.Now(), codersdk.LogLevelWarn, troubleshootingMessage(agent, "https://coder.com/docs/templates/troubleshooting#agent-connection-issues"))
253253

254254
disconnectedAt := agent.DisconnectedAt
255255
for agent.Status == codersdk.WorkspaceAgentDisconnected {

cli/dotfiles.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func (r *RootCmd) dotfiles() *serpent.Command {
204204
}
205205

206206
if fi.Mode()&0o111 == 0 {
207-
return xerrors.Errorf("script %q is not executable. See https://coder.com/docs/v2/latest/dotfiles for information on how to resolve the issue.", script)
207+
return xerrors.Errorf("script %q is not executable. See https://coder.com/docs/dotfiles for information on how to resolve the issue.", script)
208208
}
209209

210210
// it is safe to use a variable command here because it's from

cli/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
838838
}
839839
defer options.Telemetry.Close()
840840
} else {
841-
logger.Warn(ctx, `telemetry disabled, unable to notify of security issues. Read more: https://coder.com/docs/v2/latest/admin/telemetry`)
841+
logger.Warn(ctx, `telemetry disabled, unable to notify of security issues. Read more: https://coder.com/docs/admin/telemetry`)
842842
}
843843

844844
// This prevents the pprof import from being accidentally deleted.

cli/templatelist_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ func TestTemplateList(t *testing.T) {
122122
_ = coderdtest.CreateTemplate(t, client, owner.OrganizationID, firstVersion.ID)
123123

124124
secondOrg := coderdtest.CreateOrganization(t, client, coderdtest.CreateOrganizationOptions{
125-
IncludeProvisionerDaemon: true,
125+
// Listing templates does not require the template actually completes.
126+
// We cannot provision an external provisioner in AGPL tests.
127+
IncludeProvisionerDaemon: false,
126128
})
127129
secondVersion := coderdtest.CreateTemplateVersion(t, client, secondOrg.ID, nil)
128130
_ = coderdtest.CreateTemplate(t, client, secondOrg.ID, secondVersion.ID)

cli/testdata/server-config.yaml.golden

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,8 @@ termsOfServiceURL: ""
427427
# (default: ed25519, type: string)
428428
sshKeygenAlgorithm: ed25519
429429
# URL to use for agent troubleshooting when not set in the template.
430-
# (default: https://coder.com/docs/v2/latest/templates/troubleshooting, type: url)
431-
agentFallbackTroubleshootingURL: https://coder.com/docs/v2/latest/templates/troubleshooting
430+
# (default: https://coder.com/docs/templates/troubleshooting, type: url)
431+
agentFallbackTroubleshootingURL: https://coder.com/docs/templates/troubleshooting
432432
# Disable workspace apps that are not served from subdomains. Path-based apps can
433433
# make requests to the Coder API and pose a security risk when the workspace
434434
# serves malicious JavaScript. This is recommended for security purposes if a

coderd/coderdtest/coderdtest.go

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -605,12 +605,18 @@ func NewExternalProvisionerDaemon(t testing.TB, client *codersdk.Client, org uui
605605

606606
// Without this check, the provisioner will silently fail.
607607
entitlements, err := client.Entitlements(context.Background())
608-
if err == nil {
609-
feature := entitlements.Features[codersdk.FeatureExternalProvisionerDaemons]
610-
if !feature.Enabled || feature.Entitlement != codersdk.EntitlementEntitled {
611-
require.NoError(t, xerrors.Errorf("external provisioner daemons require an entitled license"))
612-
return nil
613-
}
608+
if err != nil {
609+
// AGPL instances will throw this error. They cannot use external
610+
// provisioners.
611+
t.Errorf("external provisioners requires a license with entitlements. The client failed to fetch the entitlements, is this an enterprise instance of coderd?")
612+
t.FailNow()
613+
return nil
614+
}
615+
616+
feature := entitlements.Features[codersdk.FeatureExternalProvisionerDaemons]
617+
if !feature.Enabled || feature.Entitlement != codersdk.EntitlementEntitled {
618+
require.NoError(t, xerrors.Errorf("external provisioner daemons require an entitled license"))
619+
return nil
614620
}
615621

616622
echoClient, echoServer := drpc.MemTransportPipe()
@@ -796,13 +802,30 @@ func createAnotherUserRetry(t testing.TB, client *codersdk.Client, organizationI
796802
user, err = client.UpdateUserRoles(context.Background(), user.ID.String(), codersdk.UpdateRoles{Roles: db2sdk.List(siteRoles, onlyName)})
797803
require.NoError(t, err, "update site roles")
798804

805+
// isMember keeps track of which orgs the user was added to as a member
806+
isMember := map[uuid.UUID]bool{
807+
organizationID: true,
808+
}
809+
799810
// Update org roles
800811
for orgID, roles := range orgRoles {
812+
// The user must be an organization of any orgRoles, so insert
813+
// the organization member, then assign the roles.
814+
if !isMember[orgID] {
815+
_, err = client.PostOrganizationMember(context.Background(), orgID, user.ID.String())
816+
require.NoError(t, err, "add user to organization as member")
817+
}
818+
801819
_, err = client.UpdateOrganizationMemberRoles(context.Background(), orgID, user.ID.String(),
802820
codersdk.UpdateRoles{Roles: db2sdk.List(roles, onlyName)})
803821
require.NoError(t, err, "update org membership roles")
822+
isMember[orgID] = true
804823
}
805824
}
825+
826+
user, err = client.User(context.Background(), user.Username)
827+
require.NoError(t, err, "update final user")
828+
806829
return other, user
807830
}
808831

coderd/coderdtest/coderdtest_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ package coderdtest_test
33
import (
44
"testing"
55

6+
"github.com/google/uuid"
7+
"github.com/stretchr/testify/require"
68
"go.uber.org/goleak"
79

810
"github.com/coder/coder/v2/coderd/coderdtest"
11+
"github.com/coder/coder/v2/coderd/rbac"
912
)
1013

1114
func TestMain(m *testing.M) {
@@ -27,3 +30,20 @@ func TestNew(t *testing.T) {
2730
_, _ = coderdtest.NewGoogleInstanceIdentity(t, "example", false)
2831
_, _ = coderdtest.NewAWSInstanceIdentity(t, "an-instance")
2932
}
33+
34+
// TestOrganizationMember checks the coderdtest helper can add organization members
35+
// to multiple orgs.
36+
func TestOrganizationMember(t *testing.T) {
37+
t.Parallel()
38+
39+
client := coderdtest.New(t, &coderdtest.Options{})
40+
owner := coderdtest.CreateFirstUser(t, client)
41+
42+
second := coderdtest.CreateOrganization(t, client, coderdtest.CreateOrganizationOptions{})
43+
third := coderdtest.CreateOrganization(t, client, coderdtest.CreateOrganizationOptions{})
44+
45+
// Assign the user to 3 orgs in this 1 statement
46+
_, user := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID, rbac.ScopedRoleOrgMember(second.ID), rbac.ScopedRoleOrgMember(third.ID))
47+
require.Len(t, user.OrganizationIDs, 3)
48+
require.ElementsMatch(t, user.OrganizationIDs, []uuid.UUID{owner.OrganizationID, second.ID, third.ID})
49+
}

0 commit comments

Comments
 (0)