aboutsummaryrefslogtreecommitdiff
path: root/rpkid
diff options
context:
space:
mode:
Diffstat (limited to 'rpkid')
-rwxr-xr-xrpkid/irbe_cli3
-rw-r--r--rpkid/rpki/old_irdbd.py28
-rw-r--r--rpkid/tests/testpoke.py101
3 files changed, 52 insertions, 80 deletions
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)