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

Refactor Sign In Page rendering and capture all page rendering code in pagewriter package #1043

Merged
merged 4 commits into from
Feb 14, 2021

Conversation

JoelSpeed
Copy link
Member

@JoelSpeed JoelSpeed commented Feb 13, 2021

Description

  • Move SignInPage template rending to its own struct in the app package
  • Wrap the SignInPage and ErrorPage rendering into a Writer interface
  • Move all of the code related to rendering the pages to a pagewriter package
  • Removes a bunch of options from the OAuth2 Proxy main struct as they are no longer required

Motivation and Context

This completes the extraction of the templates and page rendering from the main OAuth2 Proxy package.
Now, everything to do with the templates and how they are rendered is in it's own package with a well defined boundary.
The OAuth2 Proxy app can now pass through the options once to the Writer constructor and be able to render the pages without knowing anything about the templating etc going on in under the hood.

(This may be best reviewed commit by commit)

How Has This Been Tested?

Unit tests and the manual testing environment

Checklist:

  • My change requires a change to the documentation or CHANGELOG.
  • I have updated the documentation/CHANGELOG accordingly.
  • I have created a feature (non-master) branch for my PR.

// It uses the passed redirectURL to give users the option to go back to where
// they originally came from or try signing in again.
func (e *ErrorPage) Render(rw http.ResponseWriter, status int, redirectURL string, appError string, messages ...interface{}) {
func (e *errorPageWriter) WriteErrorPage(rw http.ResponseWriter, status int, redirectURL string, appError string, messages ...interface{}) {
Copy link

Choose a reason for hiding this comment

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

Method errorPageWriter.WriteErrorPage has 5 arguments (exceeds 4 allowed). Consider refactoring.


templateHTML := `Custom Template`
signInFile := filepath.Join(customDir, signInTemplateName)
Expect(ioutil.WriteFile(signInFile, []byte(templateHTML), 0666)).To(Succeed())
Copy link
Member

Choose a reason for hiding this comment

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

Can we tighten up the permissions on these test files? Can they be 0600 or 0400?

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 fixed up to 0600 for all the tests in this package, not sure why I ended up with 0666 🤷

"net/http"
)

// Writer is an interface for rednering html templates for both sign-in and
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Writer is an interface for rednering html templates for both sign-in and
// Writer is an interface for rendering html templates for both sign-in and

NickMeves
NickMeves previously approved these changes Feb 13, 2021
Copy link
Member

@NickMeves NickMeves left a comment

Choose a reason for hiding this comment

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

LGTM! This organization will be really handy moving forward.

I just left a couple of small NITs -- otherwise it looks great to me.

@JoelSpeed
Copy link
Member Author

Nits fixed, no other changes, will merge once tests pass

@JoelSpeed JoelSpeed merged commit ce29b16 into master Feb 14, 2021
@JoelSpeed JoelSpeed deleted the sign-in-page branch February 14, 2021 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants