diff --git a/oauthproxy.go b/oauthproxy.go index 63e1e48f..ebc713d9 100644 --- a/oauthproxy.go +++ b/oauthproxy.go @@ -17,7 +17,7 @@ import ( middlewareapi "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/middleware" "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options" sessionsapi "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/sessions" - "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/app" + "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/app/pagewriter" "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/authentication/basic" "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/cookies" "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/encryption" @@ -101,7 +101,7 @@ type OAuthProxy struct { sessionChain alice.Chain headersChain alice.Chain preAuthChain alice.Chain - pageWriter app.PageWriter + pageWriter pagewriter.Writer } // NewOAuthProxy creates a new instance of OAuthProxy from the options provided @@ -121,7 +121,7 @@ func NewOAuthProxy(opts *options.Options, validator func(string) bool) (*OAuthPr } } - pageWriter, err := app.NewPageWriter(app.PageWriterOpts{ + pageWriter, err := pagewriter.NewWriter(pagewriter.Opts{ TemplatesPath: opts.Templates.Path, ProxyPrefix: opts.ProxyPrefix, Footer: opts.Templates.Footer, diff --git a/pkg/app/error_page.go b/pkg/app/pagewriter/error_page.go similarity index 99% rename from pkg/app/error_page.go rename to pkg/app/pagewriter/error_page.go index 62663838..28d81bb1 100644 --- a/pkg/app/error_page.go +++ b/pkg/app/pagewriter/error_page.go @@ -1,4 +1,4 @@ -package app +package pagewriter import ( "fmt" diff --git a/pkg/app/error_page_test.go b/pkg/app/pagewriter/error_page_test.go similarity index 99% rename from pkg/app/error_page_test.go rename to pkg/app/pagewriter/error_page_test.go index 28880d68..56cd821b 100644 --- a/pkg/app/error_page_test.go +++ b/pkg/app/pagewriter/error_page_test.go @@ -1,4 +1,4 @@ -package app +package pagewriter import ( "errors" diff --git a/pkg/app/pagewriter.go b/pkg/app/pagewriter/pagewriter.go similarity index 84% rename from pkg/app/pagewriter.go rename to pkg/app/pagewriter/pagewriter.go index 84512789..fdc8ec30 100644 --- a/pkg/app/pagewriter.go +++ b/pkg/app/pagewriter/pagewriter.go @@ -1,29 +1,29 @@ -package app +package pagewriter import ( "fmt" "net/http" ) -// PageWriter is an interface for rendering html templates for both sign-in and +// Writer is an interface for rendering html templates for both sign-in and // error pages. // It can also be used to write errors for the http.ReverseProxy used in the // upstream package. -type PageWriter interface { +type Writer interface { WriteSignInPage(rw http.ResponseWriter, redirectURL string) WriteErrorPage(rw http.ResponseWriter, status int, redirectURL string, appError string, messages ...interface{}) ProxyErrorHandler(rw http.ResponseWriter, req *http.Request, proxyErr error) } -// pageWriter implements the PageWriter interface +// pageWriter implements the Writer interface type pageWriter struct { *errorPageWriter *signInPageWriter } -// PageWriterOpts contains all options required to configure the template +// Opts contains all options required to configure the template // rendering within OAuth2 Proxy. -type PageWriterOpts struct { +type Opts struct { // TemplatesPath is the path from which to load custom templates for the sign-in and error pages. TemplatesPath string @@ -51,9 +51,9 @@ type PageWriterOpts struct { SignInMessage string } -// NewPageWriter constructs a PageWriter from the options given to allow +// NewWriter constructs a Writer from the options given to allow // rendering of sign-in and error pages. -func NewPageWriter(opts PageWriterOpts) (PageWriter, error) { +func NewWriter(opts Opts) (Writer, error) { templates, err := loadTemplates(opts.TemplatesPath) if err != nil { return nil, fmt.Errorf("error loading templates: %v", err) diff --git a/pkg/app/app_suite_test.go b/pkg/app/pagewriter/pagewriter_suite_test.go similarity index 93% rename from pkg/app/app_suite_test.go rename to pkg/app/pagewriter/pagewriter_suite_test.go index d2df0233..ade6a94b 100644 --- a/pkg/app/app_suite_test.go +++ b/pkg/app/pagewriter/pagewriter_suite_test.go @@ -1,4 +1,4 @@ -package app +package pagewriter import ( "testing" diff --git a/pkg/app/pagewriter_test.go b/pkg/app/pagewriter/pagewriter_test.go similarity index 92% rename from pkg/app/pagewriter_test.go rename to pkg/app/pagewriter/pagewriter_test.go index 7f7dee1f..3d7669f9 100644 --- a/pkg/app/pagewriter_test.go +++ b/pkg/app/pagewriter/pagewriter_test.go @@ -1,4 +1,4 @@ -package app +package pagewriter import ( "io/ioutil" @@ -10,13 +10,13 @@ import ( . "github.com/onsi/gomega" ) -var _ = Describe("PageWriter", func() { - Context("NewPageWriter", func() { - var writer PageWriter - var opts PageWriterOpts +var _ = Describe("Writer", func() { + Context("NewWriter", func() { + var writer Writer + var opts Opts BeforeEach(func() { - opts = PageWriterOpts{ + opts = Opts{ TemplatesPath: "", ProxyPrefix: "/prefix", Footer: "