Skip to content

Clever/discovery-python

Repository files navigation

discovery-python

This library programmatically finds endpoints for dependencies. Similar to discovery-go and disocvery-node.

See Service Discovery for more details.

Installation

pip

Assuming discovery v0.1.0 is being installed:

pip install git+https://github.com/Clever/discovery-python.git@v0.1.0

setup.py

from setuptools import setup

# Assuming discovery v0.1.0 is being installed:
setup(

    # ...

    install_requires=['discovery==0.1.0'],
    dependency_links=[
      'https://github.com/Clever/discovery-python/tarball/v0.1.0#egg=discovery-0.1.0'
    ],

    # ...

)

Usage

import discovery

try:
	stoked_url = discovery.url('stoked', 'thrift')

	stoked_host_and_port = discovery.host_port('stoked', 'thrift')

	stoked_host = discovery.host('stoked', 'thrift')

	stoked_port = discovery.port('stoked', 'thrift')

  clever_com_url = discovery.external_url('clever.com')

except discovery.MissingEnvironmentVariableError as e:
	print 'ERROR: Stoked discovery failed: {}.'.format(e)

Development

Publishing a new version

  1. Bump the version in the VERSION file and update the changelog in CHANGES.md.

  2. Merge your changes into master.

  3. Checkout master

  4. Run the publish script:

    ./publish.sh

Implementation Details

Currently, discovery-{go,node,python} looks for environment variables with the following format:

SERVICE_{SERVICE_NAME}_{EXPOSE_NAME}_{PROTO,HOST,PORT}

These environment variables are autogenerated by our deployment tooling. Three env-vars are created for each app listed in the dependencies section of caller's launch yaml.

For example, if an app lists district-authorizations as a dependency, fab and catapult will generate this env-vars triplet:

SERVICE_DISTRICT_AUTHORIZATIONS_HTTP_PROTO = "http"
SERVICE_DISTRICT_AUTHORIZATIONS_HTTP_HOST = "district-authorizations.ops.clever.com"
SERVICE_DISTRICT_AUTHORIZATIONS_HTTP_PORT = "80"

About

Programmatically find service endpoints (i.e. discovery-go for python)

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 10