// emitSessionStartEventFn returns function that uses the provided emitter to
// emit an audit event when database session starts.
emitSessionStartEventFn returns function that uses the provided emitter to
emit an audit event when database session starts.
// emitSessionStartEventFn returns function that uses the provided emitter to // emit an audit event when database session starts .
func (s *Server) emitSessionStartEventFn(streamWriter libevents.StreamWriter) func(session.Context, error) error {
	return func(session session.Context, err error) error {
		event := &events.DatabaseSessionStart{
			Metadata: events.Metadata{
				Type: libevents.DatabaseSessionStartEvent,
				Code: libevents.DatabaseSessionStartCode,
			},
			ServerMetadata: events.ServerMetadata{
				ServerID:        session.Server.GetHostID(),
				ServerNamespace: defaults.Namespace,
			},
			UserMetadata: events.UserMetadata{
				User: session.Identity.Username,
			},
			SessionMetadata: events.SessionMetadata{
				SessionID: session.ID,
			},
			Status: events.Status{
				Success: true,
			},
			DatabaseMetadata: events.DatabaseMetadata{
				DatabaseService:  session.Server.GetName(),
				DatabaseProtocol: session.Server.GetProtocol(),
				DatabaseURI:      session.Server.GetURI(),
				DatabaseName:     session.DatabaseName,
				DatabaseUser:     session.DatabaseUser,
			},
		}
		if err != nil {
			event.Metadata.Code = libevents.DatabaseSessionStartFailureCode
			event.Status = events.Status{
				Success:     false,
				Error:       trace.Unwrap(err).Error(),
				UserMessage: err.Error(),
			}
		}
		return streamWriter.EmitAuditEvent(s.closeContext, event)
	}
}
func ( s * Server ) emitSessionStartEventFn ( streamWriter libevents . StreamWriter ) func ( session . Context , error ) error { return func ( session session . Context , err error ) error { event := & events . DatabaseSessionStart { Metadata : events . Metadata { Type : libevents . DatabaseSessionStartEvent , Code : libevents . DatabaseSessionStartCode , } , ServerMetadata : events . ServerMetadata { ServerID : session . Server . GetHostID ( ) , ServerNamespace : defaults . Namespace , } , UserMetadata : events . UserMetadata { User : session . Identity . Username , } , SessionMetadata : events . SessionMetadata { SessionID : session . ID , } , Status : events . Status { Success : true , } , DatabaseMetadata : events . DatabaseMetadata { DatabaseService : session . Server . GetName ( ) , DatabaseProtocol : session . Server . GetProtocol ( ) , DatabaseURI : session . Server . GetURI ( ) , DatabaseName : session . DatabaseName , DatabaseUser : session . DatabaseUser , } , } if err != nil { event . Metadata . Code = libevents . DatabaseSessionStartFailureCode event . Status = events . Status { Success : false , Error : trace . Unwrap ( err ) . Error ( ) , UserMessage : err . Error ( ) , } } return streamWriter . EmitAuditEvent ( s . closeContext , event ) } }
emitSessionStartEventFn returns function that uses the provided emitter to
emit an audit event when database session starts.
emitSessionStartEventFn returns function that uses the provided emitter to emit an audit event when database session starts .