Upload Content

Content can be added to a repository not only by synchronizing from a remote source but also by uploading.

Bulk Upload

Upload artifacts

#!/usr/bin/env bash

# Get an RPM package
curl -O https://repos.fedorapeople.org/pulp/pulp/fixtures/rpm-signed/squirrel-0.1-1.noarch.rpm
export PKG="squirrel-0.1-1.noarch.rpm"

# Upload it as an Artifact
echo "Upload an RPM package."
export ARTIFACT_HREF=$(http --form POST $BASE_ADDR/pulp/api/v3/artifacts/ \
    [email protected]/$PKG | jq -r '.pulp_href')

echo "Inspecting artifact."
http $BASE_ADDR$ARTIFACT_HREF

Artifact GET response:

{
    "file": "artifact/49/921db74808725e9228f6e8f4c25c65d81ba2382d5b97f26814b9fd80977402",
    "md5": "0c9013e04fa09f48d1996b3fb4c11724",
    "pulp_created": "2019-11-27T13:48:15.394730Z",
    "pulp_href": "/pulp/api/v3/artifacts/c3440ebb-99bc-44a0-915c-ee06cc5d4001/",
    "sha1": "183a50aa0d25fdd0faa6642e4a82ff8870f96656",
    "sha224": "9b199695812ff2fab161aaa7873920b12c743b8b32f37be926bce649",
    "sha256": "49921db74808725e9228f6e8f4c25c65d81ba2382d5b97f26814b9fd80977402",
    "sha384": "59b3d541c495abee3d0295ae87aadfb9fd20280757fd2373160120d8690435c23ae48aed4f60d8cf0713f9c4876f7ffa",
    "sha512": "eaf47a730d2397e1b58d813914b0bad2b61aa90e5fa0b58101e98654f84d3a30826c2b67f0de96c5690b2bbf5bf847fa5b9f0cfdb970d52b94b56a94d68ca7c2",
    "size": 2473
}

Create content from artifacts

#!/usr/bin/env bash

# Create RPM package from an artifact
echo "Create RPM content from artifact."
export TASK_URL=$(http POST $BASE_ADDR/pulp/api/v3/content/rpm/packages/ \
    artifact=$ARTIFACT_HREF relative_path=$PKG | jq -r '.task')

# Poll the task (here we use a function defined in docs/_scripts/base.sh)
wait_until_task_finished $BASE_ADDR$TASK_URL

# After the task is complete, it gives us a new package (RPM content)
echo "Set PACKAGE_HREF from finished task."
export PACKAGE_HREF=$(http $BASE_ADDR$TASK_URL| jq -r '.created_resources | first')

echo "Inspecting Package."
http $BASE_ADDR$PACKAGE_HREF

Package GET response (after task complete):

{
    "arch": "noarch",
    "artifact": "/pulp/api/v3/artifacts/c3440ebb-99bc-44a0-915c-ee06cc5d4001/",
    "changelogs": [],
    "checksum_type": "sha256",
    "conflicts": [],
    "description": "A dummy package of fox",
    "enhances": [],
    "epoch": "0",
    "files": [
        [
            "",
            "/tmp/",
            "fox.txt"
        ]
    ],
    "is_modular": false,
    "location_base": "",
    "location_href": "fox-1.1-2.noarch.rpm",
    "name": "fox",
    "obsoletes": [],
    "pkgId": "49921db74808725e9228f6e8f4c25c65d81ba2382d5b97f26814b9fd80977402",
    "provides": [
        [
            "fox",
            "EQ",
            "0",
            "1.1",
            "2",
            false
        ]
    ],
    "pulp_created": "2019-11-27T13:48:16.462655Z",
    "pulp_href": "/pulp/api/v3/content/rpm/packages/9ee09de7-5fff-4805-8b30-9ab95493317d/",
    "recommends": [],
    "release": "2",
    "requires": [],
    "rpm_buildhost": "smqe-ws15",
    "rpm_group": "Internet/Applications",
    "rpm_header_end": 2329,
    "rpm_header_start": 928,
    "rpm_license": "GPLv2",
    "rpm_packager": "",
    "rpm_sourcerpm": "fox-1.1-2.src.rpm",
    "rpm_vendor": "",
    "size_archive": 292,
    "size_installed": 42,
    "size_package": 2473,
    "suggests": [],
    "summary": "A dummy package of fox",
    "supplements": [],
    "time_build": 1331831360,
    "time_file": 1574862495,
    "url": "http://tstrachota.fedorapeople.org",
    "version": "1.1"
}

