2010-12-10 12:31:58 -06:00
|
|
|
# Authors:
|
|
|
|
# Rob Crittenden <rcritten@redhat.com>
|
2012-01-16 04:14:59 -06:00
|
|
|
# Martin Kosek <mkosek@redhat.com>
|
2010-12-10 12:31:58 -06:00
|
|
|
#
|
|
|
|
# Copyright (C) 2010 Red Hat
|
|
|
|
# see file 'COPYING' for use and warranty information
|
|
|
|
#
|
2010-12-09 06:59:11 -06:00
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
2010-12-10 12:31:58 -06:00
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2010-12-09 06:59:11 -06:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2011-08-24 21:48:30 -05:00
|
|
|
|
|
|
|
from ipalib import api, _, ngettext
|
2011-11-21 09:50:27 -06:00
|
|
|
from ipalib import Flag, Str
|
2011-08-24 21:48:30 -05:00
|
|
|
from ipalib.request import context
|
|
|
|
from ipalib import api, crud, errors
|
|
|
|
from ipalib import output
|
|
|
|
from ipalib import Object, Command
|
2012-01-16 04:14:59 -06:00
|
|
|
from ipalib.plugins.baseldap import gen_pkey_only_option
|
2011-08-24 21:48:30 -05:00
|
|
|
|
|
|
|
__doc__ = _("""
|
2010-12-10 12:31:58 -06:00
|
|
|
Group to Group Delegation
|
|
|
|
|
|
|
|
A permission enables fine-grained delegation of permissions. Access Control
|
|
|
|
Rules, or instructions (ACIs), grant permission to permissions to perform
|
|
|
|
given tasks such as adding a user, modifying a group, etc.
|
|
|
|
|
|
|
|
Group to Group Delegations grants the members of one group to update a set
|
|
|
|
of attributes of members of another group.
|
|
|
|
|
|
|
|
EXAMPLES:
|
|
|
|
|
2011-08-19 16:33:50 -05:00
|
|
|
Add a delegation rule to allow managers to edit employee's addresses:
|
2012-02-06 06:18:11 -06:00
|
|
|
ipa delegation-add --attrs=street --group=managers --membergroup=employees "managers edit employees' street"
|
2010-12-10 12:31:58 -06:00
|
|
|
|
|
|
|
When managing the list of attributes you need to include all attributes
|
2011-01-28 06:33:04 -06:00
|
|
|
in the list, including existing ones. Add postalCode to the list:
|
2013-02-22 07:48:50 -06:00
|
|
|
ipa delegation-mod --attrs=street --attrs=postalCode --group=managers --membergroup=employees "managers edit employees' street"
|
2010-12-10 12:31:58 -06:00
|
|
|
|
|
|
|
Display our updated rule:
|
2011-08-19 16:33:50 -05:00
|
|
|
ipa delegation-show "managers edit employees' street"
|
2010-12-10 12:31:58 -06:00
|
|
|
|
|
|
|
Delete a rule:
|
2011-08-19 16:33:50 -05:00
|
|
|
ipa delegation-del "managers edit employees' street"
|
2011-08-24 21:48:30 -05:00
|
|
|
""")
|
2010-12-10 12:31:58 -06:00
|
|
|
|
2011-01-21 02:20:01 -06:00
|
|
|
ACI_PREFIX=u"delegation"
|
|
|
|
|
2012-02-02 14:28:15 -06:00
|
|
|
output_params = (
|
|
|
|
Str('aci',
|
|
|
|
label=_('ACI'),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
2010-12-10 12:31:58 -06:00
|
|
|
class delegation(Object):
|
|
|
|
"""
|
|
|
|
Delegation object.
|
|
|
|
"""
|
|
|
|
|
2010-12-13 22:13:04 -06:00
|
|
|
bindable = False
|
2011-07-12 11:01:25 -05:00
|
|
|
object_name = _('delegation')
|
|
|
|
object_name_plural = _('delegations')
|
2011-06-24 11:39:48 -05:00
|
|
|
label = _('Delegations')
|
2011-07-13 21:10:47 -05:00
|
|
|
label_singular = _('Delegation')
|
2010-12-10 12:31:58 -06:00
|
|
|
|
|
|
|
takes_params = (
|
|
|
|
Str('aciname',
|
|
|
|
cli_name='name',
|
|
|
|
label=_('Delegation name'),
|
|
|
|
doc=_('Delegation name'),
|
|
|
|
primary_key=True,
|
|
|
|
),
|
2011-11-21 09:50:27 -06:00
|
|
|
Str('permissions*',
|
2010-12-10 12:31:58 -06:00
|
|
|
cli_name='permissions',
|
|
|
|
label=_('Permissions'),
|
2013-02-14 11:01:16 -06:00
|
|
|
doc=_('Permissions to grant (read, write). Default is write.'),
|
2011-11-21 09:50:27 -06:00
|
|
|
csv=True,
|
2010-12-10 12:31:58 -06:00
|
|
|
),
|
2011-11-21 09:50:27 -06:00
|
|
|
Str('attrs+',
|
2010-12-10 12:31:58 -06:00
|
|
|
cli_name='attrs',
|
|
|
|
label=_('Attributes'),
|
2013-02-14 11:01:16 -06:00
|
|
|
doc=_('Attributes to which the delegation applies'),
|
2011-11-21 09:50:27 -06:00
|
|
|
csv=True,
|
2010-12-17 15:57:28 -06:00
|
|
|
normalizer=lambda value: value.lower(),
|
2010-12-10 12:31:58 -06:00
|
|
|
),
|
|
|
|
Str('memberof',
|
|
|
|
cli_name='membergroup',
|
|
|
|
label=_('Member user group'),
|
|
|
|
doc=_('User group to apply delegation to'),
|
|
|
|
),
|
|
|
|
Str('group',
|
|
|
|
cli_name='group',
|
|
|
|
label=_('User group'),
|
|
|
|
doc=_('User group ACI grants access to'),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
2010-12-13 22:13:04 -06:00
|
|
|
def __json__(self):
|
|
|
|
json_friendly_attributes = (
|
2011-06-23 19:48:50 -05:00
|
|
|
'label', 'label_singular', 'takes_params', 'bindable', 'name',
|
2010-12-13 22:13:04 -06:00
|
|
|
'object_name', 'object_name_plural',
|
|
|
|
)
|
|
|
|
json_dict = dict(
|
|
|
|
(a, getattr(self, a)) for a in json_friendly_attributes
|
|
|
|
)
|
2010-10-25 18:55:57 -05:00
|
|
|
json_dict['primary_key'] = self.primary_key.name
|
|
|
|
|
2010-12-13 22:13:04 -06:00
|
|
|
json_dict['methods'] = [m for m in self.methods]
|
|
|
|
return json_dict
|
|
|
|
|
2012-02-02 14:28:15 -06:00
|
|
|
def postprocess_result(self, result):
|
|
|
|
try:
|
|
|
|
# do not include prefix in result
|
|
|
|
del result['aciprefix']
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
|
2010-12-10 12:31:58 -06:00
|
|
|
api.register(delegation)
|
|
|
|
|
|
|
|
|
|
|
|
class delegation_add(crud.Create):
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _('Add a new delegation.')
|
2010-12-10 12:31:58 -06:00
|
|
|
|
|
|
|
msg_summary = _('Added delegation "%(value)s"')
|
2012-02-02 14:28:15 -06:00
|
|
|
has_output_params = output_params
|
2010-12-10 12:31:58 -06:00
|
|
|
|
|
|
|
def execute(self, aciname, **kw):
|
|
|
|
if not 'permissions' in kw:
|
|
|
|
kw['permissions'] = (u'write',)
|
2011-01-21 02:20:01 -06:00
|
|
|
kw['aciprefix'] = ACI_PREFIX
|
2010-12-10 12:31:58 -06:00
|
|
|
result = api.Command['aci_add'](aciname, **kw)['result']
|
2012-02-02 14:28:15 -06:00
|
|
|
self.obj.postprocess_result(result)
|
2010-12-10 12:31:58 -06:00
|
|
|
|
|
|
|
return dict(
|
|
|
|
result=result,
|
|
|
|
value=aciname,
|
|
|
|
)
|
|
|
|
|
|
|
|
api.register(delegation_add)
|
|
|
|
|
|
|
|
|
|
|
|
class delegation_del(crud.Delete):
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _('Delete a delegation.')
|
2010-12-10 12:31:58 -06:00
|
|
|
|
2011-01-07 10:17:55 -06:00
|
|
|
has_output = output.standard_boolean
|
2010-12-10 12:31:58 -06:00
|
|
|
msg_summary = _('Deleted delegation "%(value)s"')
|
|
|
|
|
|
|
|
def execute(self, aciname, **kw):
|
2011-01-21 02:20:01 -06:00
|
|
|
kw['aciprefix'] = ACI_PREFIX
|
2010-12-10 12:31:58 -06:00
|
|
|
result = api.Command['aci_del'](aciname, **kw)
|
2012-02-02 14:28:15 -06:00
|
|
|
self.obj.postprocess_result(result)
|
2010-12-10 12:31:58 -06:00
|
|
|
return dict(
|
|
|
|
result=True,
|
|
|
|
value=aciname,
|
|
|
|
)
|
|
|
|
|
|
|
|
api.register(delegation_del)
|
|
|
|
|
|
|
|
|
|
|
|
class delegation_mod(crud.Update):
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _('Modify a delegation.')
|
2010-12-10 12:31:58 -06:00
|
|
|
|
|
|
|
msg_summary = _('Modified delegation "%(value)s"')
|
2012-02-02 14:28:15 -06:00
|
|
|
has_output_params = output_params
|
2010-12-10 12:31:58 -06:00
|
|
|
|
|
|
|
def execute(self, aciname, **kw):
|
2011-01-21 02:20:01 -06:00
|
|
|
kw['aciprefix'] = ACI_PREFIX
|
2010-12-10 12:31:58 -06:00
|
|
|
result = api.Command['aci_mod'](aciname, **kw)['result']
|
2012-02-02 14:28:15 -06:00
|
|
|
self.obj.postprocess_result(result)
|
2012-01-16 04:14:59 -06:00
|
|
|
|
2010-12-10 12:31:58 -06:00
|
|
|
return dict(
|
|
|
|
result=result,
|
|
|
|
value=aciname,
|
|
|
|
)
|
|
|
|
|
|
|
|
api.register(delegation_mod)
|
|
|
|
|
|
|
|
|
|
|
|
class delegation_find(crud.Search):
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _('Search for delegations.')
|
2010-12-10 12:31:58 -06:00
|
|
|
|
|
|
|
msg_summary = ngettext(
|
2011-02-23 15:47:49 -06:00
|
|
|
'%(count)d delegation matched', '%(count)d delegations matched', 0
|
2010-12-10 12:31:58 -06:00
|
|
|
)
|
|
|
|
|
2012-01-16 04:14:59 -06:00
|
|
|
takes_options = (gen_pkey_only_option("name"),)
|
2012-02-02 14:28:15 -06:00
|
|
|
has_output_params = output_params
|
2012-01-16 04:14:59 -06:00
|
|
|
|
2010-12-10 12:31:58 -06:00
|
|
|
def execute(self, term, **kw):
|
2011-01-21 02:20:01 -06:00
|
|
|
kw['aciprefix'] = ACI_PREFIX
|
2012-01-16 04:14:59 -06:00
|
|
|
results = api.Command['aci_find'](term, **kw)['result']
|
|
|
|
|
|
|
|
for aci in results:
|
2012-02-02 14:28:15 -06:00
|
|
|
self.obj.postprocess_result(aci)
|
2010-12-10 12:31:58 -06:00
|
|
|
|
|
|
|
return dict(
|
|
|
|
result=results,
|
|
|
|
count=len(results),
|
|
|
|
truncated=False,
|
|
|
|
)
|
|
|
|
|
|
|
|
api.register(delegation_find)
|
|
|
|
|
|
|
|
|
|
|
|
class delegation_show(crud.Retrieve):
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _('Display information about a delegation.')
|
|
|
|
|
2012-02-02 14:28:15 -06:00
|
|
|
has_output_params = output_params
|
2010-12-10 12:31:58 -06:00
|
|
|
|
|
|
|
def execute(self, aciname, **kw):
|
2012-02-02 14:28:15 -06:00
|
|
|
result = api.Command['aci_show'](aciname, aciprefix=ACI_PREFIX, **kw)['result']
|
|
|
|
self.obj.postprocess_result(result)
|
2010-12-10 12:31:58 -06:00
|
|
|
return dict(
|
|
|
|
result=result,
|
|
|
|
value=aciname,
|
|
|
|
)
|
|
|
|
|
|
|
|
api.register(delegation_show)
|