Skip to content

Testing: upload workflows to WorkflowHub via APIΒ #129

@simleo

Description

@simleo

Now that submitting RO-Crates is supported by the WorkflowHub API, we can programmatically upload the workflows we need for LM testing and get rid of tests/config/registries/seek/data.tar.gz.

A workflow can be submitted as follows:

import requests
from pathlib import Path

crate_archive = "/tmp/crate.zip"
hub_url = "http://localhost:3000"
api_key = "???"
proj_id = "1"

# upload workflow
headers = {"authorization": f"Token {api_key}"}
with open(crate_archive, "rb") as f:
    payload = {
        "ro_crate": (Path(crate_archive).name, f),
        "workflow[project_ids][]": (None, proj_id)
    }
    r = requests.post(f"{hub_url}/workflows", headers=headers, files=payload)
r.raise_for_status()
    
# update access policy
wf_id = r.json()["data"]["id"]
headers.update({
    "Content-type": "application/vnd.api+json",
    "Accept": "application/vnd.api+json",
    "Accept-Charset": "ISO-8859-1",
})
payload = {
    "data": {
        "id": wf_id,
        "type": "workflows",
        "attributes": {
            "policy": {
                "access": "download",
                "permissions": [
                    {
                        "resource": {"id": proj_id, "type": "projects"},
                        "access": "edit"
                    }
                ]
            }
        }
    }
}
r = requests.patch(f"{hub_url}/workflows/{wf_id}", headers=headers, json=payload)
r.raise_for_status()

This requires a recent WorkflowHub image.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions