mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
clean up attribute names
clean up command line args in ipa-delradiusclient
This commit is contained in:
@@ -36,8 +36,8 @@ import ldap
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
attrs = radius_util.client_name_to_ldap_attr.keys()
|
||||
mandatory_attrs = ['Client-IP-Address', 'Secret']
|
||||
radius_attrs = radius_util.radius_client_attr_to_ldap_attr.keys()
|
||||
mandatory_radius_attrs = ['Client-IP-Address', 'Secret']
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
@@ -45,10 +45,10 @@ def help_option_callback(option, opt_str, value, parser, *args, **kwargs):
|
||||
parser.print_help()
|
||||
print
|
||||
print "Valid interative attributes are:"
|
||||
print ipautil.format_list(attrs, quote='"')
|
||||
print ipautil.format_list(radius_attrs, quote='"')
|
||||
print
|
||||
print "Required attributes are:"
|
||||
print ipautil.format_list(mandatory_attrs, quote='"')
|
||||
print ipautil.format_list(mandatory_radius_attrs, quote='"')
|
||||
sys.exit(0)
|
||||
|
||||
def main():
|
||||
@@ -78,11 +78,16 @@ def main():
|
||||
opt_parser.add_option("-v", "--verbose", dest="verbose", action='store_true',
|
||||
help="print information")
|
||||
|
||||
#opt_parser.set_usage("Usage: %s [options] %s" % (os.path.basename(sys.argv[0]), ' '.join(mandatory_attrs)))
|
||||
opt_parser.set_usage("Usage: %s [options] Client-IP-Address" % (os.path.basename(sys.argv[0])))
|
||||
|
||||
args = ipa.config.init_config(sys.argv)
|
||||
options, args = opt_parser.parse_args(args)
|
||||
|
||||
if len(args) < 2:
|
||||
opt_parser.error("missing Client-IP-Address")
|
||||
|
||||
ip_addr = args[1]
|
||||
|
||||
# Get pairs from a file or stdin
|
||||
if options.pair_file:
|
||||
try:
|
||||
@@ -107,13 +112,13 @@ def main():
|
||||
# Get pairs interactively
|
||||
if options.interactive:
|
||||
# Remove any mandatory attriubtes which have been previously specified
|
||||
interactive_mandatory_attrs = copy.copy(mandatory_attrs)
|
||||
interactive_mandatory_attrs = copy.copy(mandatory_radius_attrs)
|
||||
for attr in pairs.keys():
|
||||
try:
|
||||
interactive_mandatory_attrs.remove(attr)
|
||||
except ValueError:
|
||||
pass
|
||||
c = ipautil.AttributeValueCompleter(attrs, pairs)
|
||||
c = ipautil.AttributeValueCompleter(radius_attrs, pairs)
|
||||
c.open()
|
||||
av = c.get_pairs("Enter: ", interactive_mandatory_attrs, validate)
|
||||
pairs.update(av)
|
||||
@@ -122,8 +127,14 @@ def main():
|
||||
# FIXME: validation should be moved to xmlrpc server
|
||||
|
||||
# Data collection done, assure mandatory data has been specified
|
||||
|
||||
if pairs.has_key('Client-IP-Address') and pairs['Client-IP-Address'] != ip_addr:
|
||||
print "ERROR, Client-IP-Address specified on command line (%s) does not match value found in pairs (%s)" % \
|
||||
(ip_addr, pairs['Client-IP-Address'])
|
||||
return 1
|
||||
|
||||
valid = True
|
||||
for attr in mandatory_attrs:
|
||||
for attr in mandatory_radius_attrs:
|
||||
if not pairs.has_key(attr):
|
||||
valid = False
|
||||
print "ERROR, %s is mandatory, but has not been specified" % (attr)
|
||||
@@ -133,12 +144,12 @@ def main():
|
||||
# Make sure each attribute is a member of the set of valid attributes
|
||||
valid = True
|
||||
for attr,value in pairs.items():
|
||||
if attr not in attrs:
|
||||
if attr not in radius_attrs:
|
||||
valid = False
|
||||
print "ERROR, %s is not a valid attribute" % (attr)
|
||||
if not valid:
|
||||
print "Valid attributes are:"
|
||||
print ipautil.format_list(attrs, quote='"')
|
||||
print ipautil.format_list(radius_attrs, quote='"')
|
||||
return 1
|
||||
|
||||
# Makse sure each value is valid
|
||||
@@ -157,7 +168,7 @@ def main():
|
||||
|
||||
radius_client = ipa.radius_client.RadiusClient()
|
||||
for attr,value in pairs.items():
|
||||
radius_client.setValue(radius_util.client_name_to_ldap_attr[attr], value)
|
||||
radius_client.setValue(radius_util.radius_client_attr_to_ldap_attr[attr], value)
|
||||
|
||||
try:
|
||||
ipa_client = ipaclient.IPAClient()
|
||||
|
||||
@@ -26,6 +26,7 @@ import ipa.ipaclient as ipaclient
|
||||
import ipa.ipavalidate as ipavalidate
|
||||
import ipa.config
|
||||
import ipa.ipaerror
|
||||
import ipa.radius_util as radius_util
|
||||
|
||||
import xmlrpclib
|
||||
import kerberos
|
||||
@@ -33,33 +34,23 @@ import ldap
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
def parse_options():
|
||||
parser = OptionParser()
|
||||
parser.add_option("--usage", action="store_true",
|
||||
help="Program usage")
|
||||
args = ipa.config.init_config(sys.argv)
|
||||
options, args = parser.parse_args(args)
|
||||
def help_option_callback(option, opt_str, value, parser, *args, **kwargs):
|
||||
parser.print_help()
|
||||
sys.exit(0)
|
||||
|
||||
return options, args
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
# FIXME
|
||||
def usage():
|
||||
print "ipa-delradiusclient ip_addr"
|
||||
sys.exit(1)
|
||||
|
||||
def main():
|
||||
ip_addr = None
|
||||
secret = None
|
||||
name = None
|
||||
nastype = None
|
||||
desc = None
|
||||
opt_parser = OptionParser(add_help_option=False)
|
||||
|
||||
options, args = parse_options()
|
||||
opt_parser.add_option("-h", "--help", action="callback", callback=help_option_callback,
|
||||
help="detailed help information")
|
||||
opt_parser.set_usage("Usage: %s [options] Client-IP-Address" % (os.path.basename(sys.argv[0])))
|
||||
|
||||
if len(args) != 2:
|
||||
usage()
|
||||
args = ipa.config.init_config(sys.argv)
|
||||
options, args = opt_parser.parse_args(args)
|
||||
|
||||
if len(args) < 2:
|
||||
opt_parser.error("missing Client-IP-Address")
|
||||
|
||||
ip_addr = args[1]
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ import ldap
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
attrs = radius_util.client_ldap_attr_to_name.keys()
|
||||
attrs = radius_util.radius_client_ldap_attr_to_radius_attr.keys()
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
@@ -81,10 +81,10 @@ def main():
|
||||
client_attrs = radius_client.attrList()
|
||||
client_attrs.sort()
|
||||
|
||||
print "%s:" % radius_client.getValues(radius_util.client_name_to_ldap_attr['Client-IP-Address'])
|
||||
print "%s:" % radius_client.getValues(radius_util.radius_client_attr_to_ldap_attr['Client-IP-Address'])
|
||||
for attr in client_attrs:
|
||||
value = radius_client.getValues(attr)
|
||||
print "\t%s = %s" % (radius_util.client_ldap_attr_to_name[attr], value)
|
||||
print "\t%s = %s" % (radius_util.radius_client_ldap_attr_to_radius_attr[attr], value)
|
||||
|
||||
except xmlrpclib.Fault, f:
|
||||
print f.faultString
|
||||
|
||||
@@ -36,8 +36,8 @@ import ldap
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
attrs = radius_util.client_name_to_ldap_attr.keys()
|
||||
mandatory_attrs = ['Client-IP-Address']
|
||||
radius_attrs = radius_util.radius_client_attr_to_ldap_attr.keys()
|
||||
mandatory_radius_attrs = ['Client-IP-Address']
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
@@ -45,10 +45,10 @@ def help_option_callback(option, opt_str, value, parser, *args, **kwargs):
|
||||
parser.print_help()
|
||||
print
|
||||
print "Valid interative attributes are:"
|
||||
print ipautil.format_list(attrs, quote='"')
|
||||
print ipautil.format_list(radius_attrs, quote='"')
|
||||
print
|
||||
print "Required attributes are:"
|
||||
print ipautil.format_list(mandatory_attrs, quote='"')
|
||||
print ipautil.format_list(mandatory_radius_attrs, quote='"')
|
||||
sys.exit(0)
|
||||
|
||||
def main():
|
||||
@@ -105,8 +105,8 @@ def main():
|
||||
|
||||
# Populate the pair list with pre-existing values
|
||||
prev_attrs = radius_client.attrList()
|
||||
for attr in attrs:
|
||||
pairs[attr] = radius_client.getValues(radius_util.client_name_to_ldap_attr[attr])
|
||||
for attr in radius_attrs:
|
||||
pairs[attr] = radius_client.getValues(radius_util.radius_client_attr_to_ldap_attr[attr])
|
||||
|
||||
# Get pairs from a file or stdin
|
||||
if options.pair_file:
|
||||
@@ -132,13 +132,13 @@ def main():
|
||||
# Get pairs interactively
|
||||
if options.interactive:
|
||||
# Remove any mandatory attriubtes which have been previously specified
|
||||
interactive_mandatory_attrs = copy.copy(mandatory_attrs)
|
||||
interactive_mandatory_attrs = copy.copy(mandatory_radius_attrs)
|
||||
for attr in pairs.keys():
|
||||
try:
|
||||
interactive_mandatory_attrs.remove(attr)
|
||||
except ValueError:
|
||||
pass
|
||||
c = ipautil.AttributeValueCompleter(attrs, pairs)
|
||||
c = ipautil.AttributeValueCompleter(radius_attrs, pairs)
|
||||
c.open()
|
||||
av = c.get_pairs("Enter: ", interactive_mandatory_attrs, validate)
|
||||
pairs.update(av)
|
||||
@@ -154,7 +154,7 @@ def main():
|
||||
return 1
|
||||
|
||||
valid = True
|
||||
for attr in mandatory_attrs:
|
||||
for attr in mandatory_radius_attrs:
|
||||
if not pairs.has_key(attr):
|
||||
valid = False
|
||||
print "ERROR, %s is mandatory, but has not been specified" % (attr)
|
||||
@@ -164,12 +164,12 @@ def main():
|
||||
# Make sure each attribute is a member of the set of valid attributes
|
||||
valid = True
|
||||
for attr,value in pairs.items():
|
||||
if attr not in attrs:
|
||||
if attr not in radius_attrs:
|
||||
valid = False
|
||||
print "ERROR, %s is not a valid attribute" % (attr)
|
||||
if not valid:
|
||||
print "Valid attributes are:"
|
||||
print ipautil.format_list(attrs, quote='"')
|
||||
print ipautil.format_list(radius_attrs, quote='"')
|
||||
return 1
|
||||
|
||||
# Makse sure each value is valid
|
||||
@@ -188,7 +188,7 @@ def main():
|
||||
|
||||
radius_client = ipa.radius_client.RadiusClient()
|
||||
for attr,value in pairs.items():
|
||||
radius_client.setValue(radius_util.client_name_to_ldap_attr[attr], value)
|
||||
radius_client.setValue(radius_util.radius_client_attr_to_ldap_attr[attr], value)
|
||||
|
||||
try:
|
||||
ipa_client.update_radius_client(radius_client)
|
||||
|
||||
Reference in New Issue
Block a user