-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathkms_kmip_server.py
executable file
·67 lines (57 loc) · 1.83 KB
/
kms_kmip_server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#! /usr/bin/env python3
"""
KMS KMIP test server.
"""
import argparse
import logging
import os
import shutil
from kmip.services.server import KmipServer
HOSTNAME = "localhost"
PORT = 5698
def main():
dir_path = os.path.dirname(os.path.realpath(__file__))
drivers_evergreen_tools = os.path.join(dir_path, "..", "..")
default_ca_file = os.path.join(
drivers_evergreen_tools, ".evergreen", "x509gen", "ca.pem"
)
default_cert_file = os.path.join(
drivers_evergreen_tools, ".evergreen", "x509gen", "server.pem"
)
parser = argparse.ArgumentParser(description="MongoDB Mock KMIP KMS Endpoint.")
parser.add_argument(
"-p", "--port", type=int, default=PORT, help="Port to listen on"
)
parser.add_argument(
"--ca_file", type=str, default=default_ca_file, help="TLS CA PEM file"
)
parser.add_argument(
"--cert_file", type=str, default=default_cert_file, help="TLS Server PEM file"
)
args = parser.parse_args()
# Ensure we start with a fresh seed database.
database_path = os.path.join(
drivers_evergreen_tools, ".evergreen", "csfle", "pykmip.db"
)
database_seed_path = os.path.join(
drivers_evergreen_tools, ".evergreen", "csfle", "pykmip.db.bak"
)
shutil.copy(database_seed_path, database_path)
server = KmipServer(
hostname=HOSTNAME,
port=args.port,
certificate_path=args.cert_file,
ca_path=args.ca_file,
config_path=None,
auth_suite="TLS1.2",
log_path=os.path.join(
drivers_evergreen_tools, ".evergreen", "csfle", "pykmip.log"
),
database_path=database_path,
logging_level=logging.DEBUG,
)
with server:
print(f"\nStarting KMS KMIP server on port {args.port}")
server.serve()
if __name__ == "__main__":
main()