Legoktm has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/375501 )

Change subject: Add a script to rotate the Gerrit HTTP password
......................................................................

Add a script to rotate the Gerrit HTTP password

Change-Id: I1468b99e404ede9c22caac92b1d391342a373383
---
A change_password.py
1 file changed, 61 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/labs/libraryupgrader 
refs/changes/01/375501/1

diff --git a/change_password.py b/change_password.py
new file mode 100755
index 0000000..795aa0b
--- /dev/null
+++ b/change_password.py
@@ -0,0 +1,61 @@
+#!/usr/bin/env python3
+"""
+Resets a Gerrit account's HTTP password
+Copyright (C) 2017 Kunal Mehta <lego...@member.fsf.org>
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU Affero General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU Affero General Public License for more details.
+
+You should have received a copy of the GNU Affero General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+"""
+
+import json
+import getpass
+import requests
+from requests.auth import HTTPDigestAuth
+import sys
+
+import upgrade
+
+s = requests.Session()
+
+
+def gerrit_request(method, path, **kwargs):
+    r = s.request(method, 'https://gerrit.wikimedia.org/r/a/' + path, **kwargs)
+    r.raise_for_status()
+
+    return json.loads(r.text[4:])
+
+
+def main():
+    pw = getpass.getpass('HTTP Password for %s: ' % upgrade.GERRIT_USER)
+    auth = HTTPDigestAuth('libraryupgrader', pw)
+    # Check that we're logged in as the right user
+    account = gerrit_request('GET', path='accounts/self', auth=auth)
+    if account['username'] != upgrade.GERRIT_USER:
+        print('Error, logged in as %(username)s (%(email)s)??' % account)
+        sys.exit(1)
+    print('Successfully logged in as %(username)s' % account)
+    new_password = gerrit_request(
+        'PUT',
+        path='accounts/self/password.http',
+        auth=auth,
+        data=json.dumps({'generate': True}),
+        headers={'Content-Type': 'application/json'}
+    )
+    print('The following is your new HTTP password, please save it:')
+    print('----------')
+    print(new_password)
+    print('----------')
+
+
+if __name__ == '__main__':
+    main()

-- 
To view, visit https://gerrit.wikimedia.org/r/375501
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1468b99e404ede9c22caac92b1d391342a373383
Gerrit-PatchSet: 1
Gerrit-Project: labs/libraryupgrader
Gerrit-Branch: master
Gerrit-Owner: Legoktm <lego...@member.fsf.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to