Add SASL/SSL configuration options to examples

This commit is contained in:
Kenneth Giusti 2015-09-03 15:20:05 -04:00
parent 98bf506ab1
commit 3bd3279206
3 changed files with 51 additions and 5 deletions

View File

@ -89,12 +89,22 @@ def main(argv=None):
help="enable protocol tracing") help="enable protocol tracing")
parser.add_option("--ca", parser.add_option("--ca",
help="Certificate Authority PEM file") help="Certificate Authority PEM file")
parser.add_option("--ssl-cert-file",
help="Self-identifying certificate (PEM file)")
parser.add_option("--ssl-key-file",
help="Key for self-identifying certificate (PEM file)")
parser.add_option("--ssl-key-password",
help="Password to unlock SSL key file")
parser.add_option("--username", type="string", parser.add_option("--username", type="string",
help="User Id for authentication") help="User Id for authentication")
parser.add_option("--password", type="string", parser.add_option("--password", type="string",
help="User password for authentication") help="User password for authentication")
parser.add_option("--sasl-mechs", type="string", parser.add_option("--sasl-mechs", type="string",
help="The list of acceptable SASL mechs") help="The list of acceptable SASL mechs")
parser.add_option("--sasl-config-dir", type="string",
help="Path to directory containing sasl config")
parser.add_option("--sasl-config-name", type="string",
help="Name of the sasl config file (without '.config')")
opts, extra = parser.parse_args(args=argv) opts, extra = parser.parse_args(args=argv)
if opts.debug: if opts.debug:
@ -111,6 +121,10 @@ def main(argv=None):
conn_properties["x-trace-protocol"] = True conn_properties["x-trace-protocol"] = True
if opts.ca: if opts.ca:
conn_properties["x-ssl-ca-file"] = opts.ca conn_properties["x-ssl-ca-file"] = opts.ca
if opts.ssl_cert_file:
conn_properties["x-ssl-identity"] = (opts.ssl_cert_file,
opts.ssl_key_file,
opts.ssl_key_password)
if opts.idle_timeout: if opts.idle_timeout:
conn_properties["idle-time-out"] = opts.idle_timeout conn_properties["idle-time-out"] = opts.idle_timeout
if opts.username: if opts.username:
@ -119,6 +133,10 @@ def main(argv=None):
conn_properties['x-password'] = opts.password conn_properties['x-password'] = opts.password
if opts.sasl_mechs: if opts.sasl_mechs:
conn_properties['x-sasl-mechs'] = opts.sasl_mechs conn_properties['x-sasl-mechs'] = opts.sasl_mechs
if opts.sasl_config_dir:
conn_properties["x-sasl-config-dir"] = opts.sasl_config_dir
if opts.sasl_config_name:
conn_properties["x-sasl-config-name"] = opts.sasl_config_name
c_handler = pyngus.ConnectionEventHandler() c_handler = pyngus.ConnectionEventHandler()
connection = container.create_connection("receiver", connection = container.create_connection("receiver",
@ -146,6 +164,10 @@ def main(argv=None):
else: else:
print("Receive failed due to connection failure!") print("Receive failed due to connection failure!")
# flush any remaining output before closing (optional)
while connection.has_output > 0:
process_connection(connection, my_socket)
receiver.close() receiver.close()
connection.close() connection.close()

View File

@ -78,12 +78,22 @@ def main(argv=None):
help="enable protocol tracing") help="enable protocol tracing")
parser.add_option("--ca", parser.add_option("--ca",
help="Certificate Authority PEM file") help="Certificate Authority PEM file")
parser.add_option("--ssl-cert-file",
help="Self-identifying certificate (PEM file)")
parser.add_option("--ssl-key-file",
help="Key for self-identifying certificate (PEM file)")
parser.add_option("--ssl-key-password",
help="Password to unlock SSL key file")
parser.add_option("--username", type="string", parser.add_option("--username", type="string",
help="User Id for authentication") help="User Id for authentication")
parser.add_option("--password", type="string", parser.add_option("--password", type="string",
help="User password for authentication") help="User password for authentication")
parser.add_option("--sasl-mechs", type="string", parser.add_option("--sasl-mechs", type="string",
help="The list of acceptable SASL mechs") help="The list of acceptable SASL mechs")
parser.add_option("--sasl-config-dir", type="string",
help="Path to directory containing sasl config")
parser.add_option("--sasl-config-name", type="string",
help="Name of the sasl config file (without '.config')")
opts, payload = parser.parse_args(args=argv) opts, payload = parser.parse_args(args=argv)
if not payload: if not payload:
@ -103,6 +113,10 @@ def main(argv=None):
conn_properties["x-trace-protocol"] = True conn_properties["x-trace-protocol"] = True
if opts.ca: if opts.ca:
conn_properties["x-ssl-ca-file"] = opts.ca conn_properties["x-ssl-ca-file"] = opts.ca
if opts.ssl_cert_file:
conn_properties["x-ssl-identity"] = (opts.ssl_cert_file,
opts.ssl_key_file,
opts.ssl_key_password)
if opts.idle_timeout: if opts.idle_timeout:
conn_properties["idle-time-out"] = opts.idle_timeout conn_properties["idle-time-out"] = opts.idle_timeout
if opts.username: if opts.username:
@ -111,6 +125,10 @@ def main(argv=None):
conn_properties['x-password'] = opts.password conn_properties['x-password'] = opts.password
if opts.sasl_mechs: if opts.sasl_mechs:
conn_properties['x-sasl-mechs'] = opts.sasl_mechs conn_properties['x-sasl-mechs'] = opts.sasl_mechs
if opts.sasl_config_dir:
conn_properties["x-sasl-config-dir"] = opts.sasl_config_dir
if opts.sasl_config_name:
conn_properties["x-sasl-config-name"] = opts.sasl_config_name
c_handler = ConnectionEventHandler() c_handler = ConnectionEventHandler()
connection = container.create_connection("sender", connection = container.create_connection("sender",
@ -151,6 +169,10 @@ def main(argv=None):
else: else:
print("Send failed due to connection failure!") print("Send failed due to connection failure!")
# flush any remaining output before closing (optional)
while connection.has_output > 0:
process_connection(connection, my_socket)
sender.close() sender.close()
connection.close() connection.close()

View File

@ -245,19 +245,21 @@ def main(argv=None):
help="enable protocol tracing") help="enable protocol tracing")
parser.add_option("--debug", dest="debug", action="store_true", parser.add_option("--debug", dest="debug", action="store_true",
help="enable debug logging") help="enable debug logging")
parser.add_option("--cert", parser.add_option("--ca",
help="Certificate Authority PEM file")
parser.add_option("--cert", "--ssl-cert-file",
help="PEM File containing the server's certificate") help="PEM File containing the server's certificate")
parser.add_option("--key", parser.add_option("--key", "--ssl-key-file",
help="PEM File containing the server's private key") help="PEM File containing the server's private key")
parser.add_option("--keypass", parser.add_option("--keypass", "--ssl-key-password",
help="Password used to decrypt key file") help="Password used to decrypt key file")
parser.add_option("--require-auth", action="store_true", parser.add_option("--require-auth", action="store_true",
help="Require clients to authenticate") help="Require clients to authenticate")
parser.add_option("--sasl-mechs", type="string", parser.add_option("--sasl-mechs", type="string",
help="The list of acceptable SASL mechs") help="The list of acceptable SASL mechs")
parser.add_option("--sasl-cfg-name", type="string", parser.add_option("--sasl-cfg-name", "--sasl-config-name", type="string",
help="name of SASL config file (no suffix)") help="name of SASL config file (no suffix)")
parser.add_option("--sasl-cfg-dir", type="string", parser.add_option("--sasl-cfg-dir", "--sasl-config-dir", type="string",
help="Path to the SASL config file") help="Path to the SASL config file")
opts, arguments = parser.parse_args(args=argv) opts, arguments = parser.parse_args(args=argv)