How to use the brewtils.schema_parser.SchemaParser.parse_patch function in brewtils

To help you get started, we’ve selected a few brewtils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github beer-garden / beer-garden / src / app / beer_garden / api / http / handlers / v1 / request.py View on Github external
200:
            description: Request with the given ID
            schema:
              $ref: '#/definitions/Request'
          400:
            $ref: '#/definitions/400Error'
          404:
            $ref: '#/definitions/404Error'
          50x:
            $ref: '#/definitions/50xError'
        tags:
          - Requests
        """
        operation = Operation(args=[request_id])

        patch = SchemaParser.parse_patch(self.request.decoded_body, from_string=True)

        for op in patch:
            if op.operation == "replace":
                if op.path == "/status":

                    # If we get a start just assume there's no other op in patch
                    if op.value.upper() == "IN_PROGRESS":
                        operation.operation_type = "REQUEST_START"
                        operation.kwargs = {}
                        break

                    elif op.value.upper() in Request.COMPLETED_STATUSES:
                        operation.operation_type = "REQUEST_COMPLETE"
                        operation.kwargs["status"] = op.value

                    else:
github beer-garden / beer-garden / src / app / beer_garden / api / http / handlers / v1 / instance.py View on Github external
$ref: '#/definitions/Patch'
        responses:
          200:
            description: Instance with the given ID
            schema:
              $ref: '#/definitions/Instance'
          400:
            $ref: '#/definitions/400Error'
          404:
            $ref: '#/definitions/404Error'
          50x:
            $ref: '#/definitions/50xError'
        tags:
          - Instances
        """
        patch = SchemaParser.parse_patch(self.request.decoded_body, from_string=True)

        for op in patch:
            operation = op.operation.lower()

            if operation == "initialize":
                runner_id = None
                if op.value:
                    runner_id = op.value.get("runner_id")

                response = await self.client(
                    Operation(
                        operation_type="INSTANCE_INITIALIZE",
                        args=[instance_id],
                        kwargs={"runner_id": runner_id},
                    )
                )
github beer-garden / beer-garden / src / app / beer_garden / api / http / handlers / v1 / job.py View on Github external
description: Job with the given ID
            schema:
              $ref: '#/definitions/Job'
          400:
            $ref: '#/definitions/400Error'
          404:
            $ref: '#/definitions/404Error'
          50x:
            $ref: '#/definitions/50xError'
        tags:
          - Jobs
        """

        response = await self.client(
            obj_id=job_id,
            brewtils_obj=SchemaParser.parse_patch(
                self.request.decoded_body, from_string=True
            ),
            route_class=Route_Class.JOB,
            route_type=Route_Type.UPDATE,
        )

        self.set_header("Content-Type", "application/json; charset=UTF-8")
        self.write(response)
github beer-garden / beer-garden / src / app / beer_garden / api / http / handlers / v2 / job.py View on Github external
$ref: '#/definitions/Patch'
        responses:
          200:
            description: Job with the given ID
            schema:
              $ref: '#/definitions/Job'
          400:
            $ref: '#/definitions/400Error'
          404:
            $ref: '#/definitions/404Error'
          50x:
            $ref: '#/definitions/50xError'
        tags:
          - Jobs
        """
        operations = SchemaParser.parse_patch(
            self.request.decoded_body, many=True, from_string=True
        )

        for op in operations:
            if op.operation == "update":
                if op.path == "/status":
                    if str(op.value).upper() == "PAUSED":
                        async with ExecutorClient() as client:
                            response = await client.pauseJob(namespace, job_id)
                    elif str(op.value).upper() == "RUNNING":
                        async with ExecutorClient() as client:
                            response = await client.resumeJob(namespace, job_id)
                    else:
                        raise ModelValidationError(
                            f"Unsupported status value '{op.value}'"
                        )
github beer-garden / beer-garden / src / app / beer_garden / api / http / handlers / v2 / admin.py View on Github external
type: string
          - name: patch
            in: body
            required: true
            description: Instructions for operations
            schema:
              $ref: '#/definitions/Patch'
        responses:
          204:
            description: Rescan successfully initiated
          50x:
            $ref: '#/definitions/50xError'
        tags:
          - Admin
        """
        operations = SchemaParser.parse_patch(
            self.request.decoded_body, many=True, from_string=True
        )

        for op in operations:
            if op.operation == "rescan":
                check_permission(self.current_user, [Permissions.SYSTEM_CREATE])
                async with ExecutorClient() as client:
                    await client.rescanSystemDirectory(namespace)
            else:
                raise ModelValidationError(f"Unsupported operation '{op.operation}'")

        self.set_status(204)
github beer-garden / beer-garden / src / app / beer_garden / api / http / handlers / v1 / logging.py View on Github external
required: true
            description: Operation to perform
            schema:
              $ref: '#/definitions/Patch'
        responses:
          200:
            description: Updated plugin logging configuration
            schema:
              $ref: '#/definitions/LoggingConfig'
          50x:
            $ref: '#/definitions/50xError'
        tags:
          - Config
        """

        patch = SchemaParser.parse_patch(
            self.request.decoded_body, many=True, from_string=True
        )

        response = None
        for op in patch:
            if op.operation == "reload":
                response = await self.client(Operation(operation_type="LOG_RELOAD"))
            else:
                raise ModelValidationError(f"Unsupported operation '{op.operation}'")

        self.set_header("Content-Type", "application/json; charset=UTF-8")
        self.write(response)
github beer-garden / beer-garden / src / app / beer_garden / api / http / handlers / v1 / system.py View on Github external
400:
            $ref: '#/definitions/400Error'
          404:
            $ref: '#/definitions/404Error'
          50x:
            $ref: '#/definitions/50xError'
        tags:
          - Systems
        """

        response = await self.client(
            Operation(
                operation_type="SYSTEM_UPDATE",
                args=[
                    system_id,
                    SchemaParser.parse_patch(
                        self.request.decoded_body, from_string=True
                    ),
                ],
            )
        )

        self.set_header("Content-Type", "application/json; charset=UTF-8")
        self.write(response)