App-Sqitch
view release on metacpan or search on metacpan
lib/App/Sqitch/Engine/clickhouse.pm view on Meta::CPAN
package App::Sqitch::Engine::clickhouse;
use 5.010;
use strict;
use warnings;
use utf8;
use Try::Tiny;
use App::Sqitch::X qw(hurl);
use Locale::TextDomain qw(App-Sqitch);
use App::Sqitch::Plan::Change;
use Path::Class;
use Scalar::Util qw(looks_like_number);
use Moo;
use App::Sqitch::Types qw(DBH URIDB ArrayRef Str HashRef);
use namespace::autoclean;
use List::MoreUtils qw(firstidx);
extends 'App::Sqitch::Engine';
our $VERSION = 'v1.6.1'; # VERSION
has uri => (
is => 'ro',
isa => URIDB,
lazy => 1,
default => \&_setup_uri,
);
sub _setup_uri {
my $self = shift;
my $uri = $self->SUPER::uri;
my $cfg = $self->_clickcnf;
if (!$uri->host && (my $host = $ENV{CLICKHOUSE_HOST} || $cfg->{host})) {
$uri->host($host);
}
if (!$uri->dbname && (my $db = $cfg->{database})) {
$uri->dbname($db);
}
# Use HTTPS port if CLI using native TLS port.
# https://clickhouse.com/docs/guides/sre/network-ports
$uri->port(8443) if !$uri->_port && ($cfg->{port} || 0) == 9440;
# Always require secure connections when required.
# https://github.com/ClickHouse/ClickHouse/blob/faf6d05/src/Client/ConnectionParameters.cpp#L27-L43
if (
$cfg->{secure}
|| ($cfg->{port} || 0) == 9440 # assume both native and http should be secure or not.
|| ($uri->host || '') =~ /\.clickhouse(?:-staging)?\.cloud\z/
) {
$uri->query_param( SSLMode => 'require' )
unless $uri->query_param( 'SSLMode' );
}
# Add ODBC params for TLS configs.
# https://clickhouse.com/docs/operations/server-configuration-parameters/settings
# https://github.com/clickHouse/clickhouse-odbc?tab=readme-ov-file#configuration
if ( my $tls = $cfg->{tls} ) {
for my $map (
[ privateKeyFile => 'PrivateKeyFile' ],
[ certificateFile => 'CertificateFile' ],
[ caConfig => 'CALocation' ],
) {
if ( my $val = $tls->{ $map->[0] } ) {
if ( my $p = $uri->query_param( $map->[1] ) ) {
# Ideally the ODBC param would override the config,
# bug there is currently no way to pass TLS options to
# the CLI.
hurl engine => __x(
'Client config {cfg_key} value "{cfg_val}" conflicts with ODBC param {odb_param} value "{odbc_val}"',
cfg_key => "openSSL.client.$map->[0]",
cfg_val => $val,
odbc_param => $map->[1],
odbc_val => $p,
) if $p ne $val;
( run in 0.901 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )