Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
spikecurtis merged 3 commits intomainfromspike/3278_agpl_entitlements_api
Aug 17, 2022
Merged

Conversation

spikecurtis
Copy link
Contributor

@spikecurtisspikecurtis commentedAug 15, 2022
edited
Loading

Relates to#3278

I intend to follow up this PR with a CLI command to view the information in the Entitlements API.

RFC description of this API

Signed-off-by: Spike Curtis <spike@coder.com>
@spikecurtisspikecurtis requested review fromEmyrk,kylecarbs anda teamAugust 15, 2022 21:59
Signed-off-by: Spike Curtis <spike@coder.com>
@spikecurtisspikecurtis requested a review froma team as acode ownerAugust 15, 2022 23:49
Copy link
Member

@Kira-PilotKira-Pilot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

FE ✅

Comment on lines +6 to +8
EntitlementEntitled Entitlement = "entitled"
EntitlementGracePeriod Entitlement = "grace_period"
EntitlementNotEntitled Entitlement = "not_entitled"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Instead ofEntitlementEntitled wouldEntitled suffice? Seems like these are implicitEntitlement based on the name.

Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I copied

type UserStatus stringconst (UserStatusActive    UserStatus = "active"UserStatusSuspended UserStatus = "suspended")

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.

Comment on lines 14 to 36
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.AllFeatures {
require.Contains(t, result.Features, f)
fe := result.Features[f]
assert.False(t, fe.Enabled)
assert.Equal(t, codersdk.EntitlementNotEntitled, fe.Entitlement)
}
})
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Doing this works around any middlewares we have that could make this not function.

Could we do this like a normalcoderd test instead? Then we'd buildcodersdk functions to fetch entitlements, which seems valuable for future API consumers.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I could. That makes the test more complex to write and slower to execute. Thisunit test is just testing the handler itself returns what we expect.

There is another test case incoderd_test.go that hits the endpoint through all the API routing and middlewares, so that's covered too.

I agree a codersdk function is important, but that's in my next PR that will include a CLI command to display these entitlements.

Comment on lines 14 to 36
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.AllFeatures {
require.Contains(t, result.Features, f)
fe := result.Features[f]
assert.False(t, fe.Enabled)
assert.Equal(t, codersdk.EntitlementNotEntitled, fe.Entitlement)
}
})
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Doing this works around any middlewares we have that could make this not function.

Could we do this like a normalcoderd test instead? Then we'd buildcodersdk functions to fetch entitlements, which seems valuable for future API consumers.

Signed-off-by: Spike Curtis <spike@coder.com>
@spikecurtisspikecurtis merged commitb1b2d1b intomainAug 17, 2022
@spikecurtisspikecurtis deleted the spike/3278_agpl_entitlements_api branchAugust 17, 2022 16:02
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@mafredrimafredrimafredri left review comments

@jsjoeiojsjoeiojsjoeio left review comments

@EmyrkEmyrkEmyrk left review comments

@Kira-PilotKira-PilotKira-Pilot approved these changes

@kylecarbskylecarbskylecarbs approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

6 participants
@spikecurtis@mafredri@jsjoeio@Emyrk@kylecarbs@Kira-Pilot

[8]ページ先頭

©2009-2025 Movatter.jp