Beispiel #1
0
def start(args):
    unique_id = six.text_type(uuid.uuid4())
    is_tar = None

    if args.tar is not None:
        dir_name = "{}-{}".format(os.path.basename(args.tar).split('.')[0], unique_id)
        dir_name = os.path.join(tempfile.gettempdir(), dir_name)
        module, config = from_tar(args.tar, unique_id, dir_name)
        is_tar = True
    else:
        module, config = from_config(args.config)

    turret = Turret(config, module, unique_id)

    try:
        turret.start()
    except (Exception, KeyboardInterrupt):
        clean_tar_tmp(dir_name, is_tar)
        raise

    clean_tar_tmp(dir_name, is_tar)
Beispiel #2
0
def from_tar(tar_path, unique_id, dir_name):
    """Load all require components from tar archive

    :param str tar_path: the path to json configuration file
    :param str unique_id: the unique identifier of the turret
    :param str dir_name: the full path for extraction
    :return: module file and loaded configuration
    """

    if not unpack(tar_path, dir_name):
        raise InvalidTarTurret("Invalide tar file provided")

    try:
        config = validate_conf(os.path.join(dir_name, 'config.json'))
    except InvalidConfiguration:
        clean_tar_tmp(dir_name, True)
        raise

    module_file = os.path.join(dir_name, config['script'])
    module = load_file(module_file)
    return module, config
Beispiel #3
0
def from_tar(tar_path, unique_id, dir_name):
    """Load all require components from tar archive

    :param str tar_path: the path to json configuration file
    :param str unique_id: the unique identifier of the turret
    :param str dir_name: the full path for extraction
    :return: module file and loaded configuration
    """

    if not unpack(tar_path, dir_name):
        raise InvalidTarTurret("Invalide tar file provided")

    try:
        config = validate_conf(os.path.join(dir_name, 'config.json'))
    except InvalidConfiguration:
        clean_tar_tmp(dir_name, True)
        raise

    module_file = os.path.join(dir_name, config['script'])
    module = load_file(module_file)
    return module, config
Beispiel #4
0
def start(args):
    unique_id = six.text_type(uuid.uuid4())
    is_tar = None

    if args.tar is not None:
        dir_name = "{}-{}".format(
            os.path.basename(args.tar).split('.')[0], unique_id)
        dir_name = os.path.join(tempfile.gettempdir(), dir_name)
        module, config = from_tar(args.tar, unique_id, dir_name)
        is_tar = True
    else:
        module, config = from_config(args.config)

    Turret = get_turret_class(config.get('turret_class'))
    turret = Turret(config, module, unique_id)

    try:
        turret.start()
    except (Exception, KeyboardInterrupt):
        clean_tar_tmp(dir_name, is_tar)
        raise

    clean_tar_tmp(dir_name, is_tar)