Skip to content

Commit

Permalink
Add airgapped flag + skip product versions request if set
Browse files Browse the repository at this point in the history
  • Loading branch information
kpollich committed Jan 3, 2024
1 parent 64d73d9 commit 1fc6e10
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/common/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {

export interface FleetConfigType {
enabled: boolean;
isAirGapped: boolean;
registryUrl?: string;
registryProxyUrl?: string;
agents: {
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export const config: PluginConfigDescriptor = {
],
schema: schema.object(
{
isAirGapped: schema.maybe(schema.boolean({ defaultValue: false })),
registryUrl: schema.maybe(schema.uri({ scheme: ['http', 'https'] })),
registryProxyUrl: schema.maybe(schema.uri({ scheme: ['http', 'https'] })),
agents: schema.object({
Expand Down
21 changes: 18 additions & 3 deletions x-pack/plugins/fleet/server/services/agents/versions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@
import { readFile } from 'fs/promises';

import fetch from 'node-fetch';
import type { DeepPartial } from 'utility-types';

import type { FleetConfigType } from '../../../public/plugin';

import { getAvailableVersions } from './versions';

let mockKibanaVersion = '300.0.0';
let mockConfig = {};
let mockConfig: DeepPartial<FleetConfigType> = {};

jest.mock('../app_context', () => {
const { loggerMock } = jest.requireActual('@kbn/logging-mocks');
return {
Expand All @@ -33,8 +39,6 @@ const emptyResponse = {
text: jest.fn().mockResolvedValue(JSON.stringify({})),
} as any;

import { getAvailableVersions } from './versions';

describe('getAvailableVersions', () => {
beforeEach(() => {
mockedReadFile.mockReset();
Expand Down Expand Up @@ -204,4 +208,15 @@ describe('getAvailableVersions', () => {
// Should sort, uniquify and filter out versions < 7.17
expect(res).toEqual(['8.1.0', '8.0.0', '7.17.0']);
});

it('should not fetch from product versions API when air-gapped config is set', async () => {
mockKibanaVersion = '300.0.0';
mockedReadFile.mockResolvedValue(`["8.1.0", "8.0.0", "7.17.0", "7.16.0"]`);

mockConfig = { isAirGapped: true };
const res = await getAvailableVersions({ ignoreCache: true });

expect(res).toEqual(['8.1.0', '8.0.0', '7.17.0']);
expect(mockedFetch).not.toBeCalled();
});
});
5 changes: 5 additions & 0 deletions x-pack/plugins/fleet/server/services/agents/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ export const getAvailableVersions = async ({
};

async function fetchAgentVersionsFromApi() {
// If the airgapped flag is set, do not attempt to reach out to the product versions API
if (appContextService.getConfig()?.isAirGapped) {
return [];
}

const logger = appContextService.getLogger();

const options = {
Expand Down

0 comments on commit 1fc6e10

Please sign in to comment.