Added KMIP Server Entry Point

Added console_scripts to setup.py, and added an entry for
pykmip-server. The pykmip-server application will run the PyKMIP
server. The two command line options below will run the server.

python -m kmip.services.server.server
pykmip-server
This commit is contained in:
Nathan Reller 2016-04-11 09:07:59 -04:00
parent 7c57416249
commit 7096ed63f3
3 changed files with 150 additions and 136 deletions

View File

@ -15,142 +15,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import optparse
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
from kmip.services.server import server
if __name__ == '__main__':
# 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 = server.KmipServer(**kwargs)
with s:
s.serve()
server.main()

View File

@ -16,10 +16,12 @@
import errno
import logging
import logging.handlers as handlers
import optparse
import os
import signal
import socket
import ssl
import sys
import threading
from kmip.core import exceptions
@ -341,3 +343,142 @@ class KmipServer(object):
def __exit__(self, exc_type, exc_value, traceback):
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.*"]),
package_data={'kmip': ['kmipconfig.ini', 'logconfig.ini'],
'kmip.demos': ['certs/server.crt', 'certs/server.key']},
entry_points={
'console_scripts':[
'pykmip-server = kmip.services.server.server:main'
]
},
install_requires=[
"cryptography",
"enum34",
"six",
"sqlalchemy"
],
classifiers=[
"Intended Audience :: Developers",