From e79cffd653bfa1339b6db07934cb6ca50122df65 Mon Sep 17 00:00:00 2001 From: Daniel McKnight <34697904+NeonDaniel@users.noreply.github.com> Date: Tue, 9 Jul 2024 15:13:51 -0700 Subject: [PATCH] Replace Ipify API call with HANA (#57) * Update public IP Address method to use HANA Closes #56 * Update default HANA url to neonaibeta to include util endpoints --------- Co-authored-by: Daniel McKnight --- __init__.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/__init__.py b/__init__.py index 0d06509..7f5cf7a 100644 --- a/__init__.py +++ b/__init__.py @@ -145,8 +145,7 @@ def handle_query_ip(self, message): {'interface': iface, 'ip': ip_spoken}, private=True, wait=True) - @staticmethod - def _get_public_ip_address(message: Message = None) -> str: + def _get_public_ip_address(self, message: Message = None) -> str: """ Get the public IP address associated with the request :returns: str public IP address @@ -156,4 +155,9 @@ def _get_public_ip_address(message: Message = None) -> str: public_addr = message.context['node_data'].get('networking', {}).get('public_ip') LOG.info(f"Got public IP from context: {public_addr}") - return public_addr or get('https://api.ipify.org').text + if not public_addr: + hana_url = self.config_core.get('hana', {}).get('url') or \ + "https://hana.neonaibeta.com" # TODO: Update to neonaiservices after HANA 0.2 release + public_addr = get(f"{hana_url}/util/client_ip").text + LOG.info(f"Got public IP from HANA: {public_addr}") + return public_addr