diff --git a/insights/specs/datasources/aws.py b/insights/specs/datasources/aws.py index b498ae6093..4aafb8d0c2 100644 --- a/insights/specs/datasources/aws.py +++ b/insights/specs/datasources/aws.py @@ -8,6 +8,10 @@ from insights.core.spec_factory import simple_command from insights.specs import Specs +_aws_imdsv2_token_invalid_keyworks = [ + 'warning: ', +] + class LocalSpecs(Specs): """ Local specs used only by aws datasources """ @@ -34,9 +38,12 @@ def aws_imdsv2_token(broker): SkipComponent: When an error occurs or no token is generated """ try: - token = broker[LocalSpecs.aws_imdsv2_token].content[0].strip() - if token: - return str(token) + _token = broker[LocalSpecs.aws_imdsv2_token].content[0].strip() + if _token: + token = str(_token) + token_lower = token.lower() + if token and not any(k in token_lower for k in _aws_imdsv2_token_invalid_keyworks): + return token except Exception as e: raise SkipComponent("Unexpected exception:{e}".format(e=str(e))) raise SkipComponent diff --git a/insights/tests/datasources/test_aws.py b/insights/tests/datasources/test_aws.py index eeb46443e4..bca8c62018 100644 --- a/insights/tests/datasources/test_aws.py +++ b/insights/tests/datasources/test_aws.py @@ -8,6 +8,8 @@ TOKEN = "1234567890\n" +TOKEN_INVALID = "Warning: /root/.curlrc:1: warning: 'proxy' requires parameter" + def test_aws_imdsv2_token(): input_spec = Mock() @@ -30,3 +32,9 @@ def test_aws_imdsv2_token_exp(): broker = {LocalSpecs.aws_imdsv2_token: input_spec} with pytest.raises(SkipComponent) as ex: aws_imdsv2_token(broker) + + input_spec = Mock() + input_spec.content = [TOKEN_INVALID, ] + broker = {LocalSpecs.aws_imdsv2_token: input_spec} + with pytest.raises(SkipComponent) as ex: + aws_imdsv2_token(broker)