Skip to content

Commit

Permalink
[Plugins] update default url for installing plugins (#1316)
Browse files Browse the repository at this point in the history
Update old and invalid reference to custom plugins within
the OpenSearch Project.

Note: At the time that this is committed there is no gurantee
that the latest build is the build that was select as the
final build.

Issue resolved:
#1038

Signed-off-by: Kawika Avilla <[email protected]>
  • Loading branch information
kavilla authored Mar 8, 2022
1 parent 1ecbd3a commit 9c82c52
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 9 deletions.
6 changes: 3 additions & 3 deletions packages/osd-opensearch/src/artifact.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -157,7 +157,7 @@ describe('Artifact', () => {
afterAll(() => {
Object.defineProperties(process, {
platform: {
value: ORIGINAL_PLATFROM,
value: ORIGINAL_PLATFORM,
},
arch: {
value: ORIGINAL_ARCHITECTURE,
Expand All @@ -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',
Expand Down
17 changes: 13 additions & 4 deletions src/cli_plugin/install/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
60 changes: 58 additions & 2 deletions src/cli_plugin/install/settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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 {
Expand All @@ -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": <absolute path>/plugins/.plugin.installing,
Expand All @@ -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": <absolute path>/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": <absolute path>/plugins,
"quiet": false,
"silent": false,
"tempArchiveFile": <absolute path>/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": <absolute path>/plugins/.plugin.installing,
Expand Down

0 comments on commit 9c82c52

Please sign in to comment.