Repository: ClickHouse/ClickHouse
File: src/Disks/DiskObjectStorage/ObjectStorages/S3/diskSettings.cpp (C++)

Code before:
    S3::ClientSettings client_settings{
        .use_virtual_addressing = url.is_virtual_hosted_style,
        .disable_checksum = auth_settings[S3AuthSetting::disable_checksum],
        .gcs_issue_compose_request = auth_settings[S3AuthSetting::gcs_issue_compose_request],
        .is_s3express_bucket = is_s3_express_bucket
    };

    auto credentials_configuration = S3::CredentialsConfiguration
    {
        auth_settings[S3AuthSetting::use_environment_credentials],
        auth_settings[S3AuthSetting::use_insecure_imds_request],
        auth_settings[S3AuthSetting::expiration_window_seconds],
        auth_settings[S3AuthSetting::no_sign_request],
        auth_settings[S3AuthSetting::role_arn],
        auth_settings[S3AuthSetting::role_session_name],
        /*sts_endpoint_override=*/""
    };

    String access_key_id = auth_settings[S3AuthSetting::access_key_id];
    String secret_access_key = auth_settings[S3AuthSetting::secret_access_key];
    String session_token = auth_settings[S3AuthSetting::session_token];

    auto updated_credentials = refresh_credentials_callback();
    if (updated_credentials)
    {
        auto s3_updated_credentials = std::static_pointer_cast<DataLake::S3Credentials>(updated_credentials);
        access_key_id = s3_updated_credentials->getAccessKeyId();
        secret_access_key = s3_updated_credentials->getSecretAccessKey();
        session_token = s3_updated_credentials->getSessionToken();
        LOG_DEBUG(getLogger("getClient"), "Got new access tokens {} {} {}", access_key_id, secret_access_key, session_token);
    }
    return S3::ClientFactory::instance().create(
        client_configuration,
        client_settings,
        access_key_id,
        secret_access_key,
        auth_settings[S3AuthSetting::server_side_encryption_customer_key_base64],
        auth_settings.server_side_encryption_kms_config,
        auth_settings.getHeaders(),
        credentials_configuration,
        session_token);
}

}

#endif


Review comment (performance):
Let's use dynamic_cast and assert it it not null (not a performance critical place)

Code after:
    S3::ClientSettings client_settings{
        .use_virtual_addressing = url.is_virtual_hosted_style,
        .disable_checksum = auth_settings[S3AuthSetting::disable_checksum],
        .gcs_issue_compose_request = auth_settings[S3AuthSetting::gcs_issue_compose_request],
        .is_s3express_bucket = is_s3_express_bucket
    };

    auto credentials_configuration = S3::CredentialsConfiguration
    {
        auth_settings[S3AuthSetting::use_environment_credentials],
        auth_settings[S3AuthSetting::use_insecure_imds_request],
        auth_settings[S3AuthSetting::expiration_window_seconds],
        auth_settings[S3AuthSetting::no_sign_request],
        auth_settings[S3AuthSetting::role_arn],
        auth_settings[S3AuthSetting::role_session_name],
        /*sts_endpoint_override=*/""
    };

    String access_key_id = auth_settings[S3AuthSetting::access_key_id];
    String secret_access_key = auth_settings[S3AuthSetting::secret_access_key];
    String session_token = auth_settings[S3AuthSetting::session_token];

    if (refresh_credentials_callback)
    {
        auto updated_credentials = (*refresh_credentials_callback)();
        if (updated_credentials)
        {
            auto s3_updated_credentials = std::static_pointer_cast<DataLake::S3Credentials>(updated_credentials);
            access_key_id = s3_updated_credentials->getAccessKeyId();
            secret_access_key = s3_updated_credentials->getSecretAccessKey();
            session_token = s3_updated_credentials->getSessionToken();
            LOG_DEBUG(getLogger("getClient"), "Got new access tokens {} {} {}", access_key_id, secret_access_key, session_token);
        }
    }
    return S3::ClientFactory::instance().create(
        client_configuration,
        client_settings,
        access_key_id,
        secret_access_key,
        auth_settings[S3AuthSetting::server_side_encryption_customer_key_base64],
        auth_settings.server_side_encryption_kms_config,
        auth_settings.getHeaders(),
        credentials_configuration,
        session_token);
}

}

#endif