Skip to content

chore: refactor entitlements to be a safe object to use #14406

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

Merged
merged 7 commits into from
Aug 23, 2024

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented Aug 22, 2024

Previously, all usage of entitlements requires mutex usage on the
api struct directly. This prevents passing the entitlements to
a sub package. It also creates the possibility for misuse.

I am refactoring this because I want to place some IDP sync code into it's own package.
I'd prefer if the IDP code handled the entitlements (it's enterprise code).

Emyrk added 2 commits August 22, 2024 16:32
Previously, all usage of entitlements requires mutex usage on the
api struct directly. This prevents passing the entitlements to
a sub package. It also creates the possibility for misuse.
"github.com/coder/coder/v2/codersdk"
)

type Set struct {
Copy link
Member Author

Choose a reason for hiding this comment

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

I implemented the methods as I saw them used. There might be a way to reduce the number of methods on this struct.

@Emyrk Emyrk marked this pull request as ready for review August 22, 2024 22:40
@Emyrk Emyrk requested a review from johnstcn August 22, 2024 22:40
return f, ok
}

func (l *Set) Enabled(feature codersdk.FeatureName) bool {
Copy link
Member

Choose a reason for hiding this comment

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

Potential follow-up: we could replace this with f, ok := Features(name); ok && f.Enabled?

Copy link
Member Author

Choose a reason for hiding this comment

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

True. Because before we had access to the whole struct, our usage of it seemed a bit arbitrary at times. Sometimes we grab it and check entitled, most times just enabled.

I'm not trying to fix all our usage right now, but it would be good to audit at some times.

Copy link
Member

Choose a reason for hiding this comment

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

missing tests for the rest of the Entitlements methods

@johnstcn
Copy link
Member

LGTM pending some more tests, but approving pre-emptively.

@Emyrk Emyrk merged commit af125c3 into main Aug 23, 2024
29 of 30 checks passed
@Emyrk Emyrk deleted the stevenmasley/safe_entitlements branch August 23, 2024 21:22
@github-actions github-actions bot locked and limited conversation to collaborators Aug 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants