-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
fix(http): /api/v2/orgs/:id/owners|members to 404 #15504
Conversation
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.
Swagger looks good to me
http/org_service.go
Outdated
@@ -73,6 +73,24 @@ const ( | |||
organizationsIDLabelsIDPath = "/api/v2/orgs/:id/labels/:lid" | |||
) | |||
|
|||
func (h *OrgHandler) handleGetOrgCheck(w http.ResponseWriter, r *http.Request) interface{} { |
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.
love the helper function!
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.
Could this just return a organization pointer?
205b6bb
to
2029873
Compare
http/org_service.go
Outdated
if err := encodeResponse(ctx, w, http.StatusOK, newOrgResponse(b)); err != nil { | ||
ctx := r.Context() | ||
|
||
org := organization.(*influxdb.Organization) |
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.
See comment above, this would remove the need to cast.
@@ -63,11 +63,16 @@ type MemberBackend struct { | |||
|
|||
UserResourceMappingService influxdb.UserResourceMappingService | |||
UserService influxdb.UserService | |||
Precheck func(w http.ResponseWriter, r *http.Request) interface{} |
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.
Could this function type have a defined return type instead of interface{}
?
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.
There seems to be a few places that could have types instead of interface{}
http/middleware.go
Outdated
@@ -151,3 +151,17 @@ func (b *bodyEchoer) Read(p []byte) (int, error) { | |||
func (b *bodyEchoer) Close() error { | |||
return b.rc.Close() | |||
} | |||
|
|||
type middleware func(http.HandlerFunc) http.HandlerFunc |
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.
can we export this type here, and refactor the LoggignMW
to use it as well?
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.
small grips, but overall looks good
http/org_service.go
Outdated
} | ||
|
||
func checkOrganziationExistsWrapper(handler *OrgHandler) func(http.HandlerFunc) http.HandlerFunc { | ||
fn := func(next http.HandlerFunc) http.HandlerFunc { |
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.
👏 looking good, very foxused func here, I dig it 👍
http/middleware.go
Outdated
|
||
type middleware func(http.HandlerFunc) http.HandlerFunc | ||
|
||
func handlerFuncWithMiddlewares(h http.HandlerFunc, m ...middleware) http.HandlerFunc { |
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.
can you rename this to something shorter maybe? applyMW
? this is a mouthful for something you'll be chaining. Its quite common to see MW
the type for middleware and how its referenced in a lot of go pkgs
http/org_service.go
Outdated
return nil | ||
} | ||
|
||
func checkOrganziationExistsWrapper(handler *OrgHandler) func(http.HandlerFunc) http.HandlerFunc { |
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.
go on and take advantage of the type you just created func organziationExists(handler *OrgHandler) Middleware {
one other thing here is that you are passing the org handler to the func this is wrapping, as a value instead of using pointer semantics. you want to stick with one or the other to be consistent here. I'd recommend using pointer semantics here as that's what we are sharing across these functional boundaries. Even better yet, just drop the func above and put it in the wrapper bit and be donezo with teh wrapper stuff lol
a2f6bb5
to
5ec5915
Compare
5ec5915
to
264adb7
Compare
This fix ensures that the endpoints: - /api/v2/orgs/:id/owners - /api/v2/orgs/:id/members 404 when the organization resource does not exist
264adb7
to
822e366
Compare
ensures that the endpoints: * /api/v2/orgs/:id/owners * /api/v2/orgs/:id/members 404 when the organization resource does not exist
Closes #
Describe your proposed changes here.