executePermissionAndRespond executes a permission handler and sends the result back via RPC.
(requestID string, permissionRequest PermissionRequest, handler PermissionHandlerFunc)
| 1554 | |
| 1555 | // executePermissionAndRespond executes a permission handler and sends the result back via RPC. |
| 1556 | func (s *Session) executePermissionAndRespond(requestID string, permissionRequest PermissionRequest, handler PermissionHandlerFunc) { |
| 1557 | defer func() { |
| 1558 | if r := recover(); r != nil { |
| 1559 | s.RPC.Permissions.HandlePendingPermissionRequest(context.Background(), &rpc.PermissionDecisionRequest{ |
| 1560 | RequestID: requestID, |
| 1561 | Result: &rpc.PermissionDecisionUserNotAvailable{}, |
| 1562 | }) |
| 1563 | } |
| 1564 | }() |
| 1565 | |
| 1566 | invocation := PermissionInvocation{ |
| 1567 | SessionID: s.SessionID, |
| 1568 | } |
| 1569 | |
| 1570 | decision, err := handler(permissionRequest, invocation) |
| 1571 | if err != nil { |
| 1572 | s.RPC.Permissions.HandlePendingPermissionRequest(context.Background(), &rpc.PermissionDecisionRequest{ |
| 1573 | RequestID: requestID, |
| 1574 | Result: &rpc.PermissionDecisionUserNotAvailable{}, |
| 1575 | }) |
| 1576 | return |
| 1577 | } |
| 1578 | if decision == nil { |
| 1579 | // Handler returned (nil, nil); treat as user-not-available rather |
| 1580 | // than sending null on the wire. |
| 1581 | s.RPC.Permissions.HandlePendingPermissionRequest(context.Background(), &rpc.PermissionDecisionRequest{ |
| 1582 | RequestID: requestID, |
| 1583 | Result: &rpc.PermissionDecisionUserNotAvailable{}, |
| 1584 | }) |
| 1585 | return |
| 1586 | } |
| 1587 | if _, ok := decision.(*rpc.PermissionDecisionNoResult); ok { |
| 1588 | return |
| 1589 | } |
| 1590 | if _, ok := decision.(rpc.PermissionDecisionNoResult); ok { |
| 1591 | return |
| 1592 | } |
| 1593 | |
| 1594 | s.RPC.Permissions.HandlePendingPermissionRequest(context.Background(), &rpc.PermissionDecisionRequest{ |
| 1595 | RequestID: requestID, |
| 1596 | Result: decision, |
| 1597 | }) |
| 1598 | } |
| 1599 | |
| 1600 | // GetEvents retrieves all events from this session's history. |
| 1601 | // |
no test coverage detected