-
Notifications
You must be signed in to change notification settings - Fork 889
AGPL Entitlements API #3523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AGPL Entitlements API #3523
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package coderd | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/coder/coder/coderd/httpapi" | ||
"github.com/coder/coder/codersdk" | ||
) | ||
|
||
func entitlements(rw http.ResponseWriter, _ *http.Request) { | ||
features := make(map[string]codersdk.Feature) | ||
for _, f := range codersdk.FeatureNames { | ||
features[f] = codersdk.Feature{ | ||
Entitlement: codersdk.EntitlementNotEntitled, | ||
Enabled: false, | ||
} | ||
} | ||
httpapi.Write(rw, http.StatusOK, codersdk.Entitlements{ | ||
Features: features, | ||
Warnings: nil, | ||
HasLicense: false, | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package coderd | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/coder/coder/codersdk" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestEntitlements(t *testing.T) { | ||
t.Parallel() | ||
t.Run("GET", func(t *testing.T) { | ||
t.Parallel() | ||
r := httptest.NewRequest("GET", "https://example.com/api/v2/entitlements", nil) | ||
rw := httptest.NewRecorder() | ||
entitlements(rw, r) | ||
resp := rw.Result() | ||
assert.Equal(t, http.StatusOK, resp.StatusCode) | ||
dec := json.NewDecoder(resp.Body) | ||
var result codersdk.Entitlements | ||
err := dec.Decode(&result) | ||
require.NoError(t, err) | ||
assert.False(t, result.HasLicense) | ||
assert.Empty(t, result.Warnings) | ||
for _, f := range codersdk.FeatureNames { | ||
require.Contains(t, result.Features, f) | ||
fe := result.Features[f] | ||
assert.False(t, fe.Enabled) | ||
assert.Equal(t, codersdk.EntitlementNotEntitled, fe.Entitlement) | ||
} | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package codersdk | ||
|
||
type Entitlement string | ||
|
||
const ( | ||
EntitlementEntitled Entitlement = "entitled" | ||
EntitlementGracePeriod Entitlement = "grace_period" | ||
EntitlementNotEntitled Entitlement = "not_entitled" | ||
Comment on lines
+6
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the consistency of either always or never including the prefix. It'd be nice if Go would support enums natively one day. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I copied
for the sake of consistency. But, if I were writing the package myself for the first time I'd have dropped the prefix. I don't really mind either way. |
||
) | ||
|
||
const ( | ||
FeatureUserLimit = "user_limit" | ||
FeatureAuditLog = "audit_log" | ||
) | ||
|
||
var FeatureNames = []string{FeatureUserLimit, FeatureAuditLog} | ||
|
||
type Feature struct { | ||
Entitlement Entitlement `json:"entitlement"` | ||
Enabled bool `json:"enabled"` | ||
Limit *int64 `json:"limit"` | ||
Actual *int64 `json:"actual"` | ||
} | ||
|
||
type Entitlements struct { | ||
Features map[string]Feature `json:"features"` | ||
Warnings []string `json:"warnings"` | ||
HasLicense bool `json:"has_license"` | ||
} |
Uh oh!
There was an error while loading. Please reload this page.