コード例 #1
0
    def action_run() -> ViewReturn:
        auth_state = check_token(request, checker)
        if not auth_state.check_authorization(
            provider_description.runnable_by, allow_all_authenticated_users=True
        ):
            log.info(f"Unauthorized call to action run, errors: {auth_state.errors}")
            raise UnauthorizedRequest
        if blueprint.url_prefix:
            request.path = request.path.lstrip(blueprint.url_prefix)
            if request.url_rule is not None:
                request.url_rule.rule = request.url_rule.rule.lstrip(
                    blueprint.url_prefix
                )

        action_request = validate_input(
            request.get_json(force=True), input_body_validator
        )

        # It's possible the user will attempt to make a malformed ActionStatus -
        # pydantic won't like that. So log and handle the error with a 500
        try:
            status = action_run_callback(action_request, auth_state)
        except ValidationError as ve:
            log.error(
                f"ActionProvider attempted to create a non-conformant ActionStatus"
                f" in {action_run_callback.__name__}: {ve.errors()}"
            )
            raise ActionProviderError

        return action_status_return_to_view_return(status, 202)
コード例 #2
0
 def action_introspect() -> ViewReturn:
     auth_state = check_token(request, checker)
     if not auth_state.check_authorization(
         provider_description.visible_to,
         allow_public=True,
         allow_all_authenticated_users=True,
     ):
         raise ActionNotFound
     return jsonify(provider_description), 200
コード例 #3
0
 def action_release(action_id: str) -> ViewReturn:
     auth_state = check_token(request, checker)
     try:
         status = action_release_callback(action_id, auth_state)
     except ValidationError as ve:
         log.error(
             f"ActionProvider attempted to create a non-conformant ActionStatus"
             f" in {action_release_callback.__name__}: {ve.errors()}"
         )
         raise ActionProviderError
     return action_status_return_to_view_return(status, 200)
コード例 #4
0
        def action_enumeration():
            auth_state = check_token(request, checker)

            valid_statuses = set(e.name.casefold() for e in ActionStatusValue)
            statuses = parse_query_args(
                request,
                arg_name="status",
                default_value="active",
                valid_vals=valid_statuses,
            )
            statuses = query_args_to_enum(statuses, ActionStatusValue)
            roles = parse_query_args(
                request,
                arg_name="roles",
                default_value="creator_id",
                valid_vals={"creator_id", "monitor_by", "manage_by"},
            )
            query_params = {"statuses": statuses, "roles": roles}
            return jsonify(action_enumeration_callback(auth_state, query_params)), 200
コード例 #5
0
 def _check_token(self) -> None:
     """
     Parses a token from a request to generate an auth_state object which is
     then made available as the second argument to decorated functions.
     """
     g.auth_state = check_token(request, self.checker)
コード例 #6
0
 def action_log(action_id: str) -> ViewReturn:
     auth_state = check_token(request, checker)
     return jsonify({"log": "message"}), 200