@@ -82,11 +82,11 @@ def parse_cli():
8282 optional .add_argument ('-a' , '--altname' , action = 'append' , dest = 'altnames' , default = [],
8383 help = 'Specify the SAN for the requested certificate (only works with -H/--hostname). '
8484 'May be specified more than once for additional SANs.' )
85- optional .add_argument ('-C' , '--config' , action = 'store' , dest = 'config_file' , default = '/etc/osg/pki/ca-issuer.conf'
86- 'Path to configuration file' )
85+ optional .add_argument ('-C' , '--config' , action = 'store' , dest = 'config_file' , default = '/etc/osg/pki/ca-issuer.conf' ,
86+ help = 'Path to configuration file' )
8787 optional .add_argument ('-d' , '--directory' , action = 'store' , dest = 'write_directory' , default = '.' ,
8888 help = "The directory to write the host certificate(s) and key(s)" )
89- optional .add_argument ('-O' , '--orgcode' , action = 'store' , dest = 'orgcode' , default = '9697,9732' , metavar = 'ORG,DEPT' ,
89+ optional .add_argument ('-O' , '--orgcode' , action = 'store' , dest = 'orgcode' , metavar = 'ORG,DEPT' ,
9090 help = 'Organization and Department codes for the InCommon Certificate Service. Defaults are Fermilab\' s codes.' )
9191 optional .add_argument ('-l' , '--key-length' , action = 'store' , default = cert_utils .Csr .KEY_LENGTH ,
9292 type = int , help = 'The key size to generate' )
@@ -132,6 +132,12 @@ def __call__(self, parser, namespace, values, option_string=None):
132132 raise IOError (f"Unable to read the file at: { values } " )
133133
134134
135+ def fail (message ):
136+ """Immediately fail with the specified message
137+ """
138+ sys .exit (message )
139+
140+
135141def build_headers (config ):
136142 """"This function build the headers for the HTTP request.
137143 Returns headers for the HTTP request
@@ -269,9 +275,20 @@ def main():
269275 args = parse_cli ()
270276
271277 config_parser = configparser .ConfigParser ()
272- config_parser .read (args .config_file )
273- CONFIG = dict (config_parser .items ('InCommon' ))
274-
278+ try :
279+ with open (args .config_file , 'r' , encoding = 'utf-8' ) as config_file :
280+ try :
281+ config_parser .read_file (config_file )
282+ except configparser .Error as exc :
283+ fail (exc )
284+ except OSError as exc :
285+ fail (exc )
286+
287+ try :
288+ CONFIG = dict (config_parser .items ('InCommon' ))
289+ except configparser .NoSectionError :
290+ fail (f'Could not find [InCommon] section header in { args .config_file } ' )
291+
275292 if args .orgcode :
276293 codes = [code .strip () for code in args .orgcode .split (',' )]
277294 CONFIG ['organization' ] = codes [0 ]
0 commit comments