Пример #1
0
 def _auto_action_status(self, action_id: str) -> ViewReturn:
     """
     Attempts to load an action_status via its action_id using an
     action_loader. If an action is successfully loaded, view access by the
     requesting user is verified before returning it to the caller.
     """
     # Attempt to use a user-defined function to lookup the Action based
     # on its action_id. If an action is found, verify access to it
     if self.action_loader_plugin:
         action = self._load_action_by_id(action_id)
         authorize_action_access_or_404(action, g.auth_state)
         try:
             result = self._action_status(action, g.auth_state)
         except AttributeError:
             # Once an action_loader is registered, there is no reason to
             # register an action_status. Therefore, an exception here is ok,
             # in which case just return the bare action as the result
             result = action
     else:
         if not hasattr(self, "_action_status"):
             current_app.logger.error("ActionProvider has no action status endpoint")
             raise ActionProviderError
         try:
             # It's possible the user will attempt to make a malformed ActionStatus -
             # pydantic won't like that. So handle the error with a 500
             result = self._action_status(action_id, g.auth_state)
         except ValidationError as ve:
             current_app.logger.error(
                 f"ActionProvider attempted to create a non-conformant ActionStatus "
                 f"in {self._action_status.__name__}: {ve.errors()}"
             )
             raise ActionProviderError
     return action_status_return_to_view_return(result, 200)
Пример #2
0
        def wrapper(action_id: str) -> ViewReturn:
            # Attempt to use a user-defined function to lookup the Action based
            # on its action_id. If an action is found, authorize access to it
            if self.action_loader_plugin:
                action = self._load_action_by_id(action_id)
                authorize_action_access_or_404(action, g.auth_state)

            status = func(action_id, g.auth_state)
            return jsonify(status), 200
Пример #3
0
def action_status(action_id: str, auth: AuthState) -> ActionStatusReturn:
    """
    action_status retrieves the most recent state of the action. This endpoint
    requires the user authenticate with a principal value which is in the
    monitor_by list established when the Action was started.
    """
    status = _retrieve_action_status(action_id)
    authorize_action_access_or_404(status, auth)
    return status, 200
Пример #4
0
def my_action_status(action_id: str, auth: AuthState) -> ActionStatusReturn:
    """
    Query for the action_id in some storage backend to return the up-to-date
    ActionStatus. It's possible that some ActionProviders will require querying
    an external system to get up to date information on an Action's status.
    """
    action_status = simple_backend.get(action_id)
    if action_status is None:
        raise ActionNotFound(f"No action with {action_id}")
    authorize_action_access_or_404(action_status, auth)
    return action_status
Пример #5
0
def test_creator_can_access(auth_state):
    status = ActionStatus(
        status=ActionStatusValue.SUCCEEDED,
        creator_id=auth_state.effective_identity,
        start_time=str(datetime.datetime.now().isoformat()),
        completion_time=str(datetime.datetime.now().isoformat()),
        release_after="P30D",
        display_status=ActionStatusValue.SUCCEEDED,
        details={},
    )

    authorize_action_access_or_404(status, auth_state)
Пример #6
0
def test_unauthorized_access(auth_state):
    status = ActionStatus(
        status=ActionStatusValue.SUCCEEDED,
        creator_id=random_creator_id(),
        start_time=str(datetime.datetime.now().isoformat()),
        completion_time=str(datetime.datetime.now().isoformat()),
        release_after="P30D",
        display_status=ActionStatusValue.SUCCEEDED,
        details={},
    )

    with pytest.raises(AuthenticationError):
        authorize_action_access_or_404(status, auth_state)
Пример #7
0
def status(action_id) -> Tuple[Response, int]:
    """
    This function implements Action Provider interface for looking up an
    action's status. This endpoint is used to query actions that may
    still be executing or may have completed.
    """
    # Ensure the requested action_id exists
    action_status = _get_action_status_or_404(action_id)

    # Ensure the user is authorized to view the action status
    authorize_action_access_or_404(action_status, request.auth)  # type: ignore

    action_status = _reconcile_action_status(action_status)

    # Remove any private data from the ActionStatus before
    # returning it to the requestor
    action_status = _filter_private_fields(action_status)
    return jsonify(action_status), 200
Пример #8
0
def test_action_status(action_id: str, auth: AuthState) -> ActionStatusReturn:
    action_status = simple_backend.get(action_id)
    if action_status is None:
        raise ActionNotFound(f"No action with {action_id}")
    authorize_action_access_or_404(action_status, auth)
    return action_status