opensearch-benchmark-provisionconfigs/1.0/plugins/v1/repository_s3/plugin.py [34:120]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
LOGGER_NAME = "osbenchmark.provisioner.repository_s3"


def resolve_binary(install_root, binary_name):
    return os.path.join(install_root, "bin", binary_name)


def resolve_keystore_config(install_root):
    return os.path.join(install_root, "config", "elasticsearch.keystore")


def create_keystore(install_root, keystore_binary, env):
    logger = logging.getLogger(LOGGER_NAME)

    keystore_create_command = "{keystore} -s create".format(keystore=keystore_binary)

    return_code = process.run_subprocess_with_logging(
        keystore_create_command,
        env=env
    )

    if return_code != 0:
        logger.error("%s has exited with code [%d]", keystore_create_command, return_code)
        raise exceptions.SystemSetupError(
            "Could not initialize a keystore. Please see the log for details.")


def add_property_to_keystore(keystore_binary, client_name, property_name, property_value, env):
    logger = logging.getLogger(LOGGER_NAME)

    p1 = subprocess.Popen(["echo", property_value], stdout=subprocess.PIPE)

    keystore_command = "{keystore} --silent add --stdin s3.client.{client_name}.{key}".format(
        keystore=keystore_binary,
        client_name=client_name,
        key=property_name)

    return_code = process.run_subprocess_with_logging(
        keystore_command,
        stdin=p1.stdout,
        env=env
    )

    if return_code != 0:
        logger.error("%s has exited with code [%d]", keystore_command, return_code)
        raise exceptions.SystemSetupError(
            "Could not add S3 keystore secure setting [{}]. Please see the log for details.".format(property_name))


def configure_keystore(config_names, variables, **kwargs):
    logger = logging.getLogger(LOGGER_NAME)
    # s3_session_token is optional
    keystore_params = ["s3_access_key", "s3_secret_key", "s3_session_token"]
    client_name = variables.get("s3_client_name")

    # skip keystore configuration entirely if any of the mandatory params is missing
    if not (client_name and variables.get(keystore_params[0]) and variables.get(keystore_params[1])):
        logger.warning("Skipping keystore configuration for repository-s3 as mandatory plugin-params [%s,%s,%s] were not supplied",
                       "s3_client_name",
                       keystore_params[0],
                       keystore_params[1])
        return False

    keystore_binary_filename = "elasticsearch-keystore"
    install_root = variables["install_root_path"]
    keystore_binary = resolve_binary(install_root, keystore_binary_filename)
    env = kwargs.get("env")

    if not os.path.isfile(resolve_keystore_config(install_root)):
        create_keystore(install_root, keystore_binary, env)

    for property_name in keystore_params:
        # the actual OpenSearch secure settings for the s3 plugin don't contain the s3_ prefix
        os_property_name = property_name.replace("s3_", "")
        property_value = variables.get(property_name)
        # skip optional properties like session_token
        if not property_value:
            continue

        add_property_to_keystore(keystore_binary, client_name, os_property_name, property_value, env)

    # Success
    return True


def register(registry):
    registry.register("post_install", configure_keystore)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



opensearch-benchmark-provisionconfigs/main/plugins/v1/repository_s3/plugin.py [34:120]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
LOGGER_NAME = "osbenchmark.provisioner.repository_s3"


def resolve_binary(install_root, binary_name):
    return os.path.join(install_root, "bin", binary_name)


def resolve_keystore_config(install_root):
    return os.path.join(install_root, "config", "elasticsearch.keystore")


def create_keystore(install_root, keystore_binary, env):
    logger = logging.getLogger(LOGGER_NAME)

    keystore_create_command = "{keystore} -s create".format(keystore=keystore_binary)

    return_code = process.run_subprocess_with_logging(
        keystore_create_command,
        env=env
    )

    if return_code != 0:
        logger.error("%s has exited with code [%d]", keystore_create_command, return_code)
        raise exceptions.SystemSetupError(
            "Could not initialize a keystore. Please see the log for details.")


def add_property_to_keystore(keystore_binary, client_name, property_name, property_value, env):
    logger = logging.getLogger(LOGGER_NAME)

    p1 = subprocess.Popen(["echo", property_value], stdout=subprocess.PIPE)

    keystore_command = "{keystore} --silent add --stdin s3.client.{client_name}.{key}".format(
        keystore=keystore_binary,
        client_name=client_name,
        key=property_name)

    return_code = process.run_subprocess_with_logging(
        keystore_command,
        stdin=p1.stdout,
        env=env
    )

    if return_code != 0:
        logger.error("%s has exited with code [%d]", keystore_command, return_code)
        raise exceptions.SystemSetupError(
            "Could not add S3 keystore secure setting [{}]. Please see the log for details.".format(property_name))


def configure_keystore(config_names, variables, **kwargs):
    logger = logging.getLogger(LOGGER_NAME)
    # s3_session_token is optional
    keystore_params = ["s3_access_key", "s3_secret_key", "s3_session_token"]
    client_name = variables.get("s3_client_name")

    # skip keystore configuration entirely if any of the mandatory params is missing
    if not (client_name and variables.get(keystore_params[0]) and variables.get(keystore_params[1])):
        logger.warning("Skipping keystore configuration for repository-s3 as mandatory plugin-params [%s,%s,%s] were not supplied",
                       "s3_client_name",
                       keystore_params[0],
                       keystore_params[1])
        return False

    keystore_binary_filename = "elasticsearch-keystore"
    install_root = variables["install_root_path"]
    keystore_binary = resolve_binary(install_root, keystore_binary_filename)
    env = kwargs.get("env")

    if not os.path.isfile(resolve_keystore_config(install_root)):
        create_keystore(install_root, keystore_binary, env)

    for property_name in keystore_params:
        # the actual OpenSearch secure settings for the s3 plugin don't contain the s3_ prefix
        os_property_name = property_name.replace("s3_", "")
        property_value = variables.get(property_name)
        # skip optional properties like session_token
        if not property_value:
            continue

        add_property_to_keystore(keystore_binary, client_name, os_property_name, property_value, env)

    # Success
    return True


def register(registry):
    registry.register("post_install", configure_keystore)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



