Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove support for the v1 launch pattern #1353

Merged
merged 6 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions app/data_models/metadata_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,8 @@ def from_dict(cls, metadata: Mapping) -> MetadataProxy:
)

survey_metadata = None
if version is AuthPayloadVersion.V2:
serialized_metadata = cls.serialize(_metadata.pop("survey_metadata", {}))
if serialized_metadata:
survey_metadata = SurveyMetadata(**serialized_metadata)
else:
serialized_metadata = cls.serialize(_metadata)
survey_metadata = SurveyMetadata(data=serialized_metadata)
if serialized_metadata := cls.serialize(_metadata.pop("survey_metadata", {})):
survey_metadata = SurveyMetadata(**serialized_metadata)

top_level_data = {
key: _metadata.pop(key, None) for key in TOP_LEVEL_METADATA_KEYS
Expand Down
14 changes: 2 additions & 12 deletions app/routes/flush.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from sdc.crypto.key_store import KeyStore
from structlog import contextvars, get_logger

from app.authentication.auth_payload_versions import AuthPayloadVersion
from app.authentication.user import User
from app.authentication.user_id_generator import UserIDGenerator
from app.data_models import QuestionnaireStore
Expand All @@ -18,7 +17,6 @@
from app.questionnaire.router import Router
from app.questionnaire.routing_path import RoutingPath
from app.submitter import GCSSubmitter, LogSubmitter, RabbitMQSubmitter
from app.submitter.converter import convert_answers
from app.submitter.converter_v2 import convert_answers_v2
from app.submitter.submission_failed import SubmissionFailedException
from app.utilities.bind_context import bind_contextvars_schema_from_metadata
Expand Down Expand Up @@ -87,7 +85,6 @@ def _submit_data(user: User) -> bool:

message: str = _get_converted_answers_message(
full_routing_path=full_routing_path,
metadata=metadata,
questionnaire_store=questionnaire_store,
schema=schema,
submitted_at=submitted_at,
Expand Down Expand Up @@ -120,24 +117,17 @@ def _submit_data(user: User) -> bool:

def _get_converted_answers_message(
full_routing_path: Iterable[RoutingPath],
metadata: MetadataProxy,
questionnaire_store: QuestionnaireStore,
schema: QuestionnaireSchema,
submitted_at: datetime,
) -> str:
"""
This gets converted answer message based on the selected version.
For version 1 `app.submitter.converter.convert_answers` is used whereas for version 2 `app.submitter.converter_v2.convert_answers_v2` is used
This gets converted answer message based on the selected version, currently only v2 is supported so `app.submitter.converter_v2.convert_answers_v2` is used
Returns:
object: str
"""
answer_converter = (
convert_answers_v2
if metadata.version is AuthPayloadVersion.V2
else convert_answers
)
return json_dumps(
answer_converter(
convert_answers_v2(
schema=schema,
questionnaire_store=questionnaire_store,
full_routing_path=full_routing_path,
Expand Down
36 changes: 9 additions & 27 deletions app/routes/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from werkzeug.exceptions import Unauthorized
from werkzeug.wrappers.response import Response

from app.authentication.auth_payload_versions import AuthPayloadVersion
from app.authentication.authenticator import (
create_session_questionnaire_store,
decrypt_token,
Expand All @@ -32,7 +31,6 @@
from app.questionnaire.router import Router
from app.routes.errors import _render_error_page
from app.services.supplementary_data import get_supplementary_data_v1
from app.utilities.metadata_parser import validate_runner_claims
from app.utilities.metadata_parser_v2 import (
validate_questionnaire_claims,
validate_runner_claims_v2,
Expand Down Expand Up @@ -111,17 +109,11 @@ def login() -> Response:
decrypted_token=decrypted_token, schema_metadata=schema_metadata
)

if metadata.version is AuthPayloadVersion.V2:
if questionnaire_claims:
runner_claims["survey_metadata"]["data"] = questionnaire_claims

claims = runner_claims
else:
claims = {**runner_claims, **questionnaire_claims}
runner_claims["survey_metadata"]["data"] = questionnaire_claims

logger.info("decrypted token and parsed metadata")

with create_session_questionnaire_store(claims) as questionnaire_store:
with create_session_questionnaire_store(runner_claims) as questionnaire_store:
_set_questionnaire_supplementary_data(
questionnaire_store=questionnaire_store, metadata=metadata, schema=g.schema
)
Expand All @@ -130,13 +122,13 @@ def login() -> Response:

set_schema_context_in_cookie(g.schema)

if account_service_url := claims.get("account_service_url"):
if account_service_url := runner_claims.get("account_service_url"):
cookie_session["account_service_base_url"] = account_service_url

if claims.get("account_service_log_out_url"):
cookie_session["account_service_log_out_url"] = claims.get( # pragma: no cover
if runner_claims.get("account_service_log_out_url"):
cookie_session["account_service_log_out_url"] = runner_claims.get(
"account_service_log_out_url"
)
) # pragma: no cover

cookie_session["language_code"] = metadata.language_code or DEFAULT_LANGUAGE_CODE

Expand Down Expand Up @@ -309,13 +301,8 @@ def get_signed_out() -> Response | str:

def get_runner_claims(decrypted_token: Mapping[str, Any]) -> dict:
try:
if version := decrypted_token.get("version"):
if version == AuthPayloadVersion.V2.value:
return validate_runner_claims_v2(decrypted_token)
return validate_runner_claims_v2(decrypted_token)

raise InvalidTokenException(f"Invalid runner claims version: {version}")

return validate_runner_claims(decrypted_token)
except ValidationError as e:
raise InvalidTokenException("Invalid runner claims") from e

Expand All @@ -324,13 +311,8 @@ def get_questionnaire_claims(
decrypted_token: Mapping, schema_metadata: Iterable[Mapping[str, str]]
) -> dict:
try:
if decrypted_token.get("version") == AuthPayloadVersion.V2.value:
claims = decrypted_token.get("survey_metadata", {}).get("data", {})
return validate_questionnaire_claims(
claims, schema_metadata, unknown=INCLUDE
)

return validate_questionnaire_claims(decrypted_token, schema_metadata)
claims = decrypted_token.get("survey_metadata", {}).get("data", {})
return validate_questionnaire_claims(claims, schema_metadata, unknown=INCLUDE)

except ValidationError as e:
raise InvalidTokenException("Invalid questionnaire claims") from e
140 changes: 0 additions & 140 deletions app/submitter/converter.py

This file was deleted.

Loading
Loading