46
46
'IntError' :'Server internal error occurred. Reason: {}' ,
47
47
'sysStart' :'Initial cherryPy server engine start have been invoked. Python version: {}, cherryPy version: {}.' ,
48
48
'MissingParm' :'Missing mandatory parameters, quitting' ,
49
+ 'KeyPathError' :'KeyPath directory not found, quitting' ,
50
+ 'CertError' :'Missing certificates in tht specified keyPath directory, quitting' ,
49
51
'CollectorErr' :'Failed to initialize connection to pmcollector, quitting' ,
50
52
'MetaError' :'Metadata could not be retrieved. Check log file for more details, quitting' ,
51
53
'MetaSuccess' : 'Successfully retrieved MetaData' ,
@@ -615,6 +617,21 @@ def validateCollectorConf(args, logger):
615
617
logger .info (MSG ['Query2port' ].format (args .serverPort ))
616
618
617
619
620
+ def findKeyFile (path ):
621
+ for name in ["privkey.pem" ,"tls.key" ]:
622
+ for root , dirs , files in os .walk (path ):
623
+ if name in files :
624
+ return name
625
+ return None
626
+
627
+ def findCertFile (path ):
628
+ for name in ["cert.pem" ,"tls.crt" ]:
629
+ for root , dirs , files in os .walk (path ):
630
+ if name in files :
631
+ return name
632
+ return None
633
+
634
+
618
635
619
636
def updateCherrypyConf (args ):
620
637
@@ -637,13 +654,15 @@ def updateCherrypyConf(args):
637
654
'tools.encode.encoding' : 'utf-8' }}
638
655
cherrypy .config .update (globalConfig )
639
656
640
- if args .port == 8443 :
641
- sslConfig = {
642
- 'global' : {
643
- 'server.ssl_module' : 'builtin' ,
644
- 'server.ssl_certificate' : args .keyPath + "/cert.pem" ,
645
- 'server.ssl_private_key' : args .keyPath + "/privkey.pem" }}
646
- cherrypy .config .update (sslConfig )
657
+ def updateCherrypySslConf (args , certFile , keyFile ):
658
+ certPath = os .path .join (args .keyPath , certFile )
659
+ keyPath = os .path .join (args .keyPath , keyFile )
660
+ sslConfig = {
661
+ 'global' : {
662
+ 'server.ssl_module' : 'builtin' ,
663
+ 'server.ssl_certificate' : certPath ,
664
+ 'server.ssl_private_key' : keyPath }}
665
+ cherrypy .config .update (sslConfig )
647
666
648
667
649
668
@@ -666,13 +685,24 @@ def main(argv):
666
685
if args .port == 8443 and not args .keyPath :
667
686
print (MSG ['MissingParm' ])
668
687
return
688
+ elif not os .path .exists (args .keyPath ):
689
+ print (MSG ['KeyPathError' ])
690
+ return
691
+ else :
692
+ certFile = findCertFile (args .keyPath )
693
+ keyFile = findKeyFile (args .keyPath )
694
+ if (not certFile ) or (not keyFile ):
695
+ print (MSG ['CertError' ])
696
+ return
669
697
670
698
# prepare the logger
671
699
logger = configureLogging (args .logFile , args .logLevel )
672
700
logger .info ('zimonGrafanaItf invoked with parameters:%s' , str (args ))
673
701
674
702
#prepare cherrypy server configuration
675
703
updateCherrypyConf (args )
704
+ if args .port == 8443 :
705
+ updateCherrypySslConf (args , certFile , keyFile )
676
706
677
707
678
708
0 commit comments