Example #1
0
def run(schema, fmt, **_):
    if schema not in schemas:
        print(
            'Schema "{}" not found. Use "faice schema list" for available schemas.'
            .format(schema),
            file=sys.stderr)
        return 1

    dump_print(schemas[schema], fmt)
    return 0
Example #2
0
def run(file, fmt, **_):
    result = {'state': 'succeeded', 'debugInfo': None}

    try:
        data = load_and_read(file, 'FILE')
        dump_print(data, fmt)
    except Exception as e:
        print_exception(e)
        result['debugInfo'] = exception_format()
        result['state'] = 'failed'

    return result
def main():
    parser = ArgumentParser(description=DESCRIPTION)
    attach_args(parser)
    args = parser.parse_args()
    result = run(**args.__dict__)

    if args.debug:
        dump_print(result, args.format)

    if result['state'] != 'succeeded':
        return 1

    return 0
Example #4
0
def main():
    args = _get_commandline_args()
    if args.outputs:
        output_mode = OutputMode.Connectors
    else:
        output_mode = OutputMode.Directory
    result = run(**args.__dict__,
                 output_mode=output_mode)

    if args.debug:
        dump_print(result, args.format)

    if result['state'] != 'succeeded':
        return 1

    return 0
Example #5
0
def run(red_file, fmt, **_):
    result = {'state': 'succeeded', 'debugInfo': None}

    try:
        red_data = load_and_read(red_file, 'REDFILE')
    except AgentError as e:
        print_exception(e)
        result['debugInfo'] = exception_format()
        result['state'] = 'failed'
        return result

    if 'cli' not in red_data:
        print_exception(
            RedSpecificationError(
                'ERROR: REDFILE does not contain cli section.'))
        result['debugInfo'] = exception_format()
        result['state'] = 'failed'
        return result

    cli = red_data['cli']

    dump_print(cli, fmt)

    return result
Example #6
0
def run(fmt):
    dump_print({'schemas': list(schemas.keys())}, fmt)
Example #7
0
def run(red_file, non_interactive, fmt, insecure, keyring_service, **_):
    secret_values = None
    result = {'state': 'succeeded', 'debugInfo': None}
    try:
        red_data = load_and_read(red_file, 'REDFILE')
        red_validation(red_data, False)
        engine_validation(red_data, 'execution', ['ccfaice', 'ccagency'],
                          'faice exec')

        secret_values = get_secret_values(red_data)

        # exec via CC-FAICE
        # equivalent to `faice agent red --debug --outputs`
        if 'execution' not in red_data:
            raise KeyError(
                'The key "execution" is needed in red file for usage with faice exec.'
            )
        if red_data['execution']['engine'] == 'ccfaice':
            # use connectors, if red file specifies outputs
            if _has_outputs(red_data):
                faice_output_mode = OutputMode.Connectors
            else:
                faice_output_mode = OutputMode.Directory

            result = run_faice_agent_red(red_file=red_file,
                                         disable_pull=False,
                                         leave_container=False,
                                         preserve_environment=[],
                                         non_interactive=non_interactive,
                                         insecure=insecure,
                                         output_mode=faice_output_mode,
                                         keyring_service=keyring_service,
                                         gpu_ids=None)
            return result

        complete_red_templates(red_data, keyring_service, non_interactive)

        red_data_normalized = deepcopy(red_data)
        normalize_keys(red_data_normalized)

        if 'access' not in red_data_normalized['execution']['settings']:
            result['debugInfo'] = [
                'ERROR: cannot send RED data to CC-Agency if access settings are not defined.'
            ]
            result['state'] = 'failed'
            return result

        if 'auth' not in red_data_normalized['execution']['settings'][
                'access']:
            result['debugInfo'] = [
                'ERROR: cannot send RED data to CC-Agency if auth is not defined in access '
                'settings.'
            ]
            result['state'] = 'failed'
            return result

        access = red_data_normalized['execution']['settings']['access']

        r = requests.post('{}/red'.format(access['url'].strip('/')),
                          auth=(access['auth']['username'],
                                access['auth']['password']),
                          json=red_data)
        if 400 <= r.status_code < 500:
            try:
                pprint(r.json())
            except ValueError:  # if the body does not contain json, we ignore it
                pass
        r.raise_for_status()

        dump_print(r.json(), fmt)
    except Exception as e:
        print_exception(e, secret_values)
        result['debugInfo'] = exception_format(secret_values)
        result['state'] = 'failed'

    return result