refactor: share provider allowlist input normalization

This commit is contained in:
Peter Steinberger
2026-03-07 23:26:16 +00:00
parent c9128e1f3f
commit 4956271da1
2 changed files with 6 additions and 6 deletions

View File

@@ -8,6 +8,7 @@ import {
import type { DiscordGuildEntry } from "../../config/types.discord.js";
import { formatErrorMessage } from "../../infra/errors.js";
import type { RuntimeEnv } from "../../runtime.js";
import { normalizeStringEntries } from "../../shared/string-normalization.js";
import { resolveDiscordChannelAllowlist } from "../resolve-channels.js";
import { resolveDiscordUserAllowlist } from "../resolve-users.js";
@@ -205,15 +206,14 @@ async function resolveAllowFromByUserAllowlist(params: {
fetcher: typeof fetch;
runtime: RuntimeEnv;
}): Promise<string[] | undefined> {
const allowEntries =
params.allowFrom?.filter((entry) => String(entry).trim() && String(entry).trim() !== "*") ?? [];
const allowEntries = normalizeStringEntries(params.allowFrom).filter((entry) => entry !== "*");
if (allowEntries.length === 0) {
return params.allowFrom;
}
try {
const resolvedUsers = await resolveDiscordUserAllowlist({
token: params.token,
entries: allowEntries.map((entry) => String(entry)),
entries: allowEntries,
fetcher: params.fetcher,
});
const { resolvedMap, mapping, unresolved } = buildAllowlistResolutionSummary(resolvedUsers, {

View File

@@ -24,6 +24,7 @@ import { computeBackoff, sleepWithAbort } from "../../infra/backoff.js";
import { installRequestBodyLimitGuard } from "../../infra/http-body.js";
import { normalizeMainKey } from "../../routing/session-key.js";
import { createNonExitingRuntime, type RuntimeEnv } from "../../runtime.js";
import { normalizeStringEntries } from "../../shared/string-normalization.js";
import { resolveSlackAccount } from "../accounts.js";
import { resolveSlackWebClientOptions } from "../client.js";
import { normalizeSlackWebhookPath, registerSlackHttpHandler } from "../http/index.js";
@@ -345,13 +346,12 @@ export async function monitorSlackProvider(opts: MonitorSlackOpts = {}) {
}
}
const allowEntries =
allowFrom?.filter((entry) => String(entry).trim() && String(entry).trim() !== "*") ?? [];
const allowEntries = normalizeStringEntries(allowFrom).filter((entry) => entry !== "*");
if (allowEntries.length > 0) {
try {
const resolvedUsers = await resolveSlackUserAllowlist({
token: resolveToken,
entries: allowEntries.map((entry) => String(entry)),
entries: allowEntries,
});
const { mapping, unresolved, additions } = buildAllowlistResolutionSummary(
resolvedUsers,