lbalhar / rpms / bodhi

Forked from rpms/bodhi 6 years ago
Clone
Blob Blame History Raw
From c1daa729abf92a421c28fe0a07a81230b473271d Mon Sep 17 00:00:00 2001
From: Randy Barlow <randy@electronsweatshop.com>
Date: Thu, 2 Nov 2017 23:01:36 -0400
Subject: [PATCH] Use FAS_USERNAME instead of USERNAME for determining the fas
 user.

The Bodhi CLI used to use the USERNAME environment variable, if
set, to know the FAS account of the user. This is problematic for
GDM users who use a different username on their local computers
than they use in FAS.

To solve this, upstream Bodhi removed support for the environment
variable entirely:

https://github.com/fedora-infra/bodhi/issues/1789

This patch is for bodhi-2 clients. Though it is also
backwards-incompatible, it will allow users to continue using an
environment variable, which makes it ever so slightly less
incompatible.

Signed-off-by: Randy Barlow <randy@electronsweatshop.com>
---
 bodhi/client/__init__.py            | 16 ++++++++--------
 bodhi/tests/client/test___init__.py | 12 ++++++------
 docs/man_pages/bodhi.rst            |  4 ++--
 3 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/bodhi/client/__init__.py b/bodhi/client/__init__.py
index d42b436b..407979f4 100644
--- a/bodhi/client/__init__.py
+++ b/bodhi/client/__init__.py
@@ -52,7 +52,7 @@ url_option = click.option('--url', envvar='BODHI_URL', default=bindings.BASE_URL
 
 
 new_edit_options = [
-    click.option('--user', envvar='USERNAME'),
+    click.option('--user', envvar='FAS_USERNAME'),
     click.option('--password', hide_input=True),
     click.option('--type', default='bugfix', help='Update type', required=True,
                  type=click.Choice(['security', 'bugfix', 'enhancement', 'newpackage'])),
@@ -80,7 +80,7 @@ save_edit_options = [
                  help='Number of days the override should exist.'),
     click.option('--notes', default="No explanation given...",
                  help='Notes on why this override is in place.'),
-    click.option('--user', envvar='USERNAME'),
+    click.option('--user', envvar='FAS_USERNAME'),
     click.option('--password', hide_input=True),
     click.option('--staging', help='Use the staging bodhi instance',
                  is_flag=True, default=False),
@@ -327,8 +327,8 @@ def query(url, mine=False, **kwargs):
     """
     client = bindings.BodhiClient(base_url=url, staging=kwargs['staging'])
     if mine:
-        if 'USERNAME' in os.environ:
-            kwargs['user'] = os.environ['USERNAME']
+        if 'FAS_USERNAME' in os.environ:
+            kwargs['user'] = os.environ['FAS_USERNAME']
         else:
             client.init_username()
             kwargs['user'] = client.username
@@ -339,7 +339,7 @@ def query(url, mine=False, **kwargs):
 @updates.command()
 @click.argument('update')
 @click.argument('state')
-@click.option('--user', envvar='USERNAME')
+@click.option('--user', envvar='FAS_USERNAME')
 @click.option('--password', hide_input=True)
 @click.option('--staging', help='Use the staging bodhi instance',
               is_flag=True, default=False)
@@ -386,7 +386,7 @@ def request(update, state, user, password, url, **kwargs):
 @click.argument('update')
 @click.argument('text')
 @click.option('--karma', default=0, type=click.INT, help='The karma for this comment (+1/0/-1)')
-@click.option('--user', envvar='USERNAME')
+@click.option('--user', envvar='FAS_USERNAME')
 @click.option('--password', hide_input=True)
 @click.option('--staging', help='Use the staging bodhi instance',
               is_flag=True, default=False)
@@ -562,8 +562,8 @@ def query_buildroot_overrides(url, user=None, mine=False, packages=None,
     """
     client = bindings.BodhiClient(base_url=url, staging=kwargs['staging'])
     if mine:
-        if 'USERNAME' in os.environ:
-            user = os.environ['USERNAME']
+        if 'FAS_USERNAME' in os.environ:
+            user = os.environ['FAS_USERNAME']
         else:
             client.init_username()
             user = client.username
diff --git a/bodhi/tests/client/test___init__.py b/bodhi/tests/client/test___init__.py
index 20b54f66..977f8007 100644
--- a/bodhi/tests/client/test___init__.py
+++ b/bodhi/tests/client/test___init__.py
@@ -163,14 +163,14 @@ class TestQuery(unittest.TestCase):
                 'cves': None})
         self.assertEqual(bindings_client.base_url, 'http://localhost:6543/')
 
