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

Issue #103 Refactor Handle function #109

Closed

Conversation

vpavlin
Copy link
Member

@vpavlin vpavlin commented Jan 16, 2018

Split out couple blocks of code, happy to do more if you see anything else.

Addresses issue #103

proxy/proxy.go Outdated
}
//If Jenkins is up, we can simply proxy through
Copy link
Contributor

Choose a reason for hiding this comment

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

I was hoping we could also split here - https://github.com/fabric8-services/fabric8-jenkins-proxy/pull/109/files#diff-3ac192716a1df66bbd1008d327af8792R112, almost splitting the method in half. Something like this:

   if isGH {
       handleGitHubRequest(w, r)
   } else {
       handleDirectJenkinsUIRequest(w,r)
   }

This way the existing comments on this if/else branch become obsolete, since the code gives you the same information.

Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to the above comment - https://github.com/fabric8-services/fabric8-jenkins-proxy/pull/109/files#diff-3ac192716a1df66bbd1008d327af8792R153

Here we could extract everything into if isIdle into a method sendStatusAcceptedToClient.

Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder whether the redirect flag would not be better named as needsAuth or if you want to keep the redirect part needsAuthRedirect.

Copy link
Contributor

Choose a reason for hiding this comment

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

What's about extracting a processCookies and processJSONToken as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! Will look into it

@vpavlin
Copy link
Member Author

vpavlin commented Jan 17, 2018

@hferentschik I've refactored more and tried to remove some complexity where it was possible.

@hferentschik
Copy link
Contributor

retest this please

@hferentschik hferentschik changed the title Refactor Handle function Issue #103 Refactor Handle function Jan 17, 2018
Copy link
Contributor

@hferentschik hferentschik left a comment

Choose a reason for hiding this comment

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

I think there is more we can do, but in order to move forward and with the need to resolve some more pressing issues first, let's merge this.

var ns string
var cacheKey string
var reqURL url.URL
var noProxy bool
Copy link
Contributor

Choose a reason for hiding this comment

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

https://github.com/fabric8-services/fabric8-jenkins-proxy/pull/109/files#diff-3ac192716a1df66bbd1008d327af8792R102 - I would think the best is to create an issue as well on the GitHub issue tracker. This can then be a place for further discussion as well.

body, err = ioutil.ReadAll(r.Body)
if err != nil {
p.HandleError(w, err)
ns, noProxy = p.handleGitHubRequest(w, r)
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

return
}
}
//Write usage stats to DB, run in a goroutine to not slow down the proxy
go func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This we want to refactor, but we can do this later. There are #75 and #115

needsAuth = false
}

if len(r.Cookies()) > 0 { //Check cookies and proxy cache to find user info
Copy link
Contributor

Choose a reason for hiding this comment

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

I think here we could further split up, but we can do this in increments.

}
http.SetCookie(w, cookie)
Copy link
Contributor

Choose a reason for hiding this comment

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

So just to sort this out in my mind, the cookie is just an optimisation which allows for short circuit JWT decoding, tenant lookup, etc. In theory, things would work without the cookie, correct?

Copy link
Member Author

Choose a reason for hiding this comment

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

The flow is

  1. redirect to auth to get JWT token
  2. Get user info and OSO token
  3. Login to Jenkins with OSO token
  4. Find the newly generated JSESSION cookie and pass it back to user - Jenkins uses it to keep the user's session and not to force him re-login for every request, afaiu - which is why we need to tak the cookie from Proxy's login request to Jenkins and pass it back to user so that it gets stored in the browser - as if the user himself logged into Jenkins

@hferentschik
Copy link
Contributor

Merged, thanks.

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.

2 participants