2022-08-17 09:02:36 -07:00
|
|
|
package codersdk
|
|
|
|
|
|
2022-08-17 11:26:16 -07:00
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"net/http"
|
|
|
|
|
)
|
|
|
|
|
|
2022-08-17 09:02:36 -07:00
|
|
|
type Entitlement string
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
EntitlementEntitled Entitlement = "entitled"
|
|
|
|
|
EntitlementGracePeriod Entitlement = "grace_period"
|
|
|
|
|
EntitlementNotEntitled Entitlement = "not_entitled"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
2022-11-16 16:34:06 -06:00
|
|
|
FeatureUserLimit = "user_limit"
|
|
|
|
|
FeatureAuditLog = "audit_log"
|
|
|
|
|
FeatureBrowserOnly = "browser_only"
|
|
|
|
|
FeatureSCIM = "scim"
|
|
|
|
|
FeatureTemplateRBAC = "template_rbac"
|
|
|
|
|
FeatureHighAvailability = "high_availability"
|
|
|
|
|
FeatureMultipleGitAuth = "multiple_git_auth"
|
|
|
|
|
FeatureExternalProvisionerDaemons = "external_provisioner_daemons"
|
2023-01-04 15:31:45 -06:00
|
|
|
FeatureAppearance = "appearance"
|
2022-08-17 09:02:36 -07:00
|
|
|
)
|
|
|
|
|
|
2022-09-30 14:01:20 -04:00
|
|
|
var FeatureNames = []string{
|
|
|
|
|
FeatureUserLimit,
|
|
|
|
|
FeatureAuditLog,
|
|
|
|
|
FeatureBrowserOnly,
|
|
|
|
|
FeatureSCIM,
|
2022-10-12 04:51:41 +10:00
|
|
|
FeatureTemplateRBAC,
|
2022-10-17 08:43:30 -05:00
|
|
|
FeatureHighAvailability,
|
2022-10-24 19:46:24 -05:00
|
|
|
FeatureMultipleGitAuth,
|
2022-11-16 16:34:06 -06:00
|
|
|
FeatureExternalProvisionerDaemons,
|
2023-01-04 15:31:45 -06:00
|
|
|
FeatureAppearance,
|
2022-09-30 14:01:20 -04:00
|
|
|
}
|
2022-08-17 09:02:36 -07:00
|
|
|
|
|
|
|
|
type Feature struct {
|
|
|
|
|
Entitlement Entitlement `json:"entitlement"`
|
|
|
|
|
Enabled bool `json:"enabled"`
|
2022-08-29 16:45:40 -07:00
|
|
|
Limit *int64 `json:"limit,omitempty"`
|
|
|
|
|
Actual *int64 `json:"actual,omitempty"`
|
2022-08-17 09:02:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Entitlements struct {
|
2022-10-04 15:45:00 -04:00
|
|
|
Features map[string]Feature `json:"features"`
|
|
|
|
|
Warnings []string `json:"warnings"`
|
2022-10-17 08:43:30 -05:00
|
|
|
Errors []string `json:"errors"`
|
2022-10-04 15:45:00 -04:00
|
|
|
HasLicense bool `json:"has_license"`
|
|
|
|
|
Experimental bool `json:"experimental"`
|
2022-10-06 19:28:22 -05:00
|
|
|
Trial bool `json:"trial"`
|
2022-08-17 09:02:36 -07:00
|
|
|
}
|
2022-08-17 11:26:16 -07:00
|
|
|
|
|
|
|
|
func (c *Client) Entitlements(ctx context.Context) (Entitlements, error) {
|
|
|
|
|
res, err := c.Request(ctx, http.MethodGet, "/api/v2/entitlements", nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return Entitlements{}, err
|
|
|
|
|
}
|
|
|
|
|
defer res.Body.Close()
|
|
|
|
|
if res.StatusCode != http.StatusOK {
|
|
|
|
|
return Entitlements{}, readBodyAsError(res)
|
|
|
|
|
}
|
|
|
|
|
var ent Entitlements
|
|
|
|
|
return ent, json.NewDecoder(res.Body).Decode(&ent)
|
|
|
|
|
}
|