def validate_user_yaml()

in source/eksfedctl/create_action.py [0:0]


def validate_user_yaml(input_yaml):
    keys = ["apiVersion", "kind", "metadata", "iamidentitymapping", "spec"]
    for key in input_yaml:
        if key not in keys:
            raise Exception(f"Unknown key \"{key}\"")

    if "apiVersion" not in input_yaml:
        raise Exception("Property \"apiVersion\" not found in yaml")
    elif input_yaml["apiVersion"] != "fedk8s/v1":
        raise Exception(f"Unknown \"apiVersion\": {input_yaml['apiVersion']}")

    if "kind" not in input_yaml:
        raise Exception("Property \"kind\" not found in yaml")
    elif input_yaml["kind"] != "FederatedEKSConfig":
        raise Exception(f"Unknown \"kind\": {input_yaml['kind']}")

    if "metadata" not in input_yaml:
        raise Exception("Property \"metadata\" not found in yaml")

    if "spec" in input_yaml:
        # Supported subset of eksctl.io/v1alpha5
        spec_keys = ["iam", "nodeGroups", "managedNodeGroups",
                     "fargateProfiles", "git", "cloudWatch"]

        supported_keys_str = f"Supported keys are: {', '.join(spec_keys)}"
        for spec_key in input_yaml["spec"]:
            if spec_key not in spec_keys:

                raise Exception(
                    f"Unknown key \"spec.{spec_key}\" {supported_keys_str}"
                )