def test_generate_api_overide_with_add_value():
    api_sch = ApiConfigResolver(resources_folder_yaml)
    api_data = api_sch.get_api_data(set_values=["name=test", "endpoints[1]=https://api.gravitee.io/echo2"])

    json_data, json_data_expected = return_json_data_and_expected(api_data, "result_api_set_add_value.json")

    assert json_data == json_data_expected
Example #2
0
def apply(ctx, api_id, file, set, debug, config_path, with_deploy):
    """
    This command allow to update an API definition configuration.
    The API definition is managed with the template engine (jinja).
    API propetries are defined in plain YAML or JSON files.
    """
    api_client: ApiClient = ctx.obj['api_client']

    api_resolver = ApiConfigResolver(config_path, file)
    api_data = api_resolver.get_api_data(debug=debug, set_values=set)

    if debug:
        click.echo("Data sent.")
        click.echo(json.dumps(api_data))
    else:
        if api_id:
            click.echo("Starting to apply API: [{}] '{}'.".format(
                api_id, api_data["name"]))
            resp = api_client.update_import(api_id, api_data)
            click.echo("API [{}] is updated".format(api_id))

            if with_deploy:
                ctx.invoke(deploy, api_id=api_id)

        else:
            click.echo("Starting to create API [{}].".format(api_data["name"]))
            resp = api_client.create_import(api_data)
            api_id = resp["id"]
            click.echo("API has been created with id [{}].".format(api_id))

            if with_deploy:
                ctx.invoke(start, api_id=api_id)
                ctx.invoke(deploy, api_id=api_id)
def test_generate_simple_api_json():
    api_sch = ApiConfigResolver(resources_folder_json)
    api_data = api_sch.get_api_data()

    json_data, json_data_expected = return_json_data_and_expected(api_data, "result_api.json")

    assert api_data['version'] == '1.0'
    assert json_data == json_data_expected
Example #4
0
def generate(obj, config_path, format, from_id):
    """Generate default templates, setting and value files for api definition"""
    if not os.path.exists(config_path):
        os.mkdir(config_path)

    api_def_string = None
    if from_id:
        api_client: ApiClient = obj['api_client']
        api_def_string = api_client.get_export(from_id, filter_api_values)

    api_resolver = ApiConfigResolver(config_path)

    api_resolver.generate_init(format=Data_Template_Format.value_of(format),
                               api_def=api_def_string)
Example #5
0
def diff(obj, api_id, file, set, config_path):
    """
    This commande compare the api definition configuration developed on local machine with the configuration on the remote server.
    """
    api_client: ApiClient = obj['api_client']

    if not config_path:
        config_path = "./"

    if not os.path.exists(config_path):
        raise GraviteeioError(
            "No resources folder {} found.".format(config_path))

    api_resolver = ApiConfigResolver(config_path, file)
    api_data = api_resolver.get_api_data(set_values=set)

    api_server = api_client.get_export(api_id, filter_api_values)

    diff_result = jsondiff(api_server, api_data)
    display_dict_differ(diff_result)