diff --git a/allure-docker-api/app.py b/allure-docker-api/app.py index 5b1d6cb..dd713d9 100644 --- a/allure-docker-api/app.py +++ b/allure-docker-api/app.py @@ -23,8 +23,8 @@ from flask_swagger_ui import get_swaggerui_blueprint from flask_jwt_extended import ( JWTManager, jwt_required, create_access_token, create_refresh_token, current_user, - get_jwt_identity, verify_jwt_in_request, jwt_refresh_token_required, get_raw_jwt, - set_access_cookies, set_refresh_cookies, unset_jwt_cookies, verify_jwt_refresh_token_in_request + get_jwt_identity, verify_jwt_in_request, get_jwt, + set_access_cookies, set_refresh_cookies, unset_jwt_cookies ) dictConfig({ @@ -151,7 +151,7 @@ def __str__(self): REPORT_INDEX_FILE = 'index.html' DEFAULT_TEMPLATE = 'default.html' LANGUAGE_TEMPLATE = 'select_language.html' -LANGUAGES = ["en", "ru", "zh", "de", "nl", "he", "br", "pl", "ja", "es", "kr", "fr"] +LANGUAGES = ["en", "ru", "zh", "de", "nl", "he", "br", "pl", "ja", "es", "kr", "fr", "az"] GLOBAL_CSS = "https://stackpath.bootstrapcdn.com/bootswatch/4.3.1/cosmo/bootstrap.css" EMAILABLE_REPORT_CSS = GLOBAL_CSS EMAILABLE_REPORT_TITLE = "Emailable Report" @@ -440,10 +440,10 @@ def generate_security_swagger_spec(): 'app_name': "Allure Docker Service" } ) -app.register_blueprint(SWAGGERUI_BLUEPRINT, url_prefix="/") -app.register_blueprint(SWAGGERUI_BLUEPRINT, url_prefix=NATIVE_PREFIX) -app.register_blueprint(SWAGGERUI_BLUEPRINT, url_prefix=SWAGGER_ENDPOINT) -app.register_blueprint(SWAGGERUI_BLUEPRINT, url_prefix=SWAGGER_ENDPOINT_PATH) +app.register_blueprint(SWAGGERUI_BLUEPRINT, name="main", url_prefix="/") +app.register_blueprint(SWAGGERUI_BLUEPRINT, name="native", url_prefix=NATIVE_PREFIX) +app.register_blueprint(SWAGGERUI_BLUEPRINT, name="swagger", url_prefix=SWAGGER_ENDPOINT) +app.register_blueprint(SWAGGERUI_BLUEPRINT, name="swagger_path", url_prefix=SWAGGER_ENDPOINT_PATH) if URL_PREFIX: app.register_blueprint(SWAGGERUI_BLUEPRINT, url_prefix='{}{}'.format(NATIVE_PREFIX, SWAGGER_ENDPOINT)) @@ -456,9 +456,9 @@ def generate_security_swagger_spec(): blacklist = set() #pylint: disable=invalid-name jwt = JWTManager(app) #pylint: disable=invalid-name -@jwt.token_in_blacklist_loader -def check_if_token_in_blacklist(decrypted_token): - jti = decrypted_token['jti'] +@jwt.token_in_blocklist_loader +def check_if_token_in_blacklist(jwt_header, jwt_data): + jti = jwt_data['jti'] return jti in blacklist @jwt.invalid_token_loader @@ -478,8 +478,8 @@ def unauthorized_loader(msg): }), 401 @jwt.expired_token_loader -def my_expired_token_callback(expired_token): - token_type = expired_token['type'] +def my_expired_token_callback(jwt_headers, jwt_payload): + token_type = jwt_payload['type'] return jsonify({ 'meta_data': { 'message': 'The {} token has expired'.format(token_type), @@ -488,7 +488,7 @@ def my_expired_token_callback(expired_token): }), 401 @jwt.revoked_token_loader -def revoked_token_loader(): +def revoked_token_loader(jwt_header, jwt_payload): return jsonify({ 'meta_data': { 'message': 'Revoked Token' @@ -500,7 +500,7 @@ def jwt_required(fn): #pylint: disable=invalid-name, function-redefined def wrapper(*args, **kwargs): if ENABLE_SECURITY_LOGIN: if is_endpoint_protected(request.endpoint): - verify_jwt_in_request() + verify_jwt_in_request(refresh=False) return fn(*args, **kwargs) return wrapper @@ -509,12 +509,13 @@ def jwt_refresh_token_required(fn): #pylint: disable=invalid-name, function-rede def wrapper(*args, **kwargs): if ENABLE_SECURITY_LOGIN: if is_endpoint_protected(request.endpoint): - verify_jwt_refresh_token_in_request() + verify_jwt_in_request(refresh=True) return fn(*args, **kwargs) return wrapper -@jwt.user_loader_callback_loader -def user_loader_callback(identity): +@jwt.user_lookup_loader +def user_loader_callback(jwt_header, jwt_data): + identity = jwt_data['sub'] if identity not in USERS_INFO: return None return UserAccess( @@ -619,7 +620,7 @@ def logout_endpoint(): resp = jsonify(body) return resp, 404 try: - jti = get_raw_jwt()['jti'] + jti = get_jwt()['jti'] blacklist.add(jti) return jsonify({'meta_data': {'message' : 'Successfully logged out'}}), 200 except Exception as ex: @@ -644,7 +645,7 @@ def logout_refresh_token_endpoint(): resp = jsonify(body) return resp, 404 try: - jti = get_raw_jwt()['jti'] + jti = get_jwt()['jti'] blacklist.add(jti) resp = jsonify({'meta_data': {'message' : 'Successfully logged out'}}) unset_jwt_cookies(resp) @@ -835,7 +836,7 @@ def latest_report_endpoint(): resp.status_code = 404 return resp - project_report_latest_path = '/latest/{}'.format(REPORT_INDEX_FILE) + project_report_latest_path = 'latest/{}'.format(REPORT_INDEX_FILE) url = url_for('get_reports_endpoint', project_id=project_id, path=project_report_latest_path, redirect='false', _external=True) return redirect(url) @@ -1257,7 +1258,7 @@ def report_export_endpoint(): data, mimetype='application/zip', as_attachment=True, - attachment_filename='allure-docker-service-report.zip' + download_name='allure-docker-service-report.zip' ) except Exception as ex: body = { diff --git a/allure-docker-scripts/runAllureApp.sh b/allure-docker-scripts/runAllureApp.sh index 1378248..08615c7 100644 --- a/allure-docker-scripts/runAllureApp.sh +++ b/allure-docker-scripts/runAllureApp.sh @@ -1,2 +1,2 @@ #!/bin/bash -python $ROOT/allure-docker-api/app.py +python${PYTHON_VERSION} $ROOT/allure-docker-api/app.py diff --git a/docker-custom/Dockerfile.bionic-custom b/docker-custom/Dockerfile.bionic-custom index e10763e..57d8904 100644 --- a/docker-custom/Dockerfile.bionic-custom +++ b/docker-custom/Dockerfile.bionic-custom @@ -7,15 +7,16 @@ ARG ALLURE_RELEASE=2.27.0 ARG ALLURE_REPO=https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline ARG UID=1000 ARG GID=1000 +ARG PYTHON_VERSION=3.8 ###### -FROM python:3.6-alpine AS dev_stage +FROM python:${PYTHON_VERSION}-alpine AS dev_stage RUN apk update RUN apk add build-base RUN pip install -U pylint -RUN pip install -Iv setuptools==47.1.1 wheel==0.34.2 waitress==1.4.4 && \ - pip install -Iv Flask==1.1.2 Flask-JWT-Extended==3.24.1 flask-swagger-ui==3.36.0 requests==2.23.0 +RUN pip install --upgrade pip setuptools wheel waitress && \ + pip install -Iv Flask==3.0.2 Flask-JWT-Extended==4.6.0 flask-swagger-ui==4.11.1 requests==2.31.0 ENV ROOT_DIR=/code RUN mkdir -p $ROOT_DIR @@ -34,6 +35,7 @@ ARG ALLURE_RELEASE ARG ALLURE_REPO ARG UID ARG GID +ARG PYTHON_VERSION=3.8 LABEL org.label-schema.build-date=${BUILD_DATE} \ org.label-schema.docker.dockerfile="docker-custom/Dockerfile.bionic-custom" \ @@ -47,18 +49,20 @@ LABEL org.label-schema.build-date=${BUILD_DATE} \ org.label-schema.vcs-url="https://github.com/fescobar/allure-docker-service" \ org.label-schema.arch=${ARCH} \ authors="Frank Escobar , Raymond Mouthaan " - RUN apt-get update && \ + apt-get install -y software-properties-common && \ + add-apt-repository ppa:deadsnakes/ppa && \ + apt-get update && \ apt-get install -y --no-install-recommends \ tzdata \ nano \ - python3 \ + python${PYTHON_VERSION} \ python3-pip \ unzip && \ ln -s `which python3` /usr/bin/python && \ pip3 install --upgrade pip && \ - pip install -Iv setuptools==47.1.1 wheel==0.34.2 waitress==1.4.4 && \ - pip install -Iv Flask==1.1.2 Flask-JWT-Extended==3.25.0 flask-swagger-ui==3.36.0 requests==2.23.0 && \ + python${PYTHON_VERSION} -m pip install --upgrade pip setuptools wheel waitress && \ + python${PYTHON_VERSION} -m pip install -v Flask==3.0.2 Flask-JWT-Extended==4.6.0 flask-swagger-ui==4.11.1 requests==2.31.0 && \ curl ${ALLURE_REPO}/${ALLURE_RELEASE}/allure-commandline-${ALLURE_RELEASE}.zip -L -o /tmp/allure-commandline.zip && \ unzip -q /tmp/allure-commandline.zip -d / && \ apt-get remove -y unzip && \ @@ -70,6 +74,7 @@ RUN apt-get update && \ RUN groupadd --gid ${GID} allure \ && useradd --uid ${UID} --gid allure --shell /bin/bash --create-home allure +ENV PYTHON_VERSION=${PYTHON_VERSION} ENV ROOT=/app ENV ALLURE_HOME=/allure-$ALLURE_RELEASE ENV ALLURE_HOME_SL=/allure diff --git a/docker/Dockerfile.bionic b/docker/Dockerfile.bionic index e74bf9c..15c3a76 100644 --- a/docker/Dockerfile.bionic +++ b/docker/Dockerfile.bionic @@ -8,15 +8,16 @@ ARG ALLURE_REPO=https://repo.maven.apache.org/maven2/io/qameta/allure/allure-com ARG QEMU_ARCH ARG UID=1000 ARG GID=1000 +ARG PYTHON_VERSION=3.8 ###### -FROM python:3.6-alpine AS dev_stage +FROM python:${PYTHON_VERSION}-alpine AS dev_stage RUN apk update RUN apk add build-base RUN pip install -U pylint -RUN pip install -Iv setuptools==47.1.1 wheel==0.34.2 waitress==1.4.4 && \ - pip install -Iv Flask==1.1.2 Flask-JWT-Extended==3.24.1 flask-swagger-ui==3.36.0 requests==2.23.0 +RUN pip install --upgrade pip setuptools wheel waitress && \ + pip install -Iv Flask==3.0.2 Flask-JWT-Extended==4.6.0 flask-swagger-ui==4.11.1 requests==2.31.0 ENV ROOT_DIR=/code RUN mkdir -p $ROOT_DIR @@ -36,6 +37,7 @@ ARG ALLURE_REPO ARG QEMU_ARCH ARG UID ARG GID +ARG PYTHON_VERSION=3.8 LABEL org.label-schema.build-date=${BUILD_DATE} \ org.label-schema.docker.dockerfile="docker/Dockerfile.bionic" \ @@ -54,17 +56,20 @@ LABEL org.label-schema.build-date=${BUILD_DATE} \ COPY tmp/qemu-$QEMU_ARCH-static /usr/bin/qemu-$QEMU_ARCH-static RUN apt-get update && \ + apt-get install -y software-properties-common && \ + add-apt-repository ppa:deadsnakes/ppa && \ + apt-get update && \ apt-get install -y --no-install-recommends \ tzdata \ nano \ - python3 \ + python${PYTHON_VERSION} \ python3-pip \ python3-dev \ unzip && \ ln -s `which python3` /usr/bin/python && \ pip3 install --upgrade pip && \ - pip install -Iv setuptools==47.1.1 wheel==0.34.2 waitress==1.4.4 && \ - pip install -Iv Flask==1.1.2 Flask-JWT-Extended==3.25.0 flask-swagger-ui==3.36.0 requests==2.23.0 && \ + python${PYTHON_VERSION} -m pip install --upgrade pip setuptools wheel waitress && \ + python${PYTHON_VERSION} -m pip install -v Flask==3.0.2 Flask-JWT-Extended==4.6.0 flask-swagger-ui==4.11.1 requests==2.31.0 && \ curl ${ALLURE_REPO}/${ALLURE_RELEASE}/allure-commandline-${ALLURE_RELEASE}.zip -L -o /tmp/allure-commandline.zip && \ unzip -q /tmp/allure-commandline.zip -d / && \ apt-get remove -y unzip && \