Пример #1
0
def main():
    args = parse_arguments([{'name': 'fields', 'type': str}])

    # extract arguments
    dataset = load_dataset(args.dataset_path)
    original_dataset = load_dataset(args.origin_path)
    fields = json.loads(args.fields)

    usernames = []
    iterate_and_apply(original_dataset, fields, usernames.append)

    # detect names by traversing the dataset
    matches = []
    find_names(dataset, usernames, matches)

    # notify the detected user names
    if len(matches) > 0:
        messages = ["Detected user names: "] + \
            ['  - %s' % m for m in matches[:10]]
        if len(matches) > 10:
            messages.append('  - ...')

        notify_validation_result(ValidationOutcome.FAILURE,
                                 '\n'.join(messages))
    else:
        notify_validation_result(ValidationOutcome.SUCCESS,
                                 'No user name detected')
Пример #2
0
def main():
    # Prepares the parameters for the algorithm (dataset_path and output_path
    # come by default). You can then use them with args.parameter_name.
    # Avoid editing the parameters here, use the dedicated utility instead and
    # the code will change accordingly.
    args = parse_arguments()

    # load the json dataset, available as a python dictionary
    dataset = load_dataset(args.dataset_path)

    # write your validation code here

    # notify the validation outcome
    # outcome should be one of ValidationOutcome.SUCCESS,
    # ValidationOutcome.WARNING or ValidationOutcome.FAILURE
    # write the information to display in info
    outcome = ValidationOutcome.SUCCESS
    info = ""

    notify_validation_result(outcome, info)
Пример #3
0
def main():
    args = parse_arguments([
        {'name': 'quasi_identifiers', 'type': str},
        {'name': 'k', 'type': int}
    ])

    dataset = load_dataset(args.dataset_path)
    quasi_identifiers = json.loads(args.quasi_identifiers)
    relevant_arrays = find_selected_arrays(dataset, quasi_identifiers)

    if len(relevant_arrays) == 0:
        notify_validation_result(
            ValidationOutcome.WARNING, "No quasi identifier was found")
    else:
        # compute k-anonymity for each array containing QI's.
        # final k-anonymity will be the lowest of them
        ks = [compute_kanonymity(a['array'], a['field_selection'])
              for a in relevant_arrays]
        k = min(ks)

        if k >= args.k:
            notify_validation_result(
                ValidationOutcome.SUCCESS,
                '%d-anonymous (>= %d)' % (k, args.k))
        else:
            notify_validation_result(
                ValidationOutcome.FAILURE,
                '%d-anonymous (< %d)' % (k, args.k))
Пример #4
0
def main():
    args = parse_arguments([
        {'name': 'quasi_identifiers', 'type': str},
        {'name': 'sensitive_attributes', 'type': str},
        {'name': 'l', 'type': int}
    ])

    dataset = load_dataset(args.dataset_path)
    quasi_identifiers = json.loads(args.quasi_identifiers)
    sensitive_attributes = json.loads(args.sensitive_attributes)
    relevant_arrays = find_selected_arrays(
        dataset, quasi_identifiers, sensitive_attributes)

    if len(relevant_arrays) == 0:
        notify_validation_result(
            ValidationOutcome.WARNING, "No sensitive attribute was found")
    else:
        # compute l-diversity for each array with SA's
        # final l-diversity will be the smallest of them
        ls = [compute_ldiversity(array['array'],
                                 array['quasi_identifiers'],
                                 array['sensitive_attributes'])
              for array in relevant_arrays]
        l = min(ls)

        if l >= args.l:
            notify_validation_result(
                ValidationOutcome.SUCCESS,
                '%d-diversified (>= %d)' % (l, args.l))
        else:
            notify_validation_result(
                ValidationOutcome.FAILURE,
                '%d-diversified (< %d)' % (l, args.l))
Пример #5
0
def main():
    notify_validation_result(ValidationOutcome.SUCCESS, "Successful")
Пример #6
0
def main():
    notify_validation_result(ValidationOutcome.FAILURE, "Failure")
def main():
    args = parse_arguments()

    dataset = load_dataset(args.dataset_path)
    has_user_name = False
    has_AP_settings = False
    has_API_data = False

    # verify in 'actions' if 'data' and 'geolocation' are present
    has_action_data = False
    has_action_geolocation = False
    actions = dataset['data']['actions']
    for action in actions:
        if 'data' in action:
            data = action['data']
            if data != None and data != '' and data != {}:
                has_action_data = True
        if 'geolocation' in action:
            geolocation = action['geolocation']
            if geolocation != None and geolocation != '' and geolocation != {}:
                has_action_geolocation = True

    # verify in 'users' if 'name' is present
    users = dataset['data']['users']
    for user in users:
        if 'name' in user:
            name = user['name']
            if name != None and name != '':
                has_user_name = True

    # verify in 'appInstances' if 'settings' is present
    appInstances = dataset['data']['appInstances']
    for ar in appInstances:
        if 'settings' in ar:
            settings = ar['settings']
            if settings != None and settings != '' and settings != {}:
                has_AP_settings = True

    # verify in 'appInstanceResources' if 'data' is present
    appInstanceResources = dataset['data']['appInstanceResources']
    for air in appInstanceResources:
        if 'data' in air:
            data = air['data']
            if data != None and data != '' and data != {}:
                has_API_data = True

    # issue a warning if any of these potentially dangerousattributes
    # are present
    potentially_dangerous = (has_action_data or has_action_geolocation
                             or has_user_name or has_AP_settings
                             or has_API_data)
    if potentially_dangerous:
        messages = ['Potentially dangerous attributes: ']
        if has_action_data:
            messages.append('- actions > data')
        if has_action_geolocation:
            messages.append('- actions > geolocation')
        if has_user_name:
            messages.append('- users > name')
        if has_AP_settings:
            messages.append('- appInstances > settings')
        if has_API_data:
            messages.append('- appInstanceResources > data')

        notify_validation_result(ValidationOutcome.WARNING,
                                 '\n'.join(messages))
    else:
        notify_validation_result(ValidationOutcome.SUCCESS,
                                 'No potentially dangerous attributes')
Пример #8
0
def main():
    notify_validation_result(ValidationOutcome.WARNING, "Warning")