Commit 3bd32792 authored by Kenneth Giusti's avatar Kenneth Giusti

Add SASL/SSL configuration options to examples

parent 98bf506a
......@@ -89,12 +89,22 @@ def main(argv=None):
help="enable protocol tracing")
parser.add_option("--ca",
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",
help="User Id for authentication")
parser.add_option("--password", type="string",
help="User password for authentication")
parser.add_option("--sasl-mechs", type="string",
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)
if opts.debug:
......@@ -111,6 +121,10 @@ def main(argv=None):
conn_properties["x-trace-protocol"] = True
if 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:
conn_properties["idle-time-out"] = opts.idle_timeout
if opts.username:
......@@ -119,6 +133,10 @@ def main(argv=None):
conn_properties['x-password'] = opts.password
if 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()
connection = container.create_connection("receiver",
......@@ -146,6 +164,10 @@ def main(argv=None):
else:
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()
connection.close()
......
......@@ -78,12 +78,22 @@ def main(argv=None):
help="enable protocol tracing")
parser.add_option("--ca",
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",
help="User Id for authentication")
parser.add_option("--password", type="string",
help="User password for authentication")
parser.add_option("--sasl-mechs", type="string",
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)
if not payload:
......@@ -103,6 +113,10 @@ def main(argv=None):
conn_properties["x-trace-protocol"] = True
if 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:
conn_properties["idle-time-out"] = opts.idle_timeout
if opts.username:
......@@ -111,6 +125,10 @@ def main(argv=None):
conn_properties['x-password'] = opts.password
if 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()
connection = container.create_connection("sender",
......@@ -151,6 +169,10 @@ def main(argv=None):
else:
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()
connection.close()
......
......@@ -245,19 +245,21 @@ def main(argv=None):
help="enable protocol tracing")
parser.add_option("--debug", dest="debug", action="store_true",
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")
parser.add_option("--key",
parser.add_option("--key", "--ssl-key-file",
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")
parser.add_option("--require-auth", action="store_true",
help="Require clients to authenticate")
parser.add_option("--sasl-mechs", type="string",
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)")
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")
opts, arguments = parser.parse_args(args=argv)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment