Example #1
0
    def post(self):
        """ get locks for a given scope, name.

        :resheader Content-Type: application/x-json-stream
        :status 200: OK.
        :status 400: Wrong DID type.
        :returns: Line separated list of dictionary with lock information.
        """

        data = json_parse(types=(dict, ))
        try:
            dids = data["dids"]
        except KeyError:
            return 'Can not find the list of DIDs in the data. Use "dids" keyword.', 400
        vo = request.environ.get('vo')
        try:
            locks = get_dataset_locks_bulk(dids, vo)  # removes duplicates

            def generate(locks):
                for lock in locks:
                    lock["scope"] = str(lock["scope"])
                    yield render_json(**lock) + '\n'

            return try_stream(generate(locks))

        except ValueError as error:
            return generate_http_error_flask(400, error)
Example #2
0
    def post(self):
        """
        Attach DIDs to DIDs

        .. :quickref: Attachements; Attach DIDs to DIDs.
        """
        parameters = json_parse((dict, list))
        if isinstance(parameters, list):
            attachments = parameters
            ignore_duplicate = False
        else:
            assert isinstance(parameters, dict)
            attachments = param_get(parameters, 'attachments')
            ignore_duplicate = param_get(parameters, 'ignore_duplicate', default=False)

        try:
            attach_dids_to_dids(attachments=attachments, ignore_duplicate=ignore_duplicate, issuer=request.environ.get('issuer'), vo=request.environ.get('vo'))
        except DataIdentifierNotFound as error:
            return generate_http_error_flask(404, error)
        except (DuplicateContent, DataIdentifierAlreadyExists, UnsupportedOperation, FileAlreadyExists) as error:
            return generate_http_error_flask(409, error)
        except AccessDenied as error:
            return generate_http_error_flask(401, error)
        except FileConsistencyMismatch as error:
            return generate_http_error_flask(412, error)

        return 'Created', 201
Example #3
0
    def post(self):
        """ get locks for a given scope, name.

        :resheader Content-Type: application/x-json-stream
        :status 200: OK.
        :status 400: Wrong DID type.
        :returns: Line separated list of dictionary with lock information.
        ---
        summary: Get locks by dids
        description: Get all dataset locks for the associated dids.
        tags:
          - Lock
        requestBody:
          content:
            application/json:
              schema:
                type: object
                properties:
                  dids:
                    description: The dids associated with the locks.
                    type: array
                    items:
                      type: object
                      description: A did
                      required:
                        - scope
                        - name
                      properties:
                        scope:
                          description: The scope of the did.
                          type: string
                        name:
                          description: The name of the did.
                          type: string
                        type:
                          description: The type of the did.
                          type: string
                          enum: ['dataset', 'container']
        responses:
          200:
            description: OK
            content:
              application/x-json-stream:
                schema:
                  description: Locks associated with the rse.
                  type: array
                  items:
                    description: A lock
                    type: object
                    properties:
                      rse_id:
                        description: The id of the associated rse.
                        type: string
                      rse:
                        description: The name of the associated rse.
                        type: string
                      scope:
                        description: The scope of the associated rse.
                        type: string
                      name:
                        description: The name of the rule.
                        type: string
                      rule_id:
                        description: The id of the rule.
                        type: string
                      account:
                        description: The associated account.
                        type: string
                      state:
                        description: The state of the rule.
                        type: string
                        enum: ['R', 'O', 'S']
                      length:
                        description: The length of the rule.
                        type: integer
                      bytes:
                        description: The bytes limit for the lock.
                        type: integere
                      accessed_at:
                        description: The last time is was accessed.
                        type: string
          401:
            description: Invalid Auth Token
          400:
            description: Wrong did type
            content:
              application/json:
                schema:
                  type: string
                  enum: ['Can not find the list of DIDs in the data. Use "dids" keyword.']
          406:
            description: Not acceptable

        """

        data = json_parse(types=(dict, ))
        try:
            dids = data["dids"]
        except KeyError:
            return 'Can not find the list of DIDs in the data. Use "dids" keyword.', 400
        vo = request.environ.get('vo')
        try:
            locks = get_dataset_locks_bulk(dids, vo)  # removes duplicates

            def generate(locks):
                for lock in locks:
                    lock["scope"] = str(lock["scope"])
                    yield render_json(**lock) + '\n'

            return try_stream(generate(locks))

        except ValueError as error:
            return generate_http_error_flask(400, error)