Repository: softlayer/softlayer-python
Pull request #2073 (2023-08-10 07:29:02)

Added new slcli user vpn-disable and slcli user vpn-enable command 
Hi @allmightyspiff,

Fixes: #2069 

**Title:**
new slcli user vpn-enable command 

**Description:**
I have added new features `slcli user vpn-disable` and `slcli user vpn-enable` commands.

I have **tested** it.

Please **review** it.

Please find the screen shots.

**Screen Shot: 1**
<img width="745" alt="Screenshot 2023-08-09 at 8 21 07 PM" src="https://github.com/softlayer/softlayer-python/assets/125332006/48023c35-3ad1-4985-8236-2b326e66916b">

**Screen Shot: 2**
<img width="678" alt="Screenshot 2023-08-09 at 8 22 33 PM" src="https://github.com/softlayer/softlayer-python/assets/125332006/a45bc21d-8cef-487c-87ba-b23be82628f6">

Thanks,
Ramkishor Chaladi.


Patch:
diff --git a/SoftLayer/CLI/routes.py b/SoftLayer/CLI/routes.py
index 54c1deaa..dbaf1cfe 100644
--- a/SoftLayer/CLI/routes.py
+++ b/SoftLayer/CLI/routes.py
@@ -403,6 +403,8 @@
     ('user:device-access', 'SoftLayer.CLI.user.device_access:cli'),
     ('user:vpn-manual', 'SoftLayer.CLI.user.vpn_manual:cli'),
     ('user:vpn-subnet', 'SoftLayer.CLI.user.vpn_subnet:cli'),
+    ('user:vpn-enable', 'SoftLayer.CLI.user.vpn_enable_or_disable:vpn_enable'),
+    ('user:vpn-disable', 'SoftLayer.CLI.user.vpn_enable_or_disable:vpn_disable'),
     ('user:remove-access', 'SoftLayer.CLI.user.remove_access:cli'),
     ('user:grant-access', 'SoftLayer.CLI.user.grant_access:cli'),
     ('user:vpn-password', 'SoftLayer.CLI.user.vpn_password:cli'),
diff --git a/SoftLayer/CLI/user/vpn_enable_or_disable.py b/SoftLayer/CLI/user/vpn_enable_or_disable.py
new file mode 100644
index 00000000..2e8216d2
--- /dev/null
+++ b/SoftLayer/CLI/user/vpn_enable_or_disable.py
@@ -0,0 +1,49 @@
+"""Enable or Disable vpn for a user."""
+# :license: MIT, see LICENSE for more details.
+
+
+import click
+
+import SoftLayer
+from SoftLayer.CLI import environment
+from SoftLayer.CLI import helpers
+
+
+@click.command(cls=SoftLayer.CLI.command.SLCommand, )
+@click.argument('user')
+@environment.pass_env
+def vpn_enable(env, user):
+    """Enable vpn for a user.
+
+    Example::
+        slcli user vpn-enable 1234567
+    """
+
+    mgr = SoftLayer.UserManager(env.client)
+    user_id = helpers.resolve_id(mgr.resolve_ids, user, 'username')
+
+    result = mgr.vpn_enable_or_disable(user_id, True)
+    message = f"{user} vpn is successfully enabled"
+
+    if result:
+        click.secho(message, fg='green')
+
+
+@click.command(cls=SoftLayer.CLI.command.SLCommand, )
+@click.argument('user')
+@environment.pass_env
+def vpn_disable(env, user):
+    """Disable vpn for a user.
+
+    Example::
+        slcli user vpn-disable 1234567
+    """
+
+    mgr = SoftLayer.UserManager(env.client)
+    user_id = helpers.resolve_id(mgr.resolve_ids, user, 'username')
+
+    result = mgr.vpn_enable_or_disable(user_id, False)
+    message = f"{user} vpn is successfully disabled"
+
+    if result:
+        click.secho(message, fg='green')
diff --git a/SoftLayer/managers/user.py b/SoftLayer/managers/user.py
index 6682c0cf..cafdf1b8 100644
--- a/SoftLayer/managers/user.py
+++ b/SoftLayer/managers/user.py
@@ -361,6 +361,17 @@ def vpn_manual(self, user_id, value):
         user_object = {'vpnManualConfig': value}
         return self.edit_user(user_id, user_object)
 
