Skip to content

Commit 61ff101

Browse files
committed
Block calls to registry when airgapped true
1 parent a84150d commit 61ff101

2 files changed

Lines changed: 23 additions & 6 deletions

File tree

x-pack/plugins/fleet/server/services/epm/packages/get.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export async function getPackages(
9898
} = options;
9999

100100
const registryItems = await Registry.fetchList({ category, prerelease }).then((items) => {
101-
return items.map((item) =>
101+
return (items ?? []).map((item) =>
102102
Object.assign({}, item, { title: item.title || nameAsTitle(item.name) }, { id: item.name })
103103
);
104104
});

x-pack/plugins/fleet/server/services/epm/registry/requests.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type FailedAttemptErrors = pRetry.FailedAttemptError | FetchError | Error;
2020
// not sure what to call this function, but we're not exporting it
2121
async function registryFetch(url: string) {
2222
const response = await fetch(url, getFetchOptions(url));
23+
2324
if (response.ok) {
2425
return response;
2526
} else {
@@ -34,7 +35,14 @@ async function registryFetch(url: string) {
3435
}
3536
}
3637

37-
export async function getResponse(url: string, retries: number = 5): Promise<Response> {
38+
export async function getResponse(url: string, retries: number = 5): Promise<Response | null> {
39+
const logger = appContextService.getLogger();
40+
41+
if (appContextService.getConfig()?.isAirGapped) {
42+
logger.debug('isAirGapped enabled, not reaching package registry');
43+
return null;
44+
}
45+
3846
try {
3947
// we only want to retry certain failures like network issues
4048
// the rest should only try the one time then fail as they do now
@@ -70,13 +78,22 @@ export async function getResponse(url: string, retries: number = 5): Promise<Res
7078
export async function getResponseStream(
7179
url: string,
7280
retries?: number
73-
): Promise<NodeJS.ReadableStream> {
81+
): Promise<NodeJS.ReadableStream | null> {
7482
const res = await getResponse(url, retries);
75-
return res.body;
83+
if (res) {
84+
return res.body;
85+
}
86+
return null;
7687
}
7788

78-
export async function fetchUrl(url: string, retries?: number): Promise<string> {
79-
return getResponseStream(url, retries).then(streamToString);
89+
export async function fetchUrl(url: string, retries?: number): Promise<string | null> {
90+
const stream = getResponseStream(url, retries);
91+
92+
if (appContextService.getConfig()?.isAirGapped || stream === null) {
93+
return null;
94+
}
95+
96+
return stream.then(streamToString);
8097
}
8198

8299
// node-fetch throws a FetchError for those types of errors and

0 commit comments

Comments
 (0)