Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a required ports kwarg to urls #1702

Closed
flapili opened this issue Jul 9, 2020 · 1 comment
Closed

add a required ports kwarg to urls #1702

flapili opened this issue Jul 9, 2020 · 1 comment

Comments

@flapili
Copy link
Contributor

flapili commented Jul 9, 2020

Feature Request

this feature will add a possibility to force a port to urls

example of my use case:

from logging.handlers import DEFAULT_TCP_LOGGING_PORT
from pydantic import BaseSettings, Field, stricturl

class Config(BaseSettings):
    TCP_logging : stricturl(allowed_schemes=["tcp"], require_port=True) = f"tcp://127.0.0.1:{DEFAULT_TCP_LOGGING_PORT}"

a other use case could be replace

from pydantic import BaseSettings, Field

class Config(BaseSettings):
    uvicorn_host: str = "0.0.0.0"
    uvicorn_port: int = Field(8000, gt=0, lt=2**16)

for

from pydantic import BaseSettings, AnyHttpUrl

class Config(BaseSettings):
    uvicorn_server: AnyHttpUrl(require_port=True) = "http://0.0.0.0:8080"

If you think this proposition make sence I could look for a PR

ps: for the second use case maybe a kind of "bindUrl"/"bindAddress" could be better ?

@samuelcolvin
Copy link
Member

I think this would be best achieved by either subclassing AnyUrl or using a validator on the Config class.

I doubt this is a common enough requirement to add it to AnyUrl or its subclasses, as per #1665 I want to move the other way and remove user_required in v2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants