(self, service_name, operation_name, parameters, parsed_globals)
| 97 | DEFAULT_SSM_ENV_NAME = "AWS_SSM_START_SESSION_RESPONSE" |
| 98 | |
| 99 | def invoke(self, service_name, operation_name, parameters, parsed_globals): |
| 100 | client = self._session.create_client( |
| 101 | service_name, |
| 102 | region_name=parsed_globals.region, |
| 103 | endpoint_url=parsed_globals.endpoint_url, |
| 104 | verify=parsed_globals.verify_ssl, |
| 105 | ) |
| 106 | response = client.start_session(**parameters) |
| 107 | session_id = response['SessionId'] |
| 108 | region_name = client.meta.region_name |
| 109 | # Profile_name is used to passed on to session manager plugin |
| 110 | # to fetch same profile credentials to make an api call in the plugin. |
| 111 | # If --profile flag is configured, pass it to Session Manager plugin. |
| 112 | # If not, set empty string. |
| 113 | profile_name = ( |
| 114 | parsed_globals.profile |
| 115 | if parsed_globals.profile is not None |
| 116 | else '' |
| 117 | ) |
| 118 | endpoint_url = client.meta.endpoint_url |
| 119 | ssm_env_name = self.DEFAULT_SSM_ENV_NAME |
| 120 | |
| 121 | try: |
| 122 | session_parameters = { |
| 123 | "SessionId": response["SessionId"], |
| 124 | "TokenValue": response["TokenValue"], |
| 125 | "StreamUrl": response["StreamUrl"], |
| 126 | } |
| 127 | start_session_response = json.dumps(session_parameters) |
| 128 | |
| 129 | plugin_version = check_output( |
| 130 | ["session-manager-plugin", "--version"], text=True |
| 131 | ) |
| 132 | env = os.environ.copy() |
| 133 | |
| 134 | # Check if this plugin supports passing the start session response |
| 135 | # as an environment variable name. If it does, it will set the |
| 136 | # value to the response from the start_session operation to the env |
| 137 | # variable defined in DEFAULT_SSM_ENV_NAME. If the session plugin |
| 138 | # version is invalid or older than the version defined in |
| 139 | # LAST_PLUGIN_VERSION_WITHOUT_ENV_VAR, it will fall back to |
| 140 | # passing the start_session response directly. |
| 141 | version_requirement = VersionRequirement( |
| 142 | min_version=self.LAST_PLUGIN_VERSION_WITHOUT_ENV_VAR |
| 143 | ) |
| 144 | if version_requirement.meets_requirement(plugin_version): |
| 145 | env[ssm_env_name] = start_session_response |
| 146 | start_session_response = ssm_env_name |
| 147 | # ignore_user_entered_signals ignores these signals |
| 148 | # because if signals which kills the process are not |
| 149 | # captured would kill the foreground process but not the |
| 150 | # background one. Capturing these would prevents process |
| 151 | # from getting killed and these signals are input to plugin |
| 152 | # and handling in there |
| 153 | with ignore_user_entered_signals(): |
| 154 | # call executable with necessary input |
| 155 | check_call( |
| 156 | [ |
nothing calls this directly
no test coverage detected