session

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FsFileSession             = "s"
	FsFileLastAccessed        = "la"
	FsFileAccessToken         = "at"
	FsFileEnvironmentToken    = "et"
	FsFilePublicKeysPrefix    = "pk-"
	FsFilePublicKeysPrefixLen = len(FsFilePublicKeysPrefix)
)

Variables

View Source
var (
	ErrMaxConnectionsPerSessionReached = errors.Newf(errors.User, "max connections per session reached")
)
View Source
var (
	ErrNoSuchSession = errors.New("no such session")
)

Functions

func IsExpired

func IsExpired(ctx context.Context, candidate Session) (bool, error)

func IsNotExpired

func IsNotExpired(ctx context.Context, candidate Session) (bool, error)

func IsStillValid

func IsStillValid(ctx context.Context, candidate Session) (bool, error)

Types

type CloseableRepository

type CloseableRepository interface {
	Repository
	io.Closer
}

type ConnectionInterceptor

type ConnectionInterceptor interface {
	io.Closer

	OnReadConnection(ssh.Context, log.Logger, net.Conn) (time.Time, ConnectionInterceptorResult, error)
	OnWriteConnection(ssh.Context, log.Logger, net.Conn) (time.Time, ConnectionInterceptorResult, error)
}

type ConnectionInterceptorResult

type ConnectionInterceptorResult uint8
const (
	ConnectionInterceptorResultNone ConnectionInterceptorResult = iota
	ConnectionInterceptorResultIdle
	ConnectionInterceptorResultMax
	ConnectionInterceptorResultDisposed
)

type Consumer

type Consumer func(context.Context, Session) (canContinue bool, err error)

type FacadeRepository added in v0.2.0

type FacadeRepository struct {
	CloseableRepository
}

func NewFacadeRepository added in v0.2.0

func NewFacadeRepository(ctx context.Context, conf *configuration.Session) (*FacadeRepository, error)

type FindOpts

type FindOpts struct {
	// Predicates are used to filter the returned sessions.
	Predicates Predicates

	// AutoCleanUpAllowed tells the repository to clean up everything
	// automatically while executing the search. The requester will never
	// see the requested result. This is false by default because it could
	// lead to quite performance impacts or other unwanted side effects.
	//
	// Therefore: Use with caution.
	AutoCleanUpAllowed *bool

	// Logger will be used (if any log is required) instead of the standard logger.
	Logger log.Logger
}

FindOpts adds some more hints what should happen when find methods of Repository are executed.

func (*FindOpts) GetLogger

func (this *FindOpts) GetLogger(or func() log.Logger) log.Logger

func (*FindOpts) GetPredicates

func (this *FindOpts) GetPredicates() Predicates

func (*FindOpts) IsAutoCleanUpAllowed

func (this *FindOpts) IsAutoCleanUpAllowed() bool

func (*FindOpts) WithPredicate

func (this *FindOpts) WithPredicate(predicates ...Predicate) *FindOpts

type FsRepository

type FsRepository struct {
	Logger log.Logger
	// contains filtered or unexported fields
}

func NewFsRepository

func NewFsRepository(_ context.Context, conf *configuration.SessionFs) (*FsRepository, error)

func (*FsRepository) Close

func (this *FsRepository) Close() error

func (*FsRepository) Create

func (this *FsRepository) Create(ctx context.Context, flow configuration.FlowName, remote common.Remote, authToken []byte) (Session, error)

func (*FsRepository) Delete

func (this *FsRepository) Delete(ctx context.Context, s Session) error

func (*FsRepository) DeleteBy

func (this *FsRepository) DeleteBy(ctx context.Context, flow configuration.FlowName, id uuid.UUID) error

func (*FsRepository) FindAll

func (this *FsRepository) FindAll(ctx context.Context, consumer Consumer, opts *FindOpts) error

func (*FsRepository) FindBy

