Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Refresh Python module #176

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 8 additions & 21 deletions python/gubernator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
# This code is py3.7 and py2.7 compatible

import gubernator.ratelimit_pb2_grpc as pb_grpc
from datetime import datetime

import time
import grpc

MILLISECOND = 1
SECOND = MILLISECOND * 1000
MINUTE = SECOND * 60


def sleep_until_reset(reset_time):
now = datetime.now()
time.sleep((reset_time - now).seconds)


def V1Client(endpoint='127.0.0.1:9090'):
channel = grpc.insecure_channel(endpoint)
return pb_grpc.RateLimitServiceV1Stub(channel)
Dreamsorcerer marked this conversation as resolved.
Show resolved Hide resolved
from gubernator.gubernator_pb2 import (
Algorithm, Behavior, GetRateLimitsReq, HealthCheckReq, RateLimitReq, Status
)
from gubernator.gubernator_pb2_grpc import V1Stub
from gubernator.peers_pb2_grpc import PeersV1Stub

__all__ = ("Algorithm", "Behavior", "GetRateLimitsReq", "HealthCheckReq", "RateLimitReq",
"Status", "PeersV1Stub", "V1Stub")
55 changes: 28 additions & 27 deletions python/gubernator/gubernator_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

115 changes: 115 additions & 0 deletions python/gubernator/gubernator_pb2.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
from google.api import annotations_pb2 as _annotations_pb2
from google.protobuf.internal import containers as _containers
from google.protobuf.internal import enum_type_wrapper as _enum_type_wrapper
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
from typing import ClassVar as _ClassVar, Iterable as _Iterable, Mapping as _Mapping, Optional as _Optional, Union as _Union

DESCRIPTOR: _descriptor.FileDescriptor

class Algorithm(int, metaclass=_enum_type_wrapper.EnumTypeWrapper):
__slots__ = []
TOKEN_BUCKET: _ClassVar[Algorithm]
LEAKY_BUCKET: _ClassVar[Algorithm]

class Behavior(int, metaclass=_enum_type_wrapper.EnumTypeWrapper):
__slots__ = []
BATCHING: _ClassVar[Behavior]
NO_BATCHING: _ClassVar[Behavior]
GLOBAL: _ClassVar[Behavior]
DURATION_IS_GREGORIAN: _ClassVar[Behavior]
RESET_REMAINING: _ClassVar[Behavior]
MULTI_REGION: _ClassVar[Behavior]

class Status(int, metaclass=_enum_type_wrapper.EnumTypeWrapper):
__slots__ = []
UNDER_LIMIT: _ClassVar[Status]
OVER_LIMIT: _ClassVar[Status]
TOKEN_BUCKET: Algorithm
LEAKY_BUCKET: Algorithm
BATCHING: Behavior
NO_BATCHING: Behavior
GLOBAL: Behavior
DURATION_IS_GREGORIAN: Behavior
RESET_REMAINING: Behavior
MULTI_REGION: Behavior
UNDER_LIMIT: Status
OVER_LIMIT: Status

class GetRateLimitsReq(_message.Message):
__slots__ = ["requests"]
REQUESTS_FIELD_NUMBER: _ClassVar[int]
requests: _containers.RepeatedCompositeFieldContainer[RateLimitReq]
def __init__(self, requests: _Optional[_Iterable[_Union[RateLimitReq, _Mapping]]] = ...) -> None: ...

class GetRateLimitsResp(_message.Message):
__slots__ = ["responses"]
RESPONSES_FIELD_NUMBER: _ClassVar[int]
responses: _containers.RepeatedCompositeFieldContainer[RateLimitResp]
def __init__(self, responses: _Optional[_Iterable[_Union[RateLimitResp, _Mapping]]] = ...) -> None: ...

