Skip to content

Commit

Permalink
Merge pull request #3 from esirK/ft-support-creating-named-keys
Browse files Browse the repository at this point in the history
Support creating of named keys.
  • Loading branch information
jadolg authored Sep 1, 2022
2 parents 098e944 + c992dc5 commit 66f8ba9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 5 additions & 2 deletions outline_vpn/outline_vpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -81,6 +81,9 @@ def create_key(self) -> OutlineKey:
access_url=key.get("accessUrl"),
used_bytes=0,
)
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")

Expand Down
3 changes: 3 additions & 0 deletions test_outline_vpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 66f8ba9

Please sign in to comment.