@@ -62,7 +62,8 @@ class Gitlab(object):
62
62
ssl_verify (bool): Whether SSL certificates should be validated.
63
63
timeout (float or tuple(float,float)): Timeout to use for requests to
64
64
the GitLab server.
65
-
65
+ http_username: (str): Username for HTTP authentication
66
+ http_password: (str): Password for HTTP authentication
66
67
Attributes:
67
68
user_keys (UserKeyManager): Manager for GitLab users' SSH keys.
68
69
users (UserManager): Manager for GitLab users
@@ -108,8 +109,9 @@ class Gitlab(object):
108
109
teams (TeamManager): Manager for GitLab teams
109
110
"""
110
111
111
- def __init__ (self , url , private_token = None ,
112
- email = None , password = None , ssl_verify = True , timeout = None ):
112
+ def __init__ (self , url , private_token = None , email = None , password = None ,
113
+ ssl_verify = True , http_username = None , http_password = None ,
114
+ timeout = None ):
113
115
114
116
self ._url = '%s/api/v3' % url
115
117
#: Timeout to use for requests to gitlab server
@@ -123,6 +125,8 @@ def __init__(self, url, private_token=None,
123
125
self .password = password
124
126
#: Whether SSL certificates should be validated
125
127
self .ssl_verify = ssl_verify
128
+ self .http_username = http_username
129
+ self .http_password = http_password
126
130
127
131
#: Create a session object for requests
128
132
self .session = requests .Session ()
@@ -176,7 +180,9 @@ def from_config(gitlab_id=None, config_files=None):
176
180
config = gitlab .config .GitlabConfigParser (gitlab_id = gitlab_id ,
177
181
config_files = config_files )
178
182
return Gitlab (config .url , private_token = config .token ,
179
- ssl_verify = config .ssl_verify , timeout = config .timeout )
183
+ ssl_verify = config .ssl_verify , timeout = config .timeout ,
184
+ http_username = config .http_username ,
185
+ http_password = config .http_password )
180
186
181
187
def auth (self ):
182
188
"""Performs an authentication.
@@ -264,13 +270,15 @@ def set_credentials(self, email, password):
264
270
def _raw_get (self , path , content_type = None , ** kwargs ):
265
271
url = '%s%s' % (self ._url , path )
266
272
headers = self ._create_headers (content_type )
267
-
268
273
try :
269
274
return self .session .get (url ,
270
275
params = kwargs ,
271
276
headers = headers ,
272
277
verify = self .ssl_verify ,
273
- timeout = self .timeout )
278
+ timeout = self .timeout ,
279
+ auth = requests .auth .HTTPBasicAuth (
280
+ self .http_username ,
281
+ self .http_password ))
274
282
except Exception as e :
275
283
raise GitlabConnectionError (
276
284
"Can't connect to GitLab server (%s)" % e )
@@ -307,7 +315,10 @@ def _raw_post(self, path, data=None, content_type=None, **kwargs):
307
315
return self .session .post (url , params = kwargs , data = data ,
308
316
headers = headers ,
309
317
verify = self .ssl_verify ,
310
- timeout = self .timeout )
318
+ timeout = self .timeout ,
319
+ auth = requests .auth .HTTPBasicAuth (
320
+ self .http_username ,
321
+ self .http_password ))
311
322
except Exception as e :
312
323
raise GitlabConnectionError (
313
324
"Can't connect to GitLab server (%s)" % e )
@@ -320,7 +331,10 @@ def _raw_put(self, path, data=None, content_type=None, **kwargs):
320
331
return self .session .put (url , data = data , params = kwargs ,
321
332
headers = headers ,
322
333
verify = self .ssl_verify ,
323
- timeout = self .timeout )
334
+ timeout = self .timeout ,
335
+ auth = requests .auth .HTTPBasicAuth (
336
+ self .http_username ,
337
+ self .http_password ))
324
338
except Exception as e :
325
339
raise GitlabConnectionError (
326
340
"Can't connect to GitLab server (%s)" % e )
@@ -334,7 +348,10 @@ def _raw_delete(self, path, content_type=None, **kwargs):
334
348
params = kwargs ,
335
349
headers = headers ,
336
350
verify = self .ssl_verify ,
337
- timeout = self .timeout )
351
+ timeout = self .timeout ,
352
+ auth = requests .auth .HTTPBasicAuth (
353
+ self .http_username ,
354
+ self .http_password ))
338
355
except Exception as e :
339
356
raise GitlabConnectionError (
340
357
"Can't connect to GitLab server (%s)" % e )
@@ -374,11 +391,13 @@ def list(self, obj_class, **kwargs):
374
391
# Also remove the next-url attribute that make queries fail
375
392
if 'next_url' in params :
376
393
del params ['next_url' ]
377
-
378
394
try :
379
395
r = self .session .get (url , params = params , headers = headers ,
380
396
verify = self .ssl_verify ,
381
- timeout = self .timeout )
397
+ timeout = self .timeout ,
398
+ auth = requests .auth .HTTPBasicAuth (
399
+ self .http_username ,
400
+ self .http_password ))
382
401
except Exception as e :
383
402
raise GitlabConnectionError (
384
403
"Can't connect to GitLab server (%s)" % e )
@@ -445,7 +464,10 @@ def get(self, obj_class, id=None, **kwargs):
445
464
446
465
try :
447
466
r = self .session .get (url , params = params , headers = headers ,
448
- verify = self .ssl_verify , timeout = self .timeout )
467
+ verify = self .ssl_verify , timeout = self .timeout ,
468
+ auth = requests .auth .HTTPBasicAuth (
469
+ self .http_username ,
470
+ self .http_password ))
449
471
except Exception as e :
450
472
raise GitlabConnectionError (
451
473
"Can't connect to GitLab server (%s)" % e )
0 commit comments