Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7ac1e4c

Browse files
author
Gauvain Pocentek
committed
Deprecate parameter related methods in gitlab.Gitlab
These methods change the auth information and URL, and might have someunwanted side effects.Users should create a new Gitlab instance to change the URL andauthentication information.
1 parentce3dd0d commit7ac1e4c

File tree

3 files changed

+52
-33
lines changed

3 files changed

+52
-33
lines changed

‎RELEASE_NOTES.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@ Release notes
44

55
This page describes important changes between python-gitlab releases.
66

7+
Changes from 0.20 to 0.21
8+
=========================
9+
10+
* Several methods have been deprecated in the ``gitlab.Gitlab`` class:
11+
12+
+ ``credentials_auth()`` is deprecated and will be removed. Call ``auth()``.
13+
+ ``token_auth()`` is deprecated and will be removed. Call ``auth()``.
14+
+ ``set_url()`` is deprecated, create a new ``Gitlab`` instance if you need
15+
an updated URL.
16+
+ ``set_token()`` is deprecated, use the ``private_token`` argument of the
17+
``Gitlab`` constructor.
18+
+ ``set_credentials()`` is deprecated, use the ``email`` and ``password``
19+
arguments of the ``Gitlab`` constructor.
20+
721
Changes from 0.19 to 0.20
822
=========================
923

‎gitlab/__init__.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def __init__(self, url, private_token=None, email=None, password=None,
7676
self.timeout=timeout
7777
#: Headers that will be used in request to GitLab
7878
self.headers= {}
79-
self.set_token(private_token)
79+
self._set_token(private_token)
8080
#: The user email
8181
self.email=email
8282
#: The user password (associated with email)
@@ -163,12 +163,17 @@ def auth(self):
163163
success.
164164
"""
165165
ifself.private_token:
166-
self.token_auth()
166+
self._token_auth()
167167
else:
168-
self.credentials_auth()
168+
self._credentials_auth()
169169

170170
defcredentials_auth(self):
171171
"""Performs an authentication using email/password."""
172+
warnings.warn('credentials_auth() is deprecated and will be removed.',
173+
DeprecationWarning)
174+
self._credentials_auth()
175+
176+
def_credentials_auth(self):
172177
ifnotself.emailornotself.password:
173178
raiseGitlabAuthenticationError("Missing email/password")
174179

@@ -179,7 +184,16 @@ def credentials_auth(self):
179184
"""(gitlab.objects.CurrentUser): Object representing the user currently
180185
logged.
181186
"""
182-
self.set_token(self.user.private_token)
187+
self._set_token(self.user.private_token)
188+
189+
deftoken_auth(self):
190+
"""Performs an authentication using the private token."""
191+
warnings.warn('token_auth() is deprecated and will be removed.',
192+
DeprecationWarning)
193+
self._token_auth()
194+
195+
def_token_auth(self):
196+
self.user=CurrentUser(self)
183197

184198
defversion(self):
185199
"""Returns the version and revision of the gitlab server.
@@ -202,16 +216,15 @@ def version(self):
202216

203217
returnself.version,self.revision
204218

205-
deftoken_auth(self):
206-
"""Performs an authentication using the private token."""
207-
self.user=CurrentUser(self)
208-
209219
defset_url(self,url):
210220
"""Updates the GitLab URL.
211221
212222
Args:
213223
url (str): Base URL of the GitLab server.
214224
"""
225+
warnings.warn('set_url() is deprecated, create a new Gitlab instance '
226+
'if you need an updated URL.',
227+
DeprecationWarning)
215228
self._url='%s/api/v3'%url
216229

217230
def_construct_url(self,id_,obj,parameters,action=None):
@@ -244,6 +257,12 @@ def set_token(self, token):
244257
Args:
245258
token (str): The private token.
246259
"""
260+
warnings.warn('set_token() is deprecated, use the private_token '
261+
'argument of the Gitlab constructor.',
262+
DeprecationWarning)
263+
self._set_token(token)
264+
265+
def_set_token(self,token):
247266
self.private_token=tokeniftokenelseNone
248267
iftoken:
249268
self.headers["PRIVATE-TOKEN"]=token
@@ -257,6 +276,9 @@ def set_credentials(self, email, password):
257276
email (str): The user email or login.
258277
password (str): The user password.
259278
"""
279+
warnings.warn('set_credentials() is deprecated, use the email and '
280+
'password arguments of the Gitlab constructor.',
281+
DeprecationWarning)
260282
self.email=email
261283
self.password=password
262284

‎gitlab/tests/test_gitlab.py

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ def test_list_kw_missing(self):
341341
self.assertRaises(GitlabListError,self.gl.list,ProjectBranch)
342342

343343
deftest_list_no_connection(self):
344-
self.gl.set_url('http://localhost:66000')
344+
self.gl._url='http://localhost:66000/api/v3'
345345
self.assertRaises(GitlabConnectionError,self.gl.list,ProjectBranch,
346346
project_id=1)
347347

@@ -613,27 +613,10 @@ def setUp(self):
613613
email="testuser@test.com",password="testpassword",
614614
ssl_verify=True)
615615

616-
deftest_set_url(self):
617-
self.gl.set_url("http://new_url")
618-
self.assertEqual(self.gl._url,"http://new_url/api/v3")
619-
620-
deftest_set_token(self):
621-
token="newtoken"
622-
expected= {"PRIVATE-TOKEN":token}
623-
self.gl.set_token(token)
624-
self.assertEqual(self.gl.private_token,token)
625-
self.assertDictContainsSubset(expected,self.gl.headers)
626-
627-
deftest_set_credentials(self):
628-
email="credentialuser@test.com"
629-
password="credentialpassword"
630-
self.gl.set_credentials(email=email,password=password)
631-
self.assertEqual(self.gl.email,email)
632-
self.assertEqual(self.gl.password,password)
633-
634616
deftest_credentials_auth_nopassword(self):
635-
self.gl.set_credentials(email=None,password=None)
636-
self.assertRaises(GitlabAuthenticationError,self.gl.credentials_auth)
617+
self.gl.email=None
618+
self.gl.password=None
619+
self.assertRaises(GitlabAuthenticationError,self.gl._credentials_auth)
637620

638621
deftest_credentials_auth_notok(self):
639622
@urlmatch(scheme="http",netloc="localhost",path="/api/v3/session",
@@ -645,18 +628,18 @@ def resp_cont(url, request):
645628

646629
withHTTMock(resp_cont):
647630
self.assertRaises(GitlabAuthenticationError,
648-
self.gl.credentials_auth)
631+
self.gl._credentials_auth)
649632

650633
deftest_auth_with_credentials(self):
651-
self.gl.set_token(None)
634+
self.gl.private_token=None
652635
self.test_credentials_auth(callback=self.gl.auth)
653636

654637
deftest_auth_with_token(self):
655638
self.test_token_auth(callback=self.gl.auth)
656639

657640
deftest_credentials_auth(self,callback=None):
658641
ifcallbackisNone:
659-
callback=self.gl.credentials_auth
642+
callback=self.gl._credentials_auth
660643
token="credauthtoken"
661644
id_=1
662645
expected= {"PRIVATE-TOKEN":token}
@@ -677,7 +660,7 @@ def resp_cont(url, request):
677660

678661
deftest_token_auth(self,callback=None):
679662
ifcallbackisNone:
680-
callback=self.gl.token_auth
663+
callback=self.gl._token_auth
681664
name="username"
682665
id_=1
683666

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp