(
env: {
ENVIRONMENT?: string;
STAGING_ALLOWED_GITHUB_IDS?: string;
STAGING_ALLOWED_EMAILS?: string;
},
user:
| { githubId?: number | null; email?: string | null }
| null
| undefined,
)
| 59 | * against pre-existing sessions/keys that predate the lockdown. See #11137. |
| 60 | */ |
| 61 | export function assertStagingAccess( |
| 62 | env: { |
| 63 | ENVIRONMENT?: string; |
| 64 | STAGING_ALLOWED_GITHUB_IDS?: string; |
| 65 | STAGING_ALLOWED_EMAILS?: string; |
| 66 | }, |
| 67 | user: |
| 68 | | { githubId?: number | null; email?: string | null } |
| 69 | | null |
| 70 | | undefined, |
| 71 | ): void { |
| 72 | if (env.ENVIRONMENT !== "staging") return; |
| 73 | const allowedGithubIds = parseGithubIdList(env.STAGING_ALLOWED_GITHUB_IDS); |
| 74 | const allowedEmails = parseEmailList(env.STAGING_ALLOWED_EMAILS); |
| 75 | const ghId = user?.githubId; |
| 76 | const email = normalizeEmail(user?.email); |
| 77 | if ( |
| 78 | (!ghId || !allowedGithubIds.has(Number(ghId))) && |
| 79 | (!email || !allowedEmails.has(email)) |
| 80 | ) { |
| 81 | throw new StagingAccessDeniedError(); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | export function parseEmailList(raw: string | undefined | null): Set<string> { |
| 86 | if (!raw) return new Set(); |
no test coverage detected