This repository has been archived by the owner on Apr 11, 2024. It is now read-only.
forked from opensearch-project/opensearch-migrations
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Refactoring] Better encapsulation of endpoint logic into the Endpoin…
…tInfo class This change adds a class method to construct API endpoint paths instead of having callers compute this on their own. It also includes better/normalized handling of slashes in endpoint and path URIs. A minor refactoring of logging in migration_monitor.py is also included, which improves unit test code coverage. Signed-off-by: Kartik Ganesh <[email protected]>
- Loading branch information
Showing
5 changed files
with
101 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,38 @@ | ||
from dataclasses import dataclass | ||
from typing import Optional | ||
|
||
|
||
@dataclass | ||
# Class that encapsulates endpoint information for an OpenSearch/Elasticsearch cluster | ||
class EndpointInfo: | ||
url: str | ||
auth: tuple = None | ||
verify_ssl: bool = True | ||
# Private member variables | ||
__url: str | ||
__auth: Optional[tuple] | ||
__verify_ssl: bool | ||
|
||
def __init__(self, url: str, auth: tuple = None, verify_ssl: bool = True): | ||
self.__url = url | ||
# Normalize url value to have trailing slash | ||
if not url.endswith("/"): | ||
self.__url += "/" | ||
self.__auth = auth | ||
self.__verify_ssl = verify_ssl | ||
|
||
def __eq__(self, obj): | ||
return isinstance(obj, EndpointInfo) and \ | ||
self.__url == obj.__url and \ | ||
self.__auth == obj.__auth and \ | ||
self.__verify_ssl == obj.__verify_ssl | ||
|
||
def add_path(self, path: str) -> str: | ||
# Remove leading slash if present | ||
if path.startswith("/"): | ||
path = path[1:] | ||
return self.__url + path | ||
|
||
def get_url(self) -> str: | ||
return self.__url | ||
|
||
def get_auth(self) -> Optional[tuple]: | ||
return self.__auth | ||
|
||
def is_verify_ssl(self) -> bool: | ||
return self.__verify_ssl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters