예제 #1
0
def get_condition_value_type(condition_key):
    """
    Get the data type of the condition key - like Date, String, etc.
    :param condition_key: A condition key, like a4b:filters_deviceType
    :return:
    """
    service_prefix, condition_name = condition_key.split(":")
    service_prefix_data = get_service_prefix_data(service_prefix)

    for condition_key_entry in service_prefix_data["conditions"]:
        if is_condition_key_match(condition_key_entry["condition"], condition_key):

            return condition_key_entry["type"].lower()
예제 #2
0
def get_condition_value_type(condition_key):
    """
    Get the data type of the condition key - like Date, String, etc.

    Arguments:
        condition_key: A condition key, like a4b:filters_deviceType
    Returns:
        String: type of the condition key, like Bool, Date, String, etc.
    """
    service_prefix, condition_name = condition_key.split(":")
    service_prefix_data = get_service_prefix_data(service_prefix)

    for condition_key_entry, condition_key_data in service_prefix_data[
            "conditions"].items():
        if is_condition_key_match(condition_key_data["condition"],
                                  condition_key):
            return condition_key_data["type"].lower()
예제 #3
0
def get_condition_key_details(service_prefix, condition_key_name):
    """
    Get details about a specific condition key in JSON format

    :param service_prefix: An AWS service prefix, like `ec2` or `kms`
    :param condition_key_name: The name of a condition key, like `ec2:Vpc`
    :return: Metadata about the condition key
    """
    service_prefix_data = get_service_prefix_data(service_prefix)
    for condition_key_entry in service_prefix_data["conditions"]:
        if is_condition_key_match(condition_key_entry["condition"], condition_key_name):
            output = {
                "name": condition_key_entry["condition"],
                "description": condition_key_entry["description"],
                "condition_value_type": condition_key_entry["type"].lower(),
            }
            return output
예제 #4
0
def get_condition_key_details(service_prefix, condition_key_name):
    """
    Get details about a specific condition key in JSON format

    Arguments:
        service_prefix: An AWS service prefix, like `ec2` or `kms`
        condition_key_name: The name of a condition key, like `ec2:Vpc`
    Returns:
        Dictionary: Metadata about the condition key
    """
    service_prefix_data = get_service_prefix_data(service_prefix)
    for condition_name, condition_data in service_prefix_data[
            "conditions"].items():
        if is_condition_key_match(condition_data["condition"],
                                  condition_key_name):
            output = {
                "name": condition_data["condition"],
                "description": condition_data["description"],
                "condition_value_type": condition_data["type"].lower(),
            }
            return output
예제 #5
0
 def test_is_condition_key_match_case_1(self):
     """exact match. return True"""
     document_key = "s3:prefix"
     str_to_match = "s3:prefix"
     self.assertTrue(is_condition_key_match(document_key, str_to_match))
예제 #6
0
 def test_is_condition_key_match_case_4(self):
     """match with string before <"""
     document_key = "s3:ExistingObjectTag/<key>"
     str_to_match = "s3:ExistingObjectTag/<sample-key>"
     self.assertTrue(is_condition_key_match(document_key, str_to_match))
예제 #7
0
 def test_is_condition_key_match_case_3(self):
     """match with string before $"""
     document_key = "aws:ResourceTag/${TagKey}"
     str_to_match = "aws:Resourcetag/${TagKey1}"
     self.assertTrue(is_condition_key_match(document_key, str_to_match))
예제 #8
0
 def test_is_condition_key_match_case_2(self):
     """no match. return False"""
     document_key = "s3:prefix"
     str_to_match = "secretsmanager:SecretId"
     self.assertFalse(is_condition_key_match(document_key, str_to_match))