Skip to content
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

Merged
merged 1 commit into from
Oct 21, 2019

Conversation

dearyhud
Copy link
Contributor

@dearyhud dearyhud commented Oct 18, 2019

Closes #

Describe your proposed changes here.

  • CHANGELOG.md updated with a link to the PR (not the Issue)
  • Well-formatted commit messages
  • Rebased/mergeable
  • Tests pass
  • http/swagger.yml updated (if modified Go structs or API)
  • Documentation updated or issue created (provide link to issue/pr)
  • Signed CLA (if not already signed)

@dearyhud dearyhud requested review from a team as code owners October 18, 2019 19:10
Copy link
Contributor

@121watts 121watts left a 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

@@ -73,6 +73,24 @@ const (
organizationsIDLabelsIDPath = "/api/v2/orgs/:id/labels/:lid"
)

func (h *OrgHandler) handleGetOrgCheck(w http.ResponseWriter, r *http.Request) interface{} {
Copy link
Contributor

Choose a reason for hiding this comment

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

love the helper function!

Copy link
Contributor

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?

@dearyhud dearyhud force-pushed the fix/http-orgs-members-owners-404 branch from 205b6bb to 2029873 Compare October 18, 2019 20:28
@imogenkinsman imogenkinsman requested review from a team and removed request for a team October 18, 2019 21:13
@ghost ghost requested review from bthesorceror and removed request for a team October 18, 2019 21:15
if err := encodeResponse(ctx, w, http.StatusOK, newOrgResponse(b)); err != nil {
ctx := r.Context()

org := organization.(*influxdb.Organization)
Copy link
Contributor

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{}
Copy link
Contributor

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{}?

Copy link
Contributor

@bthesorceror bthesorceror left a 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{}

@@ -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
Copy link
Contributor

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?

Copy link
Contributor

@jsteenb2 jsteenb2 left a 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

}

func checkOrganziationExistsWrapper(handler *OrgHandler) func(http.HandlerFunc) http.HandlerFunc {
fn := func(next http.HandlerFunc) http.HandlerFunc {
Copy link
Contributor

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 👍


type middleware func(http.HandlerFunc) http.HandlerFunc

func handlerFuncWithMiddlewares(h http.HandlerFunc, m ...middleware) http.HandlerFunc {
Copy link
Contributor

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

return nil
}

func checkOrganziationExistsWrapper(handler *OrgHandler) func(http.HandlerFunc) http.HandlerFunc {
Copy link
Contributor

@jsteenb2 jsteenb2 Oct 21, 2019

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

@dearyhud dearyhud requested a review from bthesorceror October 21, 2019 19:14
@dearyhud dearyhud force-pushed the fix/http-orgs-members-owners-404 branch 2 times, most recently from a2f6bb5 to 5ec5915 Compare October 21, 2019 19:49
@dearyhud dearyhud changed the title fix:(http) orgs resource endpoints to 404 when org does not exist fix: (http) orgs resource endpoints to 404 when org does not exist Oct 21, 2019
@dearyhud dearyhud changed the title fix: (http) orgs resource endpoints to 404 when org does not exist fix:(http)/api/v2/orgs/:id/{owners|members} to 404 Oct 21, 2019
@dearyhud dearyhud force-pushed the fix/http-orgs-members-owners-404 branch from 5ec5915 to 264adb7 Compare October 21, 2019 20:25
@dearyhud dearyhud changed the title fix:(http)/api/v2/orgs/:id/{owners|members} to 404 fix(http): /api/v2/orgs/:id/owners|members to 404 Oct 21, 2019
This fix ensures that the endpoints:
  - /api/v2/orgs/:id/owners
  - /api/v2/orgs/:id/members
404 when the organization resource does not exist
@dearyhud dearyhud force-pushed the fix/http-orgs-members-owners-404 branch from 264adb7 to 822e366 Compare October 21, 2019 20:38
@dearyhud dearyhud merged commit c04249e into master Oct 21, 2019
@dearyhud dearyhud deleted the fix/http-orgs-members-owners-404 branch October 21, 2019 21:37
asalem1 pushed a commit that referenced this pull request Oct 22, 2019
ensures that the endpoints:
  * /api/v2/orgs/:id/owners
  * /api/v2/orgs/:id/members
404 when the organization resource does not exist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants