Skip to content

Commit 426e638

Browse files
committed
fix server
1 parent b1876bb commit 426e638

File tree

1 file changed

+47
-47
lines changed

1 file changed

+47
-47
lines changed

cli/server.go

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
117117

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

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

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

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

298298
defaultRegion := &tailcfg.DERPRegion{
299299
EmbeddedRelay: true,
300-
RegionID: cfg.DERPServerRegionID.Value,
301-
RegionCode: cfg.DERPServerRegionCode.Value,
302-
RegionName: cfg.DERPServerRegionName.Value,
300+
RegionID: cfg.DERP.Server.RegionID.Value,
301+
RegionCode: cfg.DERP.Server.RegionCode.Value,
302+
RegionName: cfg.DERP.Server.RegionName.Value,
303303
Nodes: []*tailcfg.DERPNode{{
304-
Name: fmt.Sprintf("%db", cfg.DERPServerRegionID.Value),
305-
RegionID: cfg.DERPServerRegionID.Value,
304+
Name: fmt.Sprintf("%db", cfg.DERP.Server.RegionID.Value),
305+
RegionID: cfg.DERP.Server.RegionID.Value,
306306
HostName: accessURLParsed.Hostname(),
307307
DERPPort: accessURLPort,
308308
STUNPort: -1,
309309
ForceHTTP: accessURLParsed.Scheme == "http",
310310
}},
311311
}
312-
if !cfg.DERPServerEnable.Value {
312+
if !cfg.DERP.Server.Enable.Value {
313313
defaultRegion = nil
314314
}
315-
derpMap, err := tailnet.NewDERPMap(ctx, defaultRegion, cfg.DERPServerSTUNAddresses.Value, cfg.DERPConfigURL.Value, cfg.DERPConfigPath.Value)
315+
derpMap, err := tailnet.NewDERPMap(ctx, defaultRegion, cfg.DERP.Server.STUNAddresses.Value, cfg.DERP.Config.URL.Value, cfg.DERP.Config.Path.Value)
316316
if err != nil {
317317
return xerrors.Errorf("create derp map: %w", err)
318318
}
@@ -356,29 +356,29 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
356356
options.TLSCertificates = tlsConfig.Certificates
357357
}
358358

