Skip to content

Commit

Permalink
Merge pull request phidatahq#215 from neverbiasu/main
Browse files Browse the repository at this point in the history
add check_port to get_port_for_auth_server
  • Loading branch information
ashpreetbedi committed May 5, 2024
2 parents 69ce824 + 3973912 commit 04d6a95
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions phi/cli/auth_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from phi.cli.settings import phi_cli_settings

import socket

class CliAuthRequestHandler(BaseHTTPRequestHandler):
"""Request Handler to accept the CLI auth token after the web based auth flow.
Expand Down Expand Up @@ -82,9 +83,14 @@ def shut_down(self):
self._thread.close() # type: ignore


def check_port(port):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
return s.connect_ex(('localhost', port)) == 0


def get_port_for_auth_server():
# TODO: Check if port is available
return 9191
if check_port(9191):
return 9191


def get_auth_token_from_web_flow(port) -> Optional[str]:
Expand Down

0 comments on commit 04d6a95

Please sign in to comment.