nikepan / clickhouse-bulk

Collects many small inserts to ClickHouse and send in big inserts
Apache License 2.0
474 stars 86 forks source link

Doesn't work with the phpClickHouse client #27

Open ghgugle opened 4 years ago

ghgugle commented 4 years ago

When doing request using the following lib https://github.com/smi2/phpClickHouse which is the best one at the moment. It seems like the clickhouse-bulk except auth config via query param, but the new version of the phpClickHouse lib is using authorization via headers.

Unfortunately the phpClickHouse doesn't provide a way to send custom query param so I can do a workaround to add username/password to query string too.

Is there any solution for this? Or could you update the lib to except the param via new way also.

The one of the official auth methods of Clickhouse is with headers: X-ClickHouse-Key, X-ClickHouse-User

Here all options:

  1. Using HTTP Basic Authentication. Example: $ echo 'SELECT 1' | curl 'http://user:password@localhost:8123/' -d @-
  2. In the ‘user’ and ‘password’ URL parameters. Example: $ echo 'SELECT 1' | curl 'http://localhost:8123/?user=user&password=password' -d @-
  3. Using ‘X-ClickHouse-User’ and ‘X-ClickHouse-Key’ headers. Example: $ echo 'SELECT 1' | curl -H 'X-ClickHouse-User: user' -H 'X-ClickHouse-Key: password' 'http://localhost:8123/' -d @-

https://clickhouse.tech/docs/en/interfaces/http/

a110ut commented 3 years ago

Actually phpClickHouse provides several ways to authorize. See https://github.com/smi2/phpClickHouse/blob/1.4.1/README.md#auth-methods

With "HTTP Basic Authentication" your config should be like this:

$config = [
    'host' => '127.0.0.1',
    'port' => '8124',
    'auth_method' => \ClickHouseDB\Transport\Http::AUTH_METHOD_BASIC_AUTH,
    'username' => '...',
    'password' => '...',
];