summaryrefslogtreecommitdiffstats
path: root/ipalib/plugins/pwpolicy.py
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2009-12-09 09:09:53 -0700
committerJason Gerard DeRose <jderose@redhat.com>2009-12-10 08:29:15 -0700
commitb6e4972e7f6aa08e0392a2cf441b60ab0e7d88b7 (patch)
tree7e5329a51af169ce34a7d275a1bbd63c1e31c026 /ipalib/plugins/pwpolicy.py
parentd08b8858ddc3bf6265f6ea8acae6661b9fff5112 (diff)
downloadfreeipa-b6e4972e7f6aa08e0392a2cf441b60ab0e7d88b7.tar.gz
freeipa-b6e4972e7f6aa08e0392a2cf441b60ab0e7d88b7.tar.xz
freeipa-b6e4972e7f6aa08e0392a2cf441b60ab0e7d88b7.zip
Take 2: Extensible return values and validation; steps toward a single output_for_cli(); enable more webUI stuff
Diffstat (limited to 'ipalib/plugins/pwpolicy.py')
-rw-r--r--ipalib/plugins/pwpolicy.py67
1 files changed, 25 insertions, 42 deletions
diff --git a/ipalib/plugins/pwpolicy.py b/ipalib/plugins/pwpolicy.py
index 5a07c880a..faf036418 100644
--- a/ipalib/plugins/pwpolicy.py
+++ b/ipalib/plugins/pwpolicy.py
@@ -25,6 +25,7 @@ Password policy
from ipalib import api, crud, errors
from ipalib import Command, Object
from ipalib import Int, Str
+from ipalib import output
from ldap.functions import explode_dn
_fields = {
@@ -54,6 +55,7 @@ def _convert_time_on_input(entry_attrs):
if 'krbminpwdlife' in entry_attrs:
entry_attrs['krbminpwdlife'] = entry_attrs['krbminpwdlife'] * 3600
+
def make_cos_entry(group, cospriority=None):
"""
Make the CoS dn and entry for this group.
@@ -64,9 +66,10 @@ def make_cos_entry(group, cospriority=None):
"""
try:
- (groupdn, group_attrs) = api.Command['group_show'](group)
+ entry = api.Command['group_show'](group)['result']
except errors.NotFound:
raise errors.NotFound(reason="group '%s' does not exist" % group)
+ groupdn = entry['dn']
cos_entry = {}
if cospriority:
@@ -76,6 +79,7 @@ def make_cos_entry(group, cospriority=None):
return (cos_dn, cos_entry)
+
def make_policy_entry(group_cn, policy_entry):
"""
Make the krbpwdpolicy dn and entry for this group.
@@ -98,6 +102,7 @@ def make_policy_entry(group_cn, policy_entry):
return (policy_dn, policy_entry)
+
class pwpolicy(Object):
"""
Password Policy object.
@@ -138,6 +143,7 @@ class pwpolicy(Object):
api.register(pwpolicy)
+
class pwpolicy_add(crud.Create):
"""
Create a new password policy associated with a group.
@@ -150,6 +156,7 @@ class pwpolicy_add(crud.Create):
),
Int('cospriority',
cli_name='priority',
+ label='Priority',
doc='Priority of the policy. Higher number equals higher priority',
minvalue=0,
attribute=True,
@@ -182,22 +189,12 @@ class pwpolicy_add(crud.Create):
_convert_time_for_output(entry_attrs)
- return (dn, entry_attrs)
-
- def output_for_cli(self, textui, result, *args, **options):
-# textui.print_name(self.name)
-# textui.print_dashed("Added policy for '%s'." % options['group'])
- (dn, entry_attrs) = result
-
- textui.print_name(self.name)
- textui.print_plain('Password policy:')
- for (k, v) in _fields.iteritems():
- if k in entry_attrs:
- textui.print_attribute(v, entry_attrs[k])
- textui.print_dashed('Modified password policy.')
+ entry_attrs['dn'] = dn
+ return dict(result=entry_attrs, value=group_cn)
api.register(pwpolicy_add)
+
class pwpolicy_mod(crud.Update):
"""
Modify password policy.
@@ -215,6 +212,10 @@ class pwpolicy_mod(crud.Update):
),
)
+ has_output = (
+ output.Entry('result'),
+ )
+
def execute(self, *args, **options):
assert 'dn' not in options
ldap = self.api.Backend.ldap2
@@ -235,24 +236,16 @@ class pwpolicy_mod(crud.Update):
_convert_time_for_output(entry_attrs)
- return (dn, entry_attrs)
-
- def output_for_cli(self, textui, result, *args, **options):
- (dn, entry_attrs) = result
-
- textui.print_name(self.name)
- textui.print_plain('Password policy:')
- for (k, v) in _fields.iteritems():
- if k in entry_attrs:
- textui.print_attribute(v, entry_attrs[k])
- textui.print_dashed('Modified password policy.')
+ return dict(result=entry_attrs)
api.register(pwpolicy_mod)
+
class pwpolicy_del(crud.Delete):
"""
Delete a group password policy.
"""
+
takes_options = (
Str('group',
doc='Group to remove policy from',
@@ -278,12 +271,10 @@ class pwpolicy_del(crud.Delete):
ldap.delete_entry(policy_dn, normalize=False)
ldap.delete_entry(cos_dn, normalize=False)
-
- return True
-
- def output_for_cli(self, textui, result, *args, **options):
- textui.print_name(self.name)
- textui.print_dashed('Deleted policy "%s".' % options['group'])
+ return dict(
+ result=True,
+ value=group_cn,
+ )
api.register(pwpolicy_del)
@@ -292,6 +283,7 @@ class pwpolicy_show(Command):
"""
Display password policy.
"""
+
takes_options = (
Str('group?',
doc='Group to display policy',
@@ -300,6 +292,7 @@ class pwpolicy_show(Command):
doc='Display policy applied to a given user',
),
)
+
def execute(self, *args, **options):
ldap = self.api.Backend.ldap2
@@ -333,16 +326,6 @@ class pwpolicy_show(Command):
entry_attrs['group'] = 'global'
_convert_time_for_output(entry_attrs)
- return (dn, entry_attrs)
-
- def output_for_cli(self, textui, result, *args, **options):
- (dn, entry_attrs) = result
-
- textui.print_name(self.name)
- textui.print_plain('Password policy:')
- for (k, v) in _fields.iteritems():
- if k in entry_attrs:
- textui.print_attribute(v, entry_attrs[k])
+ return dict(result=entry_attrs)
api.register(pwpolicy_show)
-