Skip to content

Commit

Permalink
Add option to enable TLS
Browse files Browse the repository at this point in the history
if TLS is enabled then use HTTPS for heartbeating

Signed-off-by: Mohammed Boukhalfa <[email protected]>
  • Loading branch information
mboukhalfa committed Oct 28, 2024
1 parent ad9418f commit 1157e3b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion fake-ipa/fake_ipa/heartbeater.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,20 @@ def _heartbeat_expected(self, agent, previous_heartbeat):

def do_heartbeat(self, system, agent):
"""Send a heartbeat to Ironic."""

# if tls enabled with fakeIPA use HTTPS else HTTP
adv_protocol="http"
cert = self._config.get("FAKE_IPA_CERTFILE")
key = self._config.get("FAKE_IPA_KEYFILE")
if cert is not None and key is not None :
adv_protocol="https"
try:
agent.api_client.heartbeat(
uuid=agent.node['uuid'],
advertise_address=Host(
hostname=self._config['FAKE_IPA_ADVERTISE_ADDRESS_IP'],
port=self._config['FAKE_IPA_ADVERTISE_ADDRESS_PORT']),
advertise_protocol="https",
advertise_protocol=adv_protocol,
generated_cert=None,
)
self._logger.info('heartbeat successful')
Expand Down
9 changes: 8 additions & 1 deletion fake-ipa/fake_ipa/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,14 @@ def main():
'FAKE_IPA_ADVERTISE_ADDRESS_IP: %s',
app.config.get('FAKE_IPA_ADVERTISE_ADDRESS_IP')
)
app.run(host=app.config.get('SUSHY_FAKE_IPA_LISTEN_IP', '0.0.0.0'),
cert = app.config.get("FAKE_IPA_CERTFILE")
key = app.config.get("FAKE_IPA_KEYFILE")
if cert is not None and key is not None:
ssl = (cert, key)
else:
ssl = None
app.run(ssl_context=ssl,
host=app.config.get('SUSHY_FAKE_IPA_LISTEN_IP', '0.0.0.0'),
port=app.config.get('SUSHY_FAKE_IPA_LISTEN_PORT', DEFAULT_PORT),
debug=True)

Expand Down

0 comments on commit 1157e3b

Please sign in to comment.