MCPcopy
hub / github.com/coder/mux / loadPolicyText

Function loadPolicyText

src/node/services/policyService.ts:69–107  ·  view source on GitHub ↗
(source: string)

Source from the content-addressed store, hash-verified

67}
68
69async function loadPolicyText(source: string): Promise<string> {
70 if (!isRemotePolicySource(source)) {
71 try {
72 return await readFile(source, "utf8");
73 } catch (error) {
74 const message = getErrorMessage(error);
75 throw new Error(`Failed to read policy file: ${message}`);
76 }
77 }
78
79 const abortController = new AbortController();
80 const timeout = setTimeout(() => abortController.abort(), POLICY_FETCH_TIMEOUT_MS);
81
82 try {
83 const response = await fetch(source, {
84 signal: abortController.signal,
85 headers: {
86 accept: "application/json",
87 },
88 });
89
90 if (!response.ok) {
91 throw new Error(`HTTP ${response.status}`);
92 }
93
94 const text = await response.text();
95 const bytes = Buffer.byteLength(text, "utf8");
96 if (bytes > POLICY_MAX_BYTES) {
97 throw new Error(`Response too large (${bytes} bytes)`);
98 }
99
100 return text;
101 } catch (error) {
102 const message = getErrorMessage(error);
103 throw new Error(`Failed to fetch policy URL (${formatPolicySourceForLog(source)}): ${message}`);
104 } finally {
105 clearTimeout(timeout);
106 }
107}
108
109async function loadGovernorPolicyText(input: {
110 governorOrigin: string;

Callers 1

refreshPolicyOnceMethod · 0.85

Calls 6

getErrorMessageFunction · 0.90
isRemotePolicySourceFunction · 0.85
formatPolicySourceForLogFunction · 0.85
abortMethod · 0.65
readFileFunction · 0.50
fetchFunction · 0.50

Tested by

no test coverage detected