+    def vpn_enable_or_disable(self, user_id, value):
+        """Enable or Disable vpn for a user.
+
+        :param int user_id: User to edit.
+        :param bool value: Value for vpn enable flag.
+        or
+        :param bool value: Value for vpn disable flag.
+        """
+        user_object = {'sslVpnAllowedFlag': value}
+        return self.edit_user(user_id, user_object)
+
     def vpn_subnet_add(self, user_id, subnet_ids):
         """Add subnets for a user.
 
diff --git a/docs/cli/users.rst b/docs/cli/users.rst
index e3d45bb1..af86b4a9 100644
--- a/docs/cli/users.rst
+++ b/docs/cli/users.rst
@@ -64,6 +64,14 @@ Version 5.6.0 introduces the ability to interact with user accounts from the cli
     :prog: user vpn-password
     :show-nested:
 
+.. click:: SoftLayer.CLI.user.vpn_enable_or_disable:vpn_enable
+    :prog: user vpn-enable
+    :show-nested:
+
+.. click:: SoftLayer.CLI.user.vpn_enable_or_disable:vpn_disable
+    :prog: user vpn-disable
+    :show-nested:
+
 .. click:: SoftLayer.CLI.user.apikey:cli
     :prog: user apikey
     :show-nested:


Test patch:
diff --git a/tests/CLI/modules/user_tests.py b/tests/CLI/modules/user_tests.py
index 02956e68..804c9ef1 100644
--- a/tests/CLI/modules/user_tests.py
+++ b/tests/CLI/modules/user_tests.py
@@ -8,10 +8,9 @@
 import sys
 import unittest
 
-from unittest import mock as mock
-
 from SoftLayer.fixtures import SoftLayer_User_Customer
 from SoftLayer import testing
+from unittest import mock as mock
 
 
 class UserCLITests(testing.TestCase):
@@ -416,3 +415,27 @@ def test_remove_api_authentication_key(self):
     def test_refresh_api_authentication_key(self):
         result = self.run_command(['user', 'apikey', '123456', '--refresh'])
         self.assert_no_fail(result)
+
+    def test_vpn_disable(self):
+        result = self.run_command(['user', 'vpn-disable', '8344458'])
+        self.assert_no_fail(result)
+        self.assert_called_with('SoftLayer_User_Customer', 'editObject', identifier=8344458)
+
+        result = self.run_command(['user', 'vpn-disable', '8344458'])
+        permission_m = self.set_mock('SoftLayer_User_Customer', 'editObject')
+        permission_m.return_value = {'sslVpnAllowedFlag': False}
+        self.assert_no_fail(result)
+        self.assert_called_with('SoftLayer_User_Customer', 'editObject', identifier=8344458)
+        self.assertEqual('8344458 vpn is successfully disabled\n', result.output)
+
+    def test_vpn_enable(self):
+        result = self.run_command(['user', 'vpn-enable', '8344458'])
+        self.assert_no_fail(result)
+        self.assert_called_with('SoftLayer_User_Customer', 'editObject', identifier=8344458)
+
+        result = self.run_command(['user', 'vpn-enable', '8344458'])
+        permission_m = self.set_mock('SoftLayer_User_Customer', 'editObject')
+        permission_m.return_value = {'sslVpnAllowedFlag': True}
+        self.assert_no_fail(result)
+        self.assert_called_with('SoftLayer_User_Customer', 'editObject', identifier=8344458)
+        self.assertEqual('8344458 vpn is successfully enabled\n', result.output)