Skip to content

Commit

Permalink
support special value as empty auth url
Browse files Browse the repository at this point in the history
  • Loading branch information
zubenkoivan committed Dec 20, 2021
1 parent 89c9abf commit 1f5de8a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions platform_registry_api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ServerConfig:

@dataclass(frozen=True)
class AuthConfig:
server_endpoint_url: URL
server_endpoint_url: Optional[URL]
service_token: str = field(repr=False)


Expand Down Expand Up @@ -87,6 +87,13 @@ class EnvironConfigFactory:
def __init__(self, environ: Optional[dict[str, str]] = None) -> None:
self._environ = environ or os.environ

def _get_url(self, name: str) -> Optional[URL]:
value = self._environ[name]
if value == "-":
return None
else:
return URL(value)

def create_server(self) -> ServerConfig:
port = int(self._environ.get("NP_REGISTRY_API_PORT", ServerConfig.port))
return ServerConfig(port=port)
Expand Down Expand Up @@ -143,7 +150,7 @@ def create_upstream_registry(self) -> UpstreamRegistryConfig:
return UpstreamRegistryConfig(**upstream)

def create_auth(self) -> AuthConfig:
url = URL(self._environ["NP_REGISTRY_AUTH_URL"])
url = self._get_url("NP_REGISTRY_AUTH_URL")
token = self._environ["NP_REGISTRY_AUTH_TOKEN"]
return AuthConfig(server_endpoint_url=url, service_token=token)

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_defaults_oauth(self) -> None:
"NP_REGISTRY_UPSTREAM_TOKEN_SERVICE": "test_host",
"NP_REGISTRY_UPSTREAM_TOKEN_USERNAME": "test_username",
"NP_REGISTRY_UPSTREAM_TOKEN_PASSWORD": "test_password",
"NP_REGISTRY_AUTH_URL": "https://test_auth",
"NP_REGISTRY_AUTH_URL": "-",
"NP_REGISTRY_AUTH_TOKEN": "test_auth_token",
"NP_CLUSTER_NAME": "test-cluster",
}
Expand All @@ -41,7 +41,7 @@ def test_defaults_oauth(self) -> None:
max_catalog_entries=100,
),
auth=AuthConfig(
server_endpoint_url=URL("https://test_auth"),
server_endpoint_url=None,
service_token="test_auth_token",
),
cluster_name="test-cluster",
Expand Down

0 comments on commit 1f5de8a

Please sign in to comment.