359-
if cfg.OAuth2GithubClientSecret.Value != "" {
359+
if cfg.OAuth2.Github.ClientSecret.Value != "" {
360360
options.GithubOAuth2Config, err = configureGithubOAuth2(accessURLParsed,
361-
cfg.OAuth2GithubClientID.Value,
362-
cfg.OAuth2GithubClientSecret.Value,
363-
cfg.OAuth2GithubAllowSignups.Value,
364-
cfg.OAuth2GithubAllowedOrgs.Value,
365-
cfg.OAuth2GithubAllowedTeams.Value,
366-
cfg.OAuth2GithubEnterpriseBaseURL.Value,
361+
cfg.OAuth2.Github.ClientID.Value,
362+
cfg.OAuth2.Github.ClientSecret.Value,
363+
cfg.OAuth2.Github.AllowSignups.Value,
364+
cfg.OAuth2.Github.AllowedOrgs.Value,
365+
cfg.OAuth2.Github.AllowedTeams.Value,
366+
cfg.OAuth2.Github.EnterpriseBaseURL.Value,
367367
)
368368
if err != nil {
369369
return xerrors.Errorf("configure github oauth2: %w", err)
370370
}
371371
}
372372

373-
if cfg.OIDCClientSecret.Value != "" {
374-
if cfg.OIDCClientID.Value == "" {
373+
if cfg.OIDC.ClientSecret.Value != "" {
374+
if cfg.OIDC.ClientID.Value == "" {
375375
return xerrors.Errorf("OIDC client ID be set!")
376376
}
377-
if cfg.OIDCIssuerURL.Value == "" {
377+
if cfg.OIDC.IssuerURL.Value == "" {
378378
return xerrors.Errorf("OIDC issuer URL must be set!")
379379
}
380380

381-
oidcProvider, err := oidc.NewProvider(ctx, cfg.OIDCIssuerURL.Value)
381+
oidcProvider, err := oidc.NewProvider(ctx, cfg.OIDC.IssuerURL.Value)
382382
if err != nil {
383383
return xerrors.Errorf("configure oidc provider: %w", err)
384384
}
@@ -388,17 +388,17 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
388388
}
389389
options.OIDCConfig = &coderd.OIDCConfig{
390390
OAuth2Config: &oauth2.Config{
391-
ClientID: cfg.OIDCClientID.Value,
392-
ClientSecret: cfg.OIDCClientSecret.Value,
391+
ClientID: cfg.OIDC.ClientID.Value,
392+
ClientSecret: cfg.OIDC.ClientSecret.Value,
393393
RedirectURL: redirectURL.String(),
394394
Endpoint: oidcProvider.Endpoint(),
395-
Scopes: cfg.OIDCScopes.Value,
395+
Scopes: cfg.OIDC.Scopes.Value,
396396
},
397397
Verifier: oidcProvider.Verifier(&oidc.Config{
398-
ClientID: cfg.OIDCClientID.Value,
398+
ClientID: cfg.OIDC.ClientID.Value,
399399
}),
400-
EmailDomain: cfg.OIDCEmailDomain.Value,
401-
AllowSignups: cfg.OIDCAllowSignups.Value,
400+
EmailDomain: cfg.OIDC.EmailDomain.Value,
401+
AllowSignups: cfg.OIDC.AllowSignups.Value,
402402
}
403403
}
404404

@@ -461,26 +461,26 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
461461
}
462462

463463
// Parse the raw telemetry URL!
464-
telemetryURL, err := parseURL(ctx, cfg.TelemetryURL.Value)
464+
telemetryURL, err := parseURL(ctx, cfg.Telemetry.URL.Value)
465465
if err != nil {
466466
return xerrors.Errorf("parse telemetry url: %w", err)
467467
}
468468
// Disable telemetry if the in-memory database is used unless explicitly defined!
469-
if cfg.InMemoryDatabase.Value && !cmd.Flags().Changed(cfg.TelemetryEnable.Flag) {
470-
cfg.TelemetryEnable.Value = false
469+
if cfg.InMemoryDatabase.Value && !cmd.Flags().Changed(cfg.Telemetry.Enable.Flag) {
470+
cfg.Telemetry.Enable.Value = false
471471
}
472-
if cfg.TelemetryEnable.Value {
472+
if cfg.Telemetry.Enable.Value {
473473
options.Telemetry, err = telemetry.New(telemetry.Options{
474474
BuiltinPostgres: builtinPostgres,
475475
DeploymentID: deploymentID,
476476
Database: options.Database,
477477
Logger: logger.Named("telemetry"),
478478
URL: telemetryURL,
479-
GitHubOAuth: cfg.OAuth2GithubClientID.Value != "",
480-
OIDCAuth: cfg.OIDCClientID.Value != "",
481-
OIDCIssuerURL: cfg.OIDCIssuerURL.Value,
482-
Prometheus: cfg.PrometheusEnable.Value,
483-
STUN: len(cfg.DERPServerSTUNAddresses.Value) != 0,
479+
GitHubOAuth: cfg.OAuth2.Github.ClientID.Value != "",
480+
OIDCAuth: cfg.OIDC.ClientID.Value != "",
481+
OIDCIssuerURL: cfg.OIDC.IssuerURL.Value,
482+
Prometheus: cfg.Prometheus.Enable.Value,
483+
STUN: len(cfg.DERP.Server.STUNAddresses.Value) != 0,
484484
Tunnel: tunnel != nil,
485485
})
486486
if err != nil {
@@ -491,11 +491,11 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
491491

492492
// This prevents the pprof import from being accidentally deleted.
493493
_ = pprof.Handler
494-
if cfg.PprofEnable.Value {
494+
if cfg.Pprof.Enable.Value {
495495
//nolint:revive
496-
defer serveHandler(ctx, logger, nil, cfg.PprofAddress.Value, "pprof")()
496+
defer serveHandler(ctx, logger, nil, cfg.Pprof.Address.Value, "pprof")()
497497
}
498-
if cfg.PrometheusEnable.Value {
498+
if cfg.Prometheus.Enable.Value {
499499
options.PrometheusRegistry = prometheus.NewRegistry()
500500
closeUsersFunc, err := prometheusmetrics.ActiveUsers(ctx, options.PrometheusRegistry, options.Database, 0)
501501
if err != nil {
@@ -512,7 +512,7 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
512512
//nolint:revive
513513
defer serveHandler(ctx, logger, promhttp.InstrumentMetricHandler(
514514
options.PrometheusRegistry, promhttp.HandlerFor(options.PrometheusRegistry, promhttp.HandlerOpts{}),
515-
), cfg.PrometheusAddress.Value, "prometheus")()
515+
), cfg.Prometheus.Address.Value, "prometheus")()
516516
}
517517

518518
// We use a separate coderAPICloser so the Enterprise API
@@ -524,7 +524,7 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
524524
}
525525

526526
client := codersdk.New(localURL)
527-
if cfg.TLSEnable.Value {
527+
if cfg.TLS.Enable.Value {
528528
// Secure transport isn't needed for locally communicating!
529529
client.HTTPClient.Transport = &http.Transport{
530530
TLSClientConfig: &tls.Config{

0 commit comments

Comments
 (0)