Skip to content

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Giacomo Licari committed Mar 5, 2024
2 parents e7c995a + f201b91 commit 4ef49b4
Show file tree
Hide file tree
Showing 16 changed files with 78 additions and 228 deletions.
29 changes: 17 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,38 @@

A simple python implementation of an EVM compatible faucet.

## API
## Python API

### Requirements

Python +3.x, NodeJS v18.x
Python +3.x

### Python API
### Installation

```
cd api
python3 -m venv .venv
. .venv/bin/activate
pip3 install -r requirements.txt
python3 -m flask --app api run --port 8000
pip3 install -r requirements-dev.txt
```

#### Run application
### Run application

Check .env.example for reference.

```
cd api
python3 -m flask --app api run --port 8000
```


#### Run tests
### Run tests

```
cd api
python3 -m pytest -s
```

#### Run Flake8 and isort
### Run Flake8 and isort

```
cd api
Expand All @@ -43,7 +42,13 @@ isort **/*.py --atomic
python3 -m flake8
```

### ReactJS Frontend
## ReactJS Frontend

### Requirements

NodeJS v18.x

### Installation

```
nvm use
Expand All @@ -52,7 +57,7 @@ cd app
yarn
```

#### Run application
### Run application

```
cd app
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion api/api/const.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
NATIVE_TOKEN_ADDRESS = 'native'
NATIVE_TOKEN_ADDRESS='native'
2 changes: 1 addition & 1 deletion api/api/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,4 @@ def cli_ask():
validation_errors.append('Access denied')
return jsonify(errors=validation_errors), 403

return _ask(request.get_json(), validate_captcha=False)
return _ask(request.get_json(), validate_captcha=False)
2 changes: 1 addition & 1 deletion api/api/services/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ def ttl(self, hours=False):
if hours:
# 3600 seconds = 1h
return self._ttl // 3600
return self._ttl
return self._ttl
2 changes: 1 addition & 1 deletion api/api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@
CORS_ALLOWED_ORIGINS = os.getenv('CORS_ALLOWED_ORIGINS', '*')

CAPTCHA_VERIFY_ENDPOINT = os.getenv('CAPTCHA_VERIFY_ENDPOINT')
CAPTCHA_SECRET_KEY = os.getenv('CAPTCHA_SECRET_KEY')
CAPTCHA_SECRET_KEY = os.getenv('CAPTCHA_SECRET_KEY')
2 changes: 1 addition & 1 deletion api/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ def is_amount_valid(amount, token_address, tokens_list):
def generate_access_key():
access_key_id = secrets.token_hex(8) # returns a 16 chars long string
secret_access_key = secrets.token_hex(16) # returns a 32 chars long string
return access_key_id, secret_access_key
return access_key_id, secret_access_key
1 change: 0 additions & 1 deletion api/migrations/README

This file was deleted.

50 changes: 0 additions & 50 deletions api/migrations/alembic.ini

This file was deleted.

112 changes: 0 additions & 112 deletions api/migrations/env.py

This file was deleted.

24 changes: 0 additions & 24 deletions api/migrations/script.py.mako

This file was deleted.

32 changes: 32 additions & 0 deletions api/migrations/versions/71441c34724e_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""empty message
Revision ID: 71441c34724e
Revises:
Create Date: 2024-02-28 14:11:13.601403
"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = '71441c34724e'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('access_keys',
sa.Column('access_key_id', sa.String(length=16), nullable=False),
sa.Column('secret_access_key', sa.String(length=32), nullable=False),
sa.Column('enabled', sa.Boolean(), nullable=False),
sa.PrimaryKeyConstraint('access_key_id')
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('access_keys')
# ### end Alembic commands ###
14 changes: 14 additions & 0 deletions api/scripts/local_run_migrations.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

set -x

# DB MIGRATIONS:
FLASK_APP=api FAUCET_DATABASE_URI=sqlite:///:memory python3 -m flask db init # only the first time we initialize the DB
FLASK_APP=api FAUCET_DATABASE_URI=sqlite:///:memory python3 -m flask db migrate
# Reflect migrations into the database:
# FLASK_APP=api python3 -m flask db upgrade

# Valid SQLite URL forms are:
# sqlite:///:memory: (or, sqlite://)
# sqlite:///relative/path/to/file.db
# sqlite:////absolute/path/to/file.db
10 changes: 10 additions & 0 deletions api/scripts/production_run_api.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

set -euo pipefail


echo "==> $(date +%H:%M:%S) ==> Migrating DB models... "
FLASK_APP=api python -m flask db upgrade

echo "==> $(date +%H:%M:%S) ==> Running Gunicorn... "
exec gunicorn --bind 0.0.0.0:8000 "api:create_app()"
1 change: 0 additions & 1 deletion api/scripts/run.sh

This file was deleted.

23 changes: 0 additions & 23 deletions api/scripts/run_test_env.sh

This file was deleted.

0 comments on commit 4ef49b4

Please sign in to comment.