-
-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhance Outline VPN API Wrapper with Key Usage and Info Retrieval Functions #34
base: main
Are you sure you want to change the base?
Conversation
…I wrapper This commit introduces three new functions to the Outline VPN API wrapper, enhancing its functionality and usability. These functions include: 1. `get_all_key_usages`: Retrieves usage data for all keys, enabling administrators to monitor data usage across all issued access keys. 2. `get_key_usage`: Fetches usage information for a specific key, identified by its name, allowing for detailed monitoring of individual key usage. 3. `get_key_info_by_name`: Provides detailed information about a specific key based on its name, simplifying key management tasks. These additions aim to improve the API wrapper's utility by providing more granular control and visibility over access keys and their usage. Error handling has been standardized across these functions to ensure consistency and reliability in error reporting. The functions leverage existing API endpoints, ensuring that they integrate seamlessly with the Outline VPN server's capabilities without requiring any changes to the server setup. This update is part of ongoing efforts to enhance the Outline VPN API wrapper's features based on user feedback and evolving management requirements. It underscores our commitment to providing a robust and user-friendly tool for managing Outline VPN servers.
…I wrapper This commit introduces three new functions to the Outline VPN API wrapper, enhancing its functionality and usability. These functions include: 1. `get_all_key_usages`: Retrieves usage data for all keys, enabling administrators to monitor data usage across all issued access keys. 2. `get_key_usage`: Fetches usage information for a specific key, identified by its name, allowing for detailed monitoring of individual key usage. 3. `get_key_info_by_name`: Provides detailed information about a specific key based on its name, simplifying key management tasks. These additions aim to improve the API wrapper's utility by providing more granular control and visibility over access keys and their usage. Error handling has been standardized across these functions to ensure consistency and reliability in error reporting. The functions leverage existing API endpoints, ensuring that they integrate seamlessly with the Outline VPN server's capabilities without requiring any changes to the server setup. This update is part of ongoing efforts to enhance the Outline VPN API wrapper's features based on user feedback and evolving management requirements. It underscores our commitment to providing a robust and user-friendly tool for managing Outline VPN servers.
Quality Gate passedKudos, no new issues were introduced! 0 New issues |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much for your contributions. After reviewing I have some comments.
def get_all_key_usages(self): | ||
""" | ||
Get usage for all available keys. | ||
""" | ||
try: | ||
keys = self.get_keys() | ||
usage_data = self.get_transferred_data() | ||
key_usage_list = [] | ||
|
||
for key in keys: | ||
key_id = key.key_id | ||
used_bytes = usage_data.get("bytesTransferredByUserId", {}).get(key_id, 0) | ||
key_usage_list.append({ | ||
"key_id": key_id, | ||
"name": key.name, | ||
"used_bytes": used_bytes | ||
}) | ||
|
||
return key_usage_list | ||
except Exception as e: | ||
raise OutlineServerErrorException(f"Failed to get all key usages: {str(e)}") | ||
|
||
def get_key_usage(self, key_name: str): | ||
""" | ||
Get usage for a given key by name. | ||
""" | ||
try: | ||
keys = self.get_keys() | ||
usage_data = self.get_transferred_data() | ||
|
||
for key in keys: | ||
if key.name == key_name: | ||
key_id = key.key_id | ||
used_bytes = usage_data.get("bytesTransferredByUserId", {}).get(key_id, 0) | ||
return { | ||
"key_id": key.key_id, | ||
"name": key.name, | ||
"used_bytes": used_bytes | ||
} | ||
raise OutlineServerErrorException(f"Key with name {key_name} not found") | ||
except Exception as e: | ||
raise OutlineServerErrorException(f"Failed to get key usage for '{key_name}': {str(e)}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure these 2 are needed since we integrated the usage stat into the get_key/s methods already, so the key should return this information from the beginning.
except Exception as e: | ||
raise OutlineServerErrorException(f"Failed to get key usage for '{key_name}': {str(e)}") | ||
|
||
def get_key_info_by_name(self, name: str): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this one, I'd rather have the key itself. If there's any extra key information, it should be part of the key object itself. Also please add tests for this case.
This pull request introduces new functionalities to the Outline VPN API wrapper, aiming to improve its usability and management capabilities for Outline VPN servers. Specifically, the following functions have been added:
-get_all_key_usages:
Enables administrators to track the data usage of all access keys, facilitating better resource management and monitoring.
-get_key_usage:
Allows for detailed monitoring of data usage for individual keys, aiding in usage analysis and key management.
-get_key_info_by_name:
Provides detailed information for a specific key, enhancing key administration capabilities by allowing easier access to key details.