- Notifications
You must be signed in to change notification settings - Fork928
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -391,6 +391,10 @@ func New(options *Options) *API { | ||
r.Get("/resources", api.workspaceBuildResources) | ||
r.Get("/state", api.workspaceBuildState) | ||
}) | ||
r.Route("/entitlements", func(r chi.Router) { | ||
r.Use(apiKeyMiddleware) | ||
r.Get("/", entitlements) | ||
spikecurtis marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
}) | ||
}) | ||
r.NotFound(compressHandler(http.HandlerFunc(api.siteHandler.ServeHTTP)).ServeHTTP) | ||
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"` | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -129,6 +129,21 @@ export interface CreateWorkspaceRequest { | ||
readonly parameter_values?: CreateParameterRequest[] | ||
} | ||
// From codersdk/features.go | ||
export interface Entitlements { | ||
readonly features: Record<string, Feature> | ||
readonly warnings: string[] | ||
readonly has_license: boolean | ||
} | ||
// From codersdk/features.go | ||
export interface Feature { | ||
readonly entitlement: Entitlement | ||
readonly enabled: boolean | ||
readonly limit?: number | ||
readonly actual?: number | ||
} | ||
// From codersdk/users.go | ||
export interface GenerateAPIKeyResponse { | ||
readonly key: string | ||
@@ -530,6 +545,9 @@ export interface WorkspaceResourceMetadata { | ||
// From codersdk/workspacebuilds.go | ||
export type BuildReason = "autostart" | "autostop" | "initiator" | ||
// From codersdk/features.go | ||
export type Entitlement = "entitled" | "grace_period" | "not_entitled" | ||
spikecurtis marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
// From codersdk/provisionerdaemons.go | ||
export type LogLevel = "debug" | "error" | "info" | "trace" | "warn" | ||