-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added quick version checks to risky cluster-* and config-* cmds
Signed-off-by: Chris Helma <[email protected]>
- Loading branch information
Showing
12 changed files
with
353 additions
and
49 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
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
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,11 +1,19 @@ | ||
from dataclasses import dataclass | ||
from datetime import datetime, timezone | ||
import hashlib | ||
import json | ||
import logging | ||
from typing import Dict | ||
|
||
import arkime_interactions.config_wrangling as config_wrangling | ||
from aws_interactions.aws_client_provider import AwsClientProvider | ||
import aws_interactions.ssm_operations as ssm_ops | ||
import core.constants as constants | ||
from core.local_file import LocalFile | ||
from core.shell_interactions import call_shell_command | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
""" | ||
Manually updated/managed version number. Increment if/when a backwards incompatible change is made. | ||
""" | ||
|
@@ -74,4 +82,53 @@ def get_version_info(config_file: LocalFile, config_version: str = None) -> Vers | |
datetime.now(timezone.utc).strftime('%Y-%m-%d %H:%M:%S') | ||
) | ||
|
||
class UnableToRetrieveClusterVersion(Exception): | ||
def __init__(self, cluster_name: str, cli_version: int): | ||
super().__init__(f"It appears the cluster {cluster_name} does not exist. There's also a chance the AWS AIO version" | ||
+ f" of the CLI ({cli_version}) is incompatible with your Cluster. If you're confident the Cluster" | ||
+ " exists, you can try checking the AWS AIO version of your cluster using the clusters-list" | ||
+ " command. The CLI and Cluster versions must match.") | ||
|
||
class CaptureViewerVersionMismatch(Exception): | ||
def __init__(self, capture_version: int, viewer_version: int): | ||
super().__init__(f"The AWS AIO versions of your Capture ({capture_version}) and Viewer ({viewer_version}) components" | ||
+ " do not match. This is unexpected and should not happen. Please cut us a ticket at:" | ||
+ " https://github.com/arkime/aws-aio/issues/new") | ||
|
||
class CliClusterVersionMismatch(Exception): | ||
def __init__(self, cli_version: int, cluster_version: int): | ||
super().__init__(f"The AWS AIO versions of your CLI ({cli_version}) and Cluster ({cluster_version}) do not" | ||
+ " match. This is likely to result in unexpected behavior. Please revert your CLI to the latest" | ||
+ f" minor version under the major version ({cluster_version}). You can see a version listing of" | ||
+ " the CLI using the command: git ls-remote --tags [email protected]:arkime/aws-aio.git") | ||
|
||
def confirm_aws_aio_version_compatibility(cluster_name: str, aws_provider: AwsClientProvider, cli_version: int = AWS_AIO_VERSION): | ||
# Unfortunately, it appears currently impossible to distinguish between the scenarios where the cluster doesn't | ||
# exist and the cluster exists but is a different version. In either case, we could get the ParamDoesNotExist | ||
# exception. | ||
try: | ||
raw_capture_details_val = ssm_ops.get_ssm_param_value( | ||
constants.get_capture_config_details_ssm_param_name(cluster_name), | ||
aws_provider | ||
) | ||
capture_config_details = config_wrangling.ConfigDetails.from_dict(json.loads(raw_capture_details_val)) | ||
|
||
raw_viewer_details_val = ssm_ops.get_ssm_param_value( | ||
constants.get_viewer_config_details_ssm_param_name(cluster_name), | ||
aws_provider | ||
) | ||
viewer_config_details = config_wrangling.ConfigDetails.from_dict(json.loads(raw_viewer_details_val)) | ||
except ssm_ops.ParamDoesNotExist: | ||
raise UnableToRetrieveClusterVersion(cluster_name, cli_version) | ||
|
||
capture_version = int(capture_config_details.version.aws_aio_version) | ||
viewer_version = int(viewer_config_details.version.aws_aio_version) | ||
|
||
if capture_version != viewer_version: | ||
raise CaptureViewerVersionMismatch(capture_version, viewer_version) | ||
|
||
if capture_version != cli_version: | ||
raise CliClusterVersionMismatch(cli_version, capture_version) | ||
|
||
# Everything matches, we're good to go | ||
return |
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
Oops, something went wrong.