Skip to content

Commit fdf6d3d

Browse files
committed
renames
1 parent 23fc6e9 commit fdf6d3d

File tree

12 files changed

+39
-39
lines changed

12 files changed

+39
-39
lines changed

coderd/apidoc/docs.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apikey.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (api *API) postToken(rw http.ResponseWriter, r *http.Request) {
8484
cookie, key, err := api.createAPIKey(ctx, apikey.CreateParams{
8585
UserID: user.ID,
8686
LoginType: database.LoginTypeToken,
87-
DefaultLifetime: api.DeploymentValues.Sessions.DefaultSessionDuration.Value(),
87+
DefaultLifetime: api.DeploymentValues.Sessions.DefaultDuration.Value(),
8888
ExpiresAt: dbtime.Now().Add(lifeTime),
8989
Scope: scope,
9090
LifetimeSeconds: int64(lifeTime.Seconds()),
@@ -128,7 +128,7 @@ func (api *API) postAPIKey(rw http.ResponseWriter, r *http.Request) {
128128
lifeTime := time.Hour * 24 * 7
129129
cookie, _, err := api.createAPIKey(ctx, apikey.CreateParams{
130130
UserID: user.ID,
131-
DefaultLifetime: api.DeploymentValues.Sessions.DefaultSessionDuration.Value(),
131+
DefaultLifetime: api.DeploymentValues.Sessions.DefaultDuration.Value(),
132132
LoginType: database.LoginTypePassword,
133133
RemoteAddr: r.RemoteAddr,
134134
// All api generated keys will last 1 week. Browser login tokens have
@@ -354,7 +354,7 @@ func (api *API) tokenConfig(rw http.ResponseWriter, r *http.Request) {
354354
httpapi.Write(
355355
r.Context(), rw, http.StatusOK,
356356
codersdk.TokenConfig{
357-
MaxTokenLifetime: values.Sessions.MaxTokenLifetime.Value(),
357+
MaxTokenLifetime: values.Sessions.MaximumTokenDuration.Value(),
358358
},
359359
)
360360
}
@@ -364,10 +364,10 @@ func (api *API) validateAPIKeyLifetime(lifetime time.Duration) error {
364364
return xerrors.New("lifetime must be positive number greater than 0")
365365
}
366366

367-
if lifetime > api.DeploymentValues.Sessions.MaxTokenLifetime.Value() {
367+
if lifetime > api.DeploymentValues.Sessions.MaximumTokenDuration.Value() {
368368
return xerrors.Errorf(
369369
"lifetime must be less than %v",
370-
api.DeploymentValues.Sessions.MaxTokenLifetime,
370+
api.DeploymentValues.Sessions.MaximumTokenDuration,
371371
)
372372
}
373373

coderd/apikey_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func TestTokenUserSetMaxLifetime(t *testing.T) {
125125
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
126126
defer cancel()
127127
dc := coderdtest.DeploymentValues(t)
128-
dc.Sessions.MaxTokenLifetime = serpent.Duration(time.Hour * 24 * 7)
128+
dc.Sessions.MaximumTokenDuration = serpent.Duration(time.Hour * 24 * 7)
129129
client := coderdtest.New(t, &coderdtest.Options{
130130
DeploymentValues: dc,
131131
})
@@ -165,7 +165,7 @@ func TestSessionExpiry(t *testing.T) {
165165
//
166166
// We don't support updating the deployment config after startup, but for
167167
// this test it works because we don't copy the value (and we use pointers).
168-
dc.Sessions.DefaultSessionDuration = serpent.Duration(time.Second)
168+
dc.Sessions.DefaultDuration = serpent.Duration(time.Second)
169169

170170
userClient, _ := coderdtest.CreateAnotherUser(t, adminClient, adminUser.OrganizationID)
171171

@@ -174,8 +174,8 @@ func TestSessionExpiry(t *testing.T) {
174174
apiKey, err := db.GetAPIKeyByID(ctx, strings.Split(token, "-")[0])
175175
require.NoError(t, err)
176176

177-
require.EqualValues(t, dc.Sessions.DefaultSessionDuration.Value().Seconds(), apiKey.LifetimeSeconds)
178-
require.WithinDuration(t, apiKey.CreatedAt.Add(dc.Sessions.DefaultSessionDuration.Value()), apiKey.ExpiresAt, 2*time.Second)
177+
require.EqualValues(t, dc.Sessions.DefaultDuration.Value().Seconds(), apiKey.LifetimeSeconds)
178+
require.WithinDuration(t, apiKey.CreatedAt.Add(dc.Sessions.DefaultDuration.Value()), apiKey.ExpiresAt, 2*time.Second)
179179

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

coderd/coderd.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ func New(options *Options) *API {
566566
DB: options.Database,
567567
OAuth2Configs: oauthConfigs,
568568
RedirectToLogin: false,
569-
DisableSessionExpiryRefresh: options.DeploymentValues.Sessions.DisableSessionExpiryRefresh.Value(),
569+
DisableSessionExpiryRefresh: options.DeploymentValues.Sessions.DisableExpiryRefresh.Value(),
570570
Optional: false,
571571
SessionTokenFunc: nil, // Default behavior
572572
PostAuthAdditionalHeadersFunc: options.PostAuthAdditionalHeadersFunc,
@@ -576,7 +576,7 @@ func New(options *Options) *API {
576576
DB: options.Database,
577577
OAuth2Configs: oauthConfigs,
578578
RedirectToLogin: true,
579-
DisableSessionExpiryRefresh: options.DeploymentValues.Sessions.DisableSessionExpiryRefresh.Value(),
579+
DisableSessionExpiryRefresh: options.DeploymentValues.Sessions.DisableExpiryRefresh.Value(),
580580
Optional: false,
581581
SessionTokenFunc: nil, // Default behavior
582582
PostAuthAdditionalHeadersFunc: options.PostAuthAdditionalHeadersFunc,
@@ -586,7 +586,7 @@ func New(options *Options) *API {
586586
DB: options.Database,
587587
OAuth2Configs: oauthConfigs,
588588
RedirectToLogin: false,
589-
DisableSessionExpiryRefresh: options.DeploymentValues.Sessions.DisableSessionExpiryRefresh.Value(),
589+
DisableSessionExpiryRefresh: options.DeploymentValues.Sessions.DisableExpiryRefresh.Value(),
590590
Optional: true,
591591
SessionTokenFunc: nil, // Default behavior
592592
PostAuthAdditionalHeadersFunc: options.PostAuthAdditionalHeadersFunc,

coderd/identityprovider/tokens.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func authorizationCodeGrant(ctx context.Context, db database.Store, app database
200200
key, sessionToken, err := apikey.Generate(apikey.CreateParams{
201201
UserID: dbCode.UserID,
202202
LoginType: database.LoginTypeOAuth2ProviderApp,
203-
DefaultLifetime: lifetimes.DefaultSessionDuration.Value(),
203+
DefaultLifetime: lifetimes.DefaultDuration.Value(),
204204
// For now, we allow only one token per app and user at a time.
205205
TokenName: tokenName,
206206
})
@@ -329,7 +329,7 @@ func refreshTokenGrant(ctx context.Context, db database.Store, app database.OAut
329329
key, sessionToken, err := apikey.Generate(apikey.CreateParams{
330330
UserID: prevKey.UserID,
331331
LoginType: database.LoginTypeOAuth2ProviderApp,
332-
DefaultLifetime: lifetimes.DefaultSessionDuration.Value(),
332+
DefaultLifetime: lifetimes.DefaultDuration.Value(),
333333
// For now, we allow only one token per app and user at a time.
334334
TokenName: tokenName,
335335
})

coderd/provisionerdserver/provisionerdserver.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1726,8 +1726,8 @@ func (s *server) regenerateSessionToken(ctx context.Context, user database.User,
17261726
UserID: user.ID,
17271727
LoginType: user.LoginType,
17281728
TokenName: workspaceSessionTokenName(workspace),
1729-
DefaultLifetime: s.DeploymentValues.Sessions.DefaultSessionDuration.Value(),
1730-
LifetimeSeconds: int64(s.DeploymentValues.Sessions.MaxTokenLifetime.Value().Seconds()),
1729+
DefaultLifetime: s.DeploymentValues.Sessions.DefaultDuration.Value(),
1730+
LifetimeSeconds: int64(s.DeploymentValues.Sessions.MaximumTokenDuration.Value().Seconds()),
17311731
})
17321732
if err != nil {
17331733
return "", xerrors.Errorf("generate API key: %w", err)

coderd/provisionerdserver/provisionerdserver_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func TestAcquireJob(t *testing.T) {
168168
// deployment config.
169169
dv := &codersdk.DeploymentValues{
170170
Sessions: codersdk.SessionLifetime{
171-
MaxTokenLifetime: serpent.Duration(time.Hour),
171+
MaximumTokenDuration: serpent.Duration(time.Hour),
172172
},
173173
}
174174
gitAuthProvider := &sdkproto.ExternalAuthProviderResource{
@@ -314,8 +314,8 @@ func TestAcquireJob(t *testing.T) {
314314
require.Len(t, toks, 2, "invalid api key")
315315
key, err := db.GetAPIKeyByID(ctx, toks[0])
316316
require.NoError(t, err)
317-
require.Equal(t, int64(dv.Sessions.MaxTokenLifetime.Value().Seconds()), key.LifetimeSeconds)
318-
require.WithinDuration(t, time.Now().Add(dv.Sessions.MaxTokenLifetime.Value()), key.ExpiresAt, time.Minute)
317+
require.Equal(t, int64(dv.Sessions.MaximumTokenDuration.Value().Seconds()), key.LifetimeSeconds)
318+
require.WithinDuration(t, time.Now().Add(dv.Sessions.MaximumTokenDuration.Value()), key.ExpiresAt, time.Minute)
319319

320320
want, err := json.Marshal(&proto.AcquiredJob_WorkspaceBuild_{
321321
WorkspaceBuild: &proto.AcquiredJob_WorkspaceBuild{

coderd/userauth.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ func (api *API) postLogin(rw http.ResponseWriter, r *http.Request) {
252252
UserID: user.ID,
253253
LoginType: database.LoginTypePassword,
254254
RemoteAddr: r.RemoteAddr,
255-
DefaultLifetime: api.DeploymentValues.Sessions.DefaultSessionDuration.Value(),
255+
DefaultLifetime: api.DeploymentValues.Sessions.DefaultDuration.Value(),
256256
})
257257
if err != nil {
258258
logger.Error(ctx, "unable to create API key", slog.Error(err))
@@ -1612,7 +1612,7 @@ func (api *API) oauthLogin(r *http.Request, params *oauthLoginParams) ([]*http.C
16121612
cookie, newKey, err := api.createAPIKey(dbauthz.AsSystemRestricted(ctx), apikey.CreateParams{
16131613
UserID: user.ID,
16141614
LoginType: params.LoginType,
1615-
DefaultLifetime: api.DeploymentValues.Sessions.DefaultSessionDuration.Value(),
1615+
DefaultLifetime: api.DeploymentValues.Sessions.DefaultDuration.Value(),
16161616
RemoteAddr: r.RemoteAddr,
16171617
})
16181618
if err != nil {

coderd/workspaceapps.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,14 @@ func (api *API) workspaceApplicationAuth(rw http.ResponseWriter, r *http.Request
102102
// the current session.
103103
exp := apiKey.ExpiresAt
104104
lifetimeSeconds := apiKey.LifetimeSeconds
105-
if exp.IsZero() || time.Until(exp) > api.DeploymentValues.Sessions.DefaultSessionDuration.Value() {
106-
exp = dbtime.Now().Add(api.DeploymentValues.Sessions.DefaultSessionDuration.Value())
107-
lifetimeSeconds = int64(api.DeploymentValues.Sessions.DefaultSessionDuration.Value().Seconds())
105+
if exp.IsZero() || time.Until(exp) > api.DeploymentValues.Sessions.DefaultDuration.Value() {
106+
exp = dbtime.Now().Add(api.DeploymentValues.Sessions.DefaultDuration.Value())
107+
lifetimeSeconds = int64(api.DeploymentValues.Sessions.DefaultDuration.Value().Seconds())
108108
}
109109
cookie, _, err := api.createAPIKey(ctx, apikey.CreateParams{
110110
UserID: apiKey.UserID,
111111
LoginType: database.LoginTypePassword,
112-
DefaultLifetime: api.DeploymentValues.Sessions.DefaultSessionDuration.Value(),
112+
DefaultLifetime: api.DeploymentValues.Sessions.DefaultDuration.Value(),
113113
ExpiresAt: exp,
114114
LifetimeSeconds: lifetimeSeconds,
115115
Scope: database.APIKeyScopeApplicationConnect,

coderd/workspaceapps/db.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (p *DBTokenProvider) Issue(ctx context.Context, rw http.ResponseWriter, r *
8585
DB: p.Database,
8686
OAuth2Configs: p.OAuth2Configs,
8787
RedirectToLogin: false,
88-
DisableSessionExpiryRefresh: p.DeploymentValues.Sessions.DisableSessionExpiryRefresh.Value(),
88+
DisableSessionExpiryRefresh: p.DeploymentValues.Sessions.DisableExpiryRefresh.Value(),
8989
// Optional is true to allow for public apps. If the authorization check
9090
// (later on) fails and the user is not authenticated, they will be
9191
// redirected to the login page or app auth endpoint using code below.

codersdk/deployment.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -249,24 +249,24 @@ func ParseSSHConfigOption(opt string) (key string, value string, err error) {
249249
// TODO: These config options were created back when coder only had api keys.
250250
// Today, the config is ambigously used for all of them. For example:
251251
// - cli based api keys ignore all settings
252-
// - login uses the default lifetime, not the MaxTokenLifetime
253-
// - Tokens use the Default & MaxTokenLifetime
252+
// - login uses the default lifetime, not the MaximumTokenDuration
253+
// - Tokens use the Default & MaximumTokenDuration
254254
// - ... etc ...
255255
// The rational behind each decision is undocumented. The naming behind these
256256
// config options is also confusing without any clear documentation.
257257
// 'CreateAPIKey' is used to make all sessions, and it's parameters are just
258258
// 'LifetimeSeconds' and 'DefaultLifetime'. Which does not directly correlate to
259259
// the config options here.
260260
type SessionLifetime struct {
261-
// DisableSessionExpiryRefresh will disable automatically refreshing api
261+
// DisableExpiryRefresh will disable automatically refreshing api
262262
// keys when they are used from the api. This means the api key lifetime at
263263
// creation is the lifetime of the api key.
264-
DisableSessionExpiryRefresh serpent.Bool `json:"disable_session_expiry_refresh,omitempty" typescript:",notnull"`
264+
DisableExpiryRefresh serpent.Bool `json:"disable_expiry_refresh,omitempty" typescript:",notnull"`
265265

266-
// DefaultSessionDuration is for api keys, not tokens.
267-
DefaultSessionDuration serpent.Duration `json:"max_session_expiry" typescript:",notnull"`
266+
// DefaultDuration is for api keys, not tokens.
267+
DefaultDuration serpent.Duration `json:"default_duration" typescript:",notnull"`
268268

269-
MaxTokenLifetime serpent.Duration `json:"max_token_lifetime,omitempty" typescript:",notnull"`
269+
MaximumTokenDuration serpent.Duration `json:"max_token_lifetime,omitempty" typescript:",notnull"`
270270
}
271271

272272
type DERP struct {
@@ -1604,7 +1604,7 @@ when required by your organization's security policy.`,
16041604
// We have to add in the 25 leap days for the frontend to show the
16051605
// "100 years" correctly.
16061606
Default: ((100 * 365 * time.Hour * 24) + (25 * time.Hour * 24)).String(),
1607-
Value: &c.Sessions.MaxTokenLifetime,
1607+
Value: &c.Sessions.MaximumTokenDuration,
16081608
Group: &deploymentGroupNetworkingHTTP,
16091609
YAML: "maxTokenLifetime",
16101610
Annotations: serpent.Annotations{}.Mark(annotationFormatDuration, "true"),
@@ -1798,7 +1798,7 @@ when required by your organization's security policy.`,
17981798
Flag: "session-duration",
17991799
Env: "CODER_SESSION_DURATION",
18001800
Default: (24 * time.Hour).String(),
1801-
Value: &c.Sessions.DefaultSessionDuration,
1801+
Value: &c.Sessions.DefaultDuration,
18021802
Group: &deploymentGroupNetworkingHTTP,
18031803
YAML: "sessionDuration",
18041804
Annotations: serpent.Annotations{}.Mark(annotationFormatDuration, "true"),
@@ -1809,7 +1809,7 @@ when required by your organization's security policy.`,
18091809
Flag: "disable-session-expiry-refresh",
18101810
Env: "CODER_DISABLE_SESSION_EXPIRY_REFRESH",
18111811

1812-
Value: &c.Sessions.DisableSessionExpiryRefresh,
1812+
Value: &c.Sessions.DisableExpiryRefresh,
18131813
Group: &deploymentGroupNetworkingHTTP,
18141814
YAML: "disableSessionExpiryRefresh",
18151815
},

enterprise/coderd/coderd.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func New(ctx context.Context, options *Options) (_ *API, err error) {
148148
DB: options.Database,
149149
OAuth2Configs: oauthConfigs,
150150
RedirectToLogin: false,
151-
DisableSessionExpiryRefresh: options.DeploymentValues.Sessions.DisableSessionExpiryRefresh.Value(),
151+
DisableSessionExpiryRefresh: options.DeploymentValues.Sessions.DisableExpiryRefresh.Value(),
152152
Optional: false,
153153
SessionTokenFunc: nil, // Default behavior
154154
PostAuthAdditionalHeadersFunc: options.PostAuthAdditionalHeadersFunc,
@@ -157,7 +157,7 @@ func New(ctx context.Context, options *Options) (_ *API, err error) {
157157
DB: options.Database,
158158
OAuth2Configs: oauthConfigs,
159159
RedirectToLogin: false,
160-
DisableSessionExpiryRefresh: options.DeploymentValues.Sessions.DisableSessionExpiryRefresh.Value(),
160+
DisableSessionExpiryRefresh: options.DeploymentValues.Sessions.DisableExpiryRefresh.Value(),
161161
Optional: true,
162162
SessionTokenFunc: nil, // Default behavior
163163
PostAuthAdditionalHeadersFunc: options.PostAuthAdditionalHeadersFunc,

0 commit comments

Comments
 (0)