Skip to content

Commit 7d4252b

Browse files
committed
Merge branch 'main' into gitprovider
2 parents 29c9e47 + 585045b commit 7d4252b

File tree

16 files changed

+792
-620
lines changed

16 files changed

+792
-620
lines changed

cli/deployment/config.go

+410-354
Large diffs are not rendered by default.

cli/deployment/config_test.go

+44-44
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestConfig(t *testing.T) {
2121
for _, tc := range []struct {
2222
Name string
2323
Env map[string]string
24-
Valid func(config codersdk.DeploymentConfig)
24+
Valid func(config *codersdk.DeploymentConfig)
2525
}{{
2626
Name: "Deployment",
2727
Env: map[string]string{
@@ -39,19 +39,19 @@ func TestConfig(t *testing.T) {
3939
"CODER_TELEMETRY_TRACE": "false",
4040
"CODER_WILDCARD_ACCESS_URL": "something-wildcard.com",
4141
},
42-
Valid: func(config codersdk.DeploymentConfig) {
42+
Valid: func(config *codersdk.DeploymentConfig) {
4343
require.Equal(t, config.Address.Value, "0.0.0.0:8443")
4444
require.Equal(t, config.AccessURL.Value, "https://dev.coder.com")
4545
require.Equal(t, config.PostgresURL.Value, "some-url")
46-
require.Equal(t, config.PprofAddress.Value, "something")
47-
require.Equal(t, config.PprofEnable.Value, true)
48-
require.Equal(t, config.PrometheusAddress.Value, "hello-world")
49-
require.Equal(t, config.PrometheusEnable.Value, true)
46+
require.Equal(t, config.Pprof.Address.Value, "something")
47+
require.Equal(t, config.Pprof.Enable.Value, true)
48+
require.Equal(t, config.Prometheus.Address.Value, "hello-world")
49+
require.Equal(t, config.Prometheus.Enable.Value, true)
5050
require.Equal(t, config.ProvisionerDaemons.Value, 5)
5151
require.Equal(t, config.SecureAuthCookie.Value, true)
5252
require.Equal(t, config.SSHKeygenAlgorithm.Value, "potato")
53-
require.Equal(t, config.TelemetryEnable.Value, false)
54-
require.Equal(t, config.TelemetryTrace.Value, false)
53+
require.Equal(t, config.Telemetry.Enable.Value, false)
54+
require.Equal(t, config.Telemetry.Trace.Value, false)
5555
require.Equal(t, config.WildcardAccessURL.Value, "something-wildcard.com")
5656
},
5757
}, {
@@ -66,15 +66,15 @@ func TestConfig(t *testing.T) {
6666
"CODER_DERP_SERVER_RELAY_URL": "1.1.1.1",
6767
"CODER_DERP_SERVER_STUN_ADDRESSES": "google.org",
6868
},
69-
Valid: func(config codersdk.DeploymentConfig) {
70-
require.Equal(t, config.DERPConfigPath.Value, "/example/path")
71-
require.Equal(t, config.DERPConfigURL.Value, "https://google.com")
72-
require.Equal(t, config.DERPServerEnable.Value, false)
73-
require.Equal(t, config.DERPServerRegionCode.Value, "something")
74-
require.Equal(t, config.DERPServerRegionID.Value, 123)
75-
require.Equal(t, config.DERPServerRegionName.Value, "Code-Land")
76-
require.Equal(t, config.DERPServerRelayURL.Value, "1.1.1.1")
77-
require.Equal(t, config.DERPServerSTUNAddresses.Value, []string{"google.org"})
69+
Valid: func(config *codersdk.DeploymentConfig) {
70+
require.Equal(t, config.DERP.Config.Path.Value, "/example/path")
71+
require.Equal(t, config.DERP.Config.URL.Value, "https://google.com")
72+
require.Equal(t, config.DERP.Server.Enable.Value, false)
73+
require.Equal(t, config.DERP.Server.RegionCode.Value, "something")
74+
require.Equal(t, config.DERP.Server.RegionID.Value, 123)
75+
require.Equal(t, config.DERP.Server.RegionName.Value, "Code-Land")
76+
require.Equal(t, config.DERP.Server.RelayURL.Value, "1.1.1.1")
77+
require.Equal(t, config.DERP.Server.STUNAddresses.Value, []string{"google.org"})
7878
},
7979
}, {
8080
Name: "Enterprise",
@@ -84,7 +84,7 @@ func TestConfig(t *testing.T) {
8484
"CODER_SCIM_API_KEY": "some-key",
8585
"CODER_USER_WORKSPACE_QUOTA": "10",
8686
},
87-
Valid: func(config codersdk.DeploymentConfig) {
87+
Valid: func(config *codersdk.DeploymentConfig) {
8888
require.Equal(t, config.AuditLogging.Value, false)
8989
require.Equal(t, config.BrowserOnly.Value, true)
9090
require.Equal(t, config.SCIMAPIKey.Value, "some-key")
@@ -100,19 +100,19 @@ func TestConfig(t *testing.T) {
100100
"CODER_TLS_ENABLE": "true",
101101
"CODER_TLS_MIN_VERSION": "tls10",
102102
},
103-
Valid: func(config codersdk.DeploymentConfig) {
104-
require.Len(t, config.TLSCertFiles.Value, 2)
105-
require.Equal(t, config.TLSCertFiles.Value[0], "/etc/acme-sh/dev.coder.com")
106-
require.Equal(t, config.TLSCertFiles.Value[1], "/etc/acme-sh/*.dev.coder.com")
103+
Valid: func(config *codersdk.DeploymentConfig) {
104+
require.Len(t, config.TLS.CertFiles.Value, 2)
105+
require.Equal(t, config.TLS.CertFiles.Value[0], "/etc/acme-sh/dev.coder.com")
106+
require.Equal(t, config.TLS.CertFiles.Value[1], "/etc/acme-sh/*.dev.coder.com")
107107

108-
require.Len(t, config.TLSKeyFiles.Value, 2)
109-
require.Equal(t, config.TLSKeyFiles.Value[0], "/etc/acme-sh/dev.coder.com")
110-
require.Equal(t, config.TLSKeyFiles.Value[1], "/etc/acme-sh/*.dev.coder.com")
108+
require.Len(t, config.TLS.KeyFiles.Value, 2)
109+
require.Equal(t, config.TLS.KeyFiles.Value[0], "/etc/acme-sh/dev.coder.com")
110+
require.Equal(t, config.TLS.KeyFiles.Value[1], "/etc/acme-sh/*.dev.coder.com")
111111

112-
require.Equal(t, config.TLSClientAuth.Value, "/some/path")
113-
require.Equal(t, config.TLSClientCAFile.Value, "/some/path")
114-
require.Equal(t, config.TLSEnable.Value, true)
115-
require.Equal(t, config.TLSMinVersion.Value, "tls10")
112+
require.Equal(t, config.TLS.ClientAuth.Value, "/some/path")
113+
require.Equal(t, config.TLS.ClientCAFile.Value, "/some/path")
114+
require.Equal(t, config.TLS.Enable.Value, true)
115+
require.Equal(t, config.TLS.MinVersion.Value, "tls10")
116116
},
117117
}, {
118118
Name: "OIDC",
@@ -124,13 +124,13 @@ func TestConfig(t *testing.T) {
124124
"CODER_OIDC_ALLOW_SIGNUPS": "false",
125125
"CODER_OIDC_SCOPES": "something,here",
126126
},
127-
Valid: func(config codersdk.DeploymentConfig) {
128-
require.Equal(t, config.OIDCIssuerURL.Value, "https://accounts.google.com")
129-
require.Equal(t, config.OIDCEmailDomain.Value, "coder.com")
130-
require.Equal(t, config.OIDCClientID.Value, "client")
131-
require.Equal(t, config.OIDCClientSecret.Value, "secret")
132-
require.Equal(t, config.OIDCAllowSignups.Value, false)
133-
require.Equal(t, config.OIDCScopes.Value, []string{"something", "here"})
127+
Valid: func(config *codersdk.DeploymentConfig) {
128+
require.Equal(t, config.OIDC.IssuerURL.Value, "https://accounts.google.com")
129+
require.Equal(t, config.OIDC.EmailDomain.Value, "coder.com")
130+
require.Equal(t, config.OIDC.ClientID.Value, "client")
131+
require.Equal(t, config.OIDC.ClientSecret.Value, "secret")
132+
require.Equal(t, config.OIDC.AllowSignups.Value, false)
133+
require.Equal(t, config.OIDC.Scopes.Value, []string{"something", "here"})
134134
},
135135
}, {
136136
Name: "GitHub",
@@ -141,12 +141,12 @@ func TestConfig(t *testing.T) {
141141
"CODER_OAUTH2_GITHUB_ALLOWED_TEAMS": "coder",
142142
"CODER_OAUTH2_GITHUB_ALLOW_SIGNUPS": "true",
143143
},
144-
Valid: func(config codersdk.DeploymentConfig) {
145-
require.Equal(t, config.OAuth2GithubClientID.Value, "client")
146-
require.Equal(t, config.OAuth2GithubClientSecret.Value, "secret")
147-
require.Equal(t, []string{"coder"}, config.OAuth2GithubAllowedOrgs.Value)
148-
require.Equal(t, []string{"coder"}, config.OAuth2GithubAllowedTeams.Value)
149-
require.Equal(t, config.OAuth2GithubAllowSignups.Value, true)
144+
Valid: func(config *codersdk.DeploymentConfig) {
145+
require.Equal(t, config.OAuth2.Github.ClientID.Value, "client")
146+
require.Equal(t, config.OAuth2.Github.ClientSecret.Value, "secret")
147+
require.Equal(t, []string{"coder"}, config.OAuth2.Github.AllowedOrgs.Value)
148+
require.Equal(t, []string{"coder"}, config.OAuth2.Github.AllowedTeams.Value)
149+
require.Equal(t, config.OAuth2.Github.AllowSignups.Value, true)
150150
},
151151
}, {
152152
Name: "GitAuth",
@@ -167,9 +167,9 @@ func TestConfig(t *testing.T) {
167167
"CODER_GITAUTH_1_TOKEN_URL": "https://token-2.com",
168168
"CODER_GITAUTH_1_REGEX": "gitlab.com",
169169
},
170-
Valid: func(config codersdk.DeploymentConfig) {
170+
Valid: func(config *codersdk.DeploymentConfig) {
171171
require.Len(t, config.GitAuth.Value, 2)
172-
require.Equal(t, []codersdk.DeploymentConfigGitAuth{{
172+
require.Equal(t, []codersdk.GitAuthConfig{{
173173
ID: "hello",
174174
Type: "github",
175175
ClientID: "client",

cli/server.go

+48-48
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
118118

119119
// Coder tracing should be disabled if telemetry is disabled unless
120120
// --telemetry-trace was explicitly provided.
121-
shouldCoderTrace := cfg.TelemetryEnable.Value && !isTest()
121+
shouldCoderTrace := cfg.Telemetry.Enable.Value && !isTest()
122122
// Only override if telemetryTraceEnable was specifically set.
123123
// By default we want it to be controlled by telemetryEnable.
124124
if cmd.Flags().Changed("telemetry-trace") {
125-
shouldCoderTrace = cfg.TelemetryTrace.Value
125+
shouldCoderTrace = cfg.Telemetry.Trace.Value
126126
}
127127

128128
if cfg.TraceEnable.Value || shouldCoderTrace {
@@ -175,13 +175,13 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
175175
defer listener.Close()
176176

177177
var tlsConfig *tls.Config
178-
if cfg.TLSEnable.Value {
178+
if cfg.TLS.Enable.Value {
179179
tlsConfig, err = configureTLS(
180-
cfg.TLSMinVersion.Value,
181-
cfg.TLSClientAuth.Value,
182-
cfg.TLSCertFiles.Value,
183-
cfg.TLSKeyFiles.Value,
184-
cfg.TLSClientCAFile.Value,
180+
cfg.TLS.MinVersion.Value,
181+
cfg.TLS.ClientAuth.Value,
182+
cfg.TLS.CertFiles.Value,
183+
cfg.TLS.KeyFiles.Value,
184+
cfg.TLS.ClientCAFile.Value,
185185
)
186186
if err != nil {
187187
return xerrors.Errorf("configure tls: %w", err)
@@ -203,7 +203,7 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
203203
Scheme: "http",
204204
Host: tcpAddr.String(),
205205
}
206-
if cfg.TLSEnable.Value {
206+
if cfg.TLS.Enable.Value {
207207
localURL.Scheme = "https"
208208
}
209209

@@ -298,22 +298,22 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
298298

299299
defaultRegion := &tailcfg.DERPRegion{
300300
EmbeddedRelay: true,
301-
RegionID: cfg.DERPServerRegionID.Value,
302-
RegionCode: cfg.DERPServerRegionCode.Value,
303-
RegionName: cfg.DERPServerRegionName.Value,
301+
RegionID: cfg.DERP.Server.RegionID.Value,
302+
RegionCode: cfg.DERP.Server.RegionCode.Value,
303+
RegionName: cfg.DERP.Server.RegionName.Value,
304304
Nodes: []*tailcfg.DERPNode{{
305-
Name: fmt.Sprintf("%db", cfg.DERPServerRegionID.Value),
306-
RegionID: cfg.DERPServerRegionID.Value,
305+
Name: fmt.Sprintf("%db", cfg.DERP.Server.RegionID.Value),
306+
RegionID: cfg.DERP.Server.RegionID.Value,
307307
HostName: accessURLParsed.Hostname(),
308308
DERPPort: accessURLPort,
309309
STUNPort: -1,
310310
ForceHTTP: accessURLParsed.Scheme == "http",
311311
}},
312312
}
313-
if !cfg.DERPServerEnable.Value {
313+
if !cfg.DERP.Server.Enable.Value {
314314
defaultRegion = nil
315315
}
316-
derpMap, err := tailnet.NewDERPMap(ctx, defaultRegion, cfg.DERPServerSTUNAddresses.Value, cfg.DERPConfigURL.Value, cfg.DERPConfigPath.Value)
316+
derpMap, err := tailnet.NewDERPMap(ctx, defaultRegion, cfg.DERP.Server.STUNAddresses.Value, cfg.DERP.Config.URL.Value, cfg.DERP.Config.Path.Value)
317317
if err != nil {
318318
return xerrors.Errorf("create derp map: %w", err)
319319
}
@@ -357,35 +357,35 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
357357
MetricsCacheRefreshInterval: cfg.MetricsCacheRefreshInterval.Value,
358358
AgentStatsRefreshInterval: cfg.AgentStatRefreshInterval.Value,
359359
Experimental: ExperimentalEnabled(cmd),
360-
DeploymentConfig: &cfg,
360+
DeploymentConfig: cfg,
361361
}
362362
if tlsConfig != nil {
363363
options.TLSCertificates = tlsConfig.Certificates
364364
}
365365

366-
if cfg.OAuth2GithubClientSecret.Value != "" {
366+
if cfg.OAuth2.Github.ClientSecret.Value != "" {
367367
options.GithubOAuth2Config, err = configureGithubOAuth2(accessURLParsed,
368-
cfg.OAuth2GithubClientID.Value,
369-
cfg.OAuth2GithubClientSecret.Value,
370-
cfg.OAuth2GithubAllowSignups.Value,
371-
cfg.OAuth2GithubAllowedOrgs.Value,
372-
cfg.OAuth2GithubAllowedTeams.Value,
373-
cfg.OAuth2GithubEnterpriseBaseURL.Value,
368+
cfg.OAuth2.Github.ClientID.Value,
369+
cfg.OAuth2.Github.ClientSecret.Value,
370+
cfg.OAuth2.Github.AllowSignups.Value,
371+
cfg.OAuth2.Github.AllowedOrgs.Value,
372+
cfg.OAuth2.Github.AllowedTeams.Value,
373+
cfg.OAuth2.Github.EnterpriseBaseURL.Value,
374374
)
375375
if err != nil {
376376
return xerrors.Errorf("configure github oauth2: %w", err)
377377
}
378378
}
379379

380-
if cfg.OIDCClientSecret.Value != "" {
381-
if cfg.OIDCClientID.Value == "" {
380+
if cfg.OIDC.ClientSecret.Value != "" {
381+
if cfg.OIDC.ClientID.Value == "" {
382382
return xerrors.Errorf("OIDC client ID be set!")
383383
}
384-
if cfg.OIDCIssuerURL.Value == "" {
384+
if cfg.OIDC.IssuerURL.Value == "" {
385385
return xerrors.Errorf("OIDC issuer URL must be set!")
386386
}
387387

388-
oidcProvider, err := oidc.NewProvider(ctx, cfg.OIDCIssuerURL.Value)
388+
oidcProvider, err := oidc.NewProvider(ctx, cfg.OIDC.IssuerURL.Value)
389389
if err != nil {
390390
return xerrors.Errorf("configure oidc provider: %w", err)
391391
}
@@ -395,17 +395,17 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
395395
}
396396
options.OIDCConfig = &coderd.OIDCConfig{
397397
OAuth2Config: &oauth2.Config{
398-
ClientID: cfg.OIDCClientID.Value,
399-
ClientSecret: cfg.OIDCClientSecret.Value,
398+
ClientID: cfg.OIDC.ClientID.Value,
399+
ClientSecret: cfg.OIDC.ClientSecret.Value,
400400
RedirectURL: redirectURL.String(),
401401
Endpoint: oidcProvider.Endpoint(),
402-
Scopes: cfg.OIDCScopes.Value,
402+
Scopes: cfg.OIDC.Scopes.Value,
403403
},
404404
Verifier: oidcProvider.Verifier(&oidc.Config{
405-
ClientID: cfg.OIDCClientID.Value,
405+
ClientID: cfg.OIDC.ClientID.Value,
406406
}),
407-
EmailDomain: cfg.OIDCEmailDomain.Value,
408-
AllowSignups: cfg.OIDCAllowSignups.Value,
407+
EmailDomain: cfg.OIDC.EmailDomain.Value,
408+
AllowSignups: cfg.OIDC.AllowSignups.Value,
409409
}
410410
}
411411

@@ -469,26 +469,26 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
469469
}
470470

471471
// Parse the raw telemetry URL!
472-
telemetryURL, err := parseURL(ctx, cfg.TelemetryURL.Value)
472+
telemetryURL, err := parseURL(ctx, cfg.Telemetry.URL.Value)
473473
if err != nil {
474474
return xerrors.Errorf("parse telemetry url: %w", err)
475475
}
476476
// Disable telemetry if the in-memory database is used unless explicitly defined!
477-
if cfg.InMemoryDatabase.Value && !cmd.Flags().Changed(cfg.TelemetryEnable.Flag) {
478-
cfg.TelemetryEnable.Value = false
477+
if cfg.InMemoryDatabase.Value && !cmd.Flags().Changed(cfg.Telemetry.Enable.Flag) {
478+
cfg.Telemetry.Enable.Value = false
479479
}
480-
if cfg.TelemetryEnable.Value {
480+
if cfg.Telemetry.Enable.Value {
481481
options.Telemetry, err = telemetry.New(telemetry.Options{
482482
BuiltinPostgres: builtinPostgres,
483483
DeploymentID: deploymentID,
484484
Database: options.Database,
485485
Logger: logger.Named("telemetry"),
486486
URL: telemetryURL,
487-
GitHubOAuth: cfg.OAuth2GithubClientID.Value != "",
488-
OIDCAuth: cfg.OIDCClientID.Value != "",
489-
OIDCIssuerURL: cfg.OIDCIssuerURL.Value,
490-
Prometheus: cfg.PrometheusEnable.Value,
491-
STUN: len(cfg.DERPServerSTUNAddresses.Value) != 0,
487+
GitHubOAuth: cfg.OAuth2.Github.ClientID.Value != "",
488+
OIDCAuth: cfg.OIDC.ClientID.Value != "",
489+
OIDCIssuerURL: cfg.OIDC.IssuerURL.Value,
490+
Prometheus: cfg.Prometheus.Enable.Value,
491+
STUN: len(cfg.DERP.Server.STUNAddresses.Value) != 0,
492492
Tunnel: tunnel != nil,
493493
})
494494
if err != nil {
@@ -499,11 +499,11 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
499499

500500
// This prevents the pprof import from being accidentally deleted.
501501
_ = pprof.Handler
502-
if cfg.PprofEnable.Value {
502+
if cfg.Pprof.Enable.Value {
503503
//nolint:revive
504-
defer serveHandler(ctx, logger, nil, cfg.PprofAddress.Value, "pprof")()
504+
defer serveHandler(ctx, logger, nil, cfg.Pprof.Address.Value, "pprof")()
505505
}
506-
if cfg.PrometheusEnable.Value {
506+
if cfg.Prometheus.Enable.Value {
507507
options.PrometheusRegistry = prometheus.NewRegistry()
508508
closeUsersFunc, err := prometheusmetrics.ActiveUsers(ctx, options.PrometheusRegistry, options.Database, 0)
509509
if err != nil {
@@ -520,7 +520,7 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
520520
//nolint:revive
521521
defer serveHandler(ctx, logger, promhttp.InstrumentMetricHandler(
522522
options.PrometheusRegistry, promhttp.HandlerFor(options.PrometheusRegistry, promhttp.HandlerOpts{}),
523-
), cfg.PrometheusAddress.Value, "prometheus")()
523+
), cfg.Prometheus.Address.Value, "prometheus")()
524524
}
525525

526526
// We use a separate coderAPICloser so the Enterprise API
@@ -532,7 +532,7 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
532532
}
533533

534534
client := codersdk.New(localURL)
535-
if cfg.TLSEnable.Value {
535+
if cfg.TLS.Enable.Value {
536536
// Secure transport isn't needed for locally communicating!
537537
client.HTTPClient.Transport = &http.Transport{
538538
TLSClientConfig: &tls.Config{

coderd/deploymentconfig_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,22 @@ func TestDeploymentConfig(t *testing.T) {
2626
// values should be returned
2727
cfg.AccessURL.Value = hi
2828
// values should not be returned
29-
cfg.OAuth2GithubClientSecret.Value = hi
30-
cfg.OIDCClientSecret.Value = hi
29+
cfg.OAuth2.Github.ClientSecret.Value = hi
30+
cfg.OIDC.ClientSecret.Value = hi
3131
cfg.PostgresURL.Value = hi
3232
cfg.SCIMAPIKey.Value = hi
3333

3434
client := coderdtest.New(t, &coderdtest.Options{
35-
DeploymentConfig: &cfg,
35+
DeploymentConfig: cfg,
3636
})
3737
_ = coderdtest.CreateFirstUser(t, client)
3838
scrubbed, err := client.DeploymentConfig(ctx)
3939
require.NoError(t, err)
4040
// ensure normal values pass through
4141
require.EqualValues(t, hi, scrubbed.AccessURL.Value)
4242
// ensure secrets are removed
43-
require.Empty(t, scrubbed.OAuth2GithubClientSecret.Value)
44-
require.Empty(t, scrubbed.OIDCClientSecret.Value)
43+
require.Empty(t, scrubbed.OAuth2.Github.ClientSecret.Value)
44+
require.Empty(t, scrubbed.OIDC.ClientSecret.Value)
4545
require.Empty(t, scrubbed.PostgresURL.Value)
4646
require.Empty(t, scrubbed.SCIMAPIKey.Value)
4747
}

0 commit comments

Comments
 (0)