def validate_upload_manifest(): content_type = flask.request.headers.get('Content-Type', '').lower() if content_type == 'application/json': manifest_doc = parse.parse_request_json() else: manifest_doc = parse.parse_request_yaml() errors = manifest.validate_upload_manifest(manifest_doc) if errors: return flask.jsonify({"valid": False, "errors": errors}) else: return flask.jsonify({"valid": True})
def validate_upload_manifest(): """ Generate a list of errors found in JSON Schema validation. Summary: Validate a manifest of data files Tags: file Responses: 200 (schema_error_list): Success. """ content_type = flask.request.headers.get("Content-Type", "").lower() if content_type == "application/json": manifest_doc = parse.parse_request_json() else: manifest_doc = parse.parse_request_yaml() errors = manifest.validate_upload_manifest(manifest_doc) if errors: return flask.jsonify({"valid": False, "errors": errors}) else: return flask.jsonify({"valid": True})
def root_create(): """ Register a program. The content of the request is a JSON containing the information describing a program. Authorization for registering programs is limited to administrative users. Summary: Create a program Tags: program Args: body (schema_program): input body Responses: 200: Registered successfully. 403: Unauthorized request. :reqheader Content-Type: |reqheader_Content-Type| :reqheader Accept: |reqheader_Accept| :reqheader X-Auth-Token: |reqheader_X-Auth-Token| :resheader Content-Type: |resheader_Content-Type| **Example:** .. code-block:: http POST /v0/submission/CGCI/ HTTP/1.1 Host: example.com Content-Type: application/json X-Auth-Token: MIIDKgYJKoZIhvcNAQcC... Accept: application/json .. code-block:: JavaScript { "type": "program", "name": "CGCI", "dbgap_accession_number": "phs000178" } """ message = None node_id = None doc = parse.parse_request_json() if not isinstance(doc, dict): raise UserError( "The program creation endpoint only supports single documents (dict). Received data of type {}" .format(type(doc))) if doc.get("type") != "program": raise UserError("Invalid type in key type='{}'".format( doc.get("type"))) phsid = doc.get("dbgap_accession_number") program = doc.get("name") if not program: raise UserError("No program specified in key 'name'") # create the resource in sheepdog DB with current_app.db.session_scope(can_inherit=False) as session: node = current_app.db.nodes( models.Program).props(name=program).scalar() if node: message = "Program is updated!" node_id = node.node_id node.props["dbgap_accession_number"] = phsid else: node_id = str(uuid.uuid5(PROGRAM_SEED, program)) session.add( models.Program( # pylint: disable=not-callable node_id, name=program, dbgap_accession_number=phsid)) message = "Program registered." # create the resource in arborist auth.create_resource(phsid) return flask.jsonify({"id": node_id, "name": program, "message": message})
def root_create(): """ / PUT POST PATCH Register a program. The content of the request is a JSON containing the information describing a program. Authorization for registering programs is limited to administrative users. :reqheader Content-Type: |reqheader_Content-Type| :reqheader Accept: |reqheader_Accept| :reqheader X-Auth-Token: |reqheader_X-Auth-Token| :resheader Content-Type: |resheader_Content-Type| :statuscode 200: Registered successfully. :statuscode 404: Program not found. :statuscode 403: Unauthorized request. **Example:** .. code-block:: http POST /v0/submission/CGCI/ HTTP/1.1 Host: example.com Content-Type: application/json X-Auth-Token: MIIDKgYJKoZIhvcNAQcC... Accept: application/json .. code-block:: JavaScript { "type": "program", "name": "CGCI", "dbgap_accession_number": "phs000178" } """ auth.admin_auth() message = None node_id = None doc = parse.parse_request_json() if not isinstance(doc, dict): raise UserError('Root endpoint only supports single documents') if doc.get('type') != 'program': raise UserError("Invalid type in key type='{}'".format( doc.get('type'))) phsid = doc.get('dbgap_accession_number') program = doc.get('name') if not program: raise UserError("No program specified in key 'name'") with current_app.db.session_scope(can_inherit=False) as session: node = (current_app.db.nodes( models.Program).props(name=program).scalar()) if node: message = 'Program already exists.' node_id = node.node_id else: node_id = str(uuid.uuid5(PROGRAM_SEED, program.encode('utf-8'))) session.add( models.Program( # pylint: disable=not-callable node_id, name=program, dbgap_accession_number=phsid)) message = 'Program registered.' return flask.jsonify({ 'id': node_id, 'name': program, 'message': message, })