mirror of
https://github.com/OpenKMIP/PyKMIP.git
synced 2025-04-08 19:25:06 +02:00
Adding custom configuration support
This change updates the KMIP client to support the custom selection of client configuration options. This makes it easy to dynamically create clients that connect to different backends. All unit demos have been updated to support this feature.
This commit is contained in:
parent
80ee64e600
commit
908aece78a
@ -13,13 +13,11 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
try:
|
||||
from configparser import SafeConfigParser
|
||||
except ImportError:
|
||||
from ConfigParser import SafeConfigParser
|
||||
import logging
|
||||
import os
|
||||
|
||||
from six.moves.configparser import SafeConfigParser
|
||||
|
||||
FILE_PATH = os.path.dirname(os.path.abspath(__file__))
|
||||
CONFIG_FILE = os.path.normpath(os.path.join(FILE_PATH, '../kmipconfig.ini'))
|
||||
|
||||
|
@ -46,6 +46,7 @@ if __name__ == '__main__':
|
||||
|
||||
username = opts.username
|
||||
password = opts.password
|
||||
config = opts.config
|
||||
algorithm = opts.algorithm
|
||||
length = opts.length
|
||||
|
||||
@ -77,7 +78,7 @@ if __name__ == '__main__':
|
||||
credential = credential_factory.create_credential(credential_type,
|
||||
credential_value)
|
||||
# Build the client and connect to the server
|
||||
client = KMIPProxy()
|
||||
client = KMIPProxy(config=config)
|
||||
client.open()
|
||||
|
||||
# Build the different object attributes
|
||||
|
@ -46,6 +46,7 @@ if __name__ == '__main__':
|
||||
|
||||
username = opts.username
|
||||
password = opts.password
|
||||
config = opts.config
|
||||
algorithm = opts.algorithm
|
||||
length = opts.length
|
||||
|
||||
@ -85,7 +86,7 @@ if __name__ == '__main__':
|
||||
credential = credential_factory.create_credential(credential_type,
|
||||
credential_value)
|
||||
# Build the client and connect to the server
|
||||
client = KMIPProxy()
|
||||
client = KMIPProxy(config=config)
|
||||
client.open()
|
||||
|
||||
algorithm_obj = attribute_factory.create_attribute(attribute_type,
|
||||
|
@ -36,6 +36,7 @@ if __name__ == '__main__':
|
||||
|
||||
username = opts.username
|
||||
password = opts.password
|
||||
config = opts.config
|
||||
uuid = opts.uuid
|
||||
|
||||
# Exit early if the UUID is not specified
|
||||
@ -63,7 +64,7 @@ if __name__ == '__main__':
|
||||
credential = credential_factory.create_credential(credential_type,
|
||||
credential_value)
|
||||
# Build the client and connect to the server
|
||||
client = KMIPProxy()
|
||||
client = KMIPProxy(config=config)
|
||||
client.open()
|
||||
|
||||
# Destroy the SYMMETRIC_KEY object
|
||||
|
@ -32,15 +32,16 @@ if __name__ == '__main__':
|
||||
|
||||
username = opts.username
|
||||
password = opts.password
|
||||
config = opts.config
|
||||
|
||||
# Build and setup logging and needed factories
|
||||
# Build and setup logging
|
||||
f_log = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir,
|
||||
'logconfig.ini')
|
||||
logging.config.fileConfig(f_log)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Build the client and connect to the server
|
||||
client = KMIPProxy()
|
||||
client = KMIPProxy(config=config)
|
||||
client.open()
|
||||
|
||||
result = client.discover_versions()
|
||||
|
@ -36,6 +36,7 @@ if __name__ == '__main__':
|
||||
|
||||
username = opts.username
|
||||
password = opts.password
|
||||
config = opts.config
|
||||
uuid = opts.uuid
|
||||
|
||||
# Exit early if the UUID is not specified
|
||||
@ -63,7 +64,7 @@ if __name__ == '__main__':
|
||||
credential = credential_factory.create_credential(credential_type,
|
||||
credential_value)
|
||||
# Build the client and connect to the server
|
||||
client = KMIPProxy()
|
||||
client = KMIPProxy(config=config)
|
||||
client.open()
|
||||
|
||||
# Retrieve the SYMMETRIC_KEY object
|
||||
|
@ -41,6 +41,7 @@ if __name__ == '__main__':
|
||||
|
||||
username = opts.username
|
||||
password = opts.password
|
||||
config = opts.config
|
||||
name = opts.name
|
||||
|
||||
# Exit early if the UUID is not specified
|
||||
@ -68,7 +69,7 @@ if __name__ == '__main__':
|
||||
credential = credential_factory.create_credential(credential_type,
|
||||
credential_value)
|
||||
# Build the client and connect to the server
|
||||
client = KMIPProxy()
|
||||
client = KMIPProxy(config=config)
|
||||
client.open()
|
||||
|
||||
# Build name attribute
|
||||
|
@ -37,6 +37,7 @@ if __name__ == '__main__':
|
||||
|
||||
username = opts.username
|
||||
password = opts.password
|
||||
config = opts.config
|
||||
|
||||
# Build and setup logging and needed factories
|
||||
f_log = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir,
|
||||
@ -60,7 +61,7 @@ if __name__ == '__main__':
|
||||
QueryFunction(QueryFunctionEnum.QUERY_EXTENSION_MAP))
|
||||
|
||||
# Build the client and connect to the server
|
||||
client = KMIPProxy()
|
||||
client = KMIPProxy(config=config)
|
||||
client.open()
|
||||
|
||||
result = client.query(query_functions=query_functions)
|
||||
|
@ -44,6 +44,7 @@ if __name__ == '__main__':
|
||||
|
||||
username = opts.username
|
||||
password = opts.password
|
||||
config = opts.config
|
||||
algorithm = opts.algorithm
|
||||
length = opts.length
|
||||
|
||||
@ -76,7 +77,7 @@ if __name__ == '__main__':
|
||||
credential = credential_factory.create_credential(credential_type,
|
||||
credential_value)
|
||||
# Build the client and connect to the server
|
||||
client = KMIPProxy()
|
||||
client = KMIPProxy(config=config)
|
||||
client.open()
|
||||
|
||||
# Build the different object attributes
|
||||
|
@ -40,6 +40,14 @@ def build_cli_parser(operation):
|
||||
default=None,
|
||||
dest="password",
|
||||
help="Password for KMIP server account")
|
||||
parser.add_option(
|
||||
"-c",
|
||||
"--config",
|
||||
action="store",
|
||||
type="str",
|
||||
default="client",
|
||||
dest="config",
|
||||
help="Client configuration group to load from configuration file")
|
||||
|
||||
if operation is Operation.CREATE:
|
||||
parser.add_option(
|
||||
|
@ -72,17 +72,16 @@ class KMIPProxy(KMIP):
|
||||
cert_reqs=None, ssl_version=None, ca_certs=None,
|
||||
do_handshake_on_connect=None,
|
||||
suppress_ragged_eofs=None,
|
||||
username=None,
|
||||
password=None):
|
||||
username=None, password=None, config='client'):
|
||||
super(self.__class__, self).__init__()
|
||||
self.logger = logging.getLogger(__name__)
|
||||
self.credential_factory = CredentialFactory()
|
||||
self.config = config
|
||||
|
||||
self._set_variables(host, port, keyfile, certfile,
|
||||
cert_reqs, ssl_version, ca_certs,
|
||||
do_handshake_on_connect, suppress_ragged_eofs,
|
||||
username, password)
|
||||
|
||||
self.batch_items = []
|
||||
|
||||
def open(self):
|
||||
@ -624,42 +623,42 @@ class KMIPProxy(KMIP):
|
||||
conf = ConfigHelper()
|
||||
|
||||
self.host = conf.get_valid_value(
|
||||
host, 'client', 'host', conf.DEFAULT_HOST)
|
||||
host, self.config, 'host', conf.DEFAULT_HOST)
|
||||
|
||||
self.port = int(conf.get_valid_value(
|
||||
port, 'client', 'port', conf.DEFAULT_PORT))
|
||||
port, self.config, 'port', conf.DEFAULT_PORT))
|
||||
|
||||
self.keyfile = conf.get_valid_value(
|
||||
keyfile, 'client', 'keyfile', None)
|
||||
keyfile, self.config, 'keyfile', None)
|
||||
|
||||
self.certfile = conf.get_valid_value(
|
||||
certfile, 'client', 'certfile', None)
|
||||
certfile, self.config, 'certfile', None)
|
||||
|
||||
self.cert_reqs = getattr(ssl, conf.get_valid_value(
|
||||
cert_reqs, 'client', 'cert_reqs', 'CERT_REQUIRED'))
|
||||
cert_reqs, self.config, 'cert_reqs', 'CERT_REQUIRED'))
|
||||
|
||||
self.ssl_version = getattr(ssl, conf.get_valid_value(
|
||||
ssl_version, 'client', 'ssl_version', conf.DEFAULT_SSL_VERSION))
|
||||
ssl_version, self.config, 'ssl_version', conf.DEFAULT_SSL_VERSION))
|
||||
|
||||
self.ca_certs = conf.get_valid_value(
|
||||
ca_certs, 'client', 'ca_certs', conf.DEFAULT_CA_CERTS)
|
||||
ca_certs, self.config, 'ca_certs', conf.DEFAULT_CA_CERTS)
|
||||
|
||||
if conf.get_valid_value(
|
||||
do_handshake_on_connect, 'client',
|
||||
do_handshake_on_connect, self.config,
|
||||
'do_handshake_on_connect', 'True') == 'True':
|
||||
self.do_handshake_on_connect = True
|
||||
else:
|
||||
self.do_handshake_on_connect = False
|
||||
|
||||
if conf.get_valid_value(
|
||||
suppress_ragged_eofs, 'client',
|
||||
suppress_ragged_eofs, self.config,
|
||||
'suppress_ragged_eofs', 'True') == 'True':
|
||||
self.suppress_ragged_eofs = True
|
||||
else:
|
||||
self.suppress_ragged_eofs = False
|
||||
|
||||
self.username = conf.get_valid_value(
|
||||
username, 'client', 'username', conf.DEFAULT_USERNAME)
|
||||
username, self.config, 'username', conf.DEFAULT_USERNAME)
|
||||
|
||||
self.password = conf.get_valid_value(
|
||||
password, 'client', 'password', conf.DEFAULT_PASSWORD)
|
||||
password, self.config, 'password', conf.DEFAULT_PASSWORD)
|
||||
|
Loading…
x
Reference in New Issue
Block a user