API¶
relay_commander¶
Relay Commander is a CLI for managing LaunchDarkly relay instances.
- copyright
2018-2019 by LaunchDarkly Solutions Engineering
- license
Apache 2.0, see LICENSE for more details.
Utilities¶
relay_commander.generators¶
This module allows for generating LaunchDarkly relay configurations using Jinja templates.
-
class
relay_commander.generators.
ConfigGenerator
[source]¶ Abstract configuration generator using Jinja.
-
__weakref__
¶ list of weak references to the object (if defined)
-
generate_relay_config
(environments)[source]¶ Generate ld-relay.conf file.
Given a list of environments of a project, this will generate a
ld-relay.conf
file in the current working directory. The conf file follows the specification that is documented in the main ld-relay documentation.- Parameters
environments (
list
) – list of LaunchDarkly environments.- Return type
None
-
relay_commander.validator¶
This module provides helper functions that validate CLI input.
-
relay_commander.validator.
_REQUIRED_ENV_VARS
= ['LD_API_KEY', 'REDIS_HOSTS']¶ Internal constant that defines required environment variables.
-
relay_commander.validator.
_VALID_STATES
= ['on', 'off']¶ Internal constant that defines a valid
state
argument.
-
relay_commander.validator.
_check_env_var
(envvar)[source]¶ Check Environment Variable to verify that it is set and not empty.
- Parameters
envvar (
str
) – Environment Variable to Check.- Return type
bool
- Returns
True if Environment Variable is set and not empty.
- Raises
KeyError if Environment Variable is not set or is empty.
New in version 0.0.12.
-
relay_commander.validator.
valid_env_vars
()[source]¶ Validate that required env vars exist.
- Return type
bool
- Returns
True if required env vars exist.
New in version 0.0.12.
-
relay_commander.validator.
valid_state
(state)[source]¶ Validate State Argument
Checks that either ‘on’ or ‘off’ was entered as an argument to the CLI and make it lower case.
- Parameters
state (
str
) – state to validate.- Return type
bool
- Returns
True if state is valid.
Changed in version 0.0.12: This moethod was renamed from validateState to valid_state to conform to PEP-8. Also removed “magic” text for state and instead reference the _VALID_STATES constant.
relay_commander.replay_builder¶
This module provides functionality to generate the replay directory and keep track of pending and completed API calls.
As a part of the runbook, when a user makes a change directly to redis we make a copy of the command that they need to run in order to update the API when LaunchDarkly connectivity resumes.
These commands are stored in a directory called replay
which has the
following structure:
replay
├── archive
└── toDo
-
relay_commander.replay_builder.
check_local
()[source]¶ Verify required directories exist.
This functions checks the current working directory to ensure that the required directories exist. If they do not exist, it will create them.
- Return type
None
-
relay_commander.replay_builder.
create_file
(project, environment, feature, state)[source]¶ Create file to replay.
Create file with
rc
command that will be called against the LaunchDarkly API whenrc playback
is called from the main CLI.- Parameters
project (
str
) – LaunchDarkly Projectenvironment (
str
) – LaunchDarkly Environmentfeature (
str
) – LaunchDarkly Featurestate (
str
) – State to update feature flag
- Return type
None
Wrappers¶
relay_commander.ld¶
This module provides a wrapper for the LaunchDarkly API.
Reference API - https://pypi.org/project/launchdarkly-api/
Changed in version 0.0.12: Refactor module to make it PEP-8 and PEP-484 compliant.
-
class
relay_commander.ld.
LaunchDarklyApi
(api_key, project_key=None, environment_key=None)[source]¶ Wrapper for the LaunchDarkly API
-
__init__
(api_key, project_key=None, environment_key=None)[source]¶ Instantiate a new LaunchDarklyApi instance.
- Parameters
api_key (
str
) – API Access Key for LaunchDarkly.project_key (
Optional
[str
]) – Key for project.environment_key (
Optional
[str
]) – Environment in which to pull state from.
-
__weakref__
¶ list of weak references to the object (if defined)
-
relay_commander.redis¶
This module provides an interface for working with redis.
-
class
relay_commander.redis_wrapper.
RedisWrapper
(host, port, project_key, environment_key)[source]¶ A wrapper around the redis library.
This class implements some general data access patterns as well as LaunchDarkly relay specific functionality.
- Parameters
host – redis hostname.
port – redis port.
project_key – LaunchDarkly project key
environment_key – LaunchDarkly environment key.
-
__init__
(host, port, project_key, environment_key)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
__weakref__
¶ list of weak references to the object (if defined)
-
static
connection_string_parser
(uri)[source]¶ Parse Connection string to extract host and port.
- Parameters
uri (
str
) – full URI for redis connection in the form of host:port- Return type
list
- Returns
list of RedisConnection objects
-
relay_commander.redis_wrapper.
_DEFAULT_REDIS_PORT
= 6379¶ Internal constant that defines the default redis port.
-
class
relay_commander.redis_wrapper.
_RedisConnection
(host, port)[source]¶ Private data class that represents a redis connection.
- Parameters
host (
str
) – hostname for redisport (
int
) – port for redis
Changed in version 0.0.12: Refactored to become private, and renamed to fix typo.
-
__weakref__
¶ list of weak references to the object (if defined)