Skip to content

Commit 40397a1

Browse files
authored
Merge pull request #19 from flavienbwk/develop
1.2.0 : Refactored Flask architecture for right Python import
2 parents 6ac13d2 + fc0357a commit 40397a1

29 files changed

+88
-108
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FLASK_API_VERSION="1.1"
1+
FLASK_API_VERSION="1.2.0"
22
FLASK_SERVER_NAME="My API Project"
33
FLASK_SERVER_DESCRIPTION="Dockerized Flask API boilerplate using an LDAP and token-based authentication"
44
FLASK_SECRET_KEY="Some secret key"

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Dockerized ReactJS, Flask, LDAP boilerplate
1+
# Dockerized ReactJS, Flask & LDAP boilerplate
22

33
<p align="center">
44
<a href="https://travis-ci.com/flavienbwk/reactjs-flask-ldap-boilerplate" target="_blank">
@@ -8,18 +8,16 @@
88
</p>
99
<p align="center">ReactJS + Flask + Docker (+ K8S)<br/>boilerplate using a token-based LDAP authentication</p>
1010

11-
> :smiley: Suggestions and feedbacks are [highly appreciated](https://github.com/flavienbwk/reactjs-flask-ldap-boilerplate/issues/new)
12-
1311
## Features
1412

1513
- Docker architecture
1614
- LDAP authentication
1715
- Token-based API authentication
18-
- Automatic [token renewal](./api/app/service/auth_service.py#L45) with [a Flask middleware](./api/app/service/auth_service.py#L32)
16+
- Automatic [token renewal](./api/app/src/service/auth_service.py#L43) with [a Flask middleware](./api/app/src/service/auth_service.py#L30)
1917
- Swagger documentation
2018
- Flask-Migrate
2119
- Flask-SQLAlchemy (PostgreSQL was chosen)
22-
- [Logging and logs rotation](./api/app/utils/Logger.py#L11)
20+
- [Logging and logs rotation](./api/app/src/utils/Logger.py#L12)
2321
- [Choose](./app/app/src/App.js#L65) between sidebar and navbar (or use both !)
2422
- Responsive design
2523
- [Production](./prod.docker-compose.yml) and [development](./docker-compose.yml) builds
@@ -77,7 +75,7 @@ This section will explain how to properly run this project and set-up the LDAP s
7775
7876
4. Run the API
7977
80-
The database will be automatically set-up thanks to Flask Migrate and any future modification brought to [models](./api/app/model) will be automatically applied when the API is **restarted**.
78+
The database will be automatically set-up thanks to Flask Migrate and any future modification brought to [models](./api/app/src/model) will be automatically applied when the API is **restarted**.
8179
8280
You might wait some time before the database get updated after starting the API :
8381
@@ -142,7 +140,7 @@ I've used [Scaleway Kapsule](https://www.scaleway.com/en/kubernetes-kapsule) to
142140

143141
1. Building production images (optional)
144142

145-
Images are tagged `flavienb/reactjs-flask-ldap-boilerplate-{api,web,nginx}:latest` by default. Edit it in `prod.docker-compose.yml` before building.
143+
Images are tagged `flavienb/reactjs-flask-ldap-boilerplate-{api,app,nginx}:latest` by default. Edit it in `prod.docker-compose.yml` before building.
146144

147145
:information_source: You might be interested in pushing your images in a private registry (e.g: [Scaleway's Container Registry service](https://www.scaleway.com/en/container-registry/)).
148146
@@ -177,3 +175,5 @@ I've used [Scaleway Kapsule](https://www.scaleway.com/en/kubernetes-kapsule) to
177175
4. Configure the first user
178176
179177
**Create** your first user by accessing phpLDAPAdmin at [endpoint defined](./k8s/ingress.yaml#L35) and [following the LDAP user creation guide](./CREATE_LDAP_USER.md).
178+
179+
> :smiley: Suggestions and feedbacks are [highly appreciated](https://github.com/flavienbwk/reactjs-flask-ldap-boilerplate/issues/new)

api/app/.gitignore

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
11
__pycache__/
2-
3-
medias/*
4-
!medias/.gitkeep
5-
6-
certs/*
7-
!certs/.gitkeep

api/app/manager.py renamed to api/app/main.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
import os
2-
import json
3-
41
from flask_migrate import Migrate, MigrateCommand
52
from flask_script import Manager
63

7-
from routes import blueprint
8-
from app import create_app, database
9-
10-
from utils.ApiResponse import ApiResponse
4+
from src.routes import blueprint
5+
from src.app import create_app, database
6+
from src.utils.ApiResponse import ApiResponse
117

128
# Initialization
139

api/app/src/__init__.py

Whitespace-only changes.

api/app/app.py renamed to api/app/src/app.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import os
2-
2+
from time import sleep
33
from flask import Flask
44

5-
from utils.Database import Database
6-
from utils.ApiResponse import ApiResponse
5+
from .utils.Logger import Logger
6+
from .utils.Database import Database
7+
from .utils.ApiResponse import ApiResponse
8+
9+
from .config import config_by_name
710

8-
from config import config_by_name
911

1012
FLASK_LEVEL = os.environ.get("FLASK_LEVEL", "dev")
1113

14+
logger = Logger()
1215
database = Database()
1316

1417
def page_not_found(e):
@@ -22,5 +25,11 @@ def create_app():
2225
app.register_error_handler(404, page_not_found)
2326
app.config.from_object(config_by_name[FLASK_LEVEL])
2427
os.environ["FLASK_ENV"] = config_by_name[FLASK_LEVEL].FLASK_ENV
28+
29+
# Waiting for database to be available
30+
while database.isDatabaseAvailable(app) is False:
31+
logger.warning("Database unreachable. Waiting for 3 seconds to be up...")
32+
sleep(3.0)
33+
logger.info("Database is up and running ✓")
2534
database.initDatabase(app)
2635
return app
File renamed without changes.

api/app/src/controller/__init__.py

Whitespace-only changes.

api/app/controller/auth_controller.py renamed to api/app/src/controller/auth_controller.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
1-
import time
2-
import datetime
3-
41
from flask import request, escape
52
from flask_restplus import Resource, Namespace, fields
63

7-
import sys
8-
sys.path.append("..")
9-
10-
from utils.ApiResponse import ApiResponse
11-
from utils.Logger import Logger
12-
13-
from model.User import User
14-
from model.Token import Token
4+
from ..utils.Logger import Logger
155

16-
from service.auth_service import AuthService, requires_authentication
6+
from ..service.auth_service import AuthService, requires_authentication
177

188
logger = Logger()
199

api/app/controller/home_controller.py renamed to api/app/src/controller/home_controller.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
from flask import request, escape
2-
from flask_restplus import Resource, Namespace, fields
1+
from flask_restplus import Resource, Namespace
32

4-
import sys
5-
sys.path.append("..")
6-
7-
from utils.ApiResponse import ApiResponse
3+
from ..utils.ApiResponse import ApiResponse
84

95
api = Namespace('Home', description='Basic health operations')
106

0 commit comments

Comments
 (0)