2014-08-11 16:34:30 -04:00
|
|
|
# Copyright (c) 2014 The Johns Hopkins University/Applied Physics Laboratory
|
|
|
|
# All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License. You may obtain
|
|
|
|
# a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations
|
|
|
|
# under the License.
|
|
|
|
|
|
|
|
import logging
|
|
|
|
import optparse
|
2014-08-28 14:04:23 -04:00
|
|
|
import os
|
2014-08-11 16:34:30 -04:00
|
|
|
import sys
|
|
|
|
|
2014-08-28 14:04:23 -04:00
|
|
|
from kmip.services.kmip_server import KMIPServer
|
2014-08-11 16:34:30 -04:00
|
|
|
|
2014-08-28 14:04:23 -04:00
|
|
|
FILE_PATH = os.path.dirname(os.path.abspath(__file__))
|
2014-08-11 16:34:30 -04:00
|
|
|
|
|
|
|
|
2014-08-28 14:04:23 -04:00
|
|
|
def run_server(host='127.0.0.1', port=5696,
|
|
|
|
cert_file=FILE_PATH + '/certs/server.crt',
|
|
|
|
key_file=FILE_PATH + '/certs/server.key'):
|
2014-08-11 16:34:30 -04:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2014-08-28 14:04:23 -04:00
|
|
|
server = KMIPServer(host, port, cert_file, key_file)
|
2014-08-11 16:34:30 -04:00
|
|
|
|
|
|
|
logger.info('Starting the KMIP server')
|
|
|
|
|
|
|
|
try:
|
|
|
|
server.serve()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
logger.info('KeyboardInterrupt received while serving')
|
2014-08-28 14:04:23 -04:00
|
|
|
except Exception as e:
|
2014-08-11 16:34:30 -04:00
|
|
|
logger.info('Exception received while serving: {0}'.format(e))
|
|
|
|
finally:
|
2014-08-28 14:04:23 -04:00
|
|
|
server.close()
|
2014-08-11 16:34:30 -04:00
|
|
|
|
|
|
|
logger.info('Shutting down KMIP server')
|
|
|
|
|
|
|
|
|
|
|
|
def build_cli_parser():
|
|
|
|
parser = optparse.OptionParser(usage="%prog [options]",
|
|
|
|
description="Run KMIP Server")
|
|
|
|
parser.add_option("-n", "--hostname", action="store", default='127.0.0.1',
|
|
|
|
dest="hostname",
|
|
|
|
help="Hostname/IP address of platform running the KMIP "
|
|
|
|
"server (e.g., localhost, 127.0.0.1)")
|
|
|
|
parser.add_option("-p", "--port", action="store", default=5696,
|
|
|
|
dest="port", help="Port number for KMIP services")
|
2014-08-28 14:04:23 -04:00
|
|
|
parser.add_option("-c", "--cert_file", action="store",
|
|
|
|
default=FILE_PATH + '/certs/server.crt',
|
|
|
|
dest="cert_file")
|
|
|
|
parser.add_option("-k", "--key_file", action="store",
|
|
|
|
default=FILE_PATH + '/certs/server.key',
|
|
|
|
dest="key_file")
|
2014-08-11 16:34:30 -04:00
|
|
|
return parser
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
parser = build_cli_parser()
|
|
|
|
|
|
|
|
opts, args = parser.parse_args(sys.argv[1:])
|
|
|
|
|
2014-08-28 14:04:23 -04:00
|
|
|
run_server(opts.hostname, opts.port, opts.cert_file, opts.key_file)
|