add user profile command line arg to all radius

profile command line tools to select between shared
and per user profiles

modify AttributeValueCompleter so default values prefer
previously entered values in editing session
This commit is contained in:
John Dennis
2007-11-28 12:06:06 -05:00
parent 904b76059c
commit d7a7ba4f45
4 changed files with 32 additions and 5 deletions

View File

@@ -59,6 +59,8 @@ def main():
opt_parser.add_option("-u", "--uid", dest="uid", opt_parser.add_option("-u", "--uid", dest="uid",
help="RADIUS profile identifier") help="RADIUS profile identifier")
opt_parser.add_option("-s", "--shared", dest="shared", default=False, action='store_true',
help="profile is shared")
opt_parser.add_option("-d", "--Description", dest="desc", opt_parser.add_option("-d", "--Description", dest="desc",
help="description of the RADIUS client") help="description of the RADIUS client")
@@ -82,8 +84,14 @@ def main():
opt_parser.error('missing %s' % (distinguished_attr)) opt_parser.error('missing %s' % (distinguished_attr))
uid = args[1] uid = args[1]
user_profile = not options.shared
pairs[distinguished_attr] = uid pairs[distinguished_attr] = uid
# Per user profiles are pre-created (i.e. objectclass radiusprofile is always added for each user)
if user_profile:
print "ERROR, you cannot add a per-user radius profile, it pre-exists"
return 1
# Get pairs from a file or stdin # Get pairs from a file or stdin
if options.pair_file: if options.pair_file:
try: try:

View File

@@ -42,6 +42,8 @@ def help_option_callback(option, opt_str, value, parser, *args, **kwargs):
def main(): def main():
opt_parser = OptionParser(add_help_option=False) opt_parser = OptionParser(add_help_option=False)
opt_parser.add_option("-s", "--shared", dest="shared", default=False, action='store_true',
help="profile is shared")
opt_parser.add_option("-h", "--help", action="callback", callback=help_option_callback, opt_parser.add_option("-h", "--help", action="callback", callback=help_option_callback,
help="detailed help information") help="detailed help information")
opt_parser.set_usage("Usage: %s [options] UID" % (os.path.basename(sys.argv[0]))) opt_parser.set_usage("Usage: %s [options] UID" % (os.path.basename(sys.argv[0])))
@@ -53,10 +55,16 @@ def main():
opt_parser.error("missing UID") opt_parser.error("missing UID")
uid = args[1] uid = args[1]
user_profile = not options.shared
# Per user profiles are pre-created (i.e. objectclass radiusprofile is always added for each user)
if user_profile:
print "ERROR, you cannot delete a per-user radius profile, it always exists"
return 1
try: try:
ipa_client = ipaclient.IPAClient() ipa_client = ipaclient.IPAClient()
ipa_client.delete_radius_profile(uid) ipa_client.delete_radius_profile(uid, user_profile)
print "successfully deleted" print "successfully deleted"
except xmlrpclib.Fault, f: except xmlrpclib.Fault, f:
print f.faultString print f.faultString

View File

@@ -53,6 +53,8 @@ def help_option_callback(option, opt_str, value, parser, *args, **kwargs):
def main(): def main():
opt_parser = OptionParser(add_help_option=False) opt_parser = OptionParser(add_help_option=False)
opt_parser.add_option("-s", "--shared", dest="shared", default=False, action='store_true',
help="profile is shared")
opt_parser.add_option("-h", "--help", action="callback", callback=help_option_callback, opt_parser.add_option("-h", "--help", action="callback", callback=help_option_callback,
help="detailed help information") help="detailed help information")
@@ -65,10 +67,11 @@ def main():
opt_parser.error("missing UID(es)") opt_parser.error("missing UID(es)")
uids = args[1:] uids = args[1:]
user_profile = not options.shared
try: try:
ipa_client = ipaclient.IPAClient() ipa_client = ipaclient.IPAClient()
radius_profiles = ipa_client.find_radius_profiles(uids, sattrs=attrs) radius_profiles = ipa_client.find_radius_profiles(uids, user_profile, sattrs=attrs)
counter = radius_profiles[0] counter = radius_profiles[0]
radius_profiles = radius_profiles[1:] radius_profiles = radius_profiles[1:]

View File

@@ -528,6 +528,7 @@ class AttributeValueCompleter:
self.lhs_delims = lhs_delims self.lhs_delims = lhs_delims
self.operator = operator self.operator = operator
self.strip_rhs = strip_rhs self.strip_rhs = strip_rhs
self.pairs = None
self._reset() self._reset()
def _reset(self): def _reset(self):
@@ -589,6 +590,13 @@ class AttributeValueCompleter:
and it should return the default value for the attriubte or None''' and it should return the default value for the attriubte or None'''
if not self.lhs_complete: raise ValueError("attribute not parsed") if not self.lhs_complete: raise ValueError("attribute not parsed")
# If the user previously provided a value let that override the supplied default
if self.pairs is not None:
prev_value = self.pairs.get(self.lhs)
if prev_value is not None: return prev_value
# No previous user provided value, query for a default
default_value_type = type(self.default_value) default_value_type = type(self.default_value)
if default_value_type is DictType: if default_value_type is DictType:
return self.default_value.get(self.lhs, None) return self.default_value.get(self.lhs, None)
@@ -663,7 +671,7 @@ class AttributeValueCompleter:
return None, None return None, None
def get_pairs(self, prompt, mandatory_attrs=None, validate_callback=None, must_match=True, value_required=True): def get_pairs(self, prompt, mandatory_attrs=None, validate_callback=None, must_match=True, value_required=True):
pairs = {} self.pairs = {}
if mandatory_attrs: if mandatory_attrs:
mandatory_attrs_remaining = mandatory_attrs[:] mandatory_attrs_remaining = mandatory_attrs[:]
else: else:
@@ -702,8 +710,8 @@ class AttributeValueCompleter:
except ValueError: except ValueError:
pass pass
pairs[attribute] = value self.pairs[attribute] = value
return pairs return self.pairs
class ItemCompleter: class ItemCompleter:
''' '''