session

package
v2.0.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnauthorized when a session request is unauthorized
	// usually due to password missmatch
	ErrUnauthorized = &influxdb.Error{
		Code: influxdb.EUnauthorized,
		Msg:  "unauthorized access",
	}
)

Functions

func SetCookieSession

func SetCookieSession(key string, r *http.Request)

SetCookieSession adds a cookie for the session to an http request

Types

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service implements the influxdb.SessionService interface and handles communication between session and the necessary user and urm services

func NewService

func NewService(store *Storage, userService influxdb.UserService, urmService influxdb.UserResourceMappingService, authSvc influxdb.AuthorizationService, opts ...ServiceOption) *Service

NewService creates a new session service

func (*Service) CreateSession

func (s *Service) CreateSession(ctx context.Context, user string) (*influxdb.Session, error)

CreateSession

func (*Service) ExpireSession

func (s *Service) ExpireSession(ctx context.Context, key string) error

ExpireSession removes a session from the system

func (*Service) FindSession

func (s *Service) FindSession(ctx context.Context, key string) (*influxdb.Session, error)

FindSession finds a session based on the session key

func (*Service) RenewSession

func (s *Service) RenewSession(ctx context.Context, session *influxdb.Session, newExpiration time.Time) error

RenewSession update the sessions expiration time

func (*Service) WithMaxPermissionFunc

func (s *Service) WithMaxPermissionFunc(fn func(context.Context) bool)

WithMaxPermissionFunc sets the useAuthorizationsForMaxPermissions function which can trigger whether or not max permissions uses the users authorizations to derive maximum permissions.

type ServiceOption

type ServiceOption func(*Service)

ServiceOption is a functional option for configuring a *Service

func WithIDGenerator

func WithIDGenerator(gen influxdb.IDGenerator) ServiceOption

WithIDGenerator overrides the default ID generator with the one provided to this function when called on a *Service

func WithSessionLength

func WithSessionLength(length time.Duration) ServiceOption

WithSessionLength configures the length of the session with the provided duration when the resulting option is called on a *Service.

func WithTokenGenerator

func WithTokenGenerator(gen influxdb.TokenGenerator) ServiceOption

WithTokenGenerator overrides the default token generator with the one provided to this function when called on a *Service

type SessionHandler

type SessionHandler struct {
	chi.Router
	// contains filtered or unexported fields
}

SessionHandler represents an HTTP API handler for authorizations.

func NewSessionHandler

func NewSessionHandler(log *zap.Logger, sessionSvc influxdb.SessionService, userSvc influxdb.UserService, passwordsSvc influxdb.PasswordsService) *SessionHandler

NewSessionHandler returns a new instance of SessionHandler.

func (SessionHandler) SignInResourceHandler

func (h SessionHandler) SignInResourceHandler() *resourceHandler

SignInResourceHandler allows us to return 2 different rousource handler for the appropriate mounting location

func (SessionHandler) SignOutResourceHandler

func (h SessionHandler) SignOutResourceHandler() *resourceHandler

SignOutResourceHandler allows us to return 2 different rousource handler for the appropriate mounting location

type SessionLogger

type SessionLogger struct {
	// contains filtered or unexported fields
}

SessionLogger is a logger service middleware for sessions

func NewSessionLogger

func NewSessionLogger(log *zap.Logger, s influxdb.SessionService) *SessionLogger

NewSessionLogger returns a logging service middleware for the User Service.

func (*SessionLogger) CreateSession

func (l *SessionLogger) CreateSession(ctx context.Context, user string) (s *influxdb.Session, err error)

CreateSession calls the underlying session service and logs the results of the request

func (*SessionLogger) ExpireSession

func (l *SessionLogger) ExpireSession(ctx context.Context, key string) (err error)

ExpireSession calls the underlying session service and logs the results of the request

func (*SessionLogger) FindSession

func (l *SessionLogger) FindSession(ctx context.Context, key string) (session *influxdb.Session, err error)

FindSession calls the underlying session service and logs the results of the request

func (*SessionLogger) RenewSession

func (l *SessionLogger) RenewSession(ctx context.Context, session *influxdb.Session, newExpiration time.Time) (err error)

RenewSession calls the underlying session service and logs the results of the request

type SessionMetrics

type SessionMetrics struct {
	// contains filtered or unexported fields
}

SessionMetrics is a metrics middleware system for the session service

func NewSessionMetrics

func NewSessionMetrics(reg prometheus.Registerer, s influxdb.SessionService) *SessionMetrics

NewSessionMetrics creates a new session metrics middleware

func (*SessionMetrics) CreateSession

func (m *SessionMetrics) CreateSession(ctx context.Context, user string) (s *influxdb.Session, err error)

CreateSession calls the underlying session service and tracks RED metrics for the call

func (*SessionMetrics) ExpireSession

func (m *SessionMetrics) ExpireSession(ctx context.Context, key string) (err error)

ExpireSession calls the underlying session service and tracks RED metrics for the call

func (*SessionMetrics) FindSession

func (m *SessionMetrics) FindSession(ctx context.Context, key string) (session *influxdb.Session, err error)

FindSession calls the underlying session service and tracks RED metrics for the call

func (*SessionMetrics) RenewSession

func (m *SessionMetrics) RenewSession(ctx context.Context, session *influxdb.Session, newExpiration time.Time) (err error)

RenewSession calls the underlying session service and tracks RED metrics for the call

type Storage

type Storage struct {
	// contains filtered or unexported fields
}

Storage is a store translation layer between the data storage unit and the service layer.

func NewStorage

func NewStorage(s Store) *Storage

NewStorage creates a new storage system

func (*Storage) CreateSession

func (s *Storage) CreateSession(ctx context.Context, session *influxdb.Session) error

CreateSession creates a new session

func (*Storage) DeleteSession

func (s *Storage) DeleteSession(ctx context.Context, id influxdb.ID) error

DeleteSession removes the session and index from storage

func (*Storage) FindSessionByID

func (s *Storage) FindSessionByID(ctx context.Context, id influxdb.ID) (*influxdb.Session, error)

FindSessionByID use a provided id to retrieve the stored session

func (*Storage) FindSessionByKey

func (s *Storage) FindSessionByKey(ctx context.Context, key string) (*influxdb.Session, error)

FindSessionByKey use a given key to retrieve the stored session

func (*Storage) RefreshSession

func (s *Storage) RefreshSession(ctx context.Context, id influxdb.ID, expireAt time.Time) error

RefreshSession updates the expiration time of a session.

type Store

type Store interface {
	Set(key, val string, expireAt time.Time) error
	Get(key string) (string, error)
	Delete(key string) error
	ExpireAt(key string, expireAt time.Time) error
}

Jump to

Keyboard shortcuts

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