Example #1
0
def rid_isa_notification(id: str) -> Tuple[str, int]:
    """Implements RID ISA notification receiver."""
    req = fetch.describe_flask_request(flask.request)
    req['endpoint'] = 'identification_service_areas'
    log_name = context.resources.logger.log_new('notify_isa', req)

    claims = req.token
    owner = claims.get('sub', '<No owner in token>')
    label = colored('ISA', 'cyan')
    try:
        json = flask.request.json
        if json.get('service_area'):
            isa = json['service_area']
            owner_body = isa.get('owner')
            if owner_body and owner_body != owner:
                owner = '{} token|{} body'.format(owner, owner_body)
            version = isa.get('version', '<Unknown version>')
            time_range = _print_time_range(isa.get('time_start'),
                                           isa.get('time_end'))
            _logger.info('{} {} v{} ({}) updated{} -> {}'.format(
                label, id, version, owner, time_range, log_name))
        else:
            _logger.info('{} {} ({}) deleted -> {}'.format(
                label, id, owner, log_name))
    except ValueError as e:
        _logger.error('{} {} ({}) unable to decode JSON: {} -> {}'.format(
            label, id, owner, e, log_name))

    return RESULT
Example #2
0
def catch_all(u_path) -> Tuple[str, int]:
    req = fetch.describe_flask_request(flask.request)
    req['endpoint'] = 'catch_all'
    log_name = context.resources.logger.log_new('uss_badroute', req)

    claims = req.token
    owner = claims.get('sub', '<No owner in token>')
    label = colored('Bad route', 'red')
    _logger.error('{} to {} ({}): {}'.format(label, u_path, owner, log_name))

    return RESULT
Example #3
0
def scd_operation_notification() -> Tuple[str, int]:
    """Implements SCD Operation notification receiver."""
    req = fetch.describe_flask_request(flask.request)
    req['endpoint'] = 'operations'
    log_name = context.resources.logger.log_new('notify_op', req)

    claims = req.token
    owner = claims.get('sub', '<No owner in token>')
    label = colored('Operation', 'blue')
    try:
        json = flask.request.json
        id = json.get('operation_id', '<Unknown ID>')
        if json.get('operation'):
            op = json['operation']
            version = '<Unknown version>'
            ovn = '<Unknown OVN>'
            time_range = ''
            if op.get('reference'):
                op_ref = op['reference']
                owner_body = op_ref.get('owner')
                if owner_body and owner_body != owner:
                    owner = '{} token|{} body'.format(owner, owner_body)
                version = op_ref.get('version', version)
                ovn = op_ref.get('ovn', ovn)
                time_range = _print_time_range(
                    op_ref.get('time_start', {}).get('value'),
                    op_ref.get('time_end', {}).get('value'))
            state = '<Unknown state>'
            vlos = False
            if op.get('details'):
                op_details = op['details']
                state = op_details.get('state')
                vlos = op_details.get('vlos', vlos)
            vlos_text = 'VLOS' if vlos else 'BVLOS'
            _logger.info('{} {} {} {} v{} ({}) OVN[{}] updated{} -> {}'.format(
                label, state, vlos_text, id, version, owner, ovn, time_range,
                log_name))
        else:
            _logger.info('{} {} ({}) deleted -> {}'.format(
                label, id, owner, log_name))
    except ValueError as e:
        _logger.error('{} ({}) unable to decode JSON: {} -> {}'.format(
            label, owner, e, log_name))

    return RESULT
Example #4
0
def scd_constraint_notification() -> Tuple[str, int]:
    """Implements SCD Constraint notification receiver."""
    req = fetch.describe_flask_request(flask.request)
    req['endpoint'] = 'constraints'
    log_name = context.resources.logger.log_new('notify_constraint', req)

    claims = infrastructure.get_token_claims(
        {k: v
         for k, v in flask.request.headers})
    owner = claims.get('sub', '<No owner in token>')
    label = colored('Constraint', 'magenta')
    try:
        json = flask.request.json
        id = json.get('constraint_id', '<Unknown ID>')
        if json.get('constraint'):
            constraint = json['constraint']
            version = '<Unknown version>'
            ovn = '<Unknown OVN>'
            time_range = ''
            if constraint.get('reference'):
                constraint_ref = constraint['reference']
                owner_body = constraint_ref.get('owner')
                if owner_body and owner_body != owner:
                    owner = '{} token|{} body'.format(owner, owner_body)
                version = constraint_ref.get('version', version)
                ovn = constraint_ref.get('ovn', ovn)
                time_range = _print_time_range(
                    constraint_ref.get('time_start', {}).get('value'),
                    constraint_ref.get('time_end', {}).get('value'))
            type = '<Unspecified type>'
            if constraint.get('details'):
                constraint_details = constraint['details']
                type = constraint_details.get('type')
            _logger.info('{} {} {} v{} ({}) OVN[{}] updated{} -> {}'.format(
                label, type, id, version, owner, ovn, time_range, log_name))
        else:
            _logger.info('{} {} ({}) deleted -> {}'.format(
                label, id, owner, log_name))
    except ValueError as e:
        _logger.error('{} ({}) unable to decode JSON: {} -> {}'.format(
            label, owner, e, log_name))

    return RESULT