Skip to main content
Help us improve Python packaging – donate today!

Abstraction layer for CF and Kube env variables

Project Description

Build Status
Latest Version

Available on PyPI

This library is the Python version of the the JavaScript IBMCloudEnv library

The ibmcloudenv package allows to abstract environment variables from various Cloud compute providers, such as, but not limited to, CloudFoundry and Kubernetes, so the application could be environment-agnostic.

The module allows to define an array of search patterns that will be executed one by one until required value is found.

Installation

pip install ibmcloudenv

Usage

Create a JSON file containing your mappings and initialize the module

from ibmcloudenv import IBMCloudEnv
IBMCloudEnv.init("/path/to/the/mappings/file/relative/to/prject/root")

In case mappings file path is not specified in the IBMCloudEnv.init() the module will try to load mappings from a default path of /server/config/mappings.json.

Supported search patterns types

ibm_cloud_config supports searching for values using three search pattern types - cloudfoundry, env, file.

  • Using cloudfoundry allows to search for values in VCAP_SERVICES and VCAP_APPLICATIONS environment variables
  • Using env allows to search for values in environment variables
  • Using file allows to search for values in text/json files

Example search patterns

  • cloudfoundry:service-instance-name - searches through parsed VCAP_SERVICES environment variable and returns the credentials object of the matching service instance name
  • cloudfoundry:$.JSONPath - searches through parsed VCAP_SERVICES and VCAP_APPLICATION environment variables and returns the value that corresponds to JSONPath
  • env:env-var-name - returns environment variable named “env-var-name”
  • env:env-var-name:$.JSONPath - attempts to parse the environment variable “env-var-name” and return a value that corresponds to JSONPath
  • file:/server/config.text - returns content of /server/config.text file
  • file:/server/config.json:$.JSONPath - reads the content of /server/config.json file, tries to parse it, returns the value that corresponds to JSONPath

mappings.json file example

{
    "service1-credentials": {
        "searchPatterns": [
            "cloudfoundry:my-service1-instance-name",
            "env:my-service1-credentials",
            "file:/localdev/my-service1-credentials.json"
        ]
    },
    "service2-username": {
        "searchPatterns":[
            "cloudfoundry:$.service2[@.name=='my-service2-instance-name'].credentials.username",
            "env:my-service2-credentials:$.username",
            "file:/localdev/my-service1-credentials.json:$.username"
        ]
    }
}

Using the values in application

In your application retrieve the values using below commands

```python
service1cred

Note

ibm-cloud-env is deprecated use ibmcloudenv.

Release history Release notifications

History Node

0.1.3

History Node

0.1.2

History Node

0.1.1

History Node

0.1.0

History Node

0.0.18

History Node

0.0.17

History Node

0.0.16

History Node

0.0.15

History Node

0.0.14

History Node

0.0.13

History Node

0.0.12

This version
History Node

0.0.11

History Node

0.0.10

History Node

0.0.9

History Node

0.0.8

History Node

0.0.7

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
ibmcloudenv-0.0.11.tar.gz (5.5 kB) Copy SHA256 hash SHA256 Source None Oct 6, 2017

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page