chiark / gitweb /
make-secnet-sites: Introduce new OpMod classes
[secnet.git] / make-secnet-sites
index 6721156dd5dc945f19e9e3e6edad4526b1132382..46a887c8b73c049da7548f43e8d24f2a12ab21d9 100755 (executable)
@@ -290,7 +290,19 @@ class PkmElide(PkmBase):
        def site_finish(self,confw):
                confw.write("peer-keys \"%s\";\n"%self._pa);
 
+class OpBase():
+       pass
+
+class OpConf(OpBase):
+       def is_service(self): return 0
+
+class OpUserv(OpBase):
+       opts = ['--userv','-u']
+       help = 'userv service fragment update mode'
+       def is_service(self): return 1
+
 def parse_args():
+       global opmode
        global service
        global inputfile
        global header
@@ -308,8 +320,12 @@ def parse_args():
        global pubkeys_mode
 
        ap = argparse.ArgumentParser(description='process secnet sites files')
-       ap.add_argument('--userv', '-u', action='store_true',
-                       help='userv service fragment update mode')
+       def add_opmode(how):
+               ap.add_argument(*how().opts, action=ArgActionLambda,
+                       nargs=0,
+                       fn=(lambda v,ns,*x: setattr(ns,'opmode',how)),
+                       help=how().help)
+       add_opmode(OpUserv)
        ap.add_argument('--conf-key-prefix', action=ActionNoYes,
                        default=True,
                 help='prefix conf file key names derived from sites data')
@@ -334,7 +350,8 @@ def parse_args():
        av = ap.parse_args()
        debug_level = av.debug
        debugrepr('av',av)
-       service = 1 if av.userv else 0
+       opmode = getattr(av,'opmode',OpConf)()
+       service = opmode.is_service()
        prefix = '' if av.prefix is None else av.prefix[0]
        key_prefix = av.conf_key_prefix
        output_version = av.output_version[0]
@@ -497,7 +514,7 @@ class pubkey (inpub):
                return len(self.forpub(version,fs)) != 0
 
 class rsakey (pubkey):
-       "An RSA public key"
+       "An old-style RSA public key"
        def __init__(self,w):
                self.l=w[1].number(0,max['rsa_bits'],'rsa len')
                self.e=w[2].bignum_10('rsa','rsa e')
@@ -583,7 +600,7 @@ keywords={
  'pkg':(listof(somepubkey),"start of public key group",'pub'),
  'pkgf':(listof(somepubkey),"start of fallback public key group",'pub'),
  'pub':(listof(somepubkey),"new style public site key"),
- 'pubkey':(listof(somepubkey),"RSA public site key",'pub'),
+ 'pubkey':(listof(somepubkey),"Old-style RSA public site key",'pub'),
  'peer':(single_ipaddr,"Tunnel peer IP address"),
  'address':(address,"External contact address and port"),
  'mobile':(boolean,"Site is mobile"),