Documentation ¶
Index ¶
- type FormAuth
- type HMACJWTGen
- func (hc *HMACJWTGen) ContextKey(keyName string) *HMACJWTGen
- func (hc *HMACJWTGen) NewEchoLoginHandler(p *JWTGenPolicy, handlerIdentifier ...string) echo.HandlerFunc
- func (hc *HMACJWTGen) NewEchoMiddleware() echo.MiddlewareFunc
- func (hc *HMACJWTGen) SigningKey(secret []byte) *HMACJWTGen
- func (hc *HMACJWTGen) SigningMethod(method string) *HMACJWTGen
- type JWTGenPolicy
- type TokenResponseBody
- type WebApp
- type ZerologConfig
- func (c *ZerologConfig) SetGlobalLogger()
- func (c *ZerologConfig) SetGlobalPolicy() *ZerologConfig
- func (c *ZerologConfig) SetOffGlobalLogger()
- func (c *ZerologConfig) SetWriter(writer io.Writer) *ZerologConfig
- func (c *ZerologConfig) UseLocalTime() *ZerologConfig
- func (c *ZerologConfig) UseUTCTime() *ZerologConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FormAuth ¶ added in v0.3.0
type FormAuth struct {
// contains filtered or unexported fields
}
FormAuth creates a cofig object to configure authentication strategy.
func NewFormAuth ¶ added in v0.3.0
func NewFormAuth() *FormAuth
NewFormAuth creates an object that configures form authentication.
func (*FormAuth) NewGuardianStrategy ¶ added in v0.3.0
func (c *FormAuth) NewGuardianStrategy(fn b.AuthenticateFunc) a.Strategy
NewGuardianStrategy method provides a go-guardian to accept username and password from HTTP form body, uesful for web page authentication. The returned strategy does not support go-guardian's cache strategy for now. As an alternative solution, manipulate cache in basic.AuthenticateFunc.
func (*FormAuth) PasswordKey ¶ added in v0.3.0
PasswordKey is control option for NewGuardianFormAuthStrategy() creator, to specify form key name for retriving password.
func (*FormAuth) UsernameKey ¶ added in v0.3.0
UsernameKey is control option for NewGuardianFormAuthStrategy() creator, to specify form key name for retriving username.
type HMACJWTGen ¶ added in v0.3.0
type HMACJWTGen struct {
// contains filtered or unexported fields
}
HMACJWTGen provides JWT generation logic with symmetric encryption. By default it supports HS256, HS384 and HS512.
func NewHMACJWTGen ¶ added in v0.3.0
func NewHMACJWTGen(signingKey []byte) *HMACJWTGen
NewHMACJWTGen creates a new configuration object to generate JWT token handler and middleware.
func (*HMACJWTGen) ContextKey ¶ added in v0.3.0
func (hc *HMACJWTGen) ContextKey(keyName string) *HMACJWTGen
ContextKey specifies the key name we use to lookup token object in echo's Context object.
func (*HMACJWTGen) NewEchoLoginHandler ¶ added in v0.3.0
func (hc *HMACJWTGen) NewEchoLoginHandler(p *JWTGenPolicy, handlerIdentifier ...string) echo.HandlerFunc
NewEchoLoginHandler create an Labstack Echo framework handler. It takes parameter p, an JWT generator policy object, and a handlerIdentifier string to distinguish this handler when creating Prometheus counters.
func (*HMACJWTGen) NewEchoMiddleware ¶ added in v0.3.0
func (hc *HMACJWTGen) NewEchoMiddleware() echo.MiddlewareFunc
NewEchoMiddleware returns a token validation middleware for Labstack Echo framework.
func (*HMACJWTGen) SigningKey ¶ added in v0.3.0
func (hc *HMACJWTGen) SigningKey(secret []byte) *HMACJWTGen
SigningKey specifies signing key for JWT signing. The given secret should not be shared with anyone.
func (*HMACJWTGen) SigningMethod ¶ added in v0.3.0
func (hc *HMACJWTGen) SigningMethod(method string) *HMACJWTGen
SigningMethod specifies signing method. Supposed method is HS256, HS384 and HS512.
type JWTGenPolicy ¶ added in v0.2.0
type JWTGenPolicy struct {
// contains filtered or unexported fields
}
JWTGenPolicy is a cofiguration we use to control how we generate JWT tokens. It specifies behavior such as expiration time and login approaches.
JWTGenPolicy is designed as a separated configuration object, instead of being a part of HMACJWTConfig. This is to ensure we leave future flexibility when Barton supports JWT with public/private keys.
func NewJWTGenPolicy ¶ added in v0.2.0
func NewJWTGenPolicy(strategy auth.Strategy) *JWTGenPolicy
NewJWTGenPolicy generate a new policy configuration. It specifies behaviors like token expiration time and authentication methods. The policy is passed to HMACJWTConfig.NewEchoLoginHandler() method to generate an Echo handler function.
func (*JWTGenPolicy) AuthFailLogMsg ¶ added in v0.2.0
func (p *JWTGenPolicy) AuthFailLogMsg(msg string) *JWTGenPolicy
AuthFailLogMsg specifies a log line string when authentication check fails. This message is designed to use when developers search failure message from ElasticSearch or Splunk.
func (*JWTGenPolicy) ExpireSpan ¶ added in v0.2.0
func (p *JWTGenPolicy) ExpireSpan(expire time.Duration) *JWTGenPolicy
ExpireSpan specifies a expire time duration.
func (*JWTGenPolicy) PrintAuthFailLog ¶ added in v0.2.0
func (p *JWTGenPolicy) PrintAuthFailLog(enable bool) *JWTGenPolicy
PrintAuthFailLog specifies whether login handler writes log line on a failed authentication step. By default it's set to false. Although log line is useful for debugging, it can cause log flooding and eat up disk space of log server, when a malform client intentially generate many bad requests. This is especially true in a cost sensitive deployment.
It's recommended to enable PrintAuthFailLog in development mode, then disable it in production mode.
func (*JWTGenPolicy) TokenIssuedLogMsg ¶ added in v0.2.0
func (p *JWTGenPolicy) TokenIssuedLogMsg(msg string) *JWTGenPolicy
TokenIssuedLogMsg specifies a log line string when a token is genearted successfully. This message is designed to use when developers search failure message from ElasticSearch or Splunk.
type TokenResponseBody ¶ added in v0.3.0
TokenResponseBody represents a structure that returned JSON when trying to login JWT token.
type WebApp ¶ added in v0.3.0
type WebApp struct {
// contains filtered or unexported fields
}
WebApp is a configuration object that sets configurations, and build an Echo web server via NewEcho() method.
func NewWebApp ¶ added in v0.3.0
NewWebApp is main entry to start building an Echo app engine. It returns a chainable configuration object, WebApp, which is configured as setter functions. The final step is it calls New() function to really build an Echo engine, plus a cleanup function returned.
type ZerologConfig ¶
type ZerologConfig struct {
// contains filtered or unexported fields
}
ZerologConfig creates an object to configure and set global Zerolog object.
func NewZerologConfig ¶
func NewZerologConfig() *ZerologConfig
NewZerologConfig creates a new config object with default settings: timestamp written to RFC3339 format, and write to os.Stderr.
func (*ZerologConfig) SetGlobalLogger ¶
func (c *ZerologConfig) SetGlobalLogger()
SetGlobalLogger creates a logger object and assign it to global Zerolog object (log.Logger).
func (*ZerologConfig) SetGlobalPolicy ¶
func (c *ZerologConfig) SetGlobalPolicy() *ZerologConfig
SetGlobalPolicy sets default zerolog settings used by Gregson. The following policy are enforced:
1. Always use RFC3339 format ("2006-01-02T15:04:05Z07:00") 2. Timestamp returns UTC. 3. Prints only INFO level logs or above. 4. Sampling is disabled.
#1 and #2 are for readability reason, considering develpers may have micro-services running in different machines.
Special notes for #3: Log level customization is unrecommended. This is to avoid a practice, that developers may write less log in production, but more in dev, assuming reported issue can be reproduced in-house. This is usually not true for Internet oriented services, because issues are triggerred only under high load.
#4 is set by almost same reason with #3. Sampling sacrifaces diagnose feasibility to get smaller file size. This is usually not worthy in production environment.
func (*ZerologConfig) SetOffGlobalLogger ¶
func (c *ZerologConfig) SetOffGlobalLogger()
SetOffGlobalLogger configures global zerolog to discard messages. This is useful when writing tests, but do not use in production.
func (*ZerologConfig) SetWriter ¶
func (c *ZerologConfig) SetWriter(writer io.Writer) *ZerologConfig
SetWriter sets a writer object (io.Writer) that log lines are written to. Note that the io.Writer needs to be closed by caller side if any. By default, ZerologConfig sets writer to os.Stderr.
func (*ZerologConfig) UseLocalTime ¶
func (c *ZerologConfig) UseLocalTime() *ZerologConfig
UseLocalTime enforces timezone info added to Zerolog. Need to call SetGlobalPolicy() to make it take effect.
func (*ZerologConfig) UseUTCTime ¶
func (c *ZerologConfig) UseUTCTime() *ZerologConfig
UseUTCTime forces timezone info to UTC in Zerolog. Need to call SetGlobalPolicy() to make it take effect.