-    @mock.patch.dict('os.environ', {'USERNAME': 'dudemcpants'})
+    @mock.patch.dict('os.environ', {'FAS_USERNAME': 'dudemcpants'})
     @mock.patch('bodhi.client.bindings.BodhiClient.csrf',
                 mock.MagicMock(return_value='a_csrf_token'))
     @mock.patch('bodhi.client.bindings.BodhiClient.send_request',
                 return_value=client_test_data.EXAMPLE_UPDATE_MUNCH, autospec=True)
     def test_query_mine_flag_username_set(self, send_request):
         """
-        Assert that we use the USERNAME variable if it is set
+        Assert that we use the FAS_USERNAME variable if it is set
         """
         runner = testing.CliRunner()
 
@@ -195,7 +195,7 @@ class TestQuery(unittest.TestCase):
     @mock.patch('__builtin__.raw_input', create=True)
     def test_query_mine_flag_username_unset(self, mock_raw_input, send_request):
         """
-        Assert that we use init_username if USERNAME is not set
+        Assert that we use init_username if FAS_USERNAME is not set
         """
         mock_raw_input.return_value = 'dudemcpants'
         runner = testing.CliRunner()
@@ -241,14 +241,14 @@ class TestQueryBuildrootOverrides(unittest.TestCase):
             params={'user': u'bowlofeggs'})
         self.assertEqual(bindings_client.base_url, 'http://localhost:6543/')
 
-    @mock.patch.dict('os.environ', {'USERNAME': 'dudemcpants'})
+    @mock.patch.dict('os.environ', {'FAS_USERNAME': 'dudemcpants'})
     @mock.patch('bodhi.client.bindings.BodhiClient.csrf',
                 mock.MagicMock(return_value='a_csrf_token'))
     @mock.patch('bodhi.client.bindings.BodhiClient.send_request',
                 return_value=client_test_data.EXAMPLE_UPDATE_MUNCH, autospec=True)
     def test_queryoverrides_mine_flag_username_set(self, send_request):
         """
-        Assert that we use the USERNAME variable if it is set
+        Assert that we use the FAS_USERNAME variable if it is set
         """
         runner = testing.CliRunner()
 
@@ -264,7 +264,7 @@ class TestQueryBuildrootOverrides(unittest.TestCase):
     @mock.patch('__builtin__.raw_input', create=True)
     def test_queryoverrides_mine_flag_username_unset(self, mock_raw_input, send_request):
         """
-        Assert that we use init_username if USERNAME is not set
+        Assert that we use init_username if FAS_USERNAME is not set
         """
         mock_raw_input.return_value = 'dudemcpants'
         runner = testing.CliRunner()
diff --git a/docs/man_pages/bodhi.rst b/docs/man_pages/bodhi.rst
index fb4b5893..d89ceeee 100644
--- a/docs/man_pages/bodhi.rst
+++ b/docs/man_pages/bodhi.rst
@@ -40,10 +40,10 @@ Most of the commands will accept these options:
 ``--user <username>``
 
     Many commands accept this flag to specify a Fedora username to authenticate with. The
-    username can also be provided via the ``USERNAME`` environment variable. Note that some read
+    username can also be provided via the ``FAS_USERNAME`` environment variable. Note that some read
     operations such as querying updates and overrides use this same flag, but as a search parameter
     instead of authentication (as authentication is not required for these operations). Those
-    operations do not use the ``USERNAME`` environment variable.
+    operations do not use the ``FAS_USERNAME`` environment variable.
 
 ``--version``
 
-- 
2.14.2