Beispiel #1
0
def add():
    opts = get_opts(
        'add_user', 'Adds User to a muam', {
            'username': '******',
            'email': 'email',
            'first_name': 'first_name',
            'full_name': 'full_name',
            'last_name': 'last_name',
            'phone': 'phone',
            'create_users': 'create_users',
            'create_groups': 'create_groups',
            'grant_privs': 'grant_privs',
        })

    session = get_session(opts)
    if not session:
        sys.exit('Invalid username/password.')

    add_item = User(**vars(opts))
    success, resp = add_item.save_new(session)

    if success:
        print('Added User with id: {}'.format(','.join(add_item.get_ids())))
    else:
        print('Add failed with code {} and message: {}'.format(
            resp.status_code, resp.text))
Beispiel #2
0
def search():
    opts = get_opts('search_user', 'Searches for Users in a muam',
                    {'search_text': 'search_text'})

    session = get_session(opts)
    if not session:
        sys.exit('Invalid username/password.')

    success, resp_list = User.search(session, opts.search_text)

    if success:
        for resp in resp_list:
            print('{} - {}'.format(resp.get_ids(), resp.full_name))
    else:
        print('Search failed with code {} and message: {}'.format(
            resp.status_code, resp.text))
Beispiel #3
0
def import_csv():
    opts = get_opts('import_user', 'Adds list of User to a muam',
                    {'f': 'filename'})

    if not opts.filename or not os.path.isfile(opts.filename):
        sys.exit('Filename {} does not exist or is not a file.'.format(
            opts.filename))

    session = get_session(opts)

    field_map = {}

    with open(opts.filename, "r") as csvfile:
        tagreader = csv.reader(csvfile)
        rowcount = 0
        for row in tagreader:
            rowcount += 1
            if rowcount == 1:
                fieldcount = 0
                for field in row:
                    field_map[field] = fieldcount
                    fieldcount += 1
                continue
            obj_data = {}
            for field in field_map:
                if field == 'authorizations':
                    obj_data['authorizations'] = []
                    auth_list = row[field_map[field]].split(', ')
                    for auth_item in auth_list:
                        auth_data = auth_item.split(':')
                        auth_gid = get_id_from_name(session, auth_data[0])
                        obj_data['authorizations'].append({
                            'group_id': auth_gid,
                            'role': auth_data[1]
                        })
                else:
                    lookup_res = get_id(session, field, row[field_map[field]])
                    obj_data[field] = lookup_res if lookup_res else row[
                        field_map[field]]
            new_obj = User(**obj_data)
            success, resp = new_obj.save_new(session)
            if success:
                print('row {} id: {}'.format(str(rowcount), new_obj.get_ids()))
            else:
                sys.exit('Add failed, code: {}, text: {}'.format(
                    resp.status_code, resp.text))
Beispiel #4
0
def add():
    opts = get_opts('add_group', 'Adds Group to a muam', {
        'description': 'description',
        'gid': 'gid',
        'name': 'name',
    })

    session = get_session(opts)
    if not session:
        sys.exit('Invalid username/password.')

    add_item = Group(**vars(opts))
    success, resp = add_item.save_new(session)

    if success:
        print('Added Group with id: {}'.format(','.join(add_item.get_ids())))
    else:
        print('Add failed with code {} and message: {}'.format(
            resp.status_code, resp.text))
Beispiel #5
0
def add():
    opts = get_opts(
        'add_membership', 'Adds Membership to a muam', {
            'group_id': 'group_id',
            'user_id': 'user_id',
            'is_owner': 'is_owner',
            'is_admin': 'is_admin',
        })

    session = get_session(opts)
    if not session:
        sys.exit('Invalid username/password.')

    add_item = Membership(**vars(opts))
    success, resp = add_item.save_new(session)

    if success:
        print('Added Membership with id: {}'.format(','.join(
            add_item.get_ids())))
    else:
        print('Add failed with code {} and message: {}'.format(
            resp.status_code, resp.text))