def test_profile_based_auth(self):
     """Test AWS profile based authentication rather than access keys"""
     # Profile name given in config
     config_aws_profile = {
         'aws_profile': 'fake_profile'
     }
     with self.assertRaises(botocore.exceptions.ProfileNotFound):
         s3.create_client(config_aws_profile)
 def test_profile_based_auth_aws_env_var(self):
     """Test AWS profile based authentication using AWS environment variables"""
     try:
         # Profile name defined as env var and config is empty
         os.environ['AWS_PROFILE'] = 'fake_profile'
         config_aws_profile_env_vars = {}
         with self.assertRaises(botocore.exceptions.ProfileNotFound):
             s3.create_client(config_aws_profile_env_vars)
     # Delete temporary env var to not confuse other tests
     finally:
         del os.environ['AWS_PROFILE']
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-c', '--config', help='Config file')
    args = parser.parse_args()

    if args.config:
        with open(args.config) as input_json:
            config = json.load(input_json)
    else:
        config = {}

    config_errors = utils.validate_config(config)
    if len(config_errors) > 0:
        logger.error("Invalid configuration:\n   * {}".format(
            '\n   * '.join(config_errors)))
        sys.exit(1)

    s3_client = s3.create_client(
        config) if config.get('s3_bucket') != 'localhost' else None

    input_messages = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8')
    state = persist_messages(input_messages, config, s3_client)

    emit_state(state)
    logger.debug("Exiting normally")
Beispiel #4
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("-c", "--config", help="Config file")
    parser.add_argument("-t", "--targets", help="Target file for keys")
    args = parser.parse_args()

    if args.config:
        with open(args.config) as input_json:
            config = json.load(input_json)
    else:
        config = {}

    if args.targets:
        target_file = args.targets
    else:
        target_file = "./targets.json"

    config_errors = utils.validate_config(config)
    if len(config_errors) > 0:
        logger.error("Invalid configuration:\n   * {}".format(
            "\n   * ".join(config_errors)))
        sys.exit(1)

    s3_client = s3.create_client(config)

    input_messages = io.TextIOWrapper(sys.stdin.buffer, encoding="utf-8")
    state, targets = persist_messages(input_messages, config, s3_client)

    emit_state(state)
    emit_targets(targets, target_file)

    logger.debug("Exiting normally")
    def test_aws_env_vars(self):
        """Test loading data with credentials defined in AWS environment variables
        rather than explicitly provided access keys"""
        tap_lines = test_utils.get_test_tap_lines('messages-with-three-streams.json')
        try:
            # Move aws access key and secret from config into environment variables
            os.environ['AWS_ACCESS_KEY_ID'] = os.environ.get('TARGET_S3_CSV_ACCESS_KEY_ID')
            os.environ['AWS_SECRET_ACCESS_KEY'] = os.environ.get('TARGET_S3_CSV_SECRET_ACCESS_KEY')

            config_aws_env_vars = self.config.copy()
            config_aws_env_vars['aws_access_key_id'] = None
            config_aws_env_vars['aws_secret_access_key'] = None

            # Create a new S3 client using env vars
            s3_client_aws_env_vars = s3.create_client(config_aws_env_vars)
            self.persist_messages(tap_lines, s3_client_aws_env_vars)
            self.assert_three_streams_are_in_s3_bucket()
        # Delete temporary env var to not confuse other tests
        finally:
            del os.environ['AWS_ACCESS_KEY_ID']
            del os.environ['AWS_SECRET_ACCESS_KEY']
 def setUp(self):
     self.config = test_utils.get_test_config()
     self.s3_client = s3.create_client(self.config)