class RateLimitReq(_message.Message):
__slots__ = ["name", "unique_key", "hits", "limit", "duration", "algorithm", "behavior", "burst", "metadata"]
class MetadataEntry(_message.Message):
__slots__ = ["key", "value"]
KEY_FIELD_NUMBER: _ClassVar[int]
VALUE_FIELD_NUMBER: _ClassVar[int]
key: str
value: str
def __init__(self, key: _Optional[str] = ..., value: _Optional[str] = ...) -> None: ...
NAME_FIELD_NUMBER: _ClassVar[int]
UNIQUE_KEY_FIELD_NUMBER: _ClassVar[int]
HITS_FIELD_NUMBER: _ClassVar[int]
LIMIT_FIELD_NUMBER: _ClassVar[int]
DURATION_FIELD_NUMBER: _ClassVar[int]
ALGORITHM_FIELD_NUMBER: _ClassVar[int]
BEHAVIOR_FIELD_NUMBER: _ClassVar[int]
BURST_FIELD_NUMBER: _ClassVar[int]
METADATA_FIELD_NUMBER: _ClassVar[int]
name: str
unique_key: str
hits: int
limit: int
duration: int
algorithm: Algorithm
behavior: Behavior
burst: int
metadata: _containers.ScalarMap[str, str]
def __init__(self, name: _Optional[str] = ..., unique_key: _Optional[str] = ..., hits: _Optional[int] = ..., limit: _Optional[int] = ..., duration: _Optional[int] = ..., algorithm: _Optional[_Union[Algorithm, str]] = ..., behavior: _Optional[_Union[Behavior, str]] = ..., burst: _Optional[int] = ..., metadata: _Optional[_Mapping[str, str]] = ...) -> None: ...

class RateLimitResp(_message.Message):
__slots__ = ["status", "limit", "remaining", "reset_time", "error", "metadata"]
class MetadataEntry(_message.Message):
__slots__ = ["key", "value"]
KEY_FIELD_NUMBER: _ClassVar[int]
VALUE_FIELD_NUMBER: _ClassVar[int]
key: str
value: str
def __init__(self, key: _Optional[str] = ..., value: _Optional[str] = ...) -> None: ...
STATUS_FIELD_NUMBER: _ClassVar[int]
LIMIT_FIELD_NUMBER: _ClassVar[int]
REMAINING_FIELD_NUMBER: _ClassVar[int]
RESET_TIME_FIELD_NUMBER: _ClassVar[int]
ERROR_FIELD_NUMBER: _ClassVar[int]
METADATA_FIELD_NUMBER: _ClassVar[int]
status: Status
limit: int
remaining: int
reset_time: int
error: str
metadata: _containers.ScalarMap[str, str]
def __init__(self, status: _Optional[_Union[Status, str]] = ..., limit: _Optional[int] = ..., remaining: _Optional[int] = ..., reset_time: _Optional[int] = ..., error: _Optional[str] = ..., metadata: _Optional[_Mapping[str, str]] = ...) -> None: ...

class HealthCheckReq(_message.Message):
__slots__ = []
def __init__(self) -> None: ...

