-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove secrets from repo to opensource
- Loading branch information
0 parents
commit a6bf367
Showing
28 changed files
with
91,335 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
name: Docker ssl | ||
|
||
on: | ||
pull_request: | ||
# Publish `main` as Docker `latest` image. | ||
branches: | ||
- master | ||
|
||
# Publish `v1.2.3` tags as releases. | ||
tags: | ||
- v* | ||
|
||
# Run tests for any PRs. | ||
push: | ||
|
||
env: | ||
# Image name | ||
IMAGE_NAME: ssl-fesl-api | ||
|
||
jobs: | ||
# Push image to GitHub Packages. | ||
# See also https://docs.docker.com/docker-hub/builds/ | ||
push: | ||
|
||
runs-on: ubuntu-latest | ||
if: github.event_name == 'push' | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: jpribyl/[email protected] | ||
continue-on-error: true | ||
|
||
- name: Build image | ||
run: docker build . --file ssl.Dockerfile --tag $IMAGE_NAME | ||
|
||
- name: Log into registry | ||
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin | ||
|
||
- name: Push image | ||
run: | | ||
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME | ||
# Change all uppercase to lowercase | ||
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') | ||
# Strip git ref prefix from version | ||
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') | ||
# Strip "v" prefix from tag name | ||
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') | ||
# Use Docker `latest` tag convention | ||
[ "$VERSION" == "main" ] && VERSION=latest | ||
echo IMAGE_ID=$IMAGE_ID | ||
echo VERSION=$VERSION | ||
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION | ||
docker push $IMAGE_ID:$VERSION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
name: Docker | ||
|
||
on: | ||
pull_request: | ||
# Publish `main` as Docker `latest` image. | ||
branches: | ||
- master | ||
|
||
# Publish `v1.2.3` tags as releases. | ||
tags: | ||
- v* | ||
|
||
# Run tests for any PRs. | ||
push: | ||
|
||
env: | ||
# Image name | ||
IMAGE_NAME: fesl-api | ||
|
||
jobs: | ||
# Push image to GitHub Packages. | ||
# See also https://docs.docker.com/docker-hub/builds/ | ||
push: | ||
|
||
runs-on: ubuntu-latest | ||
if: github.event_name == 'push' | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: jpribyl/[email protected] | ||
continue-on-error: true | ||
|
||
- name: Build image | ||
run: docker build . --file Dockerfile --tag $IMAGE_NAME | ||
|
||
- name: Log into registry | ||
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin | ||
|
||
- name: Push image | ||
run: | | ||
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME | ||
# Change all uppercase to lowercase | ||
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') | ||
# Strip git ref prefix from version | ||
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') | ||
# Strip "v" prefix from tag name | ||
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') | ||
# Use Docker `latest` tag convention | ||
[ "$VERSION" == "main" ] && VERSION=latest | ||
echo IMAGE_ID=$IMAGE_ID | ||
echo VERSION=$VERSION | ||
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION | ||
docker push $IMAGE_ID:$VERSION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
pip-wheel-metadata/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# PyCharm project files | ||
.idea/ | ||
|
||
# Generated test data | ||
tests/multi-persona-lookup-test-data-sets-generated.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM python:3.11.1 | ||
|
||
COPY ./requirements.txt /requirements.txt | ||
RUN pip install --upgrade pip | ||
RUN pip install --no-cache-dir --upgrade wheel | ||
RUN pip install --no-cache-dir --upgrade -r requirements.txt | ||
|
||
COPY ./app /app | ||
COPY ./openssl.cnf /openssl.cnf | ||
COPY ./logging.yaml /logging.yaml | ||
|
||
EXPOSE 8000 | ||
ENV OPENSSL_CONF="./openssl.cnf" | ||
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--log-config", "logging.yaml"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# bfbc2-stats-api |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import sys | ||
from datetime import timedelta | ||
from typing import Any | ||
|
||
import redis.asyncio.client | ||
import redis.asyncio | ||
import redis.asyncio.cluster | ||
import redis | ||
|
||
from app.singleton import Singleton | ||
from app import config | ||
|
||
|
||
class RedisClient(metaclass=Singleton): | ||
client: redis.asyncio.Redis | ||
|
||
async def redis_connect(self) -> redis.asyncio.client.Redis: | ||
"""Connect to the redis host""" | ||
try: | ||
self.client = redis.asyncio.Redis( | ||
host=str(config.REDIS_HOST), | ||
port=int(config.REDIS_PORT), | ||
password=str(config.REDIS_PASS), | ||
socket_timeout=5, | ||
) | ||
ping = await self.client.ping() | ||
if ping is True: | ||
return | ||
except redis.AuthenticationError: | ||
print("Redis authentication error!") | ||
sys.exit(1) | ||
except redis.exceptions.RedisClusterException: | ||
self.client = redis.asyncio.Redis( | ||
host=str(config.REDIS_HOST), | ||
port=int(config.REDIS_PORT), | ||
password=str(config.REDIS_PASS), | ||
db=0, | ||
socket_timeout=5, | ||
) | ||
ping = await self.client.ping() | ||
if ping is True: | ||
return | ||
|
||
async def get_from_cache(self, key: str) -> Any: | ||
"""Data from redis.""" | ||
val = None | ||
try: | ||
val = await self.client.get(key) | ||
except Exception as e: | ||
print(f"failed to get cache! {e}") | ||
return val | ||
|
||
async def set_to_cache( | ||
self, key: str, value: str, ttl: int = config.CACHE_TTL_DEFAULT | ||
) -> bool: | ||
"""Data to redis.""" | ||
try: | ||
state = await self.client.setex(key, timedelta(seconds=ttl), value=value) | ||
return state | ||
except Exception as e: | ||
print(f"failed to set cache! {e}") | ||
|
||
async def get_multiple_from_cache(self, keys: list[str]) -> Any: | ||
try: | ||
prefixed_keys = [config.REDIS_KEY_PREFIX + key for key in keys] | ||
values = await self.client.mget(prefixed_keys) | ||
return values | ||
except Exception as e: | ||
print(f"failed to get cache! {e}") | ||
return [] | ||
|
||
async def set_multiple_to_cache( | ||
self, mapping: dict, ttl: int = config.CACHE_TTL_DEFAULT | ||
) -> bool: | ||
try: | ||
states = [] | ||
for key, value in mapping.items(): | ||
state = await self.set_to_cache(key, value, ttl) | ||
states.append(state) | ||
|
||
return all(states) | ||
except Exception as e: | ||
print(f"failed to set cache! {e}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import os | ||
|
||
# redis config values | ||
REDIS_HOST = os.getenv('REDIS_HOST', 'localhost') | ||
REDIS_PORT = int(os.getenv('REDIS_PORT', 6379)) | ||
REDIS_PASS = os.getenv('REDIS_PASS', '') | ||
REDIS_KEY_PREFIX = os.getenv('REDIS_KEY_PREFIX', '') | ||
|
||
MULTI_LOOKUP_MAX_PERSONAS = os.getenv('MULTI_LOOKUP_MAX_PERSONAS', 30) | ||
|
||
CLIENT_USERNAME = os.getenv('CLIENT_USERNAME') | ||
CLIENT_PASSWORD = os.getenv('CLIENT_PASSWORD') | ||
CLIENT_TIMEOUT = float(os.getenv('CLIENT_TIMEOUT', 3.0)) | ||
CLIENT_MAX_RETRIES = int(os.getenv('CLIENT_MAX_RETRIES', 2)) | ||
CLIENT_PING_INTERVAL = float(os.getenv('CLIENT_PING_INTERVAL', 150.0)) | ||
|
||
CACHE_TTL_DEFAULT = os.getenv('CACHE_TTL_DEFAULT', 600) | ||
CACHE_TTL_PERSONA_SEARCH = os.getenv('CACHE_TTL_PERSONA_SEARCH', 1800) | ||
CACHE_TTL_PERSONAS_BY_NAME = os.getenv('CACHE_TTL_PERSONAS_BY_NAME', 28800) | ||
CACHE_TTL_PERSONAS_BY_ID = os.getenv('CACHE_TTL_PERSONAS_BY_ID', 14400) | ||
CACHE_TTL_SERVERS = os.getenv('CACHE_TTL_SERVERS', 60) | ||
CACHE_MAX_AGE_DEFAULT = os.getenv('CACHE_MAX_AGE_DEFAULT', 600) | ||
CACHE_MAX_AGE_PERSONA_SEARCH = os.getenv('CACHE_MAX_AGE_PERSONA_SEARCH', 1800) | ||
CACHE_MAX_AGE_PERSONAS = os.getenv('CACHE_MAX_AGE_PERSONAS', 28800) | ||
CACHE_MAX_AGE_SERVERS = os.getenv('CACHE_MAX_AGE_SERVERS', 60) |
Oops, something went wrong.