Skip to content

Generate Bindings

Generate a client binding for any Pulp component for the language of your choice.

Language Support

Only python and ruby bindings have some testing, although not extensive.

For python clients, we recommend looking at pulp-glue as an alternative. That library is handcrafted, handles tasks for you and knows how to deal with different versions of Pulp and plugins.

If you need to tweak the generator to make it work for your language, have a look at how it works.

Overview

  • Requirements:
    • git
    • Python 3
    • Docker/Podman
  • General workflow:
    1. Clone pulp-openapi-generator.
    2. Get the openapi schema for the desired Pulp components.
    3. Run the generator cli from the the repository

Setup

To get started, first clone the repo into your machine. It'll be used as the workspace for the bindings generation.

git clone https://github.com/pulp/pulp-openapi-generator
cd pulp-openapi-generator

Get the schema

There are two basic options to get an openapi schema: (1) from an installed package and (2) from a running installation.

Note that the api.spec must be generated with the --bindings flag/url-option. That spec is tailored for bindings generation and isn't a fully compliant api.spec.

  1. From a python environment with Pulp packages installed.

    pulpcore-manager openapi --bindings \
        --component "core" \
        --file "core-api.json"
    

    Some Pulp settings affect client generation directly (e.g, API_ROOT and DOMAIN_ENABLED). If you run this command outside of a Pulp operating enviroment, you may need to pass an additional --settings settings.py parameter pointing to the corresponding settings of your target installation.

  2. From a running pulp instance:

    PULP_URL="http://pulp.example/pulp/api/v3/"
    COMPONENT="core"
    URL="${PULP_URL}docs/api.json?bindings&component=${COMPONENT}"
    curl "${URL}" -o "${COMPONENT}-api.json"
    

Generate the client

The script uses the openapi-generator-cli image to generate the clients, so the first run may take some time to download it.

In the example, a ruby package for pulpcore will be generated at ./pulp_rpm-client/ using an existing schema rpm-api.json:

./gen-client.sh rpm-api.json rpm ruby

Further reading