feat: Support config files with viper (#4696)

This commit is contained in:
Kyle Carberry
2022-10-21 17:08:23 -05:00
committed by GitHub
parent adc5c1a131
commit 7bc5b89f7a
36 changed files with 1099 additions and 1093 deletions
+13 -12
View File
@@ -24,10 +24,10 @@ import (
)
func server() *cobra.Command {
dflags := deployment.Flags()
cmd := agpl.Server(dflags, func(ctx context.Context, options *agplcoderd.Options) (*agplcoderd.API, io.Closer, error) {
if dflags.DerpServerRelayAddress.Value != "" {
_, err := url.Parse(dflags.DerpServerRelayAddress.Value)
vip := deployment.NewViper()
cmd := agpl.Server(vip, func(ctx context.Context, options *agplcoderd.Options) (*agplcoderd.API, io.Closer, error) {
if options.DeploymentConfig.DERPServerRelayURL.Value != "" {
_, err := url.Parse(options.DeploymentConfig.DERPServerRelayURL.Value)
if err != nil {
return nil, nil, xerrors.Errorf("derp-server-relay-address must be a valid HTTP URL: %w", err)
}
@@ -50,7 +50,7 @@ func server() *cobra.Command {
}
options.DERPServer.SetMeshKey(meshKey)
if dflags.AuditLogging.Value {
if options.DeploymentConfig.AuditLogging.Value {
options.Auditor = audit.NewAuditor(audit.DefaultFilter,
backends.NewPostgres(options.Database, true),
backends.NewSlog(options.Logger),
@@ -58,13 +58,13 @@ func server() *cobra.Command {
}
o := &coderd.Options{
AuditLogging: dflags.AuditLogging.Value,
BrowserOnly: dflags.BrowserOnly.Value,
SCIMAPIKey: []byte(dflags.SCIMAuthHeader.Value),
UserWorkspaceQuota: dflags.UserWorkspaceQuota.Value,
AuditLogging: options.DeploymentConfig.AuditLogging.Value,
BrowserOnly: options.DeploymentConfig.BrowserOnly.Value,
SCIMAPIKey: []byte(options.DeploymentConfig.SCIMAPIKey.Value),
UserWorkspaceQuota: options.DeploymentConfig.UserWorkspaceQuota.Value,
RBAC: true,
DERPServerRelayAddress: dflags.DerpServerRelayAddress.Value,
DERPServerRegionID: dflags.DerpServerRegionID.Value,
DERPServerRelayAddress: options.DeploymentConfig.DERPServerRelayURL.Value,
DERPServerRegionID: options.DeploymentConfig.DERPServerRegionID.Value,
Options: options,
}
@@ -76,6 +76,7 @@ func server() *cobra.Command {
return api.AGPL, api, nil
})
deployment.AttachFlags(cmd.Flags(), dflags, true)
deployment.AttachFlags(cmd.Flags(), vip, true)
return cmd
}