Skip to content

Commit 9cfa1a6

Browse files
committed
chore(ci): align black target to py310 and apply formatting
1 parent a99dd19 commit 9cfa1a6

25 files changed

Lines changed: 2539 additions & 2314 deletions

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,5 @@ jobs:
8888

8989
- name: Check code formatting
9090
run: |
91-
black --check app/ core/
91+
black --check --target-version py310 app/ core/
9292
continue-on-error: true

app/app.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,32 +43,33 @@
4343
zkp_manager = ZKPManager(crypto_manager)
4444
mailer = None # Initialized inside create_app
4545

46+
4647
def init_extensions(app):
4748
"""Initialize third-party extensions and global state"""
4849
setup_logging()
4950
load_dotenv()
50-
51+
5152
app.config.from_object(Config)
5253
app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get("DATABASE_URL", "sqlite:///credentials.db")
5354
app.config["SQLALCHEMY_ENGINE_OPTIONS"] = {"pool_recycle": 300, "pool_pre_ping": True}
54-
55+
5556
init_database(app)
56-
57+
5758
global mailer
5859
mailer = CredifyMailer(app)
59-
60+
6061
blockchain.difficulty = app.config.get("BLOCKCHAIN_DIFFICULTY", 0)
6162
blockchain.VALIDATORS = app.config.get("VALIDATOR_USERNAMES", ["admin", "issuer1"])
62-
63+
6364
with app.app_context():
6465
blockchain.load_blockchain()
6566
if not blockchain.chain:
6667
blockchain.create_genesis_block()
67-
68+
6869
# P2P multi-node init
69-
peer_nodes_env = os.environ.get('PEER_NODES', '')
70+
peer_nodes_env = os.environ.get("PEER_NODES", "")
7071
if peer_nodes_env:
71-
for peer in peer_nodes_env.split(','):
72+
for peer in peer_nodes_env.split(","):
7273
if peer.strip():
7374
try:
7475
blockchain.register_node(peer.strip())
@@ -77,6 +78,7 @@ def init_extensions(app):
7778
if blockchain.nodes:
7879
threading.Thread(target=_initial_sync, args=(app,), daemon=True).start()
7980

81+
8082
def _initial_sync(app):
8183
"""Background peer synchronization task"""
8284
time.sleep(5)
@@ -88,6 +90,7 @@ def _initial_sync(app):
8890
except Exception as e:
8991
logging.error(f"Sync error: {e}")
9092

93+
9194
def register_blueprints(app):
9295
"""Register all modular routing blueprints"""
9396
from app.blueprints.auth.routes import auth_bp
@@ -96,25 +99,27 @@ def register_blueprints(app):
9699
from app.blueprints.verifier.routes import verifier_bp
97100
from app.blueprints.admin.routes import admin_bp
98101
from app.blueprints.api.routes import api_bp
99-
102+
100103
app.register_blueprint(auth_bp)
101104
app.register_blueprint(issuer_bp)
102105
app.register_blueprint(holder_bp)
103106
app.register_blueprint(verifier_bp)
104107
app.register_blueprint(admin_bp)
105108
app.register_blueprint(api_bp)
106109

110+
107111
def create_app():
108112
"""Application Factory Pattern"""
109-
app = Flask(__name__, template_folder='../templates', static_folder='../static')
113+
app = Flask(__name__, template_folder="../templates", static_folder="../static")
110114
app.secret_key = os.environ.get("SESSION_SECRET", "dev-secret-key-change-in-production")
111115
cors_origins = os.environ.get("CORS_ORIGINS", "*")
112116
CORS(app, resources={r"/api/*": {"origins": cors_origins}}, supports_credentials=False)
113-
117+
114118
init_extensions(app)
115119
register_blueprints(app)
116120
return app
117121

122+
118123
if __name__ == "__main__":
119124
app_instance = create_app()
120-
app_instance.run(host='0.0.0.0', port=5000, debug=True)
125+
app_instance.run(host="0.0.0.0", port=5000, debug=True)

app/auth.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,37 +25,44 @@
2525

2626
def login_required(f):
2727
"""Decorator to require login for a route"""
28+
2829
@wraps(f)
2930
def decorated_function(*args, **kwargs):
30-
if 'user_id' not in session:
31-
flash('Please login to access this page', 'warning')
32-
return redirect(url_for('auth.login'))
31+
if "user_id" not in session:
32+
flash("Please login to access this page", "warning")
33+
return redirect(url_for("auth.login"))
3334
return f(*args, **kwargs)
35+
3436
return decorated_function
3537

3638

3739
def role_required(role):
3840
"""Decorator to require specific role for a route"""
41+
3942
def decorator(f):
4043
@wraps(f)
4144
def decorated_function(*args, **kwargs):
4245
# Check if user is logged in
43-
if 'user_id' not in session:
44-
flash(f'Please login as {role.title()} to access this portal.', 'warning')
45-
if role == 'issuer':
46-
return redirect(url_for('issuer.issuer'))
47-
elif role == 'student':
48-
return redirect(url_for('holder.holder'))
49-
return redirect(url_for('auth.login'))
50-
46+
if "user_id" not in session:
47+
flash(f"Please login as {role.title()} to access this portal.", "warning")
48+
if role == "issuer":
49+
return redirect(url_for("issuer.issuer"))
50+
elif role == "student":
51+
return redirect(url_for("holder.holder"))
52+
return redirect(url_for("auth.login"))
53+
5154
# Check user role
52-
user_role = session.get('role')
55+
user_role = session.get("role")
5356
if user_role != role:
54-
logging.info(f"Access denied for user {session.get('username', 'unknown')} (role: {user_role}) trying to access {role}-only route")
55-
flash(f'Access denied. This page is only for {role}s', 'danger')
56-
return redirect(url_for('api.index'))
57-
57+
logging.info(
58+
f"Access denied for user {session.get('username', 'unknown')} (role: {user_role}) trying to access {role}-only route"
59+
)
60+
flash(f"Access denied. This page is only for {role}s", "danger")
61+
return redirect(url_for("api.index"))
62+
5863
logging.debug(f"Access granted to {session.get('username')} ({user_role}) for {role} route")
5964
return f(*args, **kwargs)
65+
6066
return decorated_function
67+
6168
return decorator

app/blueprints/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
def _apply_no_cache_headers(response: Response) -> Response:
2626
"""Apply no-cache headers to prevent browsers from caching sensitive certificate responses."""
27-
response.headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'
28-
response.headers['Pragma'] = 'no-cache'
29-
response.headers['Expires'] = '0'
27+
response.headers["Cache-Control"] = "no-store, no-cache, must-revalidate, max-age=0"
28+
response.headers["Pragma"] = "no-cache"
29+
response.headers["Expires"] = "0"
3030
return response

0 commit comments

Comments
 (0)