class BaseParam(BaseMetaObject): takes_params = BaseMetaObject.takes_params + ( Str( 'type?', label=_("Type"), flags={'no_search'}, ), Bool( 'required?', label=_("Required"), flags={'no_search'}, ), Bool( 'multivalue?', label=_("Multi-value"), flags={'no_search'}, ), ) def get_params(self): for param in super(BaseParam, self).get_params(): if param.name == 'name': param = param.clone(primary_key=True) yield param @property def parent(self): raise AttributeError('parent') def _split_search_args(self, parent_name, criteria=None): return [parent_name], criteria
class certmapconfig(LDAPObject): """ Certificate Identity Mapping configuration object """ object_name = _('Certificate Identity Mapping configuration options') default_attributes = ['ipacertmappromptusername'] container_dn = api.env.container_certmap label = _('Certificate Identity Mapping Global Configuration') label_singular = _('Certificate Identity Mapping Global Configuration') takes_params = (Bool( 'ipacertmappromptusername', cli_name='promptusername', label=_('Prompt for the username'), doc=_('Prompt for the username when multiple identities' ' are mapped to a certificate'), ), ) permission_filter_objectclasses = ['ipacertmapconfigobject'] managed_permissions = { 'System: Read Certmap Configuration': { 'replaces_global_anonymous_aci': True, 'ipapermbindruletype': 'all', 'ipapermright': {'read', 'search', 'compare'}, 'ipapermdefaultattr': { 'ipacertmappromptusername', 'cn', }, }, 'System: Modify Certmap Configuration': { 'replaces_global_anonymous_aci': True, 'ipapermright': {'write'}, 'ipapermdefaultattr': { 'ipacertmappromptusername', }, 'default_privileges': {'Certificate Identity Mapping Administrators'}, }, }
class param(BaseParam): takes_params = BaseParam.takes_params + ( Bool( 'alwaysask?', label=_("Always ask"), flags={'no_search'}, ), Str( 'cli_metavar?', label=_("CLI metavar"), flags={'no_search'}, ), Str( 'cli_name?', label=_("CLI name"), flags={'no_search'}, ), Bool( 'confirm', label=_("Confirm (password)"), flags={'no_search'}, ), Str( 'default*', label=_("Default"), flags={'no_search'}, ), Str( 'default_from_param*', label=_("Default from"), flags={'no_search'}, ), Str( 'label?', label=_("Label"), flags={'no_search'}, ), Bool( 'no_convert?', label=_("Convert on server"), flags={'no_search'}, ), Str( 'option_group?', label=_("Option group"), flags={'no_search'}, ), Bool( 'sensitive?', label=_("Sensitive"), flags={'no_search'}, ), Bool( 'positional?', label=_("Positional argument"), flags={'no_search'}, ), ) @property def parent(self): return self.api.Object.metaobject def _get_obj(self, metaobj_param, **kwargs): metaobj, param = metaobj_param obj = dict() obj['name'] = unicode(param.name) if param.type is unicode: obj['type'] = u'str' elif param.type is bytes: obj['type'] = u'bytes' elif param.type is not None: obj['type'] = unicode(param.type.__name__) if not param.required: obj['required'] = False if param.multivalue: obj['multivalue'] = True if param.password: obj['sensitive'] = True if isinstance(metaobj, Command): if param.required and param.name not in metaobj.args: obj['positional'] = False elif not param.required and param.name in metaobj.args: obj['positional'] = True for key, value in param._Param__clonekw.items(): if key in ('doc', 'label'): obj[key] = unicode(value) elif key in ('exclude', 'include'): obj[key] = list(unicode(v) for v in value) if isinstance(metaobj, Command): if key == 'alwaysask': obj.setdefault(key, value) elif key == 'confirm': obj[key] = value elif key in ('cli_metavar', 'cli_name', 'option_group'): obj[key] = unicode(value) elif key == 'default': if param.multivalue: obj[key] = [unicode(v) for v in value] else: obj[key] = [unicode(value)] if not param.autofill: obj['alwaysask'] = True elif key == 'default_from': obj['default_from_param'] = list( unicode(k) for k in value.keys) if not param.autofill: obj['alwaysask'] = True elif key in ('exponential', 'normalizer', 'only_absolute', 'precision'): obj['no_convert'] = True if ((isinstance(metaobj, Command) and 'no_option' in param.flags) or (isinstance(metaobj, Object) and 'no_output' in param.flags)): value = obj.setdefault('exclude', []) if u'cli' not in value: value.append(u'cli') if u'webui' not in value: value.append(u'webui') return obj def _retrieve(self, metaobjectfull_name, name, **kwargs): found = False try: metaobj = self.api.Command[metaobjectfull_name] except KeyError: raise errors.NotFound( reason=_("%(metaobject)s: %(oname)s not found") % { 'metaobject': metaobjectfull_name, 'oname': self.name, }) if 'command' in self.api.Object: plugin = self.api.Object['command'] found = True elif 'class' in self.api.Object: plugin = self.api.Object['class'] found = True if found: for param in plugin._iter_params(metaobj): if param.name == name: return metaobj, param raise errors.NotFound(reason=_("%(pkey)s: %(oname)s not found") % { 'pkey': name, 'oname': self.name, }) def _search(self, metaobjectfull_name, **kwargs): try: metaobj = self.api.Command[metaobjectfull_name] plugin = self.api.Object['command'] except KeyError: try: metaobj = self.api.Object[metaobjectfull_name] plugin = self.api.Object['class'] except KeyError: return tuple() return ((metaobj, param) for param in plugin._iter_params(metaobj))
# Installation: # Copy file to <path to python lib>/ipaserver/plugins/ # # Usage: # ipa user-mod --nextcloudenabled=TRUE <username> # from ipaserver.plugins import user from ipalib.parameters import Bool from ipalib import _ user.user.takes_params = user.user.takes_params + (Bool( 'nextcloudenabled?', cli_name='nextcloudenabled', label=_('Nextcloud Share enabled?'), doc= _('Whether or not a nextcloud share is created for this user (default is false).' ), default=False, autofill=True, ), ) user.user.default_attributes.append('nextcloudenabled') def useradd_precallback(self, ldap, dn, entry, attrs_list, *keys, **options): entry['objectclass'].append('nextclouduser') return dn user.user_add.register_pre_callback(useradd_precallback)
Str( "fasgithubusername?", cli_name="fasgithubusername", label=_("GitHub username"), maxlength=255, normalizer=lambda value: value.strip(), ), Str( "fasgitlabusername?", cli_name="fasgitlabusername", label=_("GitLab username"), maxlength=255, normalizer=lambda value: value.strip(), ), URL( "faswebsiteurl?", cli_name="faswebsiteurl", label=_("Website / Blog URL"), maxlength=255, normalizer=lambda value: value.strip(), ), Bool( "fasisprivate?", cli_name="fasisprivate", label=_("Hide personal data"), doc=_("Hide personal data from other users"), ), ) i18n_messages.messages["userfas"] = {"name": _("Fedora Account System")}