Skip to content

Commit

Permalink
Merge pull request #27 from evo-company/update-rpc-servicer
Browse files Browse the repository at this point in the history
Update rpc servicer
  • Loading branch information
n4mespace authored Jan 19, 2024
2 parents b83c133 + 7d7772b commit 55b0d9f
Show file tree
Hide file tree
Showing 57 changed files with 2,754 additions and 1,547 deletions.
29 changes: 6 additions & 23 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Test

on:
pull_request:
branches:
Expand All @@ -10,33 +11,15 @@ on:
- reopened

jobs:
test-client:
test-web:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./client
strategy:
matrix:
python-version: [3.7, 3.8, 3.9, "3.10", 3.11]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: pdm-project/setup-pdm@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: python -m pip install tox tox-gh-actions tox-pdm
- name: Test with tox
run: |
tox --version
tox

test-server:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Install lets
uses: lets-cli/[email protected]

- name: Run test
run: lets test server
run: lets test
27 changes: 27 additions & 0 deletions .hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

HAS_STAGED_PY=$(git diff --staged --diff-filter=d --name-only '*.py')

if [ -n "$HAS_STAGED_PY" ]; then

echo "Running mypy ..."
lets mypy
if [[ $? -ne 0 ]]; then
exit 1
fi

echo "Running black ..."
lets black --diff --check
if [[ $? -ne 0 ]]; then
exit 1
fi

echo "Running ruff ..."
lets ruff-diff
if [[ $? -ne 0 ]]; then
exit 1
fi

fi

exit 0
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Check important architecture decisions in ``adr/`` directory.

Installation
------------
TODO: update after deploy configuration
TODO: update after deploy configuration

On PyPi: https://pypi.org/project/evo-featureflags-client

Expand Down Expand Up @@ -59,6 +59,17 @@ to start API handlers (not required for web application):
- ``lets http`` # in separate terminal
- ``lets rpc`` # in separate terminal

Pre-commit

``./scripts/enable-hooks.sh``

``./scripts/disable-hooks.sh``

TODO:

- add docs, automate docs build
- add tests

.. _fastapi: https://github.com/tiangolo/fastapi
.. _hiku: https://github.com/vmagamedov/hiku
.. _aiopg: https://github.com/aio-libs/aiopg
Expand Down
6 changes: 6 additions & 0 deletions configs/local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ app:
reload: True
thread_limiter_total_tokens: 40

http:
port: 8080
host: 0.0.0.0
reload: True
thread_limiter_total_tokens: 40

rpc:
port: 50051
host: 0.0.0.0
Expand Down
10 changes: 8 additions & 2 deletions configs/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ app:
reload: True
thread_limiter_total_tokens: 40

http:
port: 8080
host: 0.0.0.0
reload: True
thread_limiter_total_tokens: 40

rpc:
port: 50051
host: 0.0.0.0
Expand All @@ -23,11 +29,11 @@ logging:
syslog_defaults: null

postgres:
host: postgres
host: postgres-test
port: 5432
user: postgres
password: postgres
database: featureflags
database: featureflags-test
timeout: 10

ldap:
Expand Down
26 changes: 25 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
postgres:
image: postgres:13-alpine
ports:
- "5432:5432"
- "127.0.0.1:5432:5432"
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
Expand All @@ -21,6 +21,21 @@ services:
retries: 5
start_period: 80s

postgres-test:
image: postgres:13-alpine
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: featureflags-test
networks:
- main
healthcheck:
test: [ "CMD-SHELL", "pg_isready", "-d", "featureflags-test" ]
interval: 30s
timeout: 60s
retries: 5
start_period: 80s

backend: &backend
image: featureflags-server-dev
init: true
Expand Down Expand Up @@ -60,6 +75,15 @@ services:
- "127.0.0.1:50051:50051"
command: pdm run watchfiles --filter python "python3 -m featureflags rpc" featureflags

http:
<<: *backend
depends_on:
postgres:
condition: service_healthy
ports:
- "127.0.0.1:8080:8080"
command: pdm run watchfiles --filter python "python3 -m featureflags http" featureflags

ishell:
<<: *backend
command: pdm run ipython --ipython-dir=/app/.ipython
Expand Down
7 changes: 7 additions & 0 deletions featureflags/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,10 @@ def rpc() -> None:

asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
asyncio.run(rpc_main())


@cli.command(name="http", help="Run http server")
def http() -> None:
from featureflags.http.app import main as http_main

http_main()
10 changes: 9 additions & 1 deletion featureflags/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class PostgresSettings(BaseSettings):
timeout: int = 10

@property
def dsn(self):
def dsn(self) -> str:
return (
f"postgresql://{self.user}"
f":{self.password}"
Expand All @@ -59,6 +59,13 @@ class AppSettings(BaseSettings):
thread_limiter_total_tokens: int = 40


class HttpSettings(BaseSettings):
port: int = 8080
host: str = "0.0.0.0"
reload: bool = False
thread_limiter_total_tokens: int = 40


class RpcSettings(BaseSettings):
port: int = 8000
host: str = "0.0.0.0"
Expand All @@ -76,6 +83,7 @@ class Config(BaseSettings):

app: AppSettings
rpc: RpcSettings
http: HttpSettings


def _load_config() -> Config:
Expand Down
4 changes: 2 additions & 2 deletions featureflags/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Container(containers.DeclarativeContainer):
]
)

graph_engine = providers.Factory(
graph_engine: Engine = providers.Factory(
Engine,
providers.Callable(AsyncIOExecutor),
)
Expand All @@ -42,6 +42,6 @@ class Container(containers.DeclarativeContainer):
),
testing=providers.Factory(
DummyLDAP,
bound=True,
user_is_bound=True,
),
)
15 changes: 15 additions & 0 deletions featureflags/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from starlette import status


class BaseInternalServerError(Exception):
"""Internal server error."""

status_code: int = status.HTTP_500_INTERNAL_SERVER_ERROR
detail: str = "Internal server error."


class UserNotAuthorizedError(BaseInternalServerError):
"""User not authorized."""

status_code: int = status.HTTP_401_UNAUTHORIZED
detail: str = "User not authorized."
Loading

0 comments on commit 55b0d9f

Please sign in to comment.