Exemplo n.º 1
0
def get_recipe(recipe: str) -> dict:
    config = load_yaml_path(app.config['config_path'])
    recipe = load_yaml_path(app.config['config_path'].parent.joinpath(
        config['paths']['recipes_path'], recipe)
    )
    expanded_rulesets = []
    responses = []

    for ruleset_file in recipe['rulesets']:
        ruleset = load_yaml_path(app.config['config_path'].parent.joinpath(
            config['paths']['rulesets_path'], ruleset_file)
        )
        response_path = app.config['config_path'].parent.joinpath(config['paths']['responses_path'], ruleset['use'])
        response = load_yaml_path(response_path)

        response_restr = {
            'path': ruleset['use'],
            'id': hashlib.sha224(bytes(str(response_path.resolve()), 'utf-8')).hexdigest(),
            'name': ruleset['use'],
            'content': response
        }

        ruleset['path'] = ruleset_file
        ruleset['id'] = hashlib.sha224(bytes(ruleset['path'], 'utf-8')).hexdigest()
        ruleset['name'] = ruleset_file
        ruleset['use'] = response_restr

        if response_restr not in responses:
            responses.append(response_restr)
        expanded_rulesets.append(ruleset)

    recipe['rulesets'] = expanded_rulesets
    recipe['responses'] = responses
    return jsonify(recipe)
Exemplo n.º 2
0
def get_file_for_type(config_path, filetype, filename):
    if filetype == 'config':
        file = config_path
    else:
        config = load_yaml_path(config_path)
        file = config_path.parent.joinpath(
            config['paths'][f'{filetype}s_path'], filename)
    return file
Exemplo n.º 3
0
def get_config() -> dict:
    if app.config['config_path'] is not None:
        response = jsonify({
            'error': False,
            'path': str(app.config['config_path'].resolve()),
            'config': load_yaml_path(app.config['config_path'])
        })
    else:
        response = jsonify({'error': True})
    return response
Exemplo n.º 4
0
def get_recipe(recipe):
    config = app.config['context']['environment']['config']
    try:
        recipe = load_yaml_path(
            Path(config['paths']['recipes_path']).joinpath(recipe))
    except FileNotFoundError:
        abort(404)
    expanded_rulesets = OrderedDict()  # type: OrderedDict

    for ruleset_file in recipe['rulesets']:
        ruleset = load_yaml_path(
            Path(config['paths']['rulesets_path']).joinpath(ruleset_file))
        response = load_yaml_path(
            Path(config['paths']['responses_path']).joinpath(ruleset['use']))

        ruleset['use'] = {ruleset['use']: response}
        expanded_rulesets[ruleset_file] = ruleset

    recipe['rulesets'] = expanded_rulesets
    return jsonify(recipe)
Exemplo n.º 5
0
def get_recipes(path: Path) -> dict:
    config = load_yaml_path(path)
    recipes = path.parent.joinpath(
        config['paths']['recipes_path']).glob('*.yaml')

    return {
        'configdir':
        str(path.resolve()),
        'recipes': [{
            'name':
            str(recipe.name),
            'path':
            str(recipe.parent),
            'id':
            hashlib.sha224(bytes(str(recipe), 'utf-8')).hexdigest()
        } for recipe in recipes]
    }
Exemplo n.º 6
0
def create_project() -> dict:
    template_path = app.config['base_path'].joinpath('project_setup')

    options = load_yaml_path(Path(template_path).joinpath('options.yaml'))
    options['project']['name'] = request.json['name']

    outdir = Path(request.json['path']).resolve()
    print(outdir)

    SetUp(options=options,
          structure=str(Path(template_path).joinpath('structure.yaml')),
          templates=str(Path(template_path).joinpath('templates')),
          metadata=str(Path(template_path).joinpath('metadata.yaml')),
          out_dir=outdir,
          unsafe=False).setup()
    # TODO: Override project name 'new_project' <- read options.yaml and make dict to override
    file_path = outdir.joinpath(options['project']['name'], 'config.yaml').resolve()
    app.config['config_path'] = file_path
    return jsonify(helpers.get_recipes(file_path))
Exemplo n.º 7
0
def get_snippets(config_path: Path, for_roles: list) -> list:
    config = load_yaml_path(config_path)
    [importlib.import_module(ext) for ext in config['extensions']]

    task_map = {
        reg.shortname: list(
            filter(lambda x: x != 'context',
                   inspect.signature(reg).parameters.keys()))
        for reg in _tasks if reg.role.name in for_roles
    }

    snippets = []
    for task, params in task_map.items():
        snippets.append(f'snippet {task}\n\t{task}')
        if params:
            for i, k in enumerate(params):
                snippets.append('\n\t\t%s: ${%i:%s}' % (k, i, k))
        snippets.append('\n')

    return snippets
Exemplo n.º 8
0

@app.route('/api/events', methods=['GET'])
def get_events():
    service = request.args.get('services')
    try:
        r = requests.get('http://' + service + '/api/events?event=' +
                         request.args.get('event')).json()
    except Exception:
        r = None
    return jsonify({'service': service, 'response': r})


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "config_file_path",
        help="Path to the config file, ex. ./examples/config.yaml")
    args = parser.parse_args()

    config = load_yaml_path(Path(args.config_file_path))

    kvstore.purge(
        get_default_context(
            {'config': {
                'internal': {
                    'vardb_path': config['vardb_path']
                }
            }}))
    gaukl.juggler.api.run(config)