Documentation
¶
Index ¶
Constants ¶
const ValidateSessionTimeout = 90 * time.Second
ValidateSessionTimeout is the duration of the timeout when the worker queries the controller for the sessionId for which the connection is being requested.
Variables ¶
This section is empty.
Functions ¶
func NewManager ¶ added in v0.10.0
func NewManager(client pbs.SessionServiceClient) (*manager, error)
NewManager returns a *Manager which uses the provided ServiceServiceClient to perform actions on Sessions and Connections on the Controller.
Types ¶
type ConnInfo ¶
type ConnInfo struct {
Id string
Status pbs.CONNECTIONSTATUS
// The time the controller has successfully reported that this connection is
// closed.
CloseTime time.Time
// contains filtered or unexported fields
}
ConnInfo defines the information about a connection attached to a session
type Manager ¶ added in v0.10.0
type Manager interface {
Get(string) Session
// ForEachLocalSession calls the provided function with each Session object.
// If the provided function ever returns false the iteration stops.
// If changes to the sessions in the manager happen concurrently, this function
// does not guarantee that the key will or will not be provided in the
// iteration.
ForEachLocalSession(func(Session) bool)
// LoadLocalSession looks up from the source of truth the session information,
// validates it is valid, and then refreshes the local manager's data.
// On a local worker, the only value of a Session that we care about that can
// be modified is the Status. Because of that, if LoadLocalSession is called on
// a Session that is already in the manager's data, only the Status is updated.
LoadLocalSession(ctx context.Context, id string, workerId string) (Session, error)
// DeleteLocalSession removes all sessions with the provided id from the
// local manager. If ids are passed in which do not exist in the manager
// no error is returned.
DeleteLocalSession([]string)
// RequestCloseConnections sends connection close requests to the controller,
// and sets close times within the worker. It should be called during the worker
// status loop and on connection exit on the proxy.
//
// The boolean indicates whether the function was successful, e.g. had any
// errors. Individual events will be sent for the errors if there are any.
//
// closeInfo is a map of connection ids mapped to their individual session ids.
RequestCloseConnections(context.Context, map[string]string) bool
}
Manager stores session information locally and exposes ways to operate on the set of sessions locally in batch. This is thread-safe.
type Session ¶ added in v0.10.0
type Session interface {
// ApplyLocalConnectionStatus set's a connection's status to the one provided.
// If there is no connection with the provided id, an error is returned.
ApplyLocalConnectionStatus(connId string, status pbs.CONNECTIONSTATUS) error
// ApplyLocalStatus updates the given session with the status provided by
// the SessionJobInfo. It returns an error if any of the connections
// in the SessionJobInfo are not present, however, it still applies the
// status change to the session and the connections which are present.
ApplyLocalStatus(st pbs.SESSIONSTATUS)
GetStatus() pbs.SESSIONSTATUS
// GetLocalConnections returns the connections this session is handling.
GetLocalConnections() map[string]ConnInfo
GetTofuToken() string
GetConnectionLimit() int32
GetEndpoint() string
GetCredentials() []*pbs.Credential
GetExpiration() time.Time
GetCertificate() *x509.Certificate
GetPrivateKey() []byte
GetId() string
// CancelOpenLocalConnections closes the local connections in this session
//based on the connection's state by calling the connections context cancel
// function.
//
// The returned slice are connection ids that were closed.
CancelOpenLocalConnections() []string
// CancelAllLocalConnections close connections regardless of connection's state
// by calling the connection context's CancelFunc.
//
// The returned slice is the connection ids which were closed.
CancelAllLocalConnections() []string
// RequestCancel sends session cancellation request to the controller. If there is no
// error the local session's status is updated with the result of the cancel
// request
RequestCancel(ctx context.Context) error
// RequestActivate sends session activation request to the controller. The Session's
// status is then updated with the result of the call. After a successful
// call to RequestActivate, subsequent calls will fail.
RequestActivate(ctx context.Context, tofu string) error
// RequestAuthorizeConnection sends an AuthorizeConnection request to
// the controller.
// It is called by the worker handler after a connection has been received by
// the worker, and the session has been validated.
// The passed in context.CancelFunc is used to terminate any ongoing local proxy
// connections.
// The connection status is then viewable in this session's GetLocalConnections() call.
RequestAuthorizeConnection(ctx context.Context, workerId string, connCancel context.CancelFunc) (ConnInfo, int32, error)
// RequestConnectConnection sends a RequestConnectConnection request to the controller. It
// should only be called by the worker handler after a connection has been
// authorized. The local connection's status is updated with the result of the
// call.
RequestConnectConnection(ctx context.Context, info *pbs.ConnectConnectionRequest) error
}
Session is the local representation of a session. After initial loading the only values that will change will be the status (readable from GetStatus()) and the Connections (GetLocalConnections()).