Platform.sh Config Reader v0.1.7 Platformsh.Config View Source

Reads Platform.sh configuration from environment variables.
See: https://docs.platform.sh/development/variables.html
The following are 'magic' properties that may exist on a Config object. Before accessing a property, check its
existence with hasattr(config, variableName). Attempting to access a nonexistent variable will throw an exception.
Attributes:
    (The following properties are available at build time and run time.)
    project (string):
        The project ID.
    application_name (string):
        The name of the application, as defined in its configuration.
    tree_id (string):
        An ID identifying the application tree before it was built: a unique hash is generated based on the contents
        of the application's files in the repository.
    app_dir (string):
        The absolute path to the application.
    project_entropy (string):
        A random string generated for each project, useful for generating hash keys.
    (The following properties are only available at runtime.)
    branch (string):
        The Git branch name.
    environment (string):
        The environment ID (usually the Git branch plus a hash).
    document_root (string):
        The absolute path to the web root of the application.
    smtp_host (string):
        The hostname of the Platform.sh default SMTP server (an empty string if emails are disabled on the
        environment.
    port (string):
        The TCP port number the application should listen to for incoming requests.
    socket (string):
        The Unix socket the application should listen to for incoming requests.
. Platform.sh Environment Variables
        https://docs.platform.sh/development/variables.html

Link to this section Summary

Functions

Returns the application definition dict. This is, approximately, the .platform.app.yaml file as a nested dict. However, it also has other information added by Platform.sh as part of the build and deploy process. Returns

Load everything we have into the environment

Retrieves the unfiltered credentials for accessing a relationship. Returns

Retrieves the credentials for accessing a relationship. Args

Decodes a Platform.sh environment variable.

Formats a dsn for use with ecto Returns

Local index of the variables that can be accessed as direct properties (build and runtime). The key is the property that will be read. The value is the environment variables, minus prefix, that contains the value to look up.

Guesses a relational database for ecto Returns

Determines if a relationship is defined, and thus has credentials available. Args

Determines if a relationships are defined, and thus has credentials available. Returns

Determines if a routes are defined Returns

Checks whether the code is running in a build environment. Returns

Checks whether the code is running in a runtime environment. Returns

Checks whether the code is running on a platform with valid environment variables. Returns

Determines if the current environment is a Platform.sh Dedicated Enterprise environment. Returns

Determines if the current environment is a production environment. Note

Gets primary route Returns

Returns the just the names of relationships Returns

routes/0 Return the routes definition. Returns

routes/1 Get route definition by route ID. Args

value/1 Reads unprefixed environment variable, taking the prefix into account.

value/2 Reads an environment variable, taking the prefix into account.

variables/0 Returns the full variables dict. If you're looking for a specific variable, the variable() method is a more robust option. This method is for classes where you want to scan the whole variables list looking for a pattern. It's valid for there to be no variables defined at all, so there's no guard for missing values. Returns

variables/1 Returns a variable from the VARIABLES dict. Note

Link to this section Functions

Returns the application definition dict. This is, approximately, the .platform.app.yaml file as a nested dict. However, it also has other information added by Platform.sh as part of the build and deploy process. Returns:

The application definition dict.

Load everything we have into the environment

Retrieves the unfiltered credentials for accessing a relationship. Returns:

The credentials dict for the service pointed to by the relationship.
Link to this function

credentials(relationship)

View Source

Retrieves the credentials for accessing a relationship. Args:

relationship (string):
    The relationship name as defined in .platform.app.yaml
 for the moment it returns the first in the index of clustered services

Returns:

The credentials dict for the service pointed to by the relationship.

Decodes a Platform.sh environment variable.

    Args:
        variable (string):
            Base64-encoded JSON (the content of an environment variable).
    Returns:
        An dict (if representing a JSON object), or a scalar type.
    Raises:
        JSON decoding error.
Link to this function

ecto_dsn_formatter(config)

View Source

Formats a dsn for use with ecto Returns:

a string in the format of a dsn url for ecto

Local index of the variables that can be accessed as direct properties (build and runtime). The key is the property that will be read. The value is the environment variables, minus prefix, that contains the value to look up.

Link to this function

guess_relational_database()

View Source

Guesses a relational database for ecto Returns:

a string in the format of a dsn url for ecto or nil if none found, 

this is guesss work so we don't want to crash on no value

Link to this function

has_relationship(relationship)

View Source

Determines if a relationship is defined, and thus has credentials available. Args:

relationship (string):
    The name of the relationship to check.

Returns:

bool:
    True if the relationship is defined, False otherwise.

Determines if a relationships are defined, and thus has credentials available. Returns:

bool:
    True if the relationship is defined, False otherwise.

Determines if a routes are defined Returns:

bool:
    True if the relationship is defined, False otherwise.

Checks whether the code is running in a build environment. Returns:

bool: True if running in build environment, False otherwise.

Checks whether the code is running in a runtime environment. Returns:

bool: True if in a runtime environment, False otherwise.

Checks whether the code is running on a platform with valid environment variables. Returns:

bool:
    True if configuration can be used, False otherwise.
Link to this function

on_dedicated_enterprise?()

View Source

Determines if the current environment is a Platform.sh Dedicated Enterprise environment. Returns:

bool:
    True on an Enterprise environment, False otherwise.

Determines if the current environment is a production environment. Note:

There may be a few edge cases where this is not entirely correct on Enterprise, if the production branch is
not named `production`. In that case you'll need to use your own logic.

Returns:

bool:
    True if the environment is a production environment, False otherwise. It will also return False if not
    running on Platform.sh or in the build phase.

Gets primary route Returns:

 a url of the primary route

Returns the just the names of relationships Returns:

a list with relationship names

routes/0 Return the routes definition. Returns:

The routes dict.

Raises:

RuntimeError:
    If the routes are not accessible due to being in the wrong environment.

routes/1 Get route definition by route ID. Args:

route_id (string):
    The ID of the route to load.

Returns:

The route definition. The generated URL of the route is added as a 'url' key.

Raises:

KeyError:
    If there is no route by that ID, an exception is thrown.

value/1 Reads unprefixed environment variable, taking the prefix into account.

Args:
   item (string):
       The variable to read.

value/2 Reads an environment variable, taking the prefix into account.

Args:
   item (string):
       The variable to read.
   prefix (string):
       The Environment variable prefix

variables/0 Returns the full variables dict. If you're looking for a specific variable, the variable() method is a more robust option. This method is for classes where you want to scan the whole variables list looking for a pattern. It's valid for there to be no variables defined at all, so there's no guard for missing values. Returns:

The full variables dict.

variables/1 Returns a variable from the VARIABLES dict. Note:

Variables prefixed with `env`: can be accessed as normal environment variables. This method will return
such a variable by the name with the prefix still included. Generally it's better to access those variables
directly.

Args:

name (string):
    The name of the variable to retrieve.
default (mixed):
    The default value to return if the variable is not defined. Defaults to nil.

Returns:

The value of the variable, or  nil. This may be a string or a dict.