Documentation ¶
Index ¶
- Constants
- Variables
- func AuthCookie(token, path string) *http.Cookie
- func Authenticate(backend AuthenticationBackend, w http.ResponseWriter, ...) (string, error)
- func NoAuthenticationWrap(wrapped auth.AuthenticatedHandlerFunc) http.HandlerFunc
- func SetAuthHeaders(headers *http.Header, authOpts *AuthenticationOpts)
- func SetTLSHeader(w http.ResponseWriter, r *http.Request)
- func Unauthorized(w http.ResponseWriter, r *http.Request)
- type AuthenticationBackend
- type AuthenticationOpts
- type BasicAuthenticationBackend
- func (b *BasicAuthenticationBackend) Authenticate(username string, password string) (string, error)
- func (b *BasicAuthenticationBackend) DefaultUserRole(user string) string
- func (b *BasicAuthenticationBackend) Name() string
- func (b *BasicAuthenticationBackend) SetDefaultUserRole(role string)
- func (b *BasicAuthenticationBackend) Wrap(wrapped auth.AuthenticatedHandlerFunc) http.HandlerFunc
- type ConnectionType
- type CrudClient
- func (c *CrudClient) Create(resource string, value interface{}) error
- func (c *CrudClient) Delete(resource string, id string) error
- func (c *CrudClient) Get(resource string, id string, value interface{}) error
- func (c *CrudClient) List(resource string, values interface{}) error
- func (c *CrudClient) Update(resource string, id string, value interface{}) error
- type HtpasswdMapProvider
- type KeystoneAuthenticationBackend
- func (b *KeystoneAuthenticationBackend) Authenticate(username string, password string) (string, error)
- func (b *KeystoneAuthenticationBackend) CheckUser(token string) (string, error)
- func (b *KeystoneAuthenticationBackend) DefaultUserRole(user string) string
- func (b *KeystoneAuthenticationBackend) Name() string
- func (b *KeystoneAuthenticationBackend) SetDefaultUserRole(role string)
- func (b *KeystoneAuthenticationBackend) Wrap(wrapped auth.AuthenticatedHandlerFunc) http.HandlerFunc
- type NoAuthenticationBackend
- func (h *NoAuthenticationBackend) Authenticate(username string, password string) (string, error)
- func (h *NoAuthenticationBackend) DefaultUserRole(user string) string
- func (h *NoAuthenticationBackend) Name() string
- func (b *NoAuthenticationBackend) SetDefaultUserRole(role string)
- func (h *NoAuthenticationBackend) Wrap(wrapped auth.AuthenticatedHandlerFunc) http.HandlerFunc
- type PathPrefix
- type RestClient
- type Route
- type Server
- type User
Constants ¶
const (
DefaultUserRole = "admin"
)
Variables ¶
var ( // ErrWrongCredentials error wrong credentials ErrWrongCredentials = errors.New("Wrong credentials") )
Functions ¶
func AuthCookie ¶ added in v0.19.0
AuthCookie returns a authentication cookie
func Authenticate ¶ added in v0.20.0
func Authenticate(backend AuthenticationBackend, w http.ResponseWriter, username, password string) (string, error)
func NoAuthenticationWrap ¶ added in v0.19.0
func NoAuthenticationWrap(wrapped auth.AuthenticatedHandlerFunc) http.HandlerFunc
func SetAuthHeaders ¶ added in v0.19.0
func SetAuthHeaders(headers *http.Header, authOpts *AuthenticationOpts)
SetAuthHeaders apply all the cookie used for authentication to the header
func SetTLSHeader ¶ added in v0.20.0
func SetTLSHeader(w http.ResponseWriter, r *http.Request)
func Unauthorized ¶ added in v0.20.0
func Unauthorized(w http.ResponseWriter, r *http.Request)
Types ¶
type AuthenticationBackend ¶
type AuthenticationBackend interface { Name() string DefaultUserRole(user string) string SetDefaultUserRole(role string) Authenticate(username string, password string) (string, error) Wrap(wrapped auth.AuthenticatedHandlerFunc) http.HandlerFunc }
AuthenticationBackend is the interface of a authentication backend
type AuthenticationOpts ¶
type AuthenticationOpts struct { Username string Password string Token string Cookie map[string]string }
AuthenticationOpts describes the elements used by a client to authenticate to an HTTP server. It can be either a username/password couple or a token
type BasicAuthenticationBackend ¶
type BasicAuthenticationBackend struct { *auth.BasicAuth // contains filtered or unexported fields }
func NewBasicAuthenticationBackend ¶ added in v0.4.0
func NewBasicAuthenticationBackend(name string, provider auth.SecretProvider, role string) (*BasicAuthenticationBackend, error)
func (*BasicAuthenticationBackend) Authenticate ¶
func (b *BasicAuthenticationBackend) Authenticate(username string, password string) (string, error)
func (*BasicAuthenticationBackend) DefaultUserRole ¶ added in v0.19.0
func (b *BasicAuthenticationBackend) DefaultUserRole(user string) string
DefaultUserRole returns the default user role
func (*BasicAuthenticationBackend) Name ¶ added in v0.19.0
func (b *BasicAuthenticationBackend) Name() string
Name returns the name of the backend
func (*BasicAuthenticationBackend) SetDefaultUserRole ¶ added in v0.19.0
func (b *BasicAuthenticationBackend) SetDefaultUserRole(role string)
SetDefaultUserRole defines the default user role
func (*BasicAuthenticationBackend) Wrap ¶
func (b *BasicAuthenticationBackend) Wrap(wrapped auth.AuthenticatedHandlerFunc) http.HandlerFunc
type ConnectionType ¶ added in v0.12.0
type ConnectionType int
const ( // TCP connection TCP ConnectionType = 1 + iota // TLS secure connection TLS )
type CrudClient ¶
type CrudClient struct {
*RestClient
}
func NewCrudClient ¶
func NewCrudClient(url *url.URL, authOpts *AuthenticationOpts, tlsConfig *tls.Config) *CrudClient
func (*CrudClient) Create ¶
func (c *CrudClient) Create(resource string, value interface{}) error
func (*CrudClient) Get ¶
func (c *CrudClient) Get(resource string, id string, value interface{}) error
func (*CrudClient) List ¶
func (c *CrudClient) List(resource string, values interface{}) error
type HtpasswdMapProvider ¶ added in v0.19.0
HtpasswdMapProvider defines a basic auth secret provider
func NewHtpasswdMapProvider ¶ added in v0.19.0
func NewHtpasswdMapProvider(users map[string]string) *HtpasswdMapProvider
NewHtpasswdMapProvider creates a new htpassword provider based on a map
func (*HtpasswdMapProvider) AddUser ¶ added in v0.19.0
func (h *HtpasswdMapProvider) AddUser(user, password string)
AddUser add a new user with the given password
func (*HtpasswdMapProvider) SecretProvider ¶ added in v0.19.0
func (h *HtpasswdMapProvider) SecretProvider() auth.SecretProvider
SecretProvider returns a SecretProvider
type KeystoneAuthenticationBackend ¶
type KeystoneAuthenticationBackend struct { AuthURL string Tenant string Domain string // contains filtered or unexported fields }
func NewKeystoneBackend ¶
func (*KeystoneAuthenticationBackend) Authenticate ¶
func (b *KeystoneAuthenticationBackend) Authenticate(username string, password string) (string, error)
func (*KeystoneAuthenticationBackend) CheckUser ¶
func (b *KeystoneAuthenticationBackend) CheckUser(token string) (string, error)
func (*KeystoneAuthenticationBackend) DefaultUserRole ¶ added in v0.19.0
func (b *KeystoneAuthenticationBackend) DefaultUserRole(user string) string
DefaultUserRole return the default user role
func (*KeystoneAuthenticationBackend) Name ¶ added in v0.19.0
func (b *KeystoneAuthenticationBackend) Name() string
Name returns the name of the backend
func (*KeystoneAuthenticationBackend) SetDefaultUserRole ¶ added in v0.19.0
func (b *KeystoneAuthenticationBackend) SetDefaultUserRole(role string)
SetDefaultUserRole defines the default user role
func (*KeystoneAuthenticationBackend) Wrap ¶
func (b *KeystoneAuthenticationBackend) Wrap(wrapped auth.AuthenticatedHandlerFunc) http.HandlerFunc
type NoAuthenticationBackend ¶
type NoAuthenticationBackend struct { }
func NewNoAuthenticationBackend ¶
func NewNoAuthenticationBackend() *NoAuthenticationBackend
func (*NoAuthenticationBackend) Authenticate ¶
func (h *NoAuthenticationBackend) Authenticate(username string, password string) (string, error)
func (*NoAuthenticationBackend) DefaultUserRole ¶ added in v0.19.0
func (h *NoAuthenticationBackend) DefaultUserRole(user string) string
DefaultUserRole returns the name of the backend
func (*NoAuthenticationBackend) Name ¶ added in v0.19.0
func (h *NoAuthenticationBackend) Name() string
Name returns the name of the backend
func (*NoAuthenticationBackend) SetDefaultUserRole ¶ added in v0.19.0
func (b *NoAuthenticationBackend) SetDefaultUserRole(role string)
SetDefaultUserRole defines the default user role
func (*NoAuthenticationBackend) Wrap ¶
func (h *NoAuthenticationBackend) Wrap(wrapped auth.AuthenticatedHandlerFunc) http.HandlerFunc
type PathPrefix ¶
type PathPrefix string
type RestClient ¶
type RestClient struct {
// contains filtered or unexported fields
}
func NewRestClient ¶
func NewRestClient(url *url.URL, authOpts *AuthenticationOpts, tlsConfig *tls.Config) *RestClient
type Server ¶
type Server struct { sync.RWMutex http.Server Host string ServiceType common.ServiceType Router *mux.Router Addr string Port int AuthBackend AuthenticationBackend CnxType ConnectionType // contains filtered or unexported fields }
func (*Server) HandleFunc ¶
func (s *Server) HandleFunc(path string, f auth.AuthenticatedHandlerFunc, authBackend AuthenticationBackend)
HandleFunc specifies the handler function and the authentication backend used for a given path
func (*Server) ListenAndServe ¶
func (s *Server) ListenAndServe()
func (*Server) RegisterRoutes ¶
func (s *Server) RegisterRoutes(routes []Route, auth AuthenticationBackend)