#!/usr/bin/env python2.7
# Copyright 2015 gRPC authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Generates the appropriate JSON data for LB interop test scenarios."""

import json
import os

import yaml

all_scenarios = []

# TODO(https://github.com/grpc/grpc-go/issues/2347): enable
# client_falls_back_because_no_backends_* scenarios for Java/Go.

# TODO(https://github.com/grpc/grpc-java/issues/4887): enable
# *short_stream* scenarios for Java.

# TODO(https://github.com/grpc/grpc-java/issues/4912): enable
# Java TLS tests involving TLS to the balancer.


def server_sec(transport_sec):
    if transport_sec == 'google_default_credentials':
        return 'alts', 'alts', 'tls'
    return transport_sec, transport_sec, transport_sec


def generate_no_balancer_because_lb_a_record_returns_nx_domain():
    all_configs = []
    for transport_sec in [
            'insecure', 'alts', 'tls', 'google_default_credentials'
    ]:
        balancer_sec, backend_sec, fallback_sec = server_sec(transport_sec)
        config = {
            'name':
                'no_balancer_because_lb_a_record_returns_nx_domain_%s' %
                transport_sec,
            'skip_langs': [],
            'transport_sec':
                transport_sec,
            'balancer_configs': [],
            'backend_configs': [],
            'fallback_configs': [{
                'transport_sec': fallback_sec,
            }],
            'cause_no_error_no_data_for_balancer_a_record':
                False,
        }
        all_configs.append(config)
    return all_configs


all_scenarios += generate_no_balancer_because_lb_a_record_returns_nx_domain()


def generate_no_balancer_because_lb_a_record_returns_no_data():
    all_configs = []
    for transport_sec in [
            'insecure', 'alts', 'tls', 'google_default_credentials'
    ]:
        balancer_sec, backend_sec, fallback_sec = server_sec(transport_sec)
        config = {