class HealthCheckResp(_message.Message):
__slots__ = ["status", "message", "peer_count"]
STATUS_FIELD_NUMBER: _ClassVar[int]
MESSAGE_FIELD_NUMBER: _ClassVar[int]
PEER_COUNT_FIELD_NUMBER: _ClassVar[int]
status: str
message: str
peer_count: int
def __init__(self, status: _Optional[str] = ..., message: _Optional[str] = ..., peer_count: _Optional[int] = ...) -> None: ...
2 changes: 1 addition & 1 deletion python/gubernator/gubernator_pb2_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""Client and server classes corresponding to protobuf-defined services."""
import grpc

import gubernator_pb2 as gubernator__pb2
from gubernator import gubernator_pb2 as gubernator__pb2


class V1Stub(object):
Expand Down
56 changes: 56 additions & 0 deletions python/gubernator/gubernator_pb2_grpc.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""
@generated by mypy-protobuf. Do not edit manually!
isort:skip_file

Copyright 2018-2022 Mailgun Technologies Inc

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import abc
import grpc
from gubernator import gubernator_pb2

class V1Stub:
def __init__(self, channel: grpc.Channel) -> None: ...
GetRateLimits: grpc.UnaryUnaryMultiCallable[
gubernator_pb2.GetRateLimitsReq,
gubernator_pb2.GetRateLimitsResp,
]
"""Given a list of rate limit requests, return the rate limits of each."""
HealthCheck: grpc.UnaryUnaryMultiCallable[
gubernator_pb2.HealthCheckReq,
gubernator_pb2.HealthCheckResp,
]
"""This method is for round trip benchmarking and can be used by
the client to determine connectivity to the server
"""

class V1Servicer(metaclass=abc.ABCMeta):
@abc.abstractmethod
def GetRateLimits(
self,
request: gubernator_pb2.GetRateLimitsReq,
context: grpc.ServicerContext,
) -> gubernator_pb2.GetRateLimitsResp:
"""Given a list of rate limit requests, return the rate limits of each."""
@abc.abstractmethod
def HealthCheck(
self,
request: gubernator_pb2.HealthCheckReq,
context: grpc.ServicerContext,
) -> gubernator_pb2.HealthCheckResp:
"""This method is for round trip benchmarking and can be used by
the client to determine connectivity to the server
"""

def add_V1Servicer_to_server(servicer: V1Servicer, server: grpc.Server) -> None: ...
33 changes: 17 additions & 16 deletions python/gubernator/peers_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions python/gubernator/peers_pb2.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from gubernator import gubernator_pb2 as _gubernator_pb2
from google.protobuf.internal import containers as _containers
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
from typing import ClassVar as _ClassVar, Iterable as _Iterable, Mapping as _Mapping, Optional as _Optional, Union as _Union

DESCRIPTOR: _descriptor.FileDescriptor

class GetPeerRateLimitsReq(_message.Message):
__slots__ = ["requests"]
REQUESTS_FIELD_NUMBER: _ClassVar[int]
requests: _containers.RepeatedCompositeFieldContainer[_gubernator_pb2.RateLimitReq]
def __init__(self, requests: _Optional[_Iterable[_Union[_gubernator_pb2.RateLimitReq, _Mapping]]] = ...) -> None: ...

class GetPeerRateLimitsResp(_message.Message):
__slots__ = ["rate_limits"]
RATE_LIMITS_FIELD_NUMBER: _ClassVar[int]
rate_limits: _containers.RepeatedCompositeFieldContainer[_gubernator_pb2.RateLimitResp]
def __init__(self, rate_limits: _Optional[_Iterable[_Union[_gubernator_pb2.RateLimitResp, _Mapping]]] = ...) -> None: ...

class UpdatePeerGlobalsReq(_message.Message):
__slots__ = ["globals"]
GLOBALS_FIELD_NUMBER: _ClassVar[int]
globals: _containers.RepeatedCompositeFieldContainer[UpdatePeerGlobal]
def __init__(self, globals: _Optional[_Iterable[_Union[UpdatePeerGlobal, _Mapping]]] = ...) -> None: ...

class UpdatePeerGlobal(_message.Message):
__slots__ = ["key", "status", "algorithm"]
KEY_FIELD_NUMBER: _ClassVar[int]
STATUS_FIELD_NUMBER: _ClassVar[int]
ALGORITHM_FIELD_NUMBER: _ClassVar[int]
key: str
status: _gubernator_pb2.RateLimitResp
algorithm: _gubernator_pb2.Algorithm
def __init__(self, key: _Optional[str] = ..., status: _Optional[_Union[_gubernator_pb2.RateLimitResp, _Mapping]] = ..., algorithm: _Optional[_Union[_gubernator_pb2.Algorithm, str]] = ...) -> None: ...

class UpdatePeerGlobalsResp(_message.Message):
__slots__ = []
def __init__(self) -> None: ...
2 changes: 1 addition & 1 deletion python/gubernator/peers_pb2_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""Client and server classes corresponding to protobuf-defined services."""
import grpc

import peers_pb2 as peers__pb2
from gubernator import peers_pb2 as peers__pb2


class PeersV1Stub(object):
Expand Down
Loading