aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rcynic/rcynic-cron.py47
-rwxr-xr-xrpkid/irbe_cli3
-rw-r--r--rpkid/rpki/old_irdbd.py28
-rw-r--r--rpkid/tests/testpoke.py101
-rw-r--r--scripts/extract-key.py70
5 files changed, 91 insertions, 158 deletions
diff --git a/rcynic/rcynic-cron.py b/rcynic/rcynic-cron.py
index e12e1e48..fbe1ebeb 100644
--- a/rcynic/rcynic-cron.py
+++ b/rcynic/rcynic-cron.py
@@ -1,17 +1,19 @@
# $Id$
#
-# Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
+# Copyright (C) 2014 Dragon Research Labs ("DRL")
+# Portions copyright (C) 2013 Internet Systems Consortium ("ISC")
#
-# Permission to use, copy, modify, and/or distribute this software for any
+# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
-# copyright notice and this permission notice appear in all copies.
+# copyright notices and this permission notice appear in all copies.
#
-# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+# THE SOFTWARE IS PROVIDED "AS IS" AND DRL AND ISC DISCLAIM ALL
+# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DRL OR
+# ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
+# OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
"""
@@ -27,12 +29,7 @@ import sys
import pwd
import fcntl
import errno
-import getopt
-
-def usage(result):
- f = sys.stderr if result else sys.stdout
- f.write("Usage: %s [--chroot] [--help]\n" % sys.argv[0])
- sys.exit(result)
+import argparse
def run(*cmd, **kwargs):
chroot_this = kwargs.pop("chroot_this", False)
@@ -64,22 +61,14 @@ def run(*cmd, **kwargs):
else:
sys.exit("Program %s exited for unknown reason %s" % (" ".join(cmd), status))
-want_chroot = False
-
-opts, argv = getopt.getopt(sys.argv[1:], "h?", ["chroot", "help"])
-for o, a in opts:
- if o in ("-?", "-h", "--help"):
- usage(0)
- elif o =="--chroot":
- want_chroot = True
-
-if argv:
- usage("Unexpected arguments: %r" % (argv,))
+parser = argparse.ArgumentParser(description = __doc__)
+parser.add_argument("--chroot", action = "store_true", help = "run chrooted")
+args = parser.parse_args()
we_are_root = os.getuid() == 0
-if want_chroot and not we_are_root:
- usage("Only root can --chroot")
+if args.chroot and not we_are_root:
+ sys.exit("Only root can --chroot")
try:
pw = pwd.getpwnam(ac_rcynic_user)
@@ -97,7 +86,7 @@ except (IOError, OSError), e:
else:
sys.exit("Error %r opening lock %r" % (e.strerror, os.path.join(ac_rcynic_dir, "data/lock")))
-if want_chroot:
+if args.chroot:
run("/bin/rcynic", "-c", "/etc/rcynic.conf", chroot_this = True)
else:
run(os.path.join(ac_bindir, "rcynic"), "-c", os.path.join(ac_sysconfdir, "rcynic.conf"))
diff --git a/rpkid/irbe_cli b/rpkid/irbe_cli
index ab5e8dd4..9deac6d6 100755
--- a/rpkid/irbe_cli
+++ b/rpkid/irbe_cli
@@ -34,6 +34,9 @@ __doc__ = """
Command line IR back-end control program for rpkid and pubd.
"""
+# Command line processing of this program is too complex and
+# idiosyncratic to be worth trying to reimplement using argparse.
+
import sys
import getopt
import textwrap
diff --git a/rpkid/rpki/old_irdbd.py b/rpkid/rpki/old_irdbd.py
index e3c17b38..10796711 100644
--- a/rpkid/rpki/old_irdbd.py
+++ b/rpkid/rpki/old_irdbd.py
@@ -20,8 +20,6 @@
"""
IR database daemon.
-Usage: python irdbd.py [ { -c | --config } configfile ] [ { -h | --help } ]
-
This is the old (pre-Django) version of irdbd, still used by smoketest
and perhaps still useful as a minimal example. This does NOT work with
the GUI, rpkic, or any of the other more recent tools.
@@ -30,7 +28,7 @@ the GUI, rpkic, or any of the other more recent tools.
import sys
import os
import time
-import getopt
+import argparse
import urlparse
import rpki.http
import rpki.config
@@ -199,24 +197,16 @@ class main(object):
os.environ["TZ"] = "UTC"
time.tzset()
- cfg_file = None
- use_syslog = True
-
- opts, argv = getopt.getopt(sys.argv[1:], "c:dh?", ["config=", "debug", "help"])
- for o, a in opts:
- if o in ("-h", "--help", "-?"):
- print __doc__
- sys.exit(0)
- if o in ("-c", "--config"):
- cfg_file = a
- elif o in ("-d", "--debug"):
- use_syslog = False
- if argv:
- raise rpki.exceptions.CommandParseFailure, "Unexpected arguments %s" % argv
+ parser = argparse.ArgumentParser(description = __doc__)
+ parser.add_argument("-c", "--config",
+ help = "override default location of configuration file")
+ parser.add_argument("-d", "--debug", action = "store_true",
+ help = "enable debugging mode")
+ args = parser.parse_args()
- rpki.log.init("irdbd", use_syslog = use_syslog)
+ rpki.log.init("irdbd", use_syslog = not args.debug)
- self.cfg = rpki.config.parser(cfg_file, "irdbd")
+ self.cfg = rpki.config.parser(args.config, "irdbd")
startup_msg = self.cfg.get("startup-message", "")
if startup_msg:
diff --git a/rpkid/tests/testpoke.py b/rpkid/tests/testpoke.py
index f4c19125..00dbc300 100644
--- a/rpkid/tests/testpoke.py
+++ b/rpkid/tests/testpoke.py
@@ -1,90 +1,69 @@
# $Id$
#
-# Copyright (C) 2010--2012 Internet Systems Consortium ("ISC")
-#
-# Permission to use, copy, modify, and distribute this software for any
-# purpose with or without fee is hereby granted, provided that the above
-# copyright notice and this permission notice appear in all copies.
-#
-# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-# PERFORMANCE OF THIS SOFTWARE.
-#
+# Copyright (C) 2014 Dragon Research Labs ("DRL")
+# Portions copyright (C) 2009--2012 Internet Systems Consortium ("ISC")
# Portions copyright (C) 2007--2008 American Registry for Internet Numbers ("ARIN")
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
-# copyright notice and this permission notice appear in all copies.
+# copyright notices and this permission notice appear in all copies.
#
-# THE SOFTWARE IS PROVIDED "AS IS" AND ARIN DISCLAIMS ALL WARRANTIES WITH
-# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-# AND FITNESS. IN NO EVENT SHALL ARIN BE LIABLE FOR ANY SPECIAL, DIRECT,
-# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-# PERFORMANCE OF THIS SOFTWARE.
+# THE SOFTWARE IS PROVIDED "AS IS" AND DRL, ISC, AND ARIN DISCLAIM ALL
+# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DRL,
+# ISC, OR ARIN BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
+# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
"""
Trivial RPKI up-down protocol client, for testing.
Configuration file is YAML to be compatable with APNIC rpki_poke.pl tool.
-
-Usage: python testpoke.py [ { -y | --yaml } configfile ]
- [ { -r | --request } requestname ]
- [ { -d | --debug } ]
- [ { -h | --help } ]
-
-Default configuration file is testpoke.yaml, override with --yaml option.
"""
-import os, time, getopt, sys, yaml
-import rpki.resource_set, rpki.up_down, rpki.left_right, rpki.x509
-import rpki.http, rpki.config, rpki.exceptions
-import rpki.relaxng, rpki.oids, rpki.log, rpki.async
+import os
+import time
+import argparse
+import sys
+import yaml
+import rpki.resource_set
+import rpki.up_down
+import rpki.left_right
+import rpki.x509
+import rpki.http
+import rpki.config
+import rpki.exceptions
+import rpki.relaxng
+import rpki.oids
+import rpki.log
+import rpki.async
os.environ["TZ"] = "UTC"
time.tzset()
-def usage(code):
- print __doc__
- sys.exit(code)
-
-yaml_file = "testpoke.yaml"
-yaml_cmd = None
-debug = False
-
-opts, argv = getopt.getopt(sys.argv[1:], "y:r:h?d", ["yaml=", "request=", "help", "debug"])
-for o, a in opts:
- if o in ("-h", "--help", "-?"):
- usage(0)
- elif o in ("-y", "--yaml"):
- yaml_file = a
- elif o in ("-r", "--request"):
- yaml_cmd = a
- elif o in ("-d", "--debug"):
- debug = True
-if argv:
- usage(1)
+parser = argparse.ArgumentParser(description = __doc__)
+parser.add_argument("-y", "--yaml", required = True, type = argparse.FileType("r"),
+ help = "configuration file")
+parser.add_argument("-r", "--request",
+ help = "request name")
+parser.add_argument("-d", "--debug",
+ help = "enable debugging")
+args = parser.parse_args()
rpki.log.init("testpoke")
-if debug:
+if args.debug:
rpki.log.set_trace(True)
-f = open(yaml_file)
-yaml_data = yaml.load(f)
-f.close()
+yaml_data = yaml.load(args.yaml)
+
+yaml_cmd = args.request
if yaml_cmd is None and len(yaml_data["requests"]) == 1:
yaml_cmd = yaml_data["requests"].keys()[0]
-if yaml_cmd is None:
- usage(1)
-
yaml_req = yaml_data["requests"][yaml_cmd]
def get_PEM(name, cls, y = yaml_data):
@@ -155,7 +134,7 @@ def do_revoke():
dispatch = { "list" : do_list, "issue" : do_issue, "revoke" : do_revoke }
def fail(e): # pylint: disable=W0621
- rpki.log.traceback(debug)
+ rpki.log.traceback(args.debug)
sys.exit("Testpoke failed: %s" % e)
cms_ta = get_PEM("cms-ca-cert", rpki.x509.X509)
diff --git a/scripts/extract-key.py b/scripts/extract-key.py
index 402d65d8..b85c3d55 100644
--- a/scripts/extract-key.py
+++ b/scripts/extract-key.py
@@ -1,17 +1,19 @@
# $Id$
-#
-# Copyright (C) 2008 American Registry for Internet Numbers ("ARIN")
+
+# Copyright (C) 2014 Dragon Research Labs ("DRL")
+# Portions copyright (C) 2008 American Registry for Internet Numbers ("ARIN")
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
-# copyright notice and this permission notice appear in all copies.
+# copyright notices and this permission notice appear in all copies.
#
-# THE SOFTWARE IS PROVIDED "AS IS" AND ARIN DISCLAIMS ALL WARRANTIES WITH
-# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-# AND FITNESS. IN NO EVENT SHALL ARIN BE LIABLE FOR ANY SPECIAL, DIRECT,
-# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+# THE SOFTWARE IS PROVIDED "AS IS" AND DRL AND AND ARIN DISCLAIM ALL
+# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DRL OR
+# ARIN BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
+# OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
"""
@@ -24,20 +26,11 @@ MySQL. This script is just a convenience, it doesn't enable anything
that couldn't be done via the mysql command line tool.
While we're at this we also extract the corresponding certificate.
-
-Usage: python extract-key.py [ { -s | --self } self_handle ]
- [ { -b | --bsc } bsc_handle ]
- [ { -u | --user } mysql_user_id ]
- [ { -d | --db } mysql_database ]
- [ { -p | --password } mysql_password ]
- [ { -h | --help } ]
-
-Default for both user and db is "rpki".
"""
import os
import time
-import getopt
+import argparse
import sys
import MySQLdb
import rpki.x509
@@ -45,36 +38,15 @@ import rpki.x509
os.environ["TZ"] = "UTC"
time.tzset()
-def usage(code):
- print __doc__
- sys.exit(code)
-
-self_handle = None
-bsc_handle = None
-
-user = "rpki"
-passwd = "fnord"
-db = "rpki"
-
-opts, argv = getopt.getopt(sys.argv[1:], "s:b:u:p:d:h?",
- ["self=", "bsc=", "user=", "password=", "db=", "help"])
-for o, a in opts:
- if o in ("-h", "--help", "-?"):
- usage(0)
- elif o in ("-s", "--self"):
- self_handle = a
- elif o in ("-b", "--bsc"):
- bsc_handle = a
- elif o in ("-u", "--user"):
- user = a
- elif o in ("-p", "--password"):
- passwd = a
- elif o in ("-d", "--db"):
- db = a
-if argv:
- usage(1)
+parser = argparse.ArgumentParser(description = __doc__)
+parser.add_argument("-s", "--self", required = True, help = "self handle")
+parser.add_argument("-b", "--bsc", required = True, help = "BSC handle")
+parser.add_argument("-u", "--user", required = True, help = "MySQL user name")
+parser.add_argument("-d", "--db", required = True, help = "MySQL database name")
+parser.add_argument("-p", "--password", required = True, help = "MySQL password")
+args = parser.parse_args()
-cur = MySQLdb.connect(user = user, db = db, passwd = passwd).cursor()
+cur = MySQLdb.connect(user = args.user, db = args.db, passwd = args.password).cursor()
cur.execute(
"""
@@ -82,7 +54,7 @@ cur.execute(
FROM bsc, self
WHERE self.self_handle = %s AND self.self_id = bsc.self_id AND bsc_handle = %s
""",
- (self_handle, bsc_handle))
+ (args.self, args.bsc))
key, cer = cur.fetchone()