Skip to content

Commit

Permalink
addCheckPort
Browse files Browse the repository at this point in the history
  • Loading branch information
neverbiasu committed May 3, 2024
1 parent fdd6d27 commit 3973912
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 3973912

Please sign in to comment.