func (this *FsRepository) FindBy(ctx context.Context, flow configuration.FlowName, id uuid.UUID, opts *FindOpts) (Session, error)

func (*FsRepository) FindByAccessToken

func (this *FsRepository) FindByAccessToken(ctx context.Context, t []byte, opts *FindOpts) (Session, error)

func (*FsRepository) FindByPublicKey

func (this *FsRepository) FindByPublicKey(ctx context.Context, key ssh.PublicKey, opts *FindOpts) (Session, error)

type Info

type Info interface {
	Flow() configuration.FlowName
	Id() uuid.UUID
	State() State
	Created(context.Context) (InfoCreated, error)
	LastAccessed(context.Context) (InfoLastAccessed, error)
	// ValidUntil defines until when the actual Session is valid to be used.
	// If returned time.Time.IsZero() means forever.
	ValidUntil(context.Context) (time.Time, error)
	String() string
}

type InfoCreated

type InfoCreated interface {
	At() time.Time
	Remote() common.Remote
}

type InfoLastAccessed

type InfoLastAccessed interface {
	At() time.Time
	Remote() common.Remote
}

type Predicate

type Predicate func(context.Context, Session) (bool, error)

func IsExpiredWithThreshold

func IsExpiredWithThreshold(threshold time.Duration) Predicate

func IsFlow

func IsFlow(flow configuration.FlowName) Predicate

func IsRemoteName

func IsRemoteName(name string) Predicate

type Predicates

type Predicates []Predicate

func (Predicates) Matches

func (this Predicates) Matches(ctx context.Context, candidate Session) (bool, error)

type Repository

type Repository interface {
	Create(ctx context.Context, flow configuration.FlowName, remote common.Remote, authToken []byte) (Session, error)

	FindBy(context.Context, configuration.FlowName, uuid.UUID, *FindOpts) (Session, error)
	FindByPublicKey(context.Context, ssh.PublicKey, *FindOpts) (Session, error)
	FindByAccessToken(context.Context, []byte, *FindOpts) (Session, error)
	FindAll(context.Context, Consumer, *FindOpts) error

	DeleteBy(context.Context, configuration.FlowName, uuid.UUID) error
	Delete(context.Context, Session) error
}

type RepositoryFactory added in v0.2.0

type RepositoryFactory[C any, R CloseableRepository] func(ctx context.Context, conf C) (R, error)

func RegisterRepository added in v0.2.0

func RegisterRepository[C any, R CloseableRepository](factory RepositoryFactory[C, R]) RepositoryFactory[C, R]

type Session

type Session interface {
	Flow() configuration.FlowName
	Id() uuid.UUID
	Info(context.Context) (Info, error)
	AuthorizationToken(context.Context) ([]byte, error)
	EnvironmentToken(context.Context) ([]byte, error)
	HasPublicKey(context.Context, ssh.PublicKey) (bool, error)

	// ConnectionInterceptor creates a new instance of ConnectionInterceptor to
	// watch net.Conn of each connection related to this Session.
	//
	// It can return ErrMaxConnectionsPerSessionReached to indicate that no more
	// net.Conn are allowed for this Session.
	ConnectionInterceptor(context.Context) (ConnectionInterceptor, error)

	SetAuthorizationToken(context.Context, []byte) error
	SetEnvironmentToken(context.Context, []byte) error
	AddPublicKey(context.Context, ssh.PublicKey) error
	DeletePublicKey(context.Context, ssh.PublicKey) error
	NotifyLastAccess(ctx context.Context, remote common.Remote, newState State) (oldState State, err error)
	Dispose(ctx context.Context) (bool, error)

	String() string
}

type State

type State uint8
const (
	StateUnchanged State = iota
	StateNew
	StateAuthorized
	StateDisposed
)

func (State) MarshalText

func (this State) MarshalText() (text []byte, err error)

func (State) String

func (this State) String() string

func (*State) UnmarshalText

func (this *State) UnmarshalText(text []byte) error

Jump to

Keyboard shortcuts

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