Skip to content

Commit 63159a6

Browse files
committed
ugh
1 parent 69600d7 commit 63159a6

15 files changed

+112
-86
lines changed

cli/bigcli/value.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ func (i *Int64) Set(s string) error {
1919
return err
2020
}
2121

22-
func (i Int64) Int() int {
23-
return int(i)
22+
func (i Int64) Value() int64 {
23+
return int64(i)
2424
}
2525

2626
func (i Int64) String() string {
@@ -43,7 +43,7 @@ func (b Bool) String() string {
4343
return strconv.FormatBool(bool(b))
4444
}
4545

46-
func (b Bool) Bool() bool {
46+
func (b Bool) Value() bool {
4747
return bool(b)
4848
}
4949

@@ -62,6 +62,10 @@ func (s String) String() string {
6262
return string(s)
6363
}
6464

65+
func (s String) Value() string {
66+
return string(s)
67+
}
68+
6569
func (String) Type() string {
6670
return "string"
6771
}
@@ -77,7 +81,7 @@ func (s Strings) String() string {
7781
return strings.Join(s, ",")
7882
}
7983

80-
func (s Strings) Strings() []string {
84+
func (s Strings) Value() []string {
8185
return []string(s)
8286
}
8387

@@ -93,7 +97,7 @@ func (d *Duration) Set(v string) error {
9397
return err
9498
}
9599

96-
func (d *Duration) Duration() time.Duration {
100+
func (d *Duration) Value() time.Duration {
97101
return time.Duration(*d)
98102
}
99103

@@ -125,7 +129,7 @@ func (*URL) Type() string {
125129
return "url"
126130
}
127131

128-
func (u *URL) URL() *url.URL {
132+
func (u *URL) Value() *url.URL {
129133
return (*url.URL)(u)
130134
}
131135

cli/server.go

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -832,16 +832,16 @@ func Server(newAPI func(context.Context, *coderd.Options) (*coderd.API, io.Close
832832

833833
// Coder tracing should be disabled if telemetry is disabled unless
834834
// --telemetry-trace was explicitly provided.
835-
shouldCoderTrace := bool(cfg.Telemetry.Enable.Bool()) && !isTest()
835+
shouldCoderTrace := bool(cfg.Telemetry.Enable.Value()) && !isTest()
836836
// Only override if telemetryTraceEnable was specifically set.
837837
// By default we want it to be controlled by telemetryEnable.
838838
if cmd.Flags().Changed("telemetry-trace") {
839-
shouldCoderTrace = cfg.Telemetry.Trace.Bool()
839+
shouldCoderTrace = cfg.Telemetry.Trace.Value()
840840
}
841841

842-
if cfg.Trace.Enable.Bool() || shouldCoderTrace || cfg.Trace.HoneycombAPIKey != "" {
842+
if cfg.Trace.Enable.Value() || shouldCoderTrace || cfg.Trace.HoneycombAPIKey != "" {
843843
sdkTracerProvider, closeTracing, err := tracing.TracerProvider(ctx, "coderd", tracing.TracerOpts{
844-
Default: cfg.Trace.Enable.Bool(),
844+
Default: cfg.Trace.Enable.Value(),
845845
Coder: shouldCoderTrace,
846846
Honeycomb: cfg.Trace.HoneycombAPIKey.String(),
847847
})
@@ -1064,7 +1064,7 @@ func Server(newAPI func(context.Context, *coderd.Options) (*coderd.API, io.Close
10641064
}
10651065

10661066
// Warn the user if the access URL appears to be a loopback address.
1067-
isLocal, err := isLocalURL(ctx, cfg.AccessURL.URL())
1067+
isLocal, err := isLocalURL(ctx, cfg.AccessURL.Value())
10681068
if isLocal || err != nil {
10691069
reason := "could not be resolved"
10701070
if isLocal {
@@ -1092,12 +1092,12 @@ func Server(newAPI func(context.Context, *coderd.Options) (*coderd.API, io.Close
10921092

10931093
defaultRegion := &tailcfg.DERPRegion{
10941094
EmbeddedRelay: true,
1095-
RegionID: cfg.DERP.Server.RegionID.Int(),
1095+
RegionID: int(cfg.DERP.Server.RegionID.Value()),
10961096
RegionCode: cfg.DERP.Server.RegionCode.String(),
10971097
RegionName: cfg.DERP.Server.RegionName.String(),
10981098
Nodes: []*tailcfg.DERPNode{{
10991099
Name: fmt.Sprintf("%db", cfg.DERP.Server.RegionID),
1100-
RegionID: cfg.DERP.Server.RegionID.Int(),
1100+
RegionID: int(cfg.DERP.Server.RegionID.Value()),
11011101
HostName: cfg.AccessURL.Host,
11021102
DERPPort: accessURLPort,
11031103
STUNPort: -1,
@@ -1130,7 +1130,7 @@ func Server(newAPI func(context.Context, *coderd.Options) (*coderd.API, io.Close
11301130
}
11311131

11321132
options := &coderd.Options{
1133-
AccessURL: cfg.AccessURL.URL(),
1133+
AccessURL: cfg.AccessURL.Value(),
11341134
AppHostname: appHostname,
11351135
AppHostnameRegex: appHostnameRegex,
11361136
Logger: logger.Named("coderd"),
@@ -1141,15 +1141,15 @@ func Server(newAPI func(context.Context, *coderd.Options) (*coderd.API, io.Close
11411141
GoogleTokenValidator: googleTokenValidator,
11421142
// GitAuthConfigs: gitAuthConfigs,
11431143
RealIPConfig: realIPConfig,
1144-
SecureAuthCookie: cfg.SecureAuthCookie.Bool(),
1144+
SecureAuthCookie: cfg.SecureAuthCookie.Value(),
11451145
SSHKeygenAlgorithm: sshKeygenAlgorithm,
11461146
TracerProvider: tracerProvider,
11471147
Telemetry: telemetry.NewNoop(),
1148-
MetricsCacheRefreshInterval: cfg.MetricsCacheRefreshInterval.Duration(),
1149-
AgentStatsRefreshInterval: cfg.AgentStatRefreshInterval.Duration(),
1148+
MetricsCacheRefreshInterval: cfg.MetricsCacheRefreshInterval.Value(),
1149+
AgentStatsRefreshInterval: cfg.AgentStatRefreshInterval.Value(),
11501150
DeploymentConfig: cfg,
11511151
PrometheusRegistry: prometheus.NewRegistry(),
1152-
APIRateLimit: cfg.RateLimit.API.Int(),
1152+
APIRateLimit: int(cfg.RateLimit.API.Value()),
11531153
LoginRateLimit: loginRateLimit,
11541154
FilesRateLimit: filesRateLimit,
11551155
HTTPClient: httpClient,
@@ -1160,7 +1160,7 @@ func Server(newAPI func(context.Context, *coderd.Options) (*coderd.API, io.Close
11601160

11611161
if cfg.StrictTransportSecurity > 0 {
11621162
options.StrictTransportSecurityCfg, err = httpmw.HSTSConfigOptions(
1163-
cfg.StrictTransportSecurity.Int(), cfg.StrictTransportSecurityOptions,
1163+
int(cfg.StrictTransportSecurity.Value()), cfg.StrictTransportSecurityOptions,
11641164
)
11651165
if err != nil {
11661166
return xerrors.Errorf("coderd: setting hsts header failed (options: %v): %w", cfg.StrictTransportSecurityOptions, err)
@@ -1187,11 +1187,11 @@ func Server(newAPI func(context.Context, *coderd.Options) (*coderd.API, io.Close
11871187
}
11881188

11891189
if cfg.OAuth2.Github.ClientSecret != "" {
1190-
options.GithubOAuth2Config, err = configureGithubOAuth2(cfg.AccessURL.URL(),
1190+
options.GithubOAuth2Config, err = configureGithubOAuth2(cfg.AccessURL.Value(),
11911191
cfg.OAuth2.Github.ClientID.String(),
11921192
cfg.OAuth2.Github.ClientSecret.String(),
1193-
cfg.OAuth2.Github.AllowSignups.Bool(),
1194-
cfg.OAuth2.Github.AllowEveryone.Bool(),
1193+
cfg.OAuth2.Github.AllowSignups.Value(),
1194+
cfg.OAuth2.Github.AllowEveryone.Value(),
11951195
cfg.OAuth2.Github.AllowedOrgs,
11961196
cfg.OAuth2.Github.AllowedTeams,
11971197
cfg.OAuth2.Github.EnterpriseBaseURL.String(),
@@ -1219,7 +1219,7 @@ func Server(newAPI func(context.Context, *coderd.Options) (*coderd.API, io.Close
12191219
if err != nil {
12201220
return xerrors.Errorf("configure oidc provider: %w", err)
12211221
}
1222-
redirectURL, err := cfg.AccessURL.URL().Parse("/api/v2/users/oidc/callback")
1222+
redirectURL, err := cfg.AccessURL.Value().Parse("/api/v2/users/oidc/callback")
12231223
if err != nil {
12241224
return xerrors.Errorf("parse oidc oauth callback url: %w", err)
12251225
}
@@ -1236,11 +1236,11 @@ func Server(newAPI func(context.Context, *coderd.Options) (*coderd.API, io.Close
12361236
ClientID: cfg.OIDC.ClientID.String(),
12371237
}),
12381238
EmailDomain: cfg.OIDC.EmailDomain,
1239-
AllowSignups: cfg.OIDC.AllowSignups.Bool(),
1239+
AllowSignups: cfg.OIDC.AllowSignups.Value(),
12401240
UsernameField: cfg.OIDC.UsernameField.String(),
12411241
SignInText: cfg.OIDC.SignInText.String(),
12421242
IconURL: cfg.OIDC.IconURL.String(),
1243-
IgnoreEmailVerified: cfg.OIDC.IgnoreEmailVerified.Bool(),
1243+
IgnoreEmailVerified: cfg.OIDC.IgnoreEmailVerified.Value(),
12441244
}
12451245
}
12461246

@@ -1294,14 +1294,14 @@ func Server(newAPI func(context.Context, *coderd.Options) (*coderd.API, io.Close
12941294
DeploymentID: deploymentID,
12951295
Database: options.Database,
12961296
Logger: logger.Named("telemetry"),
1297-
URL: cfg.Telemetry.URL.URL(),
1297+
URL: cfg.Telemetry.URL.Value(),
12981298
Wildcard: cfg.WildcardAccessURL.String() != "",
12991299
DERPServerRelayURL: cfg.DERP.Server.RelayURL.String(),
13001300
GitAuth: gitAuth,
13011301
GitHubOAuth: cfg.OAuth2.Github.ClientID != "",
13021302
OIDCAuth: cfg.OIDC.ClientID != "",
13031303
OIDCIssuerURL: cfg.OIDC.IssuerURL.String(),
1304-
Prometheus: cfg.Prometheus.Enable.Bool(),
1304+
Prometheus: cfg.Prometheus.Enable.Value(),
13051305
STUN: len(cfg.DERP.Server.STUNAddresses) != 0,
13061306
Tunnel: tunnel != nil,
13071307
})
@@ -1340,7 +1340,7 @@ func Server(newAPI func(context.Context, *coderd.Options) (*coderd.API, io.Close
13401340
}
13411341

13421342
if cfg.Swagger.Enable {
1343-
options.SwaggerEndpoint = cfg.Swagger.Enable.Bool()
1343+
options.SwaggerEndpoint = cfg.Swagger.Enable.Value()
13441344
}
13451345

13461346
// We use a separate coderAPICloser so the Enterprise API
@@ -1384,7 +1384,7 @@ func Server(newAPI func(context.Context, *coderd.Options) (*coderd.API, io.Close
13841384
}
13851385
}()
13861386
provisionerdMetrics := provisionerd.NewMetrics(options.PrometheusRegistry)
1387-
for i := 0; i < cfg.Provisioner.Daemons.Int(); i++ {
1387+
for i := int64(0); i < cfg.Provisioner.Daemons.Value(); i++ {
13881388
daemonCacheDir := filepath.Join(cacheDir, fmt.Sprintf("provisioner-%d", i))
13891389
daemon, err := newProvisionerDaemon(ctx, coderAPI, provisionerdMetrics, logger, cfg, daemonCacheDir, errCh, false)
13901390
if err != nil {
@@ -1400,7 +1400,7 @@ func Server(newAPI func(context.Context, *coderd.Options) (*coderd.API, io.Close
14001400
// the request is not to a local IP.
14011401
var handler http.Handler = coderAPI.RootHandler
14021402
if cfg.RedirectToAccessURL {
1403-
handler = redirectToAccessURL(handler, cfg.AccessURL.URL(), tunnel != nil, appHostnameRegex)
1403+
handler = redirectToAccessURL(handler, cfg.AccessURL.Value(), tunnel != nil, appHostnameRegex)
14041404
}
14051405

14061406
// ReadHeaderTimeout is purposefully not enabled. It caused some
@@ -1478,7 +1478,7 @@ func Server(newAPI func(context.Context, *coderd.Options) (*coderd.API, io.Close
14781478
return xerrors.Errorf("notify systemd: %w", err)
14791479
}
14801480

1481-
autobuildPoller := time.NewTicker(cfg.AutobuildPollInterval.Duration())
1481+
autobuildPoller := time.NewTicker(cfg.AutobuildPollInterval.Value())
14821482
defer autobuildPoller.Stop()
14831483
autobuildExecutor := executor.New(ctx, options.Database, logger, autobuildPoller.C)
14841484
autobuildExecutor.Run()
@@ -1765,11 +1765,11 @@ func newProvisionerDaemon(
17651765
return coderAPI.CreateInMemoryProvisionerDaemon(ctx, debounce)
17661766
}, &provisionerd.Options{
17671767
Logger: logger,
1768-
JobPollInterval: cfg.Provisioner.DaemonPollInterval.Duration(),
1769-
JobPollJitter: cfg.Provisioner.DaemonPollJitter.Duration(),
1768+
JobPollInterval: cfg.Provisioner.DaemonPollInterval.Value(),
1769+
JobPollJitter: cfg.Provisioner.DaemonPollJitter.Value(),
17701770
JobPollDebounce: debounce,
17711771
UpdateInterval: 500 * time.Millisecond,
1772-
ForceCancelInterval: cfg.Provisioner.ForceCancelInterval.Duration(),
1772+
ForceCancelInterval: cfg.Provisioner.ForceCancelInterval.Value(),
17731773
Provisioners: provisioners,
17741774
WorkDirectory: tempDir,
17751775
TracerProvider: coderAPI.TracerProvider,

coderd/apikey.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ func (api *API) validateAPIKeyLifetime(lifetime time.Duration) error {
291291
return xerrors.New("lifetime must be positive number greater than 0")
292292
}
293293

294-
if lifetime > api.DeploymentConfig.MaxTokenLifetime {
294+
if lifetime > api.DeploymentConfig.MaxTokenLifetime.Value() {
295295
return xerrors.Errorf("lifetime must be less than %s", api.DeploymentConfig.MaxTokenLifetime)
296296
}
297297

@@ -311,8 +311,8 @@ func (api *API) createAPIKey(ctx context.Context, params createAPIKeyParams) (*h
311311
if params.LifetimeSeconds != 0 {
312312
params.ExpiresAt = database.Now().Add(time.Duration(params.LifetimeSeconds) * time.Second)
313313
} else {
314-
params.ExpiresAt = database.Now().Add(api.DeploymentConfig.SessionDuration)
315-
params.LifetimeSeconds = int64(api.DeploymentConfig.SessionDuration.Seconds())
314+
params.ExpiresAt = database.Now().Add(api.DeploymentConfig.SessionDuration.Value())
315+
params.LifetimeSeconds = int64(api.DeploymentConfig.SessionDuration.Value().Seconds())
316316
}
317317
}
318318
if params.LifetimeSeconds == 0 {

coderd/apikey_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/stretchr/testify/assert"
1111
"github.com/stretchr/testify/require"
1212

13+
"github.com/coder/coder/cli/bigcli"
1314
"github.com/coder/coder/coderd/coderdtest"
1415
"github.com/coder/coder/coderd/database"
1516
"github.com/coder/coder/coderd/database/dbtestutil"
@@ -95,7 +96,7 @@ func TestTokenMaxLifetime(t *testing.T) {
9596
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
9697
defer cancel()
9798
dc := coderdtest.DeploymentConfig(t)
98-
dc.MaxTokenLifetime.Value = time.Hour * 24 * 7
99+
dc.MaxTokenLifetime = bigcli.Duration(time.Hour * 24 * 7)
99100
client := coderdtest.New(t, &coderdtest.Options{
100101
DeploymentConfig: dc,
101102
})
@@ -135,7 +136,7 @@ func TestSessionExpiry(t *testing.T) {
135136
//
136137
// We don't support updating the deployment config after startup, but for
137138
// this test it works because we don't copy the value (and we use pointers).
138-
dc.SessionDuration.Value = time.Second
139+
dc.SessionDuration = bigcli.Duration(time.Second)
139140

140141
userClient, _ := coderdtest.CreateAnotherUser(t, adminClient, adminUser.OrganizationID)
141142

@@ -144,8 +145,8 @@ func TestSessionExpiry(t *testing.T) {
144145
apiKey, err := db.GetAPIKeyByID(ctx, strings.Split(token, "-")[0])
145146
require.NoError(t, err)
146147

147-
require.EqualValues(t, dc.SessionDuration.Value.Seconds(), apiKey.LifetimeSeconds)
148-
require.WithinDuration(t, apiKey.CreatedAt.Add(dc.SessionDuration.Value), apiKey.ExpiresAt, 2*time.Second)
148+
require.EqualValues(t, dc.SessionDuration.Value().Seconds(), apiKey.LifetimeSeconds)
149+
require.WithinDuration(t, apiKey.CreatedAt.Add(dc.SessionDuration.Value()), apiKey.ExpiresAt, 2*time.Second)
149150

150151
// Update the session token to be expired so we can test that it is
151152
// rejected for extra points.

coderd/coderd.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,10 @@ func New(options *Options) *API {
157157
if options == nil {
158158
options = &Options{}
159159
}
160-
experiments := initExperiments(options.Logger, options.DeploymentConfig.Experiments.Value, options.DeploymentConfig.Experimental.Value)
160+
experiments := initExperiments(
161+
options.Logger, options.DeploymentConfig.Experiments.Value(),
162+
options.DeploymentConfig.Experimental.Value(),
163+
)
161164
if options.AppHostname != "" && options.AppHostnameRegex == nil || options.AppHostname == "" && options.AppHostnameRegex != nil {
162165
panic("coderd: both AppHostname and AppHostnameRegex must be set or unset")
163166
}
@@ -268,15 +271,15 @@ func New(options *Options) *API {
268271
DB: options.Database,
269272
OAuth2Configs: oauthConfigs,
270273
RedirectToLogin: false,
271-
DisableSessionExpiryRefresh: options.DeploymentConfig.DisableSessionExpiryRefresh.Value,
274+
DisableSessionExpiryRefresh: options.DeploymentConfig.DisableSessionExpiryRefresh.Value(),
272275
Optional: false,
273276
})
274277
// Same as above but it redirects to the login page.
275278
apiKeyMiddlewareRedirect := httpmw.ExtractAPIKey(httpmw.ExtractAPIKeyConfig{
276279
DB: options.Database,
277280
OAuth2Configs: oauthConfigs,
278281
RedirectToLogin: true,
279-
DisableSessionExpiryRefresh: options.DeploymentConfig.DisableSessionExpiryRefresh.Value,
282+
DisableSessionExpiryRefresh: options.DeploymentConfig.DisableSessionExpiryRefresh.Value(),
280283
Optional: false,
281284
})
282285

@@ -304,7 +307,7 @@ func New(options *Options) *API {
304307
// The code handles the the case where the user is not
305308
// authenticated automatically.
306309
RedirectToLogin: false,
307-
DisableSessionExpiryRefresh: options.DeploymentConfig.DisableSessionExpiryRefresh.Value,
310+
DisableSessionExpiryRefresh: options.DeploymentConfig.DisableSessionExpiryRefresh.Value(),
308311
Optional: true,
309312
}),
310313
httpmw.AsAuthzSystem(
@@ -344,7 +347,7 @@ func New(options *Options) *API {
344347
// authorization check fails and the user is not authenticated,
345348
// they will be redirected to the login page by the app handler.
346349
RedirectToLogin: false,
347-
DisableSessionExpiryRefresh: options.DeploymentConfig.DisableSessionExpiryRefresh.Value,
350+
DisableSessionExpiryRefresh: options.DeploymentConfig.DisableSessionExpiryRefresh.Value(),
348351
Optional: true,
349352
}),
350353
httpmw.AsAuthzSystem(

coderd/deploymentconfig_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ func TestDeploymentConfig(t *testing.T) {
1919
// values should be returned
2020
cfg.BrowserOnly = true
2121
// values should not be returned
22-
cfg.OAuth2.Github.ClientSecret = hi
23-
cfg.OIDC.ClientSecret = hi
24-
cfg.PostgresURL = hi
25-
cfg.SCIMAPIKey = hi
22+
cfg.OAuth2.Github.ClientSecret.Set(hi)
23+
cfg.OIDC.ClientSecret.Set(hi)
24+
cfg.PostgresURL.Set(hi)
25+
cfg.SCIMAPIKey.Set(hi)
2626

2727
client := coderdtest.New(t, &coderdtest.Options{
2828
DeploymentConfig: cfg,

coderd/provisionerjobs.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,10 @@ func (api *API) provisionerJobResources(rw http.ResponseWriter, r *http.Request,
264264
}
265265
}
266266

267-
apiAgent, err := convertWorkspaceAgent(api.DERPMap, *api.TailnetCoordinator.Load(), agent, convertApps(dbApps), api.AgentInactiveDisconnectTimeout, api.DeploymentConfig.AgentFallbackTroubleshootingURL)
267+
apiAgent, err := convertWorkspaceAgent(
268+
api.DERPMap, *api.TailnetCoordinator.Load(), agent, convertApps(dbApps), api.AgentInactiveDisconnectTimeout,
269+
api.DeploymentConfig.AgentFallbackTroubleshootingURL.String(),
270+
)
268271
if err != nil {
269272
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
270273
Message: "Internal error reading job agent.",

coderd/userauth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ func (api *API) userAuthMethods(rw http.ResponseWriter, r *http.Request) {
285285

286286
httpapi.Write(r.Context(), rw, http.StatusOK, codersdk.AuthMethods{
287287
Password: codersdk.AuthMethod{
288-
Enabled: !api.DeploymentConfig.DisablePasswordAuth,
288+
Enabled: !api.DeploymentConfig.DisablePasswordAuth.Value(),
289289
},
290290
Github: codersdk.AuthMethod{Enabled: api.GithubOAuth2Config != nil},
291291
OIDC: codersdk.OIDCAuthMethod{

0 commit comments

Comments
 (0)