Merge pull request #165 from OpenKMIP/dev/pykmip-server

Added KMIP Server Entry Point
This commit is contained in:
Peter Hamilton 2016-04-11 13:33:36 -04:00
commit d7b27b211b
3 changed files with 150 additions and 136 deletions

View File

@ -15,142 +15,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import optparse from kmip.services.server import server
import sys
from kmip.services import server
def build_argument_parser():
parser = optparse.OptionParser(
usage="%prog [options]",
description="Run the PyKMIP software server.")
parser.add_option(
"-n",
"--hostname",
action="store",
type="str",
default="127.0.0.1",
dest="hostname",
help=(
"The host address the server will be bound to. A string "
"representing either a hostname in Internet domain notation or "
"an IPv4 address. Defaults to '127.0.0.1'."
),
)
parser.add_option(
"-p",
"--port",
action="store",
type="int",
default=5696,
dest="port",
help=(
"The port number the server will be bound to. An integer "
"representing a port number. Recommended to be 5696 according to "
"the KMIP specification. Defaults to 5696."
),
)
parser.add_option(
"-c",
"--certificate_path",
action="store",
type="str",
default=None,
dest="certificate_path",
help=(
"A string representing a path to a PEM-encoded server "
"certificate file. Defaults to None."
),
)
parser.add_option(
"-k",
"--key_path",
action="store",
type="str",
default=None,
dest="key_path",
help=(
"A string representing a path to a PEM-encoded server "
"certificate key file. Defaults to None."
),
)
parser.add_option(
"-a",
"--ca_path",
action="store",
type="str",
default=None,
dest="ca_path",
help=(
"A string representing a path to a PEM-encoded certificate "
"authority certificate file. Defaults to None."
),
)
parser.add_option(
"-s",
"--auth_suite",
action="store",
type="str",
default="Basic",
dest="auth_suite",
help=(
"A string representing the type of authentication suite to use "
"when establishing TLS connections. Defaults to 'Basic'."
),
)
parser.add_option(
"-f",
"--config_path",
action="store",
type="str",
default=None,
dest="config_path",
help=(
"A string representing a path to a server configuration file. "
"Defaults to None."
),
)
parser.add_option(
"-l",
"--log_path",
action="store",
type="str",
default=None,
dest="log_path",
help=(
"A string representing a path to a log file. Defaults to None."
),
)
return parser
if __name__ == '__main__': if __name__ == '__main__':
# Build argument parser and parser command-line arguments. server.main()
parser = build_argument_parser()
opts, args = parser.parse_args(sys.argv[1:])
kwargs = {}
if opts.hostname:
kwargs['hostname'] = opts.hostname
if opts.port:
kwargs['port'] = opts.port
if opts.certificate_path:
kwargs['certificate_path'] = opts.certificate_path
if opts.key_path:
kwargs['key_path'] = opts.key_path
if opts.ca_path:
kwargs['ca_path'] = opts.ca_path
if opts.auth_suite:
kwargs['auth_suite'] = opts.auth_suite
if opts.config_path:
kwargs['config_path'] = opts.config_path
if opts.log_path:
kwargs['log_path'] = opts.log_path
# Create and start the server.
s = server.KmipServer(**kwargs)
with s:
s.serve()

View File

@ -16,10 +16,12 @@
import errno import errno
import logging import logging
import logging.handlers as handlers import logging.handlers as handlers
import optparse
import os import os
import signal import signal
import socket import socket
import ssl import ssl
import sys
import threading import threading
from kmip.core import exceptions from kmip.core import exceptions
@ -341,3 +343,142 @@ class KmipServer(object):
def __exit__(self, exc_type, exc_value, traceback): def __exit__(self, exc_type, exc_value, traceback):
self.stop() self.stop()
def build_argument_parser():
parser = optparse.OptionParser(
usage="%prog [options]",
description="Run the PyKMIP software server.")
parser.add_option(
"-n",
"--hostname",
action="store",
type="str",
default="127.0.0.1",
dest="hostname",
help=(
"The host address the server will be bound to. A string "
"representing either a hostname in Internet domain notation or "
"an IPv4 address. Defaults to '127.0.0.1'."
),
)
parser.add_option(
"-p",
"--port",
action="store",
type="int",
default=5696,
dest="port",
help=(
"The port number the server will be bound to. An integer "
"representing a port number. Recommended to be 5696 according to "
"the KMIP specification. Defaults to 5696."
),
)
parser.add_option(
"-c",
"--certificate_path",
action="store",
type="str",
default=None,
dest="certificate_path",
help=(
"A string representing a path to a PEM-encoded server "
"certificate file. Defaults to None."
),
)
parser.add_option(
"-k",
"--key_path",
action="store",
type="str",
default=None,
dest="key_path",
help=(
"A string representing a path to a PEM-encoded server "
"certificate key file. Defaults to None."
),
)
parser.add_option(
"-a",
"--ca_path",
action="store",
type="str",
default=None,
dest="ca_path",
help=(
"A string representing a path to a PEM-encoded certificate "
"authority certificate file. Defaults to None."
),
)
parser.add_option(
"-s",
"--auth_suite",
action="store",
type="str",
default="Basic",
dest="auth_suite",
help=(
"A string representing the type of authentication suite to use "
"when establishing TLS connections. Defaults to 'Basic'."
),
)
parser.add_option(
"-f",
"--config_path",
action="store",
type="str",
default=None,
dest="config_path",
help=(
"A string representing a path to a server configuration file. "
"Defaults to None."
),
)
parser.add_option(
"-l",
"--log_path",
action="store",
type="str",
default=None,
dest="log_path",
help=(
"A string representing a path to a log file. Defaults to None."
),
)
return parser
def main(args=None):
# Build argument parser and parser command-line arguments.
parser = build_argument_parser()
opts, args = parser.parse_args(sys.argv[1:])
kwargs = {}
if opts.hostname:
kwargs['hostname'] = opts.hostname
if opts.port:
kwargs['port'] = opts.port
if opts.certificate_path:
kwargs['certificate_path'] = opts.certificate_path
if opts.key_path:
kwargs['key_path'] = opts.key_path
if opts.ca_path:
kwargs['ca_path'] = opts.ca_path
if opts.auth_suite:
kwargs['auth_suite'] = opts.auth_suite
if opts.config_path:
kwargs['config_path'] = opts.config_path
if opts.log_path:
kwargs['log_path'] = opts.log_path
# Create and start the server.
s = KmipServer(**kwargs)
with s:
s.serve()
if __name__ == '__main__':
main()

View File

@ -36,9 +36,16 @@ setuptools.setup(
packages=setuptools.find_packages(exclude=["kmip.tests", "kmip.tests.*"]), packages=setuptools.find_packages(exclude=["kmip.tests", "kmip.tests.*"]),
package_data={'kmip': ['kmipconfig.ini', 'logconfig.ini'], package_data={'kmip': ['kmipconfig.ini', 'logconfig.ini'],
'kmip.demos': ['certs/server.crt', 'certs/server.key']}, 'kmip.demos': ['certs/server.crt', 'certs/server.key']},
entry_points={
'console_scripts':[
'pykmip-server = kmip.services.server.server:main'
]
},
install_requires=[ install_requires=[
"cryptography",
"enum34", "enum34",
"six", "six",
"sqlalchemy"
], ],
classifiers=[ classifiers=[
"Intended Audience :: Developers", "Intended Audience :: Developers",