From d7f71322a44ad1b12316ada4978c1955ded8e173 Mon Sep 17 00:00:00 2001 From: esir Date: Thu, 1 Sep 2022 18:13:16 +0300 Subject: [PATCH 1/2] Support creating of named keys. --- outline_vpn/outline_vpn.py | 8 ++++++-- test_outline_vpn.py | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/outline_vpn/outline_vpn.py b/outline_vpn/outline_vpn.py index 1467c52..37ef22b 100644 --- a/outline_vpn/outline_vpn.py +++ b/outline_vpn/outline_vpn.py @@ -67,12 +67,12 @@ def get_keys(self): return result raise Exception("Unable to retrieve keys") - def create_key(self) -> OutlineKey: + def create_key(self, key_name=None) -> OutlineKey: """Create a new key""" response = requests.post(f"{self.api_url}/access-keys/", verify=False) if response.status_code == 201: key = response.json() - return OutlineKey( + outline_key = OutlineKey( key_id=key.get("id"), name=key.get("name"), password=key.get("password"), @@ -81,6 +81,10 @@ def create_key(self) -> OutlineKey: access_url=key.get("accessUrl"), used_bytes=0, ) + if key_name: + if self.rename_key(outline_key.key_id, key_name): + outline_key.name = key_name + return outline_key raise Exception("Unable to create key") diff --git a/test_outline_vpn.py b/test_outline_vpn.py index d507be0..2678396 100644 --- a/test_outline_vpn.py +++ b/test_outline_vpn.py @@ -36,6 +36,9 @@ def test_cud_key(client: OutlineVPN): # pylint: disable=W0621 assert new_key is not None assert int(new_key.key_id) > 0 + named_key = client.create_key(key_name="Test Key") + assert named_key.name == "Test Key" + assert client.rename_key(new_key.key_id, "a_name") assert client.delete_key(new_key.key_id) From c992dc59bb4e35526ba7304cf7ac529a8a9aedc8 Mon Sep 17 00:00:00 2001 From: esir Date: Thu, 1 Sep 2022 18:19:01 +0300 Subject: [PATCH 2/2] Remove nested if check --- outline_vpn/outline_vpn.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/outline_vpn/outline_vpn.py b/outline_vpn/outline_vpn.py index 37ef22b..5a6a31f 100644 --- a/outline_vpn/outline_vpn.py +++ b/outline_vpn/outline_vpn.py @@ -81,9 +81,8 @@ def create_key(self, key_name=None) -> OutlineKey: access_url=key.get("accessUrl"), used_bytes=0, ) - if key_name: - if self.rename_key(outline_key.key_id, key_name): - outline_key.name = key_name + if key_name and self.rename_key(outline_key.key_id, key_name): + outline_key.name = key_name return outline_key raise Exception("Unable to create key")