Exemple #1
0
def get_user_result(uid,
                    givenname,
                    sn,
                    operation='show',
                    omit=[],
                    **overrides):
    """Get a user result for a user-{add,mod,find,show} command

    This gives the result as from a user_add(uid, givenname=givenname, sn=sn);
    modifications to that can be specified in ``omit`` and ``overrides``.

    The ``operation`` can be one of:
    - add
    - show
    - show-all ((show with the --all flag)
    - find
    - mod

    Attributes named in ``omit`` are removed from the result; any additional
    or non-default values can be specified in ``overrides``.
    """
    # sn can be None; this should only be used from `get_admin_result`
    cn = overrides.get('cn', ['%s %s' % (givenname, sn or '')])
    cn[0] = cn[0].strip()
    result = add_sid(
        dict(
            homedirectory=[u'/home/%s' % uid],
            loginshell=[u'/bin/sh'],
            uid=[uid],
            uidnumber=[fuzzy_digits],
            gidnumber=[fuzzy_digits],
            krbcanonicalname=[u'%s@%s' % (uid, api.env.realm)],
            krbprincipalname=[u'%s@%s' % (uid, api.env.realm)],
            mail=[u'%s@%s' % (uid, api.env.domain)],
            has_keytab=False,
            has_password=False,
        ))
    if sn:
        result['sn'] = [sn]
    if givenname:
        result['givenname'] = [givenname]
    if operation in ('add', 'show', 'show-all', 'find'):
        result.update(dn=get_user_dn(uid), )
    if operation in ('add', 'show-all'):
        result.update(cn=cn,
                      displayname=cn,
                      gecos=cn,
                      initials=[givenname[0] + (sn or '')[:1]],
                      ipauniqueid=[fuzzy_uuid],
                      mepmanagedentry=[get_group_dn(uid)],
                      objectclass=add_oc(objectclasses.user,
                                         u'ipantuserattrs'),
                      krbprincipalname=[u'%s@%s' % (uid, api.env.realm)],
                      krbcanonicalname=[u'%s@%s' % (uid, api.env.realm)])
    if operation in ('show', 'show-all', 'find', 'mod'):
        result.update(nsaccountlock=False, )
    if operation in ('add', 'show', 'show-all', 'mod'):
        result.update(memberof_group=[u'ipausers'], )
    for key in omit:
        del result[key]
    result.update(overrides)
    return result
Exemple #2
0
def get_user_result(uid, givenname, sn, operation='show', omit=[],
                    **overrides):
    """Get a user result for a user-{add,mod,find,show} command

    This gives the result as from a user_add(uid, givenname=givenname, sn=sn);
    modifications to that can be specified in ``omit`` and ``overrides``.

    The ``operation`` can be one of:
    - add
    - show
    - show-all ((show with the --all flag)
    - find
    - mod

    Attributes named in ``omit`` are removed from the result; any additional
    or non-default values can be specified in ``overrides``.
    """
    # sn can be None; this should only be used from `get_admin_result`
    cn = overrides.get('cn', ['%s %s' % (givenname, sn or '')])
    cn[0] = cn[0].strip()
    result = add_sid(dict(
        homedirectory=[u'/home/%s' % uid],
        loginshell=[u'/bin/sh'],
        uid=[uid],
        uidnumber=[fuzzy_digits],
        gidnumber=[fuzzy_digits],
        krbcanonicalname=[u'%s@%s' % (uid, api.env.realm)],
        krbprincipalname=[u'%s@%s' % (uid, api.env.realm)],
        mail=[u'%s@%s' % (uid, api.env.domain)],
        has_keytab=False,
        has_password=False,
    ))
    if sn:
        result['sn'] = [sn]
    if givenname:
        result['givenname'] = [givenname]
    if operation in ('add', 'show', 'show-all', 'find'):
        result.update(
            dn=get_user_dn(uid),
        )
    if operation in ('add', 'show-all'):
        result.update(
            cn=cn,
            displayname=cn,
            gecos=cn,
            initials=[givenname[0] + (sn or '')[:1]],
            ipauniqueid=[fuzzy_uuid],
            mepmanagedentry=[get_group_dn(uid)],
            objectclass=add_oc(objectclasses.user, u'ipantuserattrs'),
            krbprincipalname=[u'%s@%s' % (uid, api.env.realm)],
            krbcanonicalname=[u'%s@%s' % (uid, api.env.realm)]
        )
    if operation in ('show', 'show-all', 'find', 'mod'):
        result.update(
            nsaccountlock=False,
        )
    if operation in ('add', 'show', 'show-all', 'mod'):
        result.update(
            memberof_group=[u'ipausers'],
        )
    for key in omit:
        del result[key]
    result.update(overrides)
    return result