Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

4.4 KB
Raw Blame
#!/usr/bin/env bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

import os

env_map = {
    # Catalog
    "GRAVITINO_ICEBERG_REST_HOST": "host",
    "GRAVITINO_ICEBERG_REST_HTTP_PORT": "httpPort",
    "GRAVITINO_ICEBERG_REST_METRICS_ENABLED": "metrics.enabled",
    "GRAVITINO_ICEBERG_REST_URI": "uri",
    "GRAVITINO_ICEBERG_REST_IO_IMPL": "io-impl",
    "GRAVITINO_ICEBERG_REST_CATALOG_BACKEND": "catalog-backend",
    "GRAVITINO_ICEBERG_REST_JDBC_DRIVER": "jdbc-driver",
    "GRAVITINO_ICEBERG_REST_JDBC_USER": "jdbc-user",
    "GRAVITINO_ICEBERG_REST_JDBC_PASSWORD": "jdbc-password",
    "GRAVITINO_ICEBERG_REST_WAREHOUSE": "warehouse",
    "GRAVITINO_ICEBERG_REST_REST_CLIENT_CONNECTION_TIMEOUT_MS": "rest-client-connection-timeout-ms",
    "GRAVITINO_ICEBERG_REST_REST_CLIENT_SOCKET_TIMEOUT_MS": "rest-client-socket-timeout-ms",
    # Credentials
    "GRAVITINO_ICEBERG_REST_CREDENTIAL_PROVIDERS": "credential-providers",
    # GCS
    "GRAVITINO_ICEBERG_REST_GCS_SERVICE_ACCOUNT_FILE": "gcs-service-account-file",
    # S3
    "GRAVITINO_ICEBERG_REST_S3_ACCESS_KEY": "s3-access-key-id",
    "GRAVITINO_ICEBERG_REST_S3_SECRET_KEY": "s3-secret-access-key",
    "GRAVITINO_ICEBERG_REST_S3_ENDPOINT": "s3-endpoint",
    "GRAVITINO_ICEBERG_REST_S3_REGION": "s3-region",
    "GRAVITINO_ICEBERG_REST_S3_PATH_STYLE_ACCESS": "s3-path-style-access",
    "GRAVITINO_ICEBERG_REST_S3_ROLE_ARN": "s3-role-arn",
    "GRAVITINO_ICEBERG_REST_S3_EXTERNAL_ID": "s3-external-id",
    "GRAVITINO_ICEBERG_REST_S3_TOKEN_SERVICE_ENDPOINT": "s3-token-service-endpoint",
    # Azure
    "GRAVITINO_ICEBERG_REST_AZURE_STORAGE_ACCOUNT_NAME": "azure-storage-account-name",
    "GRAVITINO_ICEBERG_REST_AZURE_STORAGE_ACCOUNT_KEY": "azure-storage-account-key",
    "GRAVITINO_ICEBERG_REST_AZURE_TENANT_ID": "azure-tenant-id",
    "GRAVITINO_ICEBERG_REST_AZURE_CLIENT_ID": "azure-client-id",
    "GRAVITINO_ICEBERG_REST_AZURE_CLIENT_SECRET": "azure-client-secret",
    # OSS
    "GRAVITINO_ICEBERG_REST_OSS_ACCESS_KEY": "oss-access-key-id",
    "GRAVITINO_ICEBERG_REST_OSS_SECRET_KEY": "oss-secret-access-key",
    "GRAVITINO_ICEBERG_REST_OSS_ENDPOINT": "oss-endpoint",
    "GRAVITINO_ICEBERG_REST_OSS_REGION": "oss-region",
    "GRAVITINO_ICEBERG_REST_OSS_ROLE_ARN": "oss-role-arn",
    "GRAVITINO_ICEBERG_REST_OSS_EXTERNAL_ID": "oss-external-id",
}

init_config = {
    "catalog-backend": "jdbc",
    "jdbc-driver": "org.sqlite.JDBC",
    "uri": "jdbc:sqlite::memory:",
    "jdbc-user": "iceberg",
    "jdbc-password": "iceberg",
    "jdbc-initialize": "true",
    "jdbc.schema-version": "V1",
}


def parse_config_file(file_path):
    config_map = {}
    with open(file_path, "r") as file:
        for line in file:
            stripped_line = line.strip()
            if stripped_line and not stripped_line.startswith("#"):
                key, value = stripped_line.split("=", 1)
                key = key.strip()
                value = value.strip()
                config_map[key] = value
    return config_map


config_prefix = "gravitino.iceberg-rest."


def update_config(config, key, value):
    config[config_prefix + key] = value


config_file_path = "conf/gravitino-iceberg-rest-server.conf"
config_map = parse_config_file(config_file_path)

# Set from init_config only if the key doesn't exist
for k, v in init_config.items():
    full_key = config_prefix + k
    if full_key not in config_map:
        update_config(config_map, k, v)

for k, v in env_map.items():
    if k in os.environ:
        update_config(config_map, v, os.environ[k])

if os.path.exists(config_file_path):
    os.remove(config_file_path)

with open(config_file_path, "w") as file:
    for key, value in config_map.items():
        line = "{} = {}\n".format(key, value)
        file.write(line)