File tree 3 files changed +41
-0
lines changed
3 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ Unreleased
11
11
HTTP by default. Previously, this setting defaulted to false. This setting
12
12
can be changed via the ``verify_ssl_cert`` connection parameter.
13
13
14
+ - Adjusted connect arguments to accept credentials within the HTTP URI.
15
+
14
16
2020/09/28 0.26.0
15
17
=================
16
18
Original file line number Diff line number Diff line change @@ -47,13 +47,36 @@ connect::
47
47
48
48
>>> connection = client.connect([crate_host],
49
49
... username='trusted_me')
50
+ >>> connection.client.username
51
+ 'trusted_me'
52
+ >>> connection.client.password
53
+
54
+ The username for trusted users can also be provided in the URL::
55
+
56
+ >>> connection = client.connect(['http://trusted_me@' + crate_host])
57
+ >>> connection.client.username
58
+ 'trusted_me'
59
+ >>> connection.client.password
50
60
51
61
To connect to CrateDB with as a user that requires password authentication, you
52
62
also need to provide ``password`` as argument for the ``connect()`` call::
53
63
54
64
>>> connection = client.connect([crate_host],
55
65
... username='me',
56
66
... password='my_secret_pw')
67
+ >>> connection.client.username
68
+ 'me'
69
+ >>> connection.client.password
70
+ 'my_secret_pw'
71
+
72
+ The authentication credentials can also be provided in the URL::
73
+
74
+ >>> connection = client.connect(['http://me:my_secret_pw@' + crate_host])
75
+ >>> connection.client.username
76
+ 'me'
77
+ >>> connection.client.password
78
+ 'my_secret_pw'
79
+
57
80
58
81
Default Schema
59
82
--------------
Original file line number Diff line number Diff line change @@ -346,6 +346,22 @@ def __init__(self,
346
346
servers = [self .default_server ]
347
347
else :
348
348
servers = _to_server_list (servers )
349
+
350
+ # Try to derive credentials from first server argument if not
351
+ # explicitly given.
352
+ if servers and not username :
353
+ try :
354
+ url = urlparse (servers [0 ])
355
+ if url .username is not None :
356
+ username = url .username
357
+ if url .password is not None :
358
+ password = url .password
359
+ except Exception as ex :
360
+ logger .warning ("Unable to decode credentials from database "
361
+ "URI, so connecting to CrateDB without "
362
+ "authentication: {ex}"
363
+ .format (ex = ex ))
364
+
349
365
self ._active_servers = servers
350
366
self ._inactive_servers = []
351
367
pool_kw = _pool_kw_args (
You can’t perform that action at this time.
0 commit comments