Skip to content

Commit b27ca7e

Browse files
committed
move readme to doc.go
1 parent 90e2f2b commit b27ca7e

File tree

5 files changed

+49
-24
lines changed

5 files changed

+49
-24
lines changed

codersdk/deployment.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ const (
3333
EntitlementNotEntitled Entitlement = "not_entitled"
3434
)
3535

36+
// entitlementWeight converts the enum types to a numerical value for easier
37+
// comparisons. Easier than sets of if statements.
3638
func entitlementWeight(e Entitlement) int {
3739
switch e {
3840
case EntitlementEntitled:
@@ -122,10 +124,10 @@ func (n FeatureName) AlwaysEnable() bool {
122124

123125
// FeatureSet represents a grouping of features. Rather than manually
124126
// assigning features al-la-carte when making a license, a set can be specified.
125-
// Sets are dynamic in the sense a feature can be added to an existing
126-
// set, granting the feature to existing licenses.
127+
// Sets are dynamic in the sense a feature can be added to a set, granting the
128+
// feature to existing licenses out in the wild.
127129
// If features were granted al-la-carte, we would need to reissue the existing
128-
// licenses to include the new feature.
130+
// old licenses to include the new feature.
129131
type FeatureSet string
130132

131133
const (
@@ -214,7 +216,7 @@ func CompareFeatures(a, b Feature) int {
214216
}
215217
if a.Limit != nil && b.Limit != nil {
216218
difference := *a.Limit - *b.Limit
217-
if *a.Limit-*b.Limit != 0 {
219+
if difference != 0 {
218220
return int(difference)
219221
}
220222
}
@@ -236,7 +238,7 @@ func CompareFeatures(a, b Feature) int {
236238
}
237239
if a.Actual != nil && b.Actual != nil {
238240
difference := *a.Actual - *b.Actual
239-
if *a.Actual-*b.Actual != 0 {
241+
if difference != 0 {
240242
return int(difference)
241243
}
242244
}

codersdk/deployment_test.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -503,12 +503,15 @@ func TestFeatureComparison(t *testing.T) {
503503
Expected: 1,
504504
},
505505
{
506-
// This is super strange, but it is possible to have a limit but no actual.
507-
// Just adding this test case to solidify the behavior.
508-
// Feel free to change this if you think it should be different.
509-
Name: "LimitVsActual",
510-
A: codersdk.Feature{Entitlement: codersdk.EntitlementEntitled, Limit: ptr.Ref(int64(100)), Actual: nil},
511-
B: codersdk.Feature{Entitlement: codersdk.EntitlementEntitled, Limit: nil, Actual: ptr.Ref(int64(200))},
506+
Name: "EnabledVsDisabled",
507+
A: codersdk.Feature{Entitlement: codersdk.EntitlementEntitled, Enabled: true, Limit: ptr.Ref(int64(300)), Actual: ptr.Ref(int64(200))},
508+
B: codersdk.Feature{Entitlement: codersdk.EntitlementEntitled, Limit: ptr.Ref(int64(300)), Actual: ptr.Ref(int64(200))},
509+
Expected: 1,
510+
},
511+
{
512+
Name: "NotNils",
513+
A: codersdk.Feature{Entitlement: codersdk.EntitlementEntitled, Limit: ptr.Ref(int64(100)), Actual: ptr.Ref(int64(50))},
514+
B: codersdk.Feature{Entitlement: codersdk.EntitlementEntitled, Limit: nil, Actual: nil},
512515
Expected: 1,
513516
},
514517
}

enterprise/coderd/license/doc.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Package license provides the license parsing and validation logic for Coderd.
2+
// Licensing in Coderd defines what features are allowed to be used in a
3+
// given deployment. Without a license, or with a license that grants 0 features,
4+
// Coderd will refuse to execute some feature code paths. These features are
5+
// typically gated with a middleware that checks the license before allowing
6+
// the http request to proceed.
7+
//
8+
// Terms:
9+
// - FeatureName: A specific functionality that Coderd provides, such as
10+
// external provisioners.
11+
//
12+
// - Feature: Entitlement definition for a FeatureName. A feature can be:
13+
// - "entitled": The feature is allowed to be used by the deployment.
14+
// - "grace period": The feature is allowed to be used by the deployment,
15+
// but the license is expired. There is a grace period
16+
// before the feature is disabled.
17+
// - "not entitled": The deployment is not allowed to use the feature.
18+
// Either by expiration, or by not being included
19+
// in the license.
20+
// A feature can also be "disabled" that prevents usage of the feature
21+
// even if entitled. This is usually a deployment configuration option.
22+
//
23+
// - License: A signed JWT that lists the features that are allowed to be used by
24+
// a given deployment. A license can have extra properties like,
25+
// `IsTrial`, `DeploymentIDs`, etc that can be used to further define
26+
// usage of the license.
27+
/**/
28+
// - Entitlements: A parsed set of licenses. Yes you can have more than 1 license
29+
// on a deployment! Entitlements will enumerate all features that
30+
// are allowed to be used.
31+
//
32+
package license

enterprise/coderd/license/license.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ type FeatureArguments struct {
6464
// now: The time to use for checking license expiration.
6565
// license: The license to check.
6666
// enablements: Features can be explicitly disabled by the deployment even if
67-
// the license has the feature entitled. Features can also have
67+
// the license has the feature entitled. Features can also have
6868
// the 'feat.AlwaysEnable()' return true to disallow disabling.
6969
// featureArguments: Additional arguments required by specific features.
7070
func LicensesEntitlements(

enterprise/coderd/license/testdata/README.md

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)