Add content to repository foo

#!/usr/bin/env bash

# Add created RPM content to repository
echo "Add created RPM Package to repository."
export TASK_URL=$(http POST $BASE_ADDR$REPO_HREF'modify/' \
    add_content_units:="[\"$PACKAGE_HREF\"]" | jq -r '.task')

# Poll the task (here we use a function defined in docs/_scripts/base.sh)
wait_until_task_finished $BASE_ADDR$TASK_URL

# After the task is complete, it gives us a new repository version
echo "Set REPOVERSION_HREF from finished task."
export REPOVERSION_HREF_WITH_PKG=$(http $BASE_ADDR$TASK_URL| jq -r '.created_resources | first')

echo "Inspecting RepositoryVersion."
http $BASE_ADDR$REPOVERSION_HREF_WITH_PKG

Repository Version GET response (after task complete):

{
    "base_version": null,
    "content_summary": {
        "added": {
            "rpm.package": {
                "count": 1,
                "href": "/pulp/api/v3/content/rpm/packages/?repository_version_added=/pulp/api/v3/repositories/rpm/rpm/805de89c-1b1d-432c-993e-3eb9a3fedd22/versions/1/"
            }
        },
        "present": {
            "rpm.package": {
                "count": 1,
                "href": "/pulp/api/v3/content/rpm/packages/?repository_version=/pulp/api/v3/repositories/rpm/rpm/805de89c-1b1d-432c-993e-3eb9a3fedd22/versions/1/"
            }
        },
        "removed": {}
    },
    "number": 1,
    "pulp_created": "2019-11-27T13:48:18.326333Z",
    "pulp_href": "/pulp/api/v3/repositories/rpm/rpm/805de89c-1b1d-432c-993e-3eb9a3fedd22/versions/1/"
}

One-shot Upload

Advisory upload

Advisory upload requires a file or an artifact containing advisory information in the JSON format. Repository is an optional argument to create new repository version with uploaded advisory.

#!/usr/bin/env bash

# Get advisory
echo '{
    "updated": "2014-09-28 00:00:00",
    "issued": "2014-09-24 00:00:00",
    "id": "RHSA-XXXX:XXXX"
}' > advisory.json
export ADVISORY="advisory.json"

# Upload advisory
echo "Upload advisory in JSON format."
export TASK_URL=$(http --form POST $BASE_ADDR/pulp/api/v3/content/rpm/advisories/ \
    [email protected]/$ADVISORY repository=$REPO_HREF \
    relative_path=$ADVISORY | jq -r '.task')

# Poll the task (here we use a function defined in docs/_scripts/base.sh)
wait_until_task_finished $BASE_ADDR$TASK_URL

# After the task is complete, it gives us a new repository version
echo "Set ADVISORY_HREF from finished task."
export ADVISORY_HREF=$(http $BASE_ADDR$TASK_URL \
    | jq -r '.created_resources | .[] | match(".*advisories.*") | .string')

echo "Inspecting advisory."
http $BASE_ADDR$ADVISORY_HREF

Advisory GET response (after task complete):

{
    "artifact": "/pulp/api/v3/artifacts/b4e3a95c-eb82-410e-8f90-aba59d573058/",
    "description": "",
    "fromstr": "[email protected]",
    "id": "RHSA-XXXX:XXXX",
    "issued_date": "2014-09-24 00:00:00",
    "pkglist": [],
    "pulp_created": "2019-11-27T13:48:20.364919Z",
    "pulp_href": "/pulp/api/v3/content/rpm/advisories/51169df4-f7c6-46df-953c-1714e5dd5869/",
    "pushcount": "",
    "reboot_suggested": false,
    "references": [],
    "release": "",
    "rights": "",
    "severity": "",
    "solution": "",
    "status": "",
    "summary": "",
    "title": "",
    "type": "",
    "updated_date": "",
    "version": ""
}