示例#1
0
def reset_defaults(obj):
    """ Reset all permissions"""

    click.echo("Listing existing permissions")
    perm_lst = obj['auth'].AllowedGroupsFactory.list_family()
    for perm_key in perm_lst:
        click.echo("Permission '{}'".format(perm_key))

    click.echo("Removing existing permissions")
    cnt = 0
    for perm_key in perm_lst:
        perm_obj = obj['auth'].AllowedGroupsFactory.from_raw(key=perm_key)
        perm_obj.delete()
        cnt += 1
    click.echo("Removed {} existing permissions".format(cnt))

    click.echo("Setting base permissions")
    perms_base_path = os.path.join(cogs.config.PERMS_PATH, "base.json")
    if os.path.isfile(perms_base_path):
        cnt = perms.set_perms_from_file(perms_base_path)
    else:
        cnt = 0
    click.echo("Set {} base permissions".format(cnt))

    click.echo("Setting file permissions")
    fle_lst = obj['server'].list_files()
    cnt = perms.create_perms(fle_lst, _FILES_KEY)
    cnt_per = cnt/len(fle_lst) if fle_lst else 0
    click.echo("Set {} file permissions ({} per file)".format(cnt, cnt_per))

    click.echo("Setting reporter permissions")
    rpt_lst = obj['server'].list_reporters()
    cnt = perms.create_perms(rpt_lst, _REPORTERS_KEY)
    cnt_per = cnt/len(rpt_lst) if rpt_lst else 0
    click.echo("Set {} reporter permissions ({} per reporter)".format(cnt, cnt_per))

    click.echo("Setting assignment permissions")
    asn_lst = obj['server'].list_assignments()
    cnt = perms.create_perms(asn_lst, _ASSIGNMENTS_KEY)
    cnt_per = cnt/len(asn_lst) if asn_lst else 0
    click.echo("Set {} assignment permissions ({} per assignment)".format(cnt, cnt_per))

    click.echo("Setting test permissions")
    tst_lst = obj['server'].list_tests()
    cnt = perms.create_perms(tst_lst, _TESTS_KEY)
    cnt_per = cnt/len(tst_lst) if tst_lst else 0
    click.echo("Set {} test permissions ({} per test)".format(cnt, cnt_per))

    click.echo("Setting submission permissions")
    sub_lst = obj['server'].list_submissions()
    cnt = perms.create_perms(sub_lst, _SUBMISSIONS_KEY)
    cnt_per = cnt/len(sub_lst) if sub_lst else 0
    click.echo("Set {} submission permissions ({} per submission)".format(cnt, cnt_per))

    click.echo("Setting run permissions")
    run_lst = obj['server'].list_runs()
    cnt = perms.create_perms(run_lst, _RUNS_KEY)
    cnt_per = cnt/len(run_lst) if run_lst else 0
    click.echo("Set {} run permissions ({} per run)".format(cnt, cnt_per))

    click.echo("Listing new permissions")
    perm_lst = obj['auth'].AllowedGroupsFactory.list_family()
    for perm_key in perm_lst:
        click.echo("Permission '{}'".format(perm_key))
示例#2
0
def reset_defaults(obj):
    """ Reset all permissions"""

    click.echo("Listing existing permissions")
    perm_lst = obj['auth'].AllowedGroupsFactory.list_family()
    for perm_key in perm_lst:
        click.echo("Permission '{}'".format(perm_key))

    click.echo("Removing existing permissions")
    cnt = 0
    for perm_key in perm_lst:
        perm_obj = obj['auth'].AllowedGroupsFactory.from_raw(key=perm_key)
        perm_obj.delete()
        cnt += 1
    click.echo("Removed {} existing permissions".format(cnt))

    click.echo("Setting base permissions")
    perms_base_path = os.path.join(cogs.config.PERMS_PATH, "base.json")
    if os.path.isfile(perms_base_path):
        cnt = perms.set_perms_from_file(perms_base_path)
    else:
        cnt = 0
    click.echo("Set {} base permissions".format(cnt))

    click.echo("Setting file permissions")
    fle_lst = obj['server'].list_files()
    cnt = perms.create_perms(fle_lst, _FILES_KEY)
    cnt_per = cnt / len(fle_lst) if fle_lst else 0
    click.echo("Set {} file permissions ({} per file)".format(cnt, cnt_per))

    click.echo("Setting reporter permissions")
    rpt_lst = obj['server'].list_reporters()
    cnt = perms.create_perms(rpt_lst, _REPORTERS_KEY)
    cnt_per = cnt / len(rpt_lst) if rpt_lst else 0
    click.echo("Set {} reporter permissions ({} per reporter)".format(
        cnt, cnt_per))

    click.echo("Setting assignment permissions")
    asn_lst = obj['server'].list_assignments()
    cnt = perms.create_perms(asn_lst, _ASSIGNMENTS_KEY)
    cnt_per = cnt / len(asn_lst) if asn_lst else 0
    click.echo("Set {} assignment permissions ({} per assignment)".format(
        cnt, cnt_per))

    click.echo("Setting test permissions")
    tst_lst = obj['server'].list_tests()
    cnt = perms.create_perms(tst_lst, _TESTS_KEY)
    cnt_per = cnt / len(tst_lst) if tst_lst else 0
    click.echo("Set {} test permissions ({} per test)".format(cnt, cnt_per))

    click.echo("Setting submission permissions")
    sub_lst = obj['server'].list_submissions()
    cnt = perms.create_perms(sub_lst, _SUBMISSIONS_KEY)
    cnt_per = cnt / len(sub_lst) if sub_lst else 0
    click.echo("Set {} submission permissions ({} per submission)".format(
        cnt, cnt_per))

    click.echo("Setting run permissions")
    run_lst = obj['server'].list_runs()
    cnt = perms.create_perms(run_lst, _RUNS_KEY)
    cnt_per = cnt / len(run_lst) if run_lst else 0
    click.echo("Set {} run permissions ({} per run)".format(cnt, cnt_per))

    click.echo("Listing new permissions")
    perm_lst = obj['auth'].AllowedGroupsFactory.list_family()
    for perm_key in perm_lst:
        click.echo("Permission '{}'".format(perm_key))
示例#3
0
def set_permissions(obj, path, endpoint):
    """Set permissions from json file"""

    cnt = perms.set_perms_from_file(path, endpoint)
    click.echo("Set {} permissions".format(cnt))
示例#4
0
def set_permissions(obj, path, endpoint):
    """Set permissions from json file"""

    cnt = perms.set_perms_from_file(path, endpoint)
    click.echo("Set {} permissions".format(cnt))