diff --git a/packages/osd-opensearch/src/artifact.test.js b/packages/osd-opensearch/src/artifact.test.js index 2711f942bf1b..adba8e71d369 100644 --- a/packages/osd-opensearch/src/artifact.test.js +++ b/packages/osd-opensearch/src/artifact.test.js @@ -42,7 +42,7 @@ let MOCKS; const DAILY_SNAPSHOT_BASE_URL = 'https://artifacts.opensearch.org/snapshots/core/opensearch'; -const ORIGINAL_PLATFROM = process.platform; +const ORIGINAL_PLATFORM = process.platform; const ORIGINAL_ARCHITECTURE = process.arch; const PLATFORM = process.platform === 'win32' ? 'windows' : process.platform; const ARCHITECTURE = process.arch === 'arm64' ? 'arm64' : 'x64'; @@ -157,7 +157,7 @@ describe('Artifact', () => { afterAll(() => { Object.defineProperties(process, { platform: { - value: ORIGINAL_PLATFROM, + value: ORIGINAL_PLATFORM, }, arch: { value: ORIGINAL_ARCHITECTURE, @@ -182,7 +182,7 @@ describe('Artifact', () => { it('should not throw when on a non-x64 arch', async () => { Object.defineProperties(process, { platform: { - value: ORIGINAL_PLATFROM, + value: ORIGINAL_PLATFORM, }, arch: { value: 'arm64', diff --git a/src/cli_plugin/install/settings.js b/src/cli_plugin/install/settings.js index 6a0b5751db5e..0d4ca970923e 100644 --- a/src/cli_plugin/install/settings.js +++ b/src/cli_plugin/install/settings.js @@ -36,11 +36,20 @@ import expiry from 'expiry-js'; import { fromRoot } from '../../core/server/utils'; +const LATEST_PLUGIN_BASE_URL = + 'https://ci.opensearch.org/ci/dbc/distribution-build-opensearch-dashboards'; + function generateUrls({ version, plugin }) { - return [ - plugin, - `https://artifacts.opensearch.org/downloads/kibana-plugins/${plugin}/${plugin}-${version}.zip`, - ]; + return [plugin, generatePluginUrl(version, plugin)]; +} + +function generatePluginUrl(version, plugin) { + const platform = process.platform === 'win32' ? 'windows' : process.platform; + const arch = process.arch === 'arm64' ? 'arm64' : 'x64'; + if (platform !== 'linux') { + throw new Error('Plugins are only available for Linux'); + } + return `${LATEST_PLUGIN_BASE_URL}/${version}/latest/${platform}/${arch}/builds/opensearch-dashboards/plugins/${plugin}-${version}.zip`; } export function parseMilliseconds(val) { diff --git a/src/cli_plugin/install/settings.test.js b/src/cli_plugin/install/settings.test.js index aee23dd2dd6f..0808ddf03cdc 100644 --- a/src/cli_plugin/install/settings.test.js +++ b/src/cli_plugin/install/settings.test.js @@ -38,6 +38,9 @@ import { parseMilliseconds, parse } from './settings'; const SECOND = 1000; const MINUTE = SECOND * 60; +const ORIGINAL_PLATFORM = process.platform; +const ORIGINAL_ARCHITECTURE = process.arch; + expect.addSnapshotSerializer(createAbsolutePathSerializer()); describe('parseMilliseconds function', function () { @@ -62,6 +65,17 @@ describe('parse function', function () { const defaultOptions = { pluginDir: fromRoot('plugins') }; const osdPackage = { version: 1234 }; + afterAll(() => { + Object.defineProperties(process, { + platform: { + value: ORIGINAL_PLATFORM, + }, + arch: { + value: ORIGINAL_ARCHITECTURE, + }, + }); + }); + it('produces expected defaults', function () { expect(parse(command, { ...defaultOptions }, osdPackage)).toMatchInlineSnapshot(` Object { @@ -74,7 +88,7 @@ describe('parse function', function () { "timeout": 0, "urls": Array [ "plugin name", - "https://artifacts.opensearch.org/downloads/kibana-plugins/plugin name/plugin name-1234.zip", + "https://ci.opensearch.org/ci/dbc/distribution-build-opensearch-dashboards/1234/latest/linux/x64/builds/opensearch-dashboards/plugins/plugin name-1234.zip", ], "version": 1234, "workingPath": /plugins/.plugin.installing, @@ -101,7 +115,49 @@ describe('parse function', function () { "timeout": 0, "urls": Array [ "plugin name", - "https://artifacts.opensearch.org/downloads/kibana-plugins/plugin name/plugin name-1234.zip", + "https://ci.opensearch.org/ci/dbc/distribution-build-opensearch-dashboards/1234/latest/linux/x64/builds/opensearch-dashboards/plugins/plugin name-1234.zip", + ], + "version": 1234, + "workingPath": /plugins/.plugin.installing, + } + `); + }); + + it('should throw when on a non-Linux platform', function () { + Object.defineProperties(process, { + platform: { + value: 'win32', + }, + arch: { + value: ORIGINAL_ARCHITECTURE, + }, + }); + expect(() => parse(command, { ...defaultOptions }, osdPackage)).toThrow( + 'Plugins are only available for Linux' + ); + }); + + it('should not throw when on a non-x64 arch', function () { + Object.defineProperties(process, { + platform: { + value: ORIGINAL_PLATFORM, + }, + arch: { + value: 'arm64', + }, + }); + expect(parse(command, { ...defaultOptions }, osdPackage)).toMatchInlineSnapshot(` + Object { + "config": "", + "plugin": "plugin name", + "pluginDir": /plugins, + "quiet": false, + "silent": false, + "tempArchiveFile": /plugins/.plugin.installing/archive.part, + "timeout": 0, + "urls": Array [ + "plugin name", + "https://ci.opensearch.org/ci/dbc/distribution-build-opensearch-dashboards/1234/latest/linux/arm64/builds/opensearch-dashboards/plugins/plugin name-1234.zip", ], "version": 1234, "workingPath": /plugins/.plugin.installing,