Skip to main content

A python package for the V2 CF Service Broker API and Open Broker API (version 2.13+)

Project description

Build Status Coverage Status Known Vulnerabilities PYUP OpenSSF Best Practices Scorecard

Open Broker API

A Python package for building Service Brokers supporting API version 2.13+.

Following Open Service Broker API Spec and Open Service Broker API

Check out the documentation.

To find out more about Platform Compatibility for OSBAPI versions, check out Platform Compatibility for OSBAPI

Not all features are supported with this library due to conflicting features.

Installation

This package is available for Python 3.8+.

pip3 install openbrokerapi

# including gevent as server
pip3 install openbrokerapi[gevent]

# recommended production setup
pip3 install openbrokerapi[gunicorn]

Or install the development version from github:

pip3 install git+https://github.com/eruvanos/openbrokerapi.git

Usage

You can start with a skeleton project or just from scratch.

from typing import Union, List

import openbrokerapi
from openbrokerapi import api
from openbrokerapi.api import ServiceBroker
from openbrokerapi.catalog import ServicePlan
from openbrokerapi.service_broker import (
    Service,
    ProvisionDetails,
    ProvisionedServiceSpec,
    DeprovisionDetails,
    DeprovisionServiceSpec
)


class MyServiceBroker(ServiceBroker):
    def catalog(self) -> Union[Service, List[Service]]:
        return Service(
            id='service id',
            name='service name',
            description='service description',
            bindable=False,
            plans=[
                ServicePlan(
                    id='plan id',
                    name='plan name',
                    description='plan description',
                )
            ]
        )

    def provision(self,
                  instance_id: str,
                  details: ProvisionDetails,
                  async_allowed: bool,
                  **kwargs) -> ProvisionedServiceSpec:
        # Create service instance
        # ...

        return ProvisionedServiceSpec()

    def deprovision(self,
                    instance_id: str,
                    details: DeprovisionDetails,
                    async_allowed: bool,
                    **kwargs) -> DeprovisionServiceSpec:
        # Delete service instance
        # ...

        return DeprovisionServiceSpec(is_async=False)

print('Start server on 127.0.0.1:5000')
print('Check the catalog at:')
print('> curl 127.0.0.1:5000/v2/catalog -H "X-Broker-API-Version: 2.14"')
api.serve(MyServiceBroker(), None)

# Simply start the server
# api.serve(ExampleServiceBroker(), api.BrokerCredentials("", ""))

# or start the server without authentication
# api.serve(ExampleServiceBroker(), None)

# or start the server with multiple authentication
# api.serve(ExampleServiceBroker(), [api.BrokerCredentials("", ""), api.BrokerCredentials("", "")])

# or with multiple service brokers and multiple credentials
# api.serve_multiple([ExampleServiceBroker(), ExampleServiceBroker()], [api.BrokerCredentials("", ""), api.BrokerCredentials("", "")])

# or register blueprint to your own FlaskApp instance
# app = Flask(__name__)
# logger = basic_config()  # Use root logger with a basic configuration provided by openbrokerapi.log_util
# openbroker_bp = api.get_blueprint(ExampleServiceBroker(), api.BrokerCredentials("", ""), logger)
# app.register_blueprint(openbroker_bp)
# app.run("0.0.0.0")

Deployment

The included api.serve function provides a server setup for local usage only.

For productive deployments use the blueprint from api.get_blueprint to setup a production ready server like Waitress or other mentioned in Flask Deployment Docs

Error Types

Openbrokerapi defines a handful of error types in errors.py for some common error cases that your service broker may encounter. Raise these from your ServiceBroker methods where appropriate, and openbrokerapi will do the “right thing” (™), and give Cloud Foundry an appropriate status code, as per the Service Broker API specification.

Bugs or Issues

Please report bugs, issues or feature requests to Github Issues

How to contribute

You want to contribute, I really appreciate!

So let us check how you can contribute:

  • Create an issue in the Github Issues. Please provide all information that you think are usefull to solve it.

  • Use the Github Issues to create a feature request, so we can discuss and find a good interface for that feature.

  • Create a Pull Request. There are some things that will make it easier to review your Pull Request:

    • Use a new branch for every Pull Request

    • Include just related commits in this branch

    • Less commits are better, one would be the best (You can squash them.)

    • Always add tests for your feature, if you are not familiar with writing tests, ask for help.

    • Hint: To update your fork with the newest changes, follow these instructions.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openbrokerapi-4.7.3.tar.gz (136.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openbrokerapi-4.7.3-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

Details for the file openbrokerapi-4.7.3.tar.gz.

File metadata

  • Download URL: openbrokerapi-4.7.3.tar.gz
  • Upload date:
  • Size: 136.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for openbrokerapi-4.7.3.tar.gz
Algorithm Hash digest
SHA256 7dfbb0de14009b9d536d81a4bfaa8581eb2505191811d8bab79ffa03665ac466
MD5 f010b5a12bf3e7843479bea2bd9f1221
BLAKE2b-256 9bc698d9a197fecac202201a8912a622d644c63aa3f4ff95befc58e4f1c6996d

See more details on using hashes here.

Provenance

The following attestation bundles were made for openbrokerapi-4.7.3.tar.gz:

Publisher: python-publish.yml on eruvanos/openbrokerapi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file openbrokerapi-4.7.3-py3-none-any.whl.

File metadata

  • Download URL: openbrokerapi-4.7.3-py3-none-any.whl
  • Upload date:
  • Size: 19.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for openbrokerapi-4.7.3-py3-none-any.whl
Algorithm Hash digest
SHA256 07c519e3ce32ae77f9c4e0dd7f022f272f783c4b2f64b4bf754d61764f4aab48
MD5 93fc2ccc3c45caaa70aa781f15e67dac
BLAKE2b-256 6dae3d257bd6cefa4f6a7e61a146e8e10abd29be131bbf2afce72202a1f2708f

See more details on using hashes here.

Provenance

The following attestation bundles were made for openbrokerapi-4.7.3-py3-none-any.whl:

Publisher: python-publish.yml on eruvanos/openbrokerapi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page