File size: 2,355 Bytes
584ed90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"""Amazon adapter for the canonical WebsiteBench verification library."""

from __future__ import annotations

import os
import sys
from pathlib import Path


for ancestor in Path(__file__).resolve().parents:
    repository_src = ancestor / "src"
    if (repository_src / "websitebench" / "public_clone_auth").is_dir():
        if str(repository_src) not in sys.path:
            sys.path.insert(0, str(repository_src))
        break

from websitebench.public_clone_auth import (  # noqa: E402
    ExternalRegistrationVerification,
    PublicCloneIdentity,
    RedisRestClient,
    ResendEmailClient,
    VerificationConfigurationError,
    VerificationIssue,
    VerificationLocked,
    VerificationRateLimited,
    VerificationUnavailable,
    ensure_sqlite_email_verified,
    load_public_clone_registration_verification,
    registration_frontend_script,
)


_LEGACY_ALIASES = {
    "AMAZON_EXTERNAL_VERIFICATION_MODE": "PUBLIC_CLONE_AUTH_MODE",
    "AMAZON_REDIS_REST_URL": "PUBLIC_CLONE_AUTH_REDIS_REST_URL",
    "AMAZON_REDIS_REST_TOKEN": "PUBLIC_CLONE_AUTH_REDIS_REST_TOKEN",
    "AMAZON_RESEND_API_URL": "PUBLIC_CLONE_AUTH_RESEND_API_URL",
    "AMAZON_RESEND_API_KEY": "PUBLIC_CLONE_AUTH_RESEND_API_KEY",
    "AMAZON_RESEND_FROM_EMAIL": "PUBLIC_CLONE_AUTH_RESEND_FROM_EMAIL",
}


def load_external_registration_verification(
    source: dict[str, str] | None = None,
) -> ExternalRegistrationVerification | None:
    """Load Amazon's public profile through the shared implementation."""

    original = os.environ if source is None else source
    values = dict(original)
    for legacy_name, common_name in _LEGACY_ALIASES.items():
        if common_name not in values and legacy_name in values:
            values[common_name] = values[legacy_name]
    values.setdefault("PUBLIC_CLONE_AUTH_SITE_ID", "amazon")
    values.setdefault("PUBLIC_CLONE_AUTH_SITE_LABEL", "Amazon Clone")
    return load_public_clone_registration_verification(values)


__all__ = [
    "ExternalRegistrationVerification",
    "PublicCloneIdentity",
    "RedisRestClient",
    "ResendEmailClient",
    "VerificationConfigurationError",
    "VerificationIssue",
    "VerificationLocked",
    "VerificationRateLimited",
    "VerificationUnavailable",
    "ensure_sqlite_email_verified",
    "load_external_registration_verification",
    "registration_frontend_script",
]