Example #1
0
    def test_local_garden_returns_local_systems(self, localgarden,
                                                remotegarden):
        """local_garden returns local systems (those of the local garden only)
        when requested"""
        garden = local_garden(all_systems=False)

        assert len(garden.systems) == 1
Example #2
0
    async def delete(self, queue_name):
        """
        ---
        summary: Clear a queue by canceling all requests
        parameters:
          - name: queue_name
            in: path
            required: true
            description: The name of the queue to clear
            type: string
        responses:
          204:
            description: Queue successfully cleared
          404:
            $ref: '#/definitions/404Error'
          50x:
            $ref: '#/definitions/50xError'
        tags:
          - Queues
        """
        self.verify_user_permission_for_object(QUEUE_DELETE, local_garden())

        await self.client(
            Operation(operation_type="QUEUE_DELETE", args=[queue_name]))

        self.set_status(204)
Example #3
0
    async def patch(self):
        """
        ---
        summary: Initiate administrative actions
        description: |
          The body of the request needs to contain a set of instructions
          detailing the operations to perform.

          Currently the supported operations are `rescan`:
          ```JSON
          [
            { "operation": "rescan" }
          ]
          ```
          * Will remove from the registry and database any currently stopped
            plugins who's directory has been removed.
          * Will add and start any new plugin directories.

          And reloading the plugin logging configuration:
          ```JSON
          [
            {
              "operation": "reload",
              "path": "/config/logging/plugin"
            }
          ]
          ```
        parameters:
          - name: patch
            in: body
            required: true
            description: Instructions for operations
            schema:
              $ref: '#/definitions/Patch'
        responses:
          204:
            description: Operation successfully initiated
          50x:
            $ref: '#/definitions/50xError'
        tags:
          - Admin
        """
        self.verify_user_permission_for_object(GARDEN_UPDATE, local_garden())

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

        for op in operations:
            if op.operation == "rescan":
                await self.client(Operation(operation_type="RUNNER_RESCAN"))
            elif op.operation == "reload":
                if op.path == "/config/logging/plugin":
                    await self.client(Operation(operation_type="PLUGIN_LOG_RELOAD"))
                else:
                    raise ModelValidationError(f"Unsupported path '{op.path}'")
            else:
                raise ModelValidationError(f"Unsupported operation '{op.operation}'")

        self.set_status(204)
Example #4
0
    async def get(self):
        """
        ---
        summary: Get the plugin logging configuration
        deprecated: true
        parameters:
          - name: system_name
            in: query
            required: false
            description: UNUSED
            type: string
        responses:
          200:
            description: Logging Configuration for system
            schema:
                $ref: '#/definitions/LoggingConfig'
          50x:
            $ref: '#/definitions/50xError'
        tags:
          - Deprecated
        """
        self.verify_user_permission_for_object(GARDEN_READ, local_garden())

        response = await self.client(
            Operation(operation_type="PLUGIN_LOG_READ_LEGACY"))

        self.set_header("Content-Type", "application/json; charset=UTF-8")
        self.write(response)
Example #5
0
    async def delete(self):
        """
        ---
        summary: Cancel and clear all requests in all queues
        responses:
          204:
            description: All queues successfully cleared
          50x:
            $ref: '#/definitions/50xError'
        tags:
          - Queues
        """
        self.verify_user_permission_for_object(QUEUE_DELETE, local_garden())

        await self.client(Operation(operation_type="QUEUE_DELETE_ALL"))

        self.set_status(204)
Example #6
0
    async def patch(self):
        """
        ---
        summary: Reload the plugin logging configuration
        deprecated: true
        description: |
          The body of the request needs to contain a set of instructions detailing the
          operation to make. Currently supported operations are below:
          ```JSON
          { "operation": "reload" }
          ```
        parameters:
          - name: patch
            in: body
            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:
          - Deprecated
        """
        self.verify_user_permission_for_object(GARDEN_UPDATE, local_garden())

        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="PLUGIN_LOG_RELOAD"))
            else:
                raise ModelValidationError(
                    f"Unsupported operation '{op.operation}'")

        self.set_header("Content-Type", "application/json; charset=UTF-8")
        self.write(response)
Example #7
0
    async def get(self):
        """
        ---
        summary: Retrieve all queue information
        responses:
          200:
            description: List of all queue information objects
            schema:
              type: array
              items:
                $ref: '#/definitions/Queue'
          50x:
            $ref: '#/definitions/50xError'
        tags:
          - Queues
        """
        self.verify_user_permission_for_object(QUEUE_READ, local_garden())

        response = await self.client(Operation(operation_type="QUEUE_READ"))

        self.set_header("Content-Type", "application/json; charset=UTF-8")
        self.write(response)
Example #8
0
    async def get(self):
        """
        ---
        summary: Get plugin logging configuration
        description: |
          Will return a Python logging configuration that can be used to configure
          plugin logging.
        parameters:
          - name: local
            in: query
            required: false
            description: Whether to request the local plugin logging configuration
            type: boolean
            default: false
        responses:
          200:
            description: Logging Configuration for system
          50x:
            $ref: '#/definitions/50xError'
        tags:
          - Logging
        """
        self.verify_user_permission_for_object(GARDEN_READ, local_garden())

        local = self.get_query_argument("local", None)
        if local is None:
            local = False
        else:
            local = bool(local.lower() == "true")

        response = await self.client(
            Operation(operation_type="PLUGIN_LOG_READ",
                      kwargs={"local": local}))

        self.set_header("Content-Type", "application/json; charset=UTF-8")
        self.write(response)
Example #9
0
    async def patch(self):
        """
        ---
        summary: Partially update a Garden
        description: |
          The body of the request needs to contain a set of instructions detailing the
          updates to apply. Currently the only operations are:

          * sync
          * sync_users

          ```JSON
          [
            { "operation": "" }
          ]
          ```
        parameters:
          - name: garden_name
            in: path
            required: true
            description: Garden to use
            type: string
          - name: patch
            in: body
            required: true
            description: Instructions for how to update the Garden
            schema:
              $ref: '#/definitions/Patch'
        responses:
          204:
            description: Patch operation has been successfully forwarded
          400:
            $ref: '#/definitions/400Error'
          404:
            $ref: '#/definitions/404Error'
          50x:
            $ref: '#/definitions/50xError'
        tags:
          - Garden
        """
        self.verify_user_permission_for_object(GARDEN_UPDATE, local_garden())

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

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

            if operation == "sync":
                await self.client(Operation(operation_type="GARDEN_SYNC", ))
            elif operation == "sync_users":
                # requires GARDEN_UPDATE for all gardens
                for garden in Garden.objects.all():
                    self.verify_user_permission_for_object(
                        GARDEN_UPDATE, garden)

                initiate_user_sync()
            else:
                raise ModelValidationError(
                    f"Unsupported operation '{op.operation}'")

        self.set_status(204)
Example #10
0
    def test_local_garden_returns_all_systems(self, localgarden, remotegarden):
        """local_garden returns all systems (those of the local garden and its children)
        when requested"""
        garden = local_garden(all_systems=True)

        assert len(garden.systems) == 2
Example #11
0
    def test_local_garden_returns_brewtils_model(self, localgarden):
        """local_garden returns a brewtils Garden"""
        garden = local_garden()

        assert type(garden) is BrewtilsGarden