Skip to content

Commit

Permalink
Prefer configured callback url (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
markwaddle authored Oct 25, 2024
1 parent cd0e617 commit 8102765
Showing 1 changed file with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Literal

from pydantic import Field, HttpUrl
from pydantic_core import Url
from pydantic_settings import BaseSettings, SettingsConfigDict
Expand Down Expand Up @@ -27,7 +25,6 @@ class Settings(BaseSettings):

assistant_service_url: HttpUrl | None = None

protocol: Literal["http", "https"] = "http"
host: str = "127.0.0.1"
port: int = 0

Expand All @@ -40,19 +37,19 @@ class Settings(BaseSettings):

@property
def callback_url(self) -> str:
# use the configured assistant service url if available
if self.assistant_service_url:
return str(self.assistant_service_url)

# use config from Azure App Service if available
if self.website_hostname:
url = f"{self.website_protocol}://{self.website_hostname}"
if self.website_port is None:
return url
return f"{url}:{self.website_port}"

# fallback to the configured assistant service url if available
if self.assistant_service_url:
return str(self.assistant_service_url)

# finally, fallback to the local service name
url = f"{self.protocol}://{self.host}"
# finally, fallback to the host name/ip and port the app is running on
url = f"http://{self.host}"
if self.port is None:
return url
return f"{url}:{self.port}"

0 comments on commit 8102765

Please sign in to comment.