MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / readArguments

Method readArguments

programs/client/Client.cpp:1113–1360  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1111
1112
1113void Client::readArguments(
1114 int argc,
1115 char ** argv,
1116 Arguments & common_arguments,
1117 std::vector<Arguments> & external_tables_arguments,
1118 std::vector<Arguments> & hosts_and_ports_arguments)
1119{
1120 // Default to oauth authentication for ClickHouse Cloud for a hostname argument.
1121 bool is_hostname_argument = false;
1122#if USE_JWT_CPP && USE_SSL
1123 if (argc >= 2)
1124 {
1125 std::string_view first_arg(argv[1]);
1126
1127 /// Only process as positional hostname if it doesn't start with '-' (i.e., it's not a flag)
1128 if (!first_arg.starts_with('-'))
1129 {
1130 std::string hostname(argv[1]);
1131 std::string port;
1132 bool has_auth_in_connection_string = false;
1133
1134 try
1135 {
1136 Poco::URI uri{hostname};
1137 if (const auto & host = uri.getHost(); !host.empty())
1138 {
1139 hostname = host;
1140 port = std::to_string(uri.getPort());
1141 }
1142 /// Check if connection string contains user credentials (e.g., clickhouse://user:password@host)
1143 has_auth_in_connection_string = !uri.getUserInfo().empty();
1144 }
1145 catch (const Poco::URISyntaxException &) // NOLINT(bugprone-empty-catch)
1146 {
1147 // intentionally ignored. argv[1] is not a uri, but could be a query.
1148 }
1149
1150 if (isCloudEndpoint(hostname) && !has_auth_in_connection_string)
1151 {
1152 is_hostname_argument = true;
1153
1154 /// Check if user provided authentication credentials via command line
1155 bool has_auth_in_cmdline = false;
1156 for (int i = 1; i < argc; ++i)
1157 {
1158 std::string_view arg(argv[i]);
1159 if (arg.starts_with("--user") || arg.starts_with("--password") ||
1160 arg.starts_with("--jwt") || arg.starts_with("--ssh-key-file") ||
1161 arg == "-u")
1162 {
1163 has_auth_in_cmdline = true;
1164 break;
1165 }
1166 }
1167
1168 /// Only auto-add --login if no authentication credentials provided via command line or connection string
1169 if (!has_auth_in_cmdline && !has_auth_in_connection_string)
1170 {

Callers

nothing calls this directly

Calls 15

isCloudEndpointFunction · 0.85
tryParseConnectionStringFunction · 0.85
string_viewClass · 0.85
getHostMethod · 0.80
getUserInfoMethod · 0.80
to_stringFunction · 0.50
ExceptionClass · 0.50
StringClass · 0.50
emptyMethod · 0.45
getPortMethod · 0.45
emplace_backMethod · 0.45

Tested by

no test coverage detected