Debian Codegraph @

ansible_collections/amazon/aws/plugins/lookup/aws_collection_constants.py

raw
1 # -*- coding: utf-8 -*-
2
3 # (c) 2023 Ansible Project
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 DOCUMENTATION = r"""
7 name: aws_collection_constants
8 author:
9 - Mark Chappell (@tremble)
10 short_description: expose various collection related constants
11 version_added: 6.0.0
12 description:
13 - Exposes various collection related constants for use in integration tests.
14 options:
15 _terms:
16 description: Name of the constant.
17 choices:
18 - MINIMUM_BOTOCORE_VERSION
19 - MINIMUM_BOTO3_VERSION
20 - HAS_BOTO3
21 - AMAZON_AWS_COLLECTION_VERSION
22 - AMAZON_AWS_COLLECTION_NAME
23 - COMMUNITY_AWS_COLLECTION_VERSION
24 - COMMUNITY_AWS_COLLECTION_NAME
25 required: true
26 """
27
28 EXAMPLES = r"""
29 """
30
31 RETURN = r"""
32 _raw:
33 description: Value.
34 type: str
35 """
36
37 from ansible.errors import AnsibleLookupError
38 from ansible.plugins.lookup import LookupBase
39
40 import ansible_collections.amazon.aws.plugins.module_utils.botocore as botocore_utils
41 import ansible_collections.amazon.aws.plugins.module_utils.common as common_utils
42
43 try:
44 import ansible_collections.community.aws.plugins.module_utils.common as community_utils
45
46 HAS_COMMUNITY = True
47 except ImportError:
48 HAS_COMMUNITY = False
49
50
51 class LookupModule(LookupBase):
52 def lookup_constant(self, name): # pylint: disable=too-many-return-statements
53 if name == "MINIMUM_BOTOCORE_VERSION":
54 return botocore_utils.MINIMUM_BOTOCORE_VERSION
55 if name == "MINIMUM_BOTO3_VERSION":
56 return botocore_utils.MINIMUM_BOTO3_VERSION
57 if name == "HAS_BOTO3":
58 return botocore_utils.HAS_BOTO3
59
60 if name == "AMAZON_AWS_COLLECTION_VERSION":
61 return common_utils.AMAZON_AWS_COLLECTION_VERSION
62 if name == "AMAZON_AWS_COLLECTION_NAME":
63 return common_utils.AMAZON_AWS_COLLECTION_NAME
64
65 if name == "COMMUNITY_AWS_COLLECTION_VERSION":
66 if not HAS_COMMUNITY:
67 raise AnsibleLookupError("Unable to load ansible_collections.community.aws.plugins.module_utils.common")
68 return community_utils.COMMUNITY_AWS_COLLECTION_VERSION
69 if name == "COMMUNITY_AWS_COLLECTION_NAME":
70 if not HAS_COMMUNITY:
71 raise AnsibleLookupError("Unable to load ansible_collections.community.aws.plugins.module_utils.common")
72 return community_utils.COMMUNITY_AWS_COLLECTION_NAME
73
74 def run(self, terms, variables, **kwargs):
75 self.set_options(var_options=variables, direct=kwargs)
76 if not terms:
77 raise AnsibleLookupError("Constant name not provided")
78 if len(terms) > 1:
79 raise AnsibleLookupError("Multiple constant names provided")
80 name = terms[0].upper()
81
82 return [self.lookup_constant(name)]