-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Add warning for outdated SessionManagerPlugin version #10520
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
Open
rongjina987
wants to merge
1
commit into
aws:develop
Choose a base branch
from
rongjina987:session-manager-plugin-version-warn
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+207
−0
Open
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions
5
.changes/next-release/enhancement-SSMSessionManager-91936.json
This file contains hidden or 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,5 @@ | ||
| { | ||
| "type": "enhancement", | ||
| "category": "SSM SessionManager", | ||
| "description": "Add warning message for outdated SessionManagerPlugin version" | ||
| } |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -15,10 +15,12 @@ | |
| import errno | ||
| import os | ||
| import re | ||
| import sys | ||
|
|
||
| from subprocess import check_call, check_output | ||
| from awscli.compat import ignore_user_entered_signals | ||
| from awscli.clidriver import ServiceOperation, CLIOperationCaller | ||
| from awscli.customizations.utils import uni_print | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
@@ -29,6 +31,15 @@ | |
| 'session-manager-plugin-not-found' | ||
| ) | ||
|
|
||
| OUTDATED_PLUGIN_VERSION_MESSAGE = ( | ||
| '\n' | ||
| 'WARNING: An outdated SessionManagerPlugin version detected. Please upgrade it to the latest version. \n' | ||
| 'For more information, refer:\n' | ||
| ' https://docs.aws.amazon.com/systems-manager/latest/userguide/' | ||
| 'session-manager-working-with-install-plugin.html\n' | ||
| '\n' | ||
| ) | ||
|
|
||
|
|
||
| def register_ssm_session(event_handlers): | ||
| event_handlers.register('building-command-table.ssm', | ||
|
|
@@ -63,6 +74,22 @@ def meets_requirement(self, version): | |
| else: | ||
| return False | ||
|
|
||
| def meets_or_exceeds(self, version): | ||
|
Collaborator
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. This function seems to implement identical behavior to ...
if inclusive:
return norm_version >= norm_min_version
return norm_version > norm_min_version |
||
| """Check a version against ``min_version`` inclusively.""" | ||
| ssm_plugin_version = self._sanitize_plugin_version(version) | ||
| if not self._is_valid_version(ssm_plugin_version): | ||
| return False | ||
| norm_version, norm_min_version = self._normalize( | ||
| ssm_plugin_version, self.min_version | ||
| ) | ||
| return norm_version >= norm_min_version | ||
|
|
||
| def is_valid_plugin_version(self, version): | ||
| """Check whether the reported version string is parseable.""" | ||
| return self._is_valid_version( | ||
| self._sanitize_plugin_version(version) | ||
| ) | ||
|
|
||
| def _sanitize_plugin_version(self, plugin_version): | ||
| return re.sub(self.WHITESPACE_REGEX, "", plugin_version) | ||
|
|
||
|
|
@@ -93,8 +120,24 @@ def create_help_command(self): | |
|
|
||
| class StartSessionCaller(CLIOperationCaller): | ||
| LAST_PLUGIN_VERSION_WITHOUT_ENV_VAR = "1.2.497.0" | ||
| RECOMMENDED_MINIMUM_PLUGIN_VERSION = "1.2.764.0" | ||
| DEFAULT_SSM_ENV_NAME = "AWS_SSM_START_SESSION_RESPONSE" | ||
|
|
||
| def _warn_if_plugin_version_is_outdated(self, plugin_version): | ||
| """Warn when the plugin is older than the recommended minimum.""" | ||
| version_requirement = VersionRequirement( | ||
| min_version=self.RECOMMENDED_MINIMUM_PLUGIN_VERSION | ||
| ) | ||
| if not version_requirement.is_valid_plugin_version(plugin_version): | ||
| logger.debug( | ||
| 'Unable to parse SessionManagerPlugin version %r, skipping ' | ||
| 'outdated version warning', plugin_version | ||
| ) | ||
| return | ||
| if version_requirement.meets_or_exceeds(plugin_version): | ||
| return | ||
| uni_print(OUTDATED_PLUGIN_VERSION_MESSAGE, sys.stderr) | ||
|
|
||
| def invoke(self, service_name, operation_name, parameters, | ||
| parsed_globals): | ||
| client = self._session.create_client( | ||
|
|
@@ -126,6 +169,10 @@ def invoke(self, service_name, operation_name, parameters, | |
| ) | ||
| env = os.environ.copy() | ||
|
|
||
| # Warn, but do not fail, when the plugin is older than the | ||
| # recommended minimum version. | ||
| self._warn_if_plugin_version_is_outdated(plugin_version) | ||
|
|
||
| # Check if this plugin supports passing the start session response | ||
| # as an environment variable name. If it does, it will set the | ||
| # value to the response from the start_session operation to the env | ||
|
|
||
This file contains hidden or 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
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.
super nit - split this string into two lines for readability. The string value is unaffected