-
Notifications
You must be signed in to change notification settings - Fork 896
chore: protect organization endpoints with license #14001
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
01cdd55
to
d602947
Compare
f0ssel
approved these changes
Jul 25, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Glad we are doing this. The fact that none of the golden files, API docs, or codersdk code changed with all of this gives me confidence this should be pretty safe.
018aa1d
to
ca00727
Compare
Rebasing in case any new tests were added that I need to move |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What this does
Closes #13969
Creating, editing, and deleting an organization now require a license (and experiment). Endpoints are in the
/enterprise
directory now.Any tests that created an organization in the AGPL directory didn't make sense anyway. They had no means of having a provisioner daemon, so had no functionality besides adding/removing members.
This PR is 99% moving tests from AGPL to Enterprise. And changing
To
Test Coverage
There is a chance our test coverage will go down since we probably do not track cross pkg test coverage. To try and maintain the coverage and move the tests sounds like a massive headache. We can refactor some of these tests and bring them back into AGPL if it is an issue. Refactoring all the tests now would not be ideal since we need multi-org tests.
I am sure we have redundant tests, but there is no easy way to identify them.
Ignore, text before I found a good solution
Enterprise has an issue overriding sub endpoints. The only way to properly extend them is to save them somewhere, and reference the sub routers directly.
When trying to "merge" routes, you either overwrite the endpoint, or get a panic.
https://goplay.tools/snippet/6JXkSIdJ997
Alternatives
Duplicate routes
One idea is to just replace the entire sub router in Enterprise. Essentially copying the routes to both places, and using a unit test to ensure Enterprise is a super set.
This unfortunately cannot work because you cannot overwrite a route in chi.
Write some
r.Merge(r1, r2)
orr.Extend("/organizations")
functionThe idea is to fetch the router dynamically, and extend it. Rather than hard coding it in some field in the
API
struct. Unfortunately traversing the router is only supported byr.Routes()
andchi.Walk()
. Both expose thehttp.Handler
but not therouter
. So you cannot fetch thechi.Mux
dynamically without some serious changes 😢Write a
MergeRouters(a, b chi.Routes)
This is possible, but such a pain. Essentially you can call
r.Routes()
to traverse all the sub routers and endpoints. If you assume no typecasting (route.(*chi.Mux)
), then you cannot extend these routes, only read them.So to merge them, we'd have to build our own
/pattern
tree (handling things liker.Route("/nested/stuff")
being depth=2 in the tree.Then merge 2 route trees that we build.
Then convert that route tree back to a chi.Mux by doing a depth first search and doing the
This really feels like we'd just writing our own
http.Mux
. It can be done, and it's not that challenging, it's just a lot of leg work that I don't find very useful at this time.