def update_redis(project: str, environment: str, feature: str, state: str) \ -> None: """ Update redis state for a feature flag. :param project: LaunchDarkly project key. :param environment: LaunchDarkly environment key. :param feature: LaunchDarkly feature key. :param state: State for a feature flag. """ try: hosts = RedisWrapper.connection_string_parser( os.environ.get('REDIS_HOSTS')) except RuntimeError as ex: LOG.error(ex) sys.exit(1) for host in hosts: LOG.info("connecting to %s:%s", host.host, host.port) try: if valid_state(state): new_state = state.lower() redis = RedisWrapper(host.host, host.port, project, environment) redis.update_flag_record(new_state, feature) create_file(project, environment, feature, new_state) LOG.info("%s was successfully updated.", feature) else: raise Exception('Invalid state: {0}, -s needs \ to be either on or off.'.format(state)) except KeyError as ex: LOG.error("unable to update %s. Exception: %s", host.host, ex) sys.exit(1)
def update_ld_api(project: str, environment: str, feature: str, state: str): """ Execute command against the LaunchDarkly API. This command is generally not used directly, instead it is called as a part of running the ``playback()`` function. :param project: LaunchDarkly project key. :param environment: LaunchDarkly environment key. :param feature: LaunchDarkly feature key. :param state: State for a feature flag. """ valid_ld_api_vars() ld_api = LaunchDarklyApi(os.environ.get('LD_API_KEY'), project, environment) if valid_state(state): if state.lower() == 'off': new_state = False else: new_state = True ld_api.update_flag(new_state, feature) else: raise ValueError('Invalid state: {0}, -s needs to be either \ on or off.'.format(state))
def update_dynamodb(table: str, project: str, environment: str, feature: str, state: str) \ -> None: """ Update DynamoDB for a feature flag :param table: table name for DynamoDB. :param project_key: LaunchDarkly project key :param environment_key: LaunchDarkly environment key. :param feature: LaunchDarkly feature key. :param state: State for a feature flag. """ try: ddb = DdbWrapper(table, project, environment) except RuntimeError as ex: LOG.error(ex) sys.exit(1) LOG.info("connecting to DynamoDB table: %s", table) if valid_state(state): if state.lower() == 'off': new_state = False else: new_state = True ddb.update_ddb_flag_record(feature, new_state) create_file(project, environment, feature, state) LOG.info("%s was successfully updated.", feature) else: LOG.error( 'Invalid state: {0}, -s needs to be either on or off.'.format( state))
def test_invalid_input(self): result = valid_state('bad') self.assertFalse(result)
def test_valid_input_mixed_case(self): result = valid_state('oN') self.assertTrue(result) result = valid_state('OfF') self.assertTrue(result)
def test_valid_input(self): result = valid_state('on') self.assertTrue(result) result = valid_state('off') self.assertTrue(result)