Skip to content
This repository has been archived by the owner on Dec 7, 2020. It is now read-only.

Commit

Permalink
- adding the middleware metrics as optional
Browse files Browse the repository at this point in the history
- fixed up the server test code
  • Loading branch information
gambol99 committed Jul 6, 2016
1 parent f569f4b commit 21cc48b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 24 deletions.
17 changes: 10 additions & 7 deletions config.go
Expand Up @@ -190,9 +190,6 @@ func readOptions(cx *cli.Context, config *Config) (err error) {
if cx.IsSet("skip-upstream-tls-verify") {
config.SkipUpstreamTLSVerify = cx.Bool("skip-upstream-tls-verify")
}
if cx.IsSet("enable-refresh-tokens") {
config.EnableRefreshTokens = cx.Bool("enable-refresh-tokens")
}
if cx.IsSet("encryption-key") {
config.EncryptionKey = cx.String("encryption-key")
}
Expand Down Expand Up @@ -226,12 +223,18 @@ func readOptions(cx *cli.Context, config *Config) (err error) {
if cx.IsSet("tls-ca-certificate") {
config.TLSCaCertificate = cx.String("tls-ca-certificate")
}
if cx.IsSet("enable-metrics") {
config.EnableMetrics = cx.Bool("enable-metrics")
}
if cx.IsSet("enable-proxy-protocol") {
config.EnableProxyProtocol = cx.Bool("enable-proxy-protocol")
}
if cx.IsSet("enable-forwarding") {
config.EnableForwarding = cx.Bool("enable-forwarding")
}
if cx.IsSet("enable-refresh-tokens") {
config.EnableRefreshTokens = cx.Bool("enable-refresh-tokens")
}
if cx.IsSet("forwarding-username") {
config.ForwardingUsername = cx.String("forwarding-username")
}
Expand Down Expand Up @@ -389,10 +392,6 @@ func getOptions() []cli.Flag {
Value: "/oauth2/revoke",
EnvVar: "PROXY_REVOCATION_URL",
},
cli.BoolFlag{
Name: "enable-metrics",
Usage: "enable the prometheus metrics collector",
},
cli.StringFlag{
Name: "store-url",
Usage: "url for the storage subsystem, e.g redis://127.0.0.1:6379, file:///etc/tokens.file",
Expand Down Expand Up @@ -448,6 +447,10 @@ func getOptions() []cli.Flag {
Name: "hostname",
Usage: "a list of hostnames the service will respond to, defaults to all",
},
cli.BoolFlag{
Name: "enable-metrics",
Usage: "enable the prometheus metrics collector on /oauth/metrics",
},
cli.BoolFlag{
Name: "enable-proxy-protocol",
Usage: "whether to enable proxy protocol",
Expand Down
6 changes: 0 additions & 6 deletions middleware.go
Expand Up @@ -68,16 +68,10 @@ func (r *oauthProxy) metricsHandler() gin.HandlerFunc {
[]string{"code", "method"},
)

fmt.Println("ENBAKED")

// step: register the metric with prometheus
prometheus.MustRegisterOrGet(httpMetrics)

return func(cx *gin.Context) {

fmt.Println("ENBAKED")


// step: permit to next stage
cx.Next()
// step: update the metrics
Expand Down
4 changes: 2 additions & 2 deletions proxy.go
Expand Up @@ -21,7 +21,7 @@ import (
"os/signal"
"syscall"

"github.com/codegangsta/cli"
"github.com/urfave/cli"
)

func newOauthProxyApp() *cli.App {
Expand Down Expand Up @@ -87,7 +87,7 @@ func newOauthProxyApp() *cli.App {
return app
}

// printUsage display the command line usage and error
// printError display the command line usage and error
func printError(message string, args ...interface{}) *cli.ExitError {
return cli.NewExitError(fmt.Sprintf("[error] "+message, args...), 1)
}
22 changes: 13 additions & 9 deletions server.go
Expand Up @@ -94,8 +94,7 @@ func newProxy(config *Config) (*oauthProxy, error) {
}

// step: parse the upstream endpoint
service.endpoint, err = url.Parse(config.Upstream)
if err != nil {
if service.endpoint, err = url.Parse(config.Upstream); err != nil {
return nil, err
}

Expand All @@ -120,7 +119,7 @@ func newProxy(config *Config) (*oauthProxy, error) {
log.Warnf("Note: client credentials are not set, depending on provider (confidential|public) you might be able to auth")
}

// step:
// step: are we running in forwarding more?
switch config.EnableForwarding {
case true:
if err := createForwardingProxy(config, service); err != nil {
Expand Down Expand Up @@ -154,6 +153,11 @@ func createReverseProxy(config *Config, service *oauthProxy) error {
return err
}

// step: create the endpoints
if err := service.createEndpoints(); err != nil {
return err
}

// step: load the templates
if err := service.createTemplates(); err != nil {
return err
Expand Down Expand Up @@ -344,9 +348,9 @@ func (r *oauthProxy) createEndpoints() error {
}

// step: enabling the metrics?
//if r.config.EnableMetrics {
// engine.Use(r.metricsHandler())
//}
if r.config.EnableMetrics {
engine.Use(r.metricsHandler())
}

// step: add the routing
oauth := engine.Group(oauthURL).Use(r.crossOriginResourceHandler(r.config.CrossOrigin))
Expand All @@ -358,9 +362,9 @@ func (r *oauthProxy) createEndpoints() error {
oauth.GET(expiredURL, r.expirationHandler)
oauth.GET(logoutURL, r.logoutHandler)
oauth.POST(loginURL, r.loginHandler)
// if r.config.EnableMetrics {
// oauth.GET(metricsURL, r.metricsEndpointHandler)
// }
if r.config.EnableMetrics {
oauth.GET(metricsURL, r.metricsEndpointHandler)
}
}

engine.Use(
Expand Down
2 changes: 2 additions & 0 deletions server_test.go
Expand Up @@ -129,11 +129,13 @@ func newTestProxyService(t *testing.T, config *Config) (*oauthProxy, *fakeOAuthS
if config == nil {
config = newFakeKeycloakConfig()
}

// step: set the config
config.LogRequests = true
config.SkipTokenVerification = false
config.DiscoveryURL = auth.getLocation()
config.Verbose = false

// step: create a proxy
proxy, err := newProxy(config)
if err != nil {
Expand Down

0 comments on commit 21cc48b

Please sign in to comment.