def _process_discovery_args()

in src/aws_encryption_sdk_cli/internal/arg_parsing.py [0:0]


def _process_discovery_args(key_config):  # noqa: C901
    """Process rules for discovery filters on Account ID and Partition ID
    :param key_config: The key configuration being parsed
    :raises: ParameterParseError
    """
    if "discovery" not in key_config:
        if "discovery-account" in key_config or "discovery-partition" in key_config:
            raise ParameterParseError(
                "Discovery-account and discovery-partition are valid only when the discovery attribute is set to true"
            )

        key_config["discovery"] = False
        return

    # Translate the raw value of 'discovery' as passed by customer into a bool we can work with
    discovery = discovery_pseudobool(key_config.pop("discovery")[0])
    key_config["discovery"] = discovery

    accounts = key_config.get("discovery-account", None)
    partition = key_config.get("discovery-partition", None)

    if not discovery:
        if accounts or partition:
            raise ParameterParseError(
                "Discovery-account and discovery-partition are valid only when the discovery attribute is set to true"
            )
    else:
        if accounts and not partition:
            raise ParameterParseError("When specifying discovery-account, you must also specify discovery-partition")
        if partition and not accounts:
            raise ParameterParseError("When specifying discovery-partition, you must also specify discovery-account")

        if accounts and partition:
            for account in accounts:
                if len(account) == 0:
                    raise ParameterParseError("Value passed to discovery-account cannot be empty")
            if len(partition) != 1:
                raise ParameterParseError("You can only specify discovery-partition once")
            if not partition[0]:
                raise ParameterParseError("Value passed to discovery-partition cannot be empty")

            key_config["discovery-partition"] = partition[0]