http

package
v0.20.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 17, 2018 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultUserRole = "admin"
)

Variables

View Source
var (
	// ErrWrongCredentials error wrong credentials
	ErrWrongCredentials = errors.New("Wrong credentials")
)

Functions

func AuthCookie added in v0.19.0

func AuthCookie(token, path string) *http.Cookie

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

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) Delete

func (c *CrudClient) Delete(resource string, id string) 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

func (*CrudClient) Update

func (c *CrudClient) Update(resource string, id string, value interface{}) error

type HtpasswdMapProvider added in v0.19.0

type HtpasswdMapProvider struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

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 NewKeystoneBackend(name string, authURL string, tenant string, domain string, role string) (*KeystoneAuthenticationBackend, error)

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

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

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

func (*RestClient) Request

func (c *RestClient) Request(method, path string, body io.Reader, header http.Header) (*http.Response, error)

type Route

type Route struct {
	Name        string
	Method      string
	Path        interface{}
	HandlerFunc auth.AuthenticatedHandlerFunc
}

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 NewServer

func NewServer(host string, serviceType common.ServiceType, addr string, port int, tlsConfig *tls.Config) *Server

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) Listen added in v0.13.0

func (s *Server) Listen() error

func (*Server) ListenAndServe

func (s *Server) ListenAndServe()

func (*Server) RegisterRoutes

func (s *Server) RegisterRoutes(routes []Route, auth AuthenticationBackend)

func (*Server) Serve added in v0.13.0

func (s *Server) Serve()

func (*Server) Stop

func (s *Server) Stop()

type User added in v0.8.0

type User struct {
	ID   string `mapstructure:"id"`
	Name string `mapstructure:"name"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL