getAuth retrieves auth credentials from request according to CH documentation @see "https://clickhouse.yandex/docs/en/interfaces/http/"
(req *http.Request)
| 26 | // getAuth retrieves auth credentials from request |
| 27 | // according to CH documentation @see "https://clickhouse.yandex/docs/en/interfaces/http/" |
| 28 | func getAuth(req *http.Request) (string, string) { |
| 29 | // check X-ClickHouse- headers |
| 30 | name := req.Header.Get("X-ClickHouse-User") |
| 31 | pass := req.Header.Get("X-ClickHouse-Key") |
| 32 | if name != "" { |
| 33 | return name, pass |
| 34 | } |
| 35 | // if header is empty - check basicAuth |
| 36 | if name, pass, ok := req.BasicAuth(); ok { |
| 37 | return name, pass |
| 38 | } |
| 39 | // if basicAuth is empty - check URL params `user` and `password` |
| 40 | params := req.URL.Query() |
| 41 | if name := params.Get("user"); name != "" { |
| 42 | pass := params.Get("password") |
| 43 | return name, pass |
| 44 | } |
| 45 | // if still no credentials - treat it as `default` user request |
| 46 | return defaultUser, "" |
| 47 | } |
| 48 | |
| 49 | // getSessionId retrieves session id |
| 50 | func getSessionId(req *http.Request) string { |