mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-19 05:58:53 -04:00
Fixed merge conflict
This commit is contained in:
@@ -2,10 +2,12 @@ import base64
|
||||
import re
|
||||
from urllib.parse import urlparse
|
||||
|
||||
import oscrypto.asymmetric
|
||||
import oscrypto.errors
|
||||
import requests
|
||||
import six
|
||||
from cryptography import x509
|
||||
from cryptography.exceptions import InvalidSignature
|
||||
from cryptography.hazmat.primitives import hashes
|
||||
from cryptography.hazmat.primitives.asymmetric import padding
|
||||
|
||||
from app import redis_store
|
||||
from app.config import Config
|
||||
@@ -110,15 +112,16 @@ def validate_sns_cert(sns_payload):
|
||||
if isinstance(certificate, six.text_type):
|
||||
certificate = certificate.encode()
|
||||
|
||||
# load the certificate
|
||||
certificate = x509.load_pem_x509_certificate(certificate)
|
||||
|
||||
signature = base64.b64decode(sns_payload["Signature"])
|
||||
|
||||
try:
|
||||
oscrypto.asymmetric.rsa_pkcs1v15_verify(
|
||||
oscrypto.asymmetric.load_certificate(certificate),
|
||||
signature,
|
||||
string_to_sign,
|
||||
"sha1",
|
||||
public_key = certificate.public_key()
|
||||
public_key.verify(
|
||||
signature, string_to_sign, padding.PKCS1v15(), hashes.SHA256() # or SHA1?
|
||||
)
|
||||
return True
|
||||
except oscrypto.errors.SignatureError:
|
||||
except InvalidSignature:
|
||||
raise ValidationError("Invalid signature")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from flask import Blueprint, jsonify, request
|
||||
from flask import Blueprint, current_app, jsonify, request
|
||||
from sqlalchemy import text
|
||||
|
||||
from app import db, version
|
||||
@@ -11,32 +11,52 @@ status = Blueprint("status", __name__)
|
||||
@status.route("/", methods=["GET"])
|
||||
@status.route("/_status", methods=["GET", "POST"])
|
||||
def show_status():
|
||||
if request.args.get("simple", None):
|
||||
return jsonify(status="ok"), 200
|
||||
else:
|
||||
return (
|
||||
jsonify(
|
||||
status="ok", # This should be considered part of the public API
|
||||
git_commit=version.__git_commit__,
|
||||
build_time=version.__time__,
|
||||
db_version=get_db_version(),
|
||||
),
|
||||
200,
|
||||
try:
|
||||
if request.args.get("simple", None):
|
||||
return jsonify(status="ok"), 200
|
||||
else:
|
||||
return (
|
||||
jsonify(
|
||||
status="ok", # This should be considered part of the public API
|
||||
git_commit=version.__git_commit__,
|
||||
build_time=version.__time__,
|
||||
db_version=get_db_version(),
|
||||
),
|
||||
200,
|
||||
)
|
||||
except Exception as e:
|
||||
current_app.logger.error(
|
||||
f"Unexpected error in show_status: {str(e)}", exc_info=True
|
||||
)
|
||||
raise Exception(status_code=503, detail="Service temporarily unavailable")
|
||||
|
||||
|
||||
@status.route("/_status/live-service-and-organization-counts")
|
||||
def live_service_and_organization_counts():
|
||||
return (
|
||||
jsonify(
|
||||
organizations=dao_count_organizations_with_live_services(),
|
||||
services=dao_count_live_services(),
|
||||
),
|
||||
200,
|
||||
)
|
||||
try:
|
||||
return (
|
||||
jsonify(
|
||||
organizations=dao_count_organizations_with_live_services(),
|
||||
services=dao_count_live_services(),
|
||||
),
|
||||
200,
|
||||
)
|
||||
except Exception as e:
|
||||
current_app.logger.error(
|
||||
f"Unexpected error in live_service_and_organization_counts: {str(e)}",
|
||||
exc_info=True,
|
||||
)
|
||||
raise Exception(status_code=503, detail="Service temporarily unavailable")
|
||||
|
||||
|
||||
def get_db_version():
|
||||
query = "SELECT version_num FROM alembic_version"
|
||||
full_name = db.session.execute(text(query)).fetchone()[0]
|
||||
return full_name
|
||||
try:
|
||||
query = "SELECT version_num FROM alembic_version"
|
||||
full_name = db.session.execute(text(query)).fetchone()[0]
|
||||
return full_name
|
||||
except Exception as e:
|
||||
current_app.logger.error(
|
||||
f"Unexpected error in get_db_version: {str(e)}",
|
||||
exc_info=True,
|
||||
)
|
||||
raise Exception(status_code=503, detail="Database temporarily unavailable")
|
||||
|
||||
Reference in New Issue
Block a user