MCPcopy Create free account
hub / github.com/chartbrew/chartbrew / createPinnedLookup

Function createPinnedLookup

server/modules/safeRequest.js:54–94  ·  view source on GitHub ↗
(expectedHostname, resolvedAddresses = [])

Source from the content-addressed store, hash-verified

52}
53
54function createPinnedLookup(expectedHostname, resolvedAddresses = []) {
55 const normalizedExpectedHostname = normalizeHostname(expectedHostname);
56 const candidates = resolvedAddresses
57 .map((address) => ({
58 address,
59 family: net.isIP(address),
60 }))
61 .filter((entry) => entry.family);
62
63 return (hostname, options, callback) => {
64 const lookupOptions = typeof options === "function" ? {} : options || {};
65 const cb = typeof options === "function" ? options : callback;
66 const normalizedHostname = normalizeHostname(hostname);
67
68 if (!cb) return;
69
70 if (normalizedHostname !== normalizedExpectedHostname) {
71 process.nextTick(() => cb(createLookupError(hostname)));
72 return;
73 }
74
75 const requestedFamily = Number(lookupOptions.family) || 0;
76 const matches = requestedFamily
77 ? candidates.filter((entry) => entry.family === requestedFamily)
78 : candidates;
79
80 if (matches.length === 0) {
81 process.nextTick(() => cb(createLookupError(hostname)));
82 return;
83 }
84
85 process.nextTick(() => {
86 if (lookupOptions.all) {
87 cb(null, matches.map((entry) => ({ ...entry })));
88 return;
89 }
90
91 cb(null, matches[0].address, matches[0].family);
92 });
93 };
94}
95
96async function safeRequest(requestOptions, policyContext = {}) {
97 const baseOptions = { ...requestOptions };

Callers 1

safeRequestFunction · 0.85

Calls 3

createLookupErrorFunction · 0.85
filterMethod · 0.80
normalizeHostnameFunction · 0.70

Tested by

no test coverage detected