Skip to content

Commit 4df3f35

Browse files
committed
feat: Add trial property to licenses
This allows the frontend to display whether the user is on a trial license of Coder. This is useful for advertising Enterprise functionality.
1 parent 504cd46 commit 4df3f35

File tree

5 files changed

+12
-0
lines changed

5 files changed

+12
-0
lines changed

codersdk/features.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type Entitlements struct {
4242
Warnings []string `json:"warnings"`
4343
HasLicense bool `json:"has_license"`
4444
Experimental bool `json:"experimental"`
45+
Trial bool `json:"trial"`
4546
}
4647

4748
func (c *Client) Entitlements(ctx context.Context) (Entitlements, error) {

enterprise/coderd/coderd.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ type API struct {
122122

123123
type entitlements struct {
124124
hasLicense bool
125+
trial bool
125126
activeUsers codersdk.Feature
126127
auditLogs codersdk.Entitlement
127128
browserOnly codersdk.Entitlement
@@ -154,6 +155,7 @@ func (api *API) updateEntitlements(ctx context.Context) error {
154155
scim: codersdk.EntitlementNotEntitled,
155156
browserOnly: codersdk.EntitlementNotEntitled,
156157
workspaceQuota: codersdk.EntitlementNotEntitled,
158+
trial: true,
157159
}
158160

159161
// Here we loop through licenses to detect enabled features.
@@ -195,6 +197,9 @@ func (api *API) updateEntitlements(ctx context.Context) error {
195197
if claims.Features.WorkspaceQuota > 0 {
196198
entitlements.workspaceQuota = entitlement
197199
}
200+
if !claims.Trial {
201+
entitlements.trial = claims.Trial
202+
}
198203
}
199204

200205
if entitlements.auditLogs != api.entitlements.auditLogs {
@@ -240,6 +245,7 @@ func (api *API) serveEntitlements(rw http.ResponseWriter, r *http.Request) {
240245
Features: make(map[string]codersdk.Feature),
241246
Warnings: make([]string, 0),
242247
HasLicense: entitlements.hasLicense,
248+
Trial: entitlements.trial,
243249
Experimental: api.Experimental,
244250
}
245251

enterprise/coderd/coderdenttest/coderdenttest.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ func NewWithAPI(t *testing.T, options *Options) (*codersdk.Client, io.Closer, *c
8484
type LicenseOptions struct {
8585
AccountType string
8686
AccountID string
87+
Trial bool
8788
GraceAt time.Time
8889
ExpiresAt time.Time
8990
UserLimit int64
@@ -137,6 +138,7 @@ func GenerateLicense(t *testing.T, options LicenseOptions) string {
137138
LicenseExpires: jwt.NewNumericDate(options.GraceAt),
138139
AccountType: options.AccountType,
139140
AccountID: options.AccountID,
141+
Trial: options.Trial,
140142
Version: coderd.CurrentVersion,
141143
Features: coderd.Features{
142144
UserLimit: options.UserLimit,

enterprise/coderd/licenses.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type Claims struct {
6262
LicenseExpires *jwt.NumericDate `json:"license_expires,omitempty"`
6363
AccountType string `json:"account_type,omitempty"`
6464
AccountID string `json:"account_id,omitempty"`
65+
Trial bool `json:"trial"`
6566
Version uint64 `json:"version"`
6667
Features Features `json:"features"`
6768
}

enterprise/coderd/licenses_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ func TestGetLicense(t *testing.T) {
8989
AuditLog: true,
9090
SCIM: true,
9191
BrowserOnly: true,
92+
Trial: true,
9293
UserLimit: 200,
9394
})
9495

@@ -106,6 +107,7 @@ func TestGetLicense(t *testing.T) {
106107
}, licenses[0].Claims["features"])
107108
assert.Equal(t, int32(2), licenses[1].ID)
108109
assert.Equal(t, "testing2", licenses[1].Claims["account_id"])
110+
assert.Equal(t, true, licenses[1].Claims["trial"])
109111
assert.Equal(t, map[string]interface{}{
110112
codersdk.FeatureUserLimit: json.Number("200"),
111113
codersdk.FeatureAuditLog: json.Number("1"),

0 commit comments

Comments
 (0)