session

package
v0.5.13 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2025 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

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

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(glssh.Context, log.Logger, gonet.Conn) (time.Time, ConnectionInterceptorResult, error)
	OnWriteConnection(glssh.Context, log.Logger, gonet.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 net.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 Id) 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 Id, 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 Id added in v0.4.0

type Id uuid.UUID

func MustNewId added in v0.4.0

func MustNewId() Id

func NewId added in v0.4.0

func NewId() (Id, error)

func (*Id) DecodeMsgPack added in v0.4.0

func (this *Id) DecodeMsgPack(dec codec.MsgPackDecoder) error

func (*Id) DecodeMsgpack added in v0.4.0

func (this *Id) DecodeMsgpack(dec *msgpack.Decoder) error

func (Id) EncodeMsgPack added in v0.4.0

func (this Id) EncodeMsgPack(enc codec.MsgPackEncoder) error

func (Id) EncodeMsgpack added in v0.4.0

func (this Id) EncodeMsgpack(enc *msgpack.Encoder) error

func (Id) IsEqualTo added in v0.4.0

func (this Id) IsEqualTo(other any) bool

func (Id) IsZero added in v0.4.0

func (this Id) IsZero() bool

func (Id) MarshalBinary added in v0.4.0

func (this Id) MarshalBinary() (b []byte, err error)

func (Id) MarshalText added in v0.4.0

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

func (*Id) Set added in v0.4.0

func (this *Id) Set(text string) error

func (Id) String added in v0.4.0

func (this Id) String() string

func (*Id) UnmarshalBinary added in v0.4.0

func (this *Id) UnmarshalBinary(b []byte) error

func (*Id) UnmarshalText added in v0.4.0

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

type Info

type Info interface {
	Flow() configuration.FlowName
	Id() Id
	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() net.Remote
}

type InfoLastAccessed

type InfoLastAccessed interface {
	At() time.Time
	Remote() net.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 net.Remote, authToken []byte) (Session, error)

	FindBy(context.Context, configuration.FlowName, Id, *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, Id) 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() Id
	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 net.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