-
Notifications
You must be signed in to change notification settings - Fork 27
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
[Console] Update format of services.yaml #718
Merged
mikaylathompson
merged 6 commits into
opensearch-project:main
from
mikaylathompson:services-yaml-format-update
Jun 15, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c63dccc
Update schema for clusters
mikaylathompson e6b2ef2
Update README
mikaylathompson 03de8ae
Update metrics sources
mikaylathompson 49e378b
more readme updates
mikaylathompson fd7ae90
add a test for calling the api
mikaylathompson b1dc04f
add a metrics source test for coverage
mikaylathompson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
from requests.auth import HTTPBasicAuth | ||
from cerberus import Validator | ||
import logging | ||
from console_link.models.schema_tools import contains_one_of | ||
|
||
requests.packages.urllib3.disable_warnings() # ignore: type | ||
|
||
|
@@ -12,38 +13,47 @@ | |
AuthMethod = Enum("AuthMethod", ["NO_AUTH", "BASIC_AUTH", "SIGV4"]) | ||
HttpMethod = Enum("HttpMethod", ["GET", "POST", "PUT", "DELETE"]) | ||
|
||
|
||
NO_AUTH_SCHEMA = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Do you have a link you can comment for what schema options like "nullable" are available for a schema There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
"nullable": True, | ||
} | ||
|
||
BASIC_AUTH_SCHEMA = { | ||
"type": "dict", | ||
"schema": { | ||
"username": { | ||
"type": "string", | ||
"required": False, | ||
}, | ||
"password": { | ||
"type": "string", | ||
"required": False, | ||
"excludes": ["aws_secret_arn"] | ||
}, | ||
"aws_secret_arn": { | ||
"type": "string", | ||
"required": False, | ||
"excludes": ["password"] | ||
} | ||
}, | ||
} | ||
|
||
SIGV4_SCHEMA = { | ||
"nullable": True, | ||
} | ||
|
||
SCHEMA = { | ||
"endpoint": {"type": "string", "required": True}, | ||
"allow_insecure": {"type": "boolean", "required": False}, | ||
"authorization": { | ||
"cluster": { | ||
"type": "dict", | ||
"required": True, | ||
"schema": { | ||
"type": { | ||
"type": "string", | ||
"required": True, | ||
"allowed": [e.name.lower() for e in AuthMethod] | ||
}, | ||
"details": { | ||
"type": "dict", | ||
"required": False, | ||
"schema": { | ||
"username": { | ||
"type": "string", | ||
"required": False | ||
}, | ||
"password": { | ||
"type": "string", | ||
"required": False | ||
}, | ||
"aws_secret_arn": { | ||
"type": "string", | ||
"required": False | ||
}, | ||
} | ||
} | ||
} | ||
}, | ||
"endpoint": {"type": "string", "required": True}, | ||
"allow_insecure": {"type": "boolean", "required": False}, | ||
"no_auth": NO_AUTH_SCHEMA, | ||
"basic_auth": BASIC_AUTH_SCHEMA, | ||
"sigv4": SIGV4_SCHEMA | ||
}, | ||
"check_with": contains_one_of({auth.name.lower() for auth in AuthMethod}) | ||
} | ||
} | ||
|
||
|
||
|
@@ -60,15 +70,19 @@ class Cluster: | |
def __init__(self, config: Dict) -> None: | ||
logger.info(f"Initializing cluster with config: {config}") | ||
v = Validator(SCHEMA) | ||
if not v.validate(config): | ||
if not v.validate({'cluster': config}): | ||
raise ValueError("Invalid config file for cluster", v.errors) | ||
|
||
self.endpoint = config["endpoint"] | ||
if self.endpoint.startswith("https"): | ||
self.allow_insecure = config.get("allow_insecure", False) | ||
self.auth_type = AuthMethod[config["authorization"]["type"].upper()] | ||
self.auth_details = config["authorization"].get("details", None) | ||
self.aws_secret_arn = None if self.auth_details is None else self.auth_details.get("aws_secret_arn", None) | ||
if 'no_auth' in config: | ||
self.auth_type = AuthMethod.NO_AUTH | ||
elif 'basic_auth' in config: | ||
self.auth_type = AuthMethod.BASIC_AUTH | ||
self.auth_details = config["basic_auth"] | ||
elif 'sigv4' in config: | ||
self.auth_type = AuthMethod.SIGV4 | ||
|
||
def call_api(self, path, method: HttpMethod = HttpMethod.GET) -> requests.Response: | ||
""" | ||
|
@@ -80,7 +94,7 @@ def call_api(self, path, method: HttpMethod = HttpMethod.GET) -> requests.Respon | |
self.auth_details.get("username", None), | ||
self.auth_details.get("password", None) | ||
) | ||
elif self.auth_type is None: | ||
elif self.auth_type is AuthMethod.NO_AUTH: | ||
auth = None | ||
else: | ||
raise NotImplementedError(f"Auth type {self.auth_type} not implemented") | ||
|
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
14 changes: 14 additions & 0 deletions
14
...ion/src/main/docker/migrationConsole/lib/console_link/console_link/models/schema_tools.py
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from typing import Set | ||
|
||
|
||
def contains_one_of(values_to_restrict: Set): | ||
""" | ||
Generates a validator that checks if a value contains exactly one of the specified keys. | ||
""" | ||
def one_of(field, value, error): | ||
found_objects = values_to_restrict.intersection(value.keys()) | ||
if len(found_objects) > 1: | ||
error(field, f"More than one value is present: {sorted(found_objects)}") | ||
elif len(found_objects) < 1: | ||
error(field, f"No values are present from set: {sorted(values_to_restrict)}") | ||
return one_of |
14 changes: 5 additions & 9 deletions
14
...ficCapture/dockerSolution/src/main/docker/migrationConsole/lib/console_link/services.yaml
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,21 +1,17 @@ | ||
source_cluster: | ||
endpoint: "https://capture-proxy-es:9200" | ||
allow_insecure: true | ||
authorization: | ||
type: "basic_auth" | ||
details: | ||
basic_auth: | ||
username: "admin" | ||
password: "admin" | ||
target_cluster: | ||
endpoint: "https://opensearchtarget:9200" | ||
allow_insecure: true | ||
authorization: | ||
type: "basic_auth" | ||
details: | ||
basic_auth: | ||
username: "admin" | ||
password: "myStrongPassword123!" | ||
metrics_source: | ||
type: "prometheus" | ||
endpoint: "http://prometheus:9090" | ||
prometheus: | ||
endpoint: "http://prometheus:9090" | ||
replayer: | ||
deployment_type: "docker" | ||
docker: |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Thanks!