Package backend :: Package satellite_tools :: Module rhn_ssl_dbstore
[hide private]
[frames] | no frames]

Source Code for Module backend.satellite_tools.rhn_ssl_dbstore

 1  # 
 2  # Copyright (c) 2009--2016 Red Hat, Inc. 
 3  # 
 4  # This software is licensed to you under the GNU General Public License, 
 5  # version 2 (GPLv2). There is NO WARRANTY for this software, express or 
 6  # implied, including the implied warranties of MERCHANTABILITY or FITNESS 
 7  # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 
 8  # along with this software; if not, see 
 9  # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 
10  # 
11  # Red Hat trademarks are not licensed under GPLv2. No permission is 
12  # granted to use or replicate Red Hat trademarks that are incorporated 
13  # in this software or its documentation. 
14  # 
15   
16  import os 
17  import sys 
18  from optparse import Option, OptionParser 
19   
20  from spacewalk.common import rhnTB 
21  from spacewalk.server import rhnSQL 
22   
23  import satCerts 
24   
25  DEFAULT_TRUSTED_CERT = 'RHN-ORG-TRUSTED-SSL-CERT' 
26   
27   
28 -def processCommandline():
29 30 options = [ 31 Option('--ca-cert', action='store', default=DEFAULT_TRUSTED_CERT, type="string", 32 help='public CA certificate, default is %s' % DEFAULT_TRUSTED_CERT), 33 Option('--label', action='store', default='RHN-ORG-TRUSTED-SSL-CERT', type="string", 34 help='FOR TESTING ONLY - alternative database label for this CA certificate, ' 35 + 'default is "RHN-ORG-TRUSTED-SSL-CERT"'), 36 Option('-v', '--verbose', action='count', 37 help='be verbose (accumulable: -vvv means "be *really* verbose").'), 38 ] 39 40 values, args = OptionParser(option_list=options).parse_args() 41 42 # we take no extra commandline arguments that are not linked to an option 43 if args: 44 msg = ("ERROR: these arguments make no sense in this context (try " 45 "--help): %s\n" % repr(args)) 46 raise ValueError(msg) 47 48 if not os.path.exists(values.ca_cert): 49 sys.stderr.write("ERROR: can't find CA certificate at this location: " 50 "%s\n" % values.ca_cert) 51 sys.exit(10) 52 53 # pylint: disable=W0703 54 try: 55 rhnSQL.initDB() 56 except Exception: 57 sys.stderr.write("""\ 58 ERROR: there was a problem trying to initialize the database: 59 60 %s\n""" % rhnTB.fetchTraceback()) 61 sys.exit(11) 62 63 if values.verbose: 64 print('Public CA SSL certificate: %s' % values.ca_cert) 65 66 return values
67 68 69 #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 70
71 -def main():
72 """ main routine 73 10 CA certificate not found 74 11 DB initialization failure 75 13 Couldn't insert the certificate for whatever reason. 76 """ 77 78 values = processCommandline() 79 80 def writeError(e): 81 sys.stderr.write('\nERROR: %s\n' % e)
82 83 try: 84 satCerts.store_CaCert(values.label, values.ca_cert, verbosity=values.verbose) 85 except satCerts.CaCertInsertionError: 86 writeError("Cannot insert certificate into DB!\n\n%s\n" % rhnTB.fetchTraceback()) 87 sys.exit(13) 88 return 0 89 90 #------------------------------------------------------------------------------- 91 if __name__ == "__main__": 92 sys.stderr.write('\nWARNING: intended to be wrapped by another executable\n' 93 ' calling program.\n') 94 sys.exit(main() or 0) 95 #=============================================================================== 96