diff --git a/.env.example b/.env.example deleted file mode 100644 index 9561b39..0000000 --- a/.env.example +++ /dev/null @@ -1,3 +0,0 @@ -CLIENT_ID= -CLIENT_SECRET="..." -REFRESH_BUCKETS_SEC= \ No newline at end of file diff --git a/.github/workflows/publish_to_pypi.yml b/.github/workflows/publish_to_pypi.yml new file mode 100644 index 0000000..642a401 --- /dev/null +++ b/.github/workflows/publish_to_pypi.yml @@ -0,0 +1,40 @@ +name: Publish to PyPI + +on: + release: + types: [published] + +jobs: + build-and-publish: + name: Build and publish to PyPI + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python 3.8 + uses: actions/setup-python@v2 + with: + python-version: 3.8 + + - name: Install pypa/build + run: >- + python -m + pip install + build + --user + + - name: Build a binary wheel and a source tarball + env: + GITHUB_REF_TAG: ${{ github.ref }} + run: | + echo "Extracting version from GITHUB_REF_TAG: $GITHUB_REF_TAG" + export RATE_LIMITING_GUARD_VERSION=$(echo "$GITHUB_REF_TAG" | sed -e "s#^refs/tags/##") + python -m build --sdist --wheel --outdir dist/ . + + - name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} + verbose: true diff --git a/.gitignore b/.gitignore index b44f310..72ece00 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ -.env +**/.env .cache +dist +build +src/rate_limiting_guard.egg-info \ No newline at end of file diff --git a/README.md b/README.md index 682ba7f..2152f86 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ This repository provides: | | | | +-------------+ +---------v--------+ | | | | | | | - | | Redis <-----+ Syncer | | + | | Store <-----+ Syncer | | | | | | | | (2) request| +--^-------^--+ +------------------+ |request (2) data| | | |data @@ -86,26 +86,37 @@ This repository provides: ## Installation -Both service and library are provided as examples. We encourage you to investigate them and to adapt them to your needs. +``` +pip install rate_limiting_guard +``` ### Syncer service -The purpose of `syncer` service is to synchronize the internal state (counters which are kept in Redis) with Sentinel Hub. It does so by periodically refilling the buckets according to user's rate limiting policies. +```python +from rate_limiting_guard.syncer import start_syncer +``` + +The purpose of `syncer` service is to synchronize the internal state (counters which are kept in Redis/Zookeper) with Sentinel Hub. It does so by periodically refilling the buckets according to user's rate limiting policies. Before running the `syncer` service, first edit `.env` file and set user credentials: ``` CLIENT_ID=... CLIENT_SECRET="..." +REFRESH_BUCKETS_SEC=... +ZOOKEEPER_HOSTS=... +REDIS_HOST=... +REDIS_PORT=... +REVISIT_TIME_MSEC=... +LOGLEVEL=... ``` Note: since `CLIENT_SECRET` contains special characters by design, you should enclose it in double quotes. -Syncer service depends on Redis. You can run both of them using Docker and Docker-compose: +Syncer service depends on Redis/Zookeper. You can run both of them using Docker and Docker-compose: ``` $ docker-compose build $ docker-compose up -d ``` - With time, the values in the buckets might drift away from the actual values on Sentinel Hub. `RLGuard` can automatically refresh the values in the buckets, just edit the `.env` file and set: ``` REFRESH_BUCKETS_SEC= @@ -113,19 +124,15 @@ REFRESH_BUCKETS_SEC= ### RLGuard library -The purpose of `RLGuard` library is to make applying for a permission to make a request to Sentinel Hub a bit easier. It provides two functions: -- `apply_for_request`: updates the counters in the central storage (Redis) and calculates the delay worker should wait for before making a request to Sentinel Hub, and -- `calculate_processing_units`: helper function to calculate the number of [Processing Units](https://docs.sentinel-hub.com/api/latest/api/overview/processing-unit/) the request will use - -For the time being, the library is only available as part of this repository (i.e., it can't be installed via `pip` and similar mechanisms). +```python +from rate_limiting_guard.lib import calculate_processing_units, apply_for_request, RedisRepository, ZooKeeperRepository +``` -To use it: -- copy `lib/rlguard.py` file to your project, -- import it, and -- use `calculate_processing_units` and `apply_for_request` in your code. +The purpose of `rate_limiting_guard.lib` module is to make applying for a permission to make a request to Sentinel Hub a bit easier. It provides two functions: +- `apply_for_request`: updates the counters in the central storage (Redis/Zookeper) and calculates the delay worker should wait for before making a request to Sentinel Hub, and +- `calculate_processing_units`: helper function to calculate the number of [Processing Units](https://docs.sentinel-hub.com/api/latest/api/overview/processing-unit/) the request will use -For an example see `lib/example.py`. ## Additional information -See [DETAILS.md](./DETAILS.md) for additional implementation information. +See [DETAILS.md](https://github.com/sentinel-hub/rate-limiting-guard/blob/master/DETAILS.md) for additional implementation information. diff --git a/e2etest/performance.py b/e2etest/performance.py index eb62b15..0e5f787 100644 --- a/e2etest/performance.py +++ b/e2etest/performance.py @@ -13,8 +13,7 @@ currentdir = os.path.dirname(os.path.realpath(__file__)) parentdir = os.path.dirname(currentdir) sys.path.append(parentdir) -from lib.rlguard import apply_for_request, SyncerDownException -from lib.rlguard.repository import RedisRepository +from src.rate_limiting_guard.lib import apply_for_request, SyncerDownException, RedisRepository MOCKSH_ROOT_URL = "http://127.0.0.1:8000" diff --git a/example/.env.example b/example/.env.example new file mode 100644 index 0000000..9ddb49b --- /dev/null +++ b/example/.env.example @@ -0,0 +1,8 @@ +CLIENT_ID= +CLIENT_SECRET="..." +REFRESH_BUCKETS_SEC= +ZOOKEEPER_HOSTS= +REDIS_HOST= +REDIS_PORT= +REVISIT_TIME_MSEC= +LOGLEVEL= \ No newline at end of file diff --git a/lib/Pipfile b/example/Pipfile similarity index 78% rename from lib/Pipfile rename to example/Pipfile index 3db77bf..03d6839 100644 --- a/lib/Pipfile +++ b/example/Pipfile @@ -10,6 +10,7 @@ black = "==20.8b1" requests = "*" redis = "*" kazoo = "*" +rate-limiting-guard = {editable = true, path = "./.."} [requires] python_version = "3.8" diff --git a/lib/example.py b/example/example.py similarity index 96% rename from lib/example.py rename to example/example.py index e99a89a..4ef39c9 100644 --- a/lib/example.py +++ b/example/example.py @@ -7,9 +7,7 @@ import requests import requests.exceptions -from rlguard import calculate_processing_units, OutputFormat, apply_for_request, SyncerDownException -from rlguard.repository import Repository, RedisRepository - +from rate_limiting_guard.lib import calculate_processing_units, OutputFormat, apply_for_request, SyncerDownException, Repository, RedisRepository logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO").upper()) diff --git a/lib/pyproject.toml b/example/pyproject.toml similarity index 100% rename from lib/pyproject.toml rename to example/pyproject.toml diff --git a/lib/Pipfile.lock b/lib/Pipfile.lock deleted file mode 100644 index 46dac3e..0000000 --- a/lib/Pipfile.lock +++ /dev/null @@ -1,212 +0,0 @@ -{ - "_meta": { - "hash": { - "sha256": "1288387fa0768a6d38a46ac388436a2d88999578210550ba0b1003fc69ae838a" - }, - "pipfile-spec": 6, - "requires": { - "python_version": "3.8" - }, - "sources": [ - { - "name": "pypi", - "url": "https://pypi.org/simple", - "verify_ssl": true - } - ] - }, - "default": { - "certifi": { - "hashes": [ - "sha256:2bbf76fd432960138b3ef6dda3dde0544f27cbf8546c458e60baf371917ba9ee", - "sha256:50b1e4f8446b06f41be7dd6338db18e0990601dce795c2b1686458aa7e8fa7d8" - ], - "version": "==2021.5.30" - }, - "chardet": { - "hashes": [ - "sha256:0d6f53a15db4120f2b08c94f11e7d93d2c911ee118b6b30a04ec3ee8310179fa", - "sha256:f864054d66fd9118f2e67044ac8981a54775ec5b67aed0441892edb553d21da5" - ], - "version": "==4.0.0" - }, - "idna": { - "hashes": [ - "sha256:b307872f855b18632ce0c21c5e45be78c0ea7ae4c15c828c20788b26921eb3f6", - "sha256:b97d804b1e9b523befed77c48dacec60e6dcb0b5391d57af6a65a312a90648c0" - ], - "version": "==2.10" - }, - "kazoo": { - "hashes": [ - "sha256:2dc46de17efc02e0ef42a9d92f3bbabce6204bbcc0792a1d9211344d0b8a03b8", - "sha256:588e27868e4a0ed70ae4a7a5b0f3bca4cec5e5c49dbd7e41349c0883182bf2fe" - ], - "index": "pypi", - "version": "==2.8.0" - }, - "redis": { - "hashes": [ - "sha256:0e7e0cfca8660dea8b7d5cd8c4f6c5e29e11f31158c0b0ae91a397f00e5a05a2", - "sha256:432b788c4530cfe16d8d943a09d40ca6c16149727e4afe8c2c9d5580c59d9f24" - ], - "index": "pypi", - "version": "==3.5.3" - }, - "requests": { - "hashes": [ - "sha256:27973dd4a904a4f13b263a19c866c13b92a39ed1c964655f025f3f8d3d75b804", - "sha256:c210084e36a42ae6b9219e00e48287def368a26d03a048ddad7bfee44f75871e" - ], - "index": "pypi", - "version": "==2.25.1" - }, - "six": { - "hashes": [ - "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926", - "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254" - ], - "version": "==1.16.0" - }, - "urllib3": { - "hashes": [ - "sha256:753a0374df26658f99d826cfe40394a686d05985786d946fbe4165b5148f5a7c", - "sha256:a7acd0977125325f516bda9735fa7142b909a8d01e8b2e4c8108d0984e6e0098" - ], - "version": "==1.26.5" - } - }, - "develop": { - "appdirs": { - "hashes": [ - "sha256:7d5d0167b2b1ba821647616af46a749d1c653740dd0d2415100fe26e27afdf41", - "sha256:a841dacd6b99318a741b166adb07e19ee71a274450e68237b4650ca1055ab128" - ], - "version": "==1.4.4" - }, - "black": { - "hashes": [ - "sha256:1c02557aa099101b9d21496f8a914e9ed2222ef70336404eeeac8edba836fbea" - ], - "index": "pypi", - "version": "==20.8b1" - }, - "click": { - "hashes": [ - "sha256:8c04c11192119b1ef78ea049e0a6f0463e4c48ef00a30160c704337586f3ad7a", - "sha256:fba402a4a47334742d782209a7c79bc448911afe1149d07bdabdf480b3e2f4b6" - ], - "version": "==8.0.1" - }, - "mypy-extensions": { - "hashes": [ - "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d", - "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8" - ], - "version": "==0.4.3" - }, - "pathspec": { - "hashes": [ - "sha256:86379d6b86d75816baba717e64b1a3a3469deb93bb76d613c9ce79edc5cb68fd", - "sha256:aa0cb481c4041bf52ffa7b0d8fa6cd3e88a2ca4879c533c9153882ee2556790d" - ], - "version": "==0.8.1" - }, - "regex": { - "hashes": [ - "sha256:01afaf2ec48e196ba91b37451aa353cb7eda77efe518e481707e0515025f0cd5", - "sha256:11d773d75fa650cd36f68d7ca936e3c7afaae41b863b8c387a22aaa78d3c5c79", - "sha256:18c071c3eb09c30a264879f0d310d37fe5d3a3111662438889ae2eb6fc570c31", - "sha256:1e1c20e29358165242928c2de1482fb2cf4ea54a6a6dea2bd7a0e0d8ee321500", - "sha256:281d2fd05555079448537fe108d79eb031b403dac622621c78944c235f3fcf11", - "sha256:314d66636c494ed9c148a42731b3834496cc9a2c4251b1661e40936814542b14", - "sha256:32e65442138b7b76dd8173ffa2cf67356b7bc1768851dded39a7a13bf9223da3", - "sha256:339456e7d8c06dd36a22e451d58ef72cef293112b559010db3d054d5560ef439", - "sha256:3916d08be28a1149fb97f7728fca1f7c15d309a9f9682d89d79db75d5e52091c", - "sha256:3a9cd17e6e5c7eb328517969e0cb0c3d31fd329298dd0c04af99ebf42e904f82", - "sha256:47bf5bf60cf04d72bf6055ae5927a0bd9016096bf3d742fa50d9bf9f45aa0711", - "sha256:4c46e22a0933dd783467cf32b3516299fb98cfebd895817d685130cc50cd1093", - "sha256:4c557a7b470908b1712fe27fb1ef20772b78079808c87d20a90d051660b1d69a", - "sha256:52ba3d3f9b942c49d7e4bc105bb28551c44065f139a65062ab7912bef10c9afb", - "sha256:563085e55b0d4fb8f746f6a335893bda5c2cef43b2f0258fe1020ab1dd874df8", - "sha256:598585c9f0af8374c28edd609eb291b5726d7cbce16be6a8b95aa074d252ee17", - "sha256:619d71c59a78b84d7f18891fe914446d07edd48dc8328c8e149cbe0929b4e000", - "sha256:67bdb9702427ceddc6ef3dc382455e90f785af4c13d495f9626861763ee13f9d", - "sha256:6d1b01031dedf2503631d0903cb563743f397ccaf6607a5e3b19a3d76fc10480", - "sha256:741a9647fcf2e45f3a1cf0e24f5e17febf3efe8d4ba1281dcc3aa0459ef424dc", - "sha256:7c2a1af393fcc09e898beba5dd59196edaa3116191cc7257f9224beaed3e1aa0", - "sha256:7d9884d86dd4dd489e981d94a65cd30d6f07203d90e98f6f657f05170f6324c9", - "sha256:90f11ff637fe8798933fb29f5ae1148c978cccb0452005bf4c69e13db951e765", - "sha256:919859aa909429fb5aa9cf8807f6045592c85ef56fdd30a9a3747e513db2536e", - "sha256:96fcd1888ab4d03adfc9303a7b3c0bd78c5412b2bfbe76db5b56d9eae004907a", - "sha256:97f29f57d5b84e73fbaf99ab3e26134e6687348e95ef6b48cfd2c06807005a07", - "sha256:980d7be47c84979d9136328d882f67ec5e50008681d94ecc8afa8a65ed1f4a6f", - "sha256:a91aa8619b23b79bcbeb37abe286f2f408d2f2d6f29a17237afda55bb54e7aac", - "sha256:ade17eb5d643b7fead300a1641e9f45401c98eee23763e9ed66a43f92f20b4a7", - "sha256:b9c3db21af35e3b3c05764461b262d6f05bbca08a71a7849fd79d47ba7bc33ed", - "sha256:bd28bc2e3a772acbb07787c6308e00d9626ff89e3bfcdebe87fa5afbfdedf968", - "sha256:bf5824bfac591ddb2c1f0a5f4ab72da28994548c708d2191e3b87dd207eb3ad7", - "sha256:c0502c0fadef0d23b128605d69b58edb2c681c25d44574fc673b0e52dce71ee2", - "sha256:c38c71df845e2aabb7fb0b920d11a1b5ac8526005e533a8920aea97efb8ec6a4", - "sha256:ce15b6d103daff8e9fee13cf7f0add05245a05d866e73926c358e871221eae87", - "sha256:d3029c340cfbb3ac0a71798100ccc13b97dddf373a4ae56b6a72cf70dfd53bc8", - "sha256:e512d8ef5ad7b898cdb2d8ee1cb09a8339e4f8be706d27eaa180c2f177248a10", - "sha256:e8e5b509d5c2ff12f8418006d5a90e9436766133b564db0abaec92fd27fcee29", - "sha256:ee54ff27bf0afaf4c3b3a62bcd016c12c3fdb4ec4f413391a90bd38bc3624605", - "sha256:fa4537fb4a98fe8fde99626e4681cc644bdcf2a795038533f9f711513a862ae6", - "sha256:fd45ff9293d9274c5008a2054ecef86a9bfe819a67c7be1afb65e69b405b3042" - ], - "version": "==2021.4.4" - }, - "toml": { - "hashes": [ - "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b", - "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f" - ], - "version": "==0.10.2" - }, - "typed-ast": { - "hashes": [ - "sha256:01ae5f73431d21eead5015997ab41afa53aa1fbe252f9da060be5dad2c730ace", - "sha256:067a74454df670dcaa4e59349a2e5c81e567d8d65458d480a5b3dfecec08c5ff", - "sha256:0fb71b8c643187d7492c1f8352f2c15b4c4af3f6338f21681d3681b3dc31a266", - "sha256:1b3ead4a96c9101bef08f9f7d1217c096f31667617b58de957f690c92378b528", - "sha256:2068531575a125b87a41802130fa7e29f26c09a2833fea68d9a40cf33902eba6", - "sha256:209596a4ec71d990d71d5e0d312ac935d86930e6eecff6ccc7007fe54d703808", - "sha256:2c726c276d09fc5c414693a2de063f521052d9ea7c240ce553316f70656c84d4", - "sha256:398e44cd480f4d2b7ee8d98385ca104e35c81525dd98c519acff1b79bdaac363", - "sha256:52b1eb8c83f178ab787f3a4283f68258525f8d70f778a2f6dd54d3b5e5fb4341", - "sha256:5feca99c17af94057417d744607b82dd0a664fd5e4ca98061480fd8b14b18d04", - "sha256:7538e495704e2ccda9b234b82423a4038f324f3a10c43bc088a1636180f11a41", - "sha256:760ad187b1041a154f0e4d0f6aae3e40fdb51d6de16e5c99aedadd9246450e9e", - "sha256:777a26c84bea6cd934422ac2e3b78863a37017618b6e5c08f92ef69853e765d3", - "sha256:95431a26309a21874005845c21118c83991c63ea800dd44843e42a916aec5899", - "sha256:9ad2c92ec681e02baf81fdfa056fe0d818645efa9af1f1cd5fd6f1bd2bdfd805", - "sha256:9c6d1a54552b5330bc657b7ef0eae25d00ba7ffe85d9ea8ae6540d2197a3788c", - "sha256:aee0c1256be6c07bd3e1263ff920c325b59849dc95392a05f258bb9b259cf39c", - "sha256:af3d4a73793725138d6b334d9d247ce7e5f084d96284ed23f22ee626a7b88e39", - "sha256:b36b4f3920103a25e1d5d024d155c504080959582b928e91cb608a65c3a49e1a", - "sha256:b9574c6f03f685070d859e75c7f9eeca02d6933273b5e69572e5ff9d5e3931c3", - "sha256:bff6ad71c81b3bba8fa35f0f1921fb24ff4476235a6e94a26ada2e54370e6da7", - "sha256:c190f0899e9f9f8b6b7863debfb739abcb21a5c054f911ca3596d12b8a4c4c7f", - "sha256:c907f561b1e83e93fad565bac5ba9c22d96a54e7ea0267c708bffe863cbe4075", - "sha256:cae53c389825d3b46fb37538441f75d6aecc4174f615d048321b716df2757fb0", - "sha256:dd4a21253f42b8d2b48410cb31fe501d32f8b9fbeb1f55063ad102fe9c425e40", - "sha256:dde816ca9dac1d9c01dd504ea5967821606f02e510438120091b84e852367428", - "sha256:f2362f3cb0f3172c42938946dbc5b7843c2a28aec307c49100c8b38764eb6927", - "sha256:f328adcfebed9f11301eaedfa48e15bdece9b519fb27e6a8c01aa52a17ec31b3", - "sha256:f8afcf15cc511ada719a88e013cec87c11aff7b91f019295eb4530f96fe5ef2f", - "sha256:fb1bbeac803adea29cedd70781399c99138358c26d05fcbd23c13016b7f5ec65" - ], - "version": "==1.4.3" - }, - "typing-extensions": { - "hashes": [ - "sha256:0ac0f89795dd19de6b97debb0c6af1c70987fd80a2d62d1958f7e56fcc31b497", - "sha256:50b6f157849174217d0656f99dc82fe932884fb250826c18350e159ec6cdf342", - "sha256:779383f6086d90c99ae41cf0ff39aac8a7937a9283ce0a414e5dd782f4c94a84" - ], - "version": "==3.10.0.0" - } - } -} diff --git a/lib/setup.py b/lib/setup.py deleted file mode 100644 index d4ee43d..0000000 --- a/lib/setup.py +++ /dev/null @@ -1,3 +0,0 @@ -from setuptools import setup, find_packages - -setup(name="rlguard-lib", version="0.0.6", packages=find_packages(), install_requires=["kazoo", "redis"]) diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..f40bcf6 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,11 @@ +[options] +package_dir= + =src +packages=find: + +[options.packages.find] +where=src + +[metadata] +long_description = file: README.md +long_description_content_type = text/markdown \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..15496d3 --- /dev/null +++ b/setup.py @@ -0,0 +1,12 @@ +import os +from setuptools import setup, find_packages + +setup( + name="rate_limiting_guard", + author="Sinergise ltd.", + author_email="info@sentinel-hub.com", + license="MIT", + version=os.environ.get("RATE_LIMITING_GUARD_VERSION", "0.0.0"), + packages=["rate_limiting_guard", "rate_limiting_guard.lib", "rate_limiting_guard.syncer"], + install_requires =["redis", "kazoo", "requests", "pyjwt"] +) diff --git a/src/rate_limiting_guard/__init__.py b/src/rate_limiting_guard/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/rate_limiting_guard/lib/__init__.py b/src/rate_limiting_guard/lib/__init__.py new file mode 100644 index 0000000..86354cf --- /dev/null +++ b/src/rate_limiting_guard/lib/__init__.py @@ -0,0 +1,2 @@ +from .rlguard import * +from .repository import * \ No newline at end of file diff --git a/lib/rlguard/repository.py b/src/rate_limiting_guard/lib/repository.py similarity index 100% rename from lib/rlguard/repository.py rename to src/rate_limiting_guard/lib/repository.py diff --git a/lib/rlguard/__init__.py b/src/rate_limiting_guard/lib/rlguard.py similarity index 100% rename from lib/rlguard/__init__.py rename to src/rate_limiting_guard/lib/rlguard.py diff --git a/syncer/.env.example b/src/rate_limiting_guard/syncer/.env.example similarity index 100% rename from syncer/.env.example rename to src/rate_limiting_guard/syncer/.env.example diff --git a/syncer/Dockerfile b/src/rate_limiting_guard/syncer/Dockerfile similarity index 100% rename from syncer/Dockerfile rename to src/rate_limiting_guard/syncer/Dockerfile diff --git a/syncer/Pipfile b/src/rate_limiting_guard/syncer/Pipfile similarity index 100% rename from syncer/Pipfile rename to src/rate_limiting_guard/syncer/Pipfile diff --git a/syncer/Pipfile.lock b/src/rate_limiting_guard/syncer/Pipfile.lock similarity index 100% rename from syncer/Pipfile.lock rename to src/rate_limiting_guard/syncer/Pipfile.lock diff --git a/src/rate_limiting_guard/syncer/__init__.py b/src/rate_limiting_guard/syncer/__init__.py new file mode 100644 index 0000000..510e160 --- /dev/null +++ b/src/rate_limiting_guard/syncer/__init__.py @@ -0,0 +1 @@ +from .syncer import start_syncer \ No newline at end of file diff --git a/syncer/pyproject.toml b/src/rate_limiting_guard/syncer/pyproject.toml similarity index 100% rename from syncer/pyproject.toml rename to src/rate_limiting_guard/syncer/pyproject.toml diff --git a/syncer/syncer.py b/src/rate_limiting_guard/syncer/syncer.py similarity index 98% rename from syncer/syncer.py rename to src/rate_limiting_guard/syncer/syncer.py index d9b6fed..abdd91b 100644 --- a/syncer/syncer.py +++ b/src/rate_limiting_guard/syncer/syncer.py @@ -11,8 +11,7 @@ import kazoo.client from kazoo.client import KazooClient -from rlguard import PolicyType -from rlguard.repository import Repository, RedisRepository, ZooKeeperRepository +from rate_limiting_guard.lib import PolicyType, Repository, RedisRepository, ZooKeeperRepository POLICY_TYPES_SHORT_NAMES = { @@ -238,7 +237,7 @@ def refresh_buckets(rate_limits, auth_token): scheduler.run() -def main(argv): +def start_syncer(argv): if len(argv) > 1 and argv[1] == "zookeeper": ZOOKEEPER_HOSTS = os.environ.get("ZOOKEEPER_HOSTS", "127.0.0.1:2181") zk = KazooClient(hosts=ZOOKEEPER_HOSTS) @@ -291,4 +290,4 @@ def main(argv): if __name__ == "__main__": - main(sys.argv) + start_syncer(sys.argv)