Documentation
¶
Index ¶
- Constants
- Variables
- func IsExpired(ctx context.Context, candidate Session) (bool, error)
- func IsNotExpired(ctx context.Context, candidate Session) (bool, error)
- func IsStillValid(ctx context.Context, candidate Session) (bool, error)
- type AutoCleanUpAllowedFor
- type CloseableRepository
- type ConnectionInterceptor
- type ConnectionInterceptorResult
- type Consumer
- type EnvironmentCleanupTokenUpdater
- type FacadeRepository
- type FindDiagnostic
- type FindDiagnosticConsumer
- type FindOpts
- func (this *FindOpts) GetLogger(or func() log.Logger) log.Logger
- func (this *FindOpts) GetPredicates() Predicates
- func (this *FindOpts) IsAutoCleanUpAllowed() bool
- func (this *FindOpts) IsAutoCleanUpAllowedFor(ctx context.Context, flow configuration.FlowName, id Id) bool
- func (this *FindOpts) ReportDiagnostic(ctx context.Context, diagnostic FindDiagnostic) error
- func (this *FindOpts) WithPredicate(predicates ...Predicate) *FindOpts
- type FsRepository
- func (this *FsRepository) Close() error
- func (this *FsRepository) Create(ctx context.Context, flow configuration.FlowName, remote net.Remote, ...) (Session, error)
- func (this *FsRepository) Delete(ctx context.Context, s Session) error
- func (this *FsRepository) DeleteBy(ctx context.Context, flow configuration.FlowName, id Id) error
- func (this *FsRepository) FindAll(ctx context.Context, consumer Consumer, opts *FindOpts) error
- func (this *FsRepository) FindBy(ctx context.Context, flow configuration.FlowName, id Id, opts *FindOpts) (Session, error)
- func (this *FsRepository) FindByAccessToken(ctx context.Context, t []byte, opts *FindOpts) (Session, error)
- func (this *FsRepository) FindByPublicKey(ctx context.Context, key ssh.PublicKey, opts *FindOpts) (Session, error)
- type Id
- func (this *Id) DecodeMsgPack(dec codec.MsgPackDecoder) error
- func (this *Id) DecodeMsgpack(dec *msgpack.Decoder) error
- func (this Id) EncodeMsgPack(enc codec.MsgPackEncoder) error
- func (this Id) EncodeMsgpack(enc *msgpack.Encoder) error
- func (this Id) IsEqualTo(other any) bool
- func (this Id) IsZero() bool
- func (this Id) MarshalBinary() (b []byte, err error)
- func (this Id) MarshalText() (text []byte, err error)
- func (this *Id) Set(text string) error
- func (this Id) String() string
- func (this *Id) UnmarshalBinary(b []byte) error
- func (this *Id) UnmarshalText(text []byte) error
- type Info
- type InfoCreated
- type InfoLastAccessed
- type Predicate
- type Predicates
- type Repository
- type RepositoryFactory
- type Session
- type State
Constants ¶
const ( FsFileSession = "s" FsFileLastAccessed = "la" FsFileAccessToken = "at" FsFileEnvironmentToken = "et" FsFilePublicKeysPrefix = "pk-" FsFilePublicKeysPrefixLen = len(FsFilePublicKeysPrefix) )
const (
EnvName = "BIFROEST_SESSION_ID"
)
Variables ¶
var ( ErrNoSuchSession = errors.New("no such session") ErrCorruptSession = errors.New("corrupt session") )
var (
ErrMaxConnectionsPerSessionReached = errors.Newf(errors.User, "max connections per session reached")
)
Functions ¶
Types ¶
type AutoCleanUpAllowedFor ¶
AutoCleanUpAllowedFor decides whether automatic cleanup is allowed for one persisted session entry. A zero Id denotes content belonging to the flow but not to a valid session directory.
type CloseableRepository ¶
type CloseableRepository interface {
Repository
io.Closer
}
type ConnectionInterceptor ¶
type ConnectionInterceptorResult ¶
type ConnectionInterceptorResult uint8
const ( ConnectionInterceptorResultNone ConnectionInterceptorResult = iota ConnectionInterceptorResultIdle ConnectionInterceptorResultMax ConnectionInterceptorResultDisposed )
type EnvironmentCleanupTokenUpdater ¶
type EnvironmentCleanupTokenUpdater interface {
UpdateEnvironmentTokenForCleanup(context.Context, []byte, []byte) error
}
EnvironmentCleanupTokenUpdater permits a compare-and-swap update to an existing environment token after the session has been disposed. It is used only to persist cleanup progress, never to create a new environment token.
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 FindDiagnostic ¶
type FindDiagnostic struct {
Flow configuration.FlowName
Id Id
Path string
Err error
}
FindDiagnostic identifies one persisted session entry that could not be loaded.
func (FindDiagnostic) Error ¶
func (this FindDiagnostic) Error() string
func (FindDiagnostic) Unwrap ¶
func (this FindDiagnostic) Unwrap() error
type FindDiagnosticConsumer ¶
type FindDiagnosticConsumer func(context.Context, FindDiagnostic) error
FindDiagnosticConsumer handles one non-destructive session lookup diagnostic.
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
// AutoCleanUpAllowedFor optionally restricts AutoCleanUpAllowed for one
// session entry. It cannot enable cleanup when AutoCleanUpAllowed is false.
AutoCleanUpAllowedFor AutoCleanUpAllowedFor
// Logger will be used (if any log is required) instead of the standard logger.
Logger log.Logger
// DiagnosticConsumer receives non-destructive per-entry diagnostics while
// iterating all sessions. Without one, the first diagnostic remains fatal.
DiagnosticConsumer FindDiagnosticConsumer
}
FindOpts adds some more hints what should happen when find methods of Repository are executed.
func (*FindOpts) GetPredicates ¶
func (this *FindOpts) GetPredicates() Predicates
func (*FindOpts) IsAutoCleanUpAllowed ¶
func (*FindOpts) IsAutoCleanUpAllowedFor ¶
func (*FindOpts) ReportDiagnostic ¶
func (this *FindOpts) ReportDiagnostic(ctx context.Context, diagnostic FindDiagnostic) error
ReportDiagnostic forwards a diagnostic or returns it when no consumer exists.
func (*FindOpts) WithPredicate ¶
type FsRepository ¶
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) FindBy ¶
func (this *FsRepository) FindBy(ctx context.Context, flow configuration.FlowName, id Id, opts *FindOpts) (Session, error)
func (*FsRepository) FindByAccessToken ¶
func (*FsRepository) FindByPublicKey ¶
type Id ¶ added in v0.4.0
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 (Id) EncodeMsgPack ¶ added in v0.4.0
func (this Id) EncodeMsgPack(enc codec.MsgPackEncoder) error
func (Id) MarshalBinary ¶ added in v0.4.0
func (Id) MarshalText ¶ added in v0.4.0
func (*Id) UnmarshalBinary ¶ added in v0.4.0
func (*Id) UnmarshalText ¶ added in v0.4.0
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 Predicate ¶
func IsExpiredWithThreshold ¶
func IsFlow ¶
func IsFlow(flow configuration.FlowName) Predicate
func IsRemoteName ¶
type Predicates ¶
type Predicates []Predicate
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
}