gRPC argument validator utility.
Project description
gRPC argument validator
gRPC argument validator is a library that provides decorators to automatically validate arguments in requests to rpc methods.
Getting Started
This is an example of how you may give instructions on setting up your project locally. To get a local copy up and running follow these simple example steps.
Prerequisites
Poetry is required to locally run the tests for this library
- poetry
pip install --user poetry
Installation
- Clone the repo
git clone https://github.com/messagebird/grpc-argument-validator.git
- Install packages
poetry install
- Run the tests
cd src/tests poetry run python -m unittest
Example
from google.protobuf.descriptor import FieldDescriptor
from grpc_argument_validator import validate_args
from grpc_argument_validator import AbstractArgumentValidator, ValidationResult
class PathValidator(AbstractArgumentValidator):
def check(self, name: str, value: Path, field_descriptor: FieldDescriptor) -> ValidationResult:
if len(value.points) > 5:
return ValidationResult(valid=True)
return ValidationResult(False, f"path for '{name}' should be at least five points long")
class RouteService(RouteCheckerServicer):
@validate_args(
non_empty=["tags", "tags[]", "path.points"],
validators={"path": PathValidator()},
)
def Create(self, request: Route, context: grpc.ServicerContext):
return BoolValue(value=True)
Contributing
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Documentation
Generate the docs by running:
pdoc --html -o docs src/grpc_argument_validator
License
Distributed under The BSD 3-Clause License. Copyright (c) 2021, MessageBird
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for grpc-argument-validator-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9497fd6c4ee4699c117bc93fac06bf6558a694207dc46256eae8663d4174192 |
|
MD5 | f6e1af9ef5fcf8f98110dad21affa90b |
|
BLAKE2b-256 | 271238ef23f55c8fcc913d3db901db13263918fbc3fb3384449391a8c5b95855 |
Hashes for grpc_argument_validator-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02bed45f4eca020bf2761387f2565d0a90b4d07295d9b197e4608d14aef79697 |
|
MD5 | 885cea654e7f4567417e149c7773e666 |
|
BLAKE2b-256 | eeb5d845212f0e84cfe47100577d187483f0b78fc97011826e15370ef8a78700 |