You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We need to provide an easy way to load configuration for API clients using marshmallow.
Proposed solution
Add the following types:
fromtypingimportAnnotatedfrommarshmallow.fieldsimportStringfrommarshmallow.validateimportURL, LengthclassGrpcUrlField(String):
"""A marshmallow field for a gRPC URL."""def__init__(self, *_: Any, **kwargs: Any) ->None:
"""Initialize this instance."""validators=kwargs.pop("validate", [])
ifnotisinstance(validators, list):
validators= [validators]
validators.append(URL(schemes=["grpc"], error="Not a valid gRPC URL."))
super().__init__(validate=validators, **kwargs)
classApiKeyField(String):
"""A marshmallow field for an API key."""def__init__(self, *_: Any, **kwargs: Any) ->None:
"""Initialize this instance."""validators=kwargs.pop("validate", [])
ifnotisinstance(validators, list):
validators= [validators]
validators.append(Length(min=1, error="API key must be non-empty."))
super().__init__(validate=validators, **kwargs)
GrpcUrl=Annotated[str, GrpcUrlField]
]
"""A marshmallow field for a gRPC URL."""ApiKey=Annotated[str, ApiKeyField]
"""A marshmallow field for an API key."""
What's needed?
We need to provide an easy way to load configuration for API clients using
marshmallow
.Proposed solution
Add the following types:
Use cases
Validating environment variables, for example:
Alternatives and workarounds
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: