Skip to content

Commit

Permalink
Remove invalid license options from kbn/es (#170978)
Browse files Browse the repository at this point in the history
## Summary

- Removes invalid license options from docs.
- Removes invalid `oss` license from cli
  • Loading branch information
Ikuni17 authored Nov 9, 2023
1 parent f92dbb7 commit 85d4522
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 73 deletions.
2 changes: 1 addition & 1 deletion packages/kbn-es/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ es.run({

Type: `String`

License type, one of: trial, basic, gold, platinum
License type, one of: basic, trial

##### options.version

Expand Down
31 changes: 9 additions & 22 deletions packages/kbn-es/src/artifact.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,18 @@ beforeEach(() => {

MOCKS = {
valid: {
archives: [createArchive({ license: 'oss' }), createArchive({ license: 'default' })],
archives: [createArchive({ license: 'default' })],
},
invalidArch: {
archives: [
createArchive({ license: 'oss', architecture: 'invalid_arch' }),
createArchive({ license: 'default', architecture: 'invalid_arch' }),
],
archives: [createArchive({ license: 'default', architecture: 'invalid_arch' })],
},
differentVersion: {
archives: [
createArchive({ license: 'oss', version: 'another-version' }),
createArchive({ license: 'default', version: 'another-version' }),
],
archives: [createArchive({ license: 'default', version: 'another-version' })],
},
multipleArch: {
archives: [
createArchive({ architecture: 'fake_arch', license: 'oss' }),
createArchive({ architecture: ARCHITECTURE, license: 'oss' }),
createArchive({ architecture: 'fake_arch', license: 'default' }),
createArchive({ architecture: ARCHITECTURE, license: 'default' }),
],
},
};
Expand Down Expand Up @@ -116,8 +110,6 @@ describe('Artifact', () => {
mockFetch(MOCKS.valid);
});

it('should return artifact metadata for a daily oss artifact', artifactTest('oss', 'oss'));

it(
'should return artifact metadata for a daily default artifact',
artifactTest('default', 'default')
Expand Down Expand Up @@ -147,11 +139,6 @@ describe('Artifact', () => {
mockFetch(MOCKS.valid);
});

it(
'should return artifact metadata for a permanent oss artifact',
artifactTest('oss', 'oss', 2)
);

it(
'should return artifact metadata for a permanent default artifact',
artifactTest('default', 'default', 2)
Expand Down Expand Up @@ -181,8 +168,8 @@ describe('Artifact', () => {
});

it('should return artifact metadata for the correct architecture', async () => {
const artifact = await Artifact.getSnapshot('oss', MOCK_VERSION, log);
expect(artifact.spec.filename).toEqual(MOCK_FILENAME + `-${ARCHITECTURE}.oss`);
const artifact = await Artifact.getSnapshot('default', MOCK_VERSION, log);
expect(artifact.spec.filename).toEqual(MOCK_FILENAME + `-${ARCHITECTURE}.default`);
});
});

Expand All @@ -195,7 +182,7 @@ describe('Artifact', () => {
});

it('should use the custom URL when looking for a snapshot', async () => {
await Artifact.getSnapshot('oss', MOCK_VERSION, log);
await Artifact.getSnapshot('default', MOCK_VERSION, log);
expect(fetch.mock.calls[0][0]).toEqual(CUSTOM_URL);
});

Expand All @@ -211,7 +198,7 @@ describe('Artifact', () => {
});

it('should use the daily unverified URL when looking for a snapshot', async () => {
await Artifact.getSnapshot('oss', MOCK_VERSION, log);
await Artifact.getSnapshot('default', MOCK_VERSION, log);
expect(fetch.mock.calls[0][0]).toEqual(
`${DAILY_SNAPSHOT_BASE_URL}/${MOCK_VERSION}/manifest-latest.json`
);
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-es/src/artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const PERMANENT_SNAPSHOTS_BASE_URL =
'https://storage.googleapis.com/kibana-ci-es-snapshots-permanent';

type ChecksumType = 'sha512';
export type ArtifactLicense = 'oss' | 'basic' | 'trial';
export type ArtifactLicense = 'basic' | 'trial';

interface ArtifactManifest {
id: string;
Expand Down Expand Up @@ -122,7 +122,7 @@ async function getArtifactSpecForSnapshot(
log: ToolingLog
): Promise<ArtifactSpec> {
const desiredVersion = urlVersion.replace('-SNAPSHOT', '');
const desiredLicense = license === 'oss' ? 'oss' : 'default';
const desiredLicense = 'default';

const customManifestUrl = process.env.ES_SNAPSHOT_MANIFEST;
const primaryManifestUrl = `${DAILY_SNAPSHOTS_BASE_URL}/${desiredVersion}/manifest-latest${
Expand Down
52 changes: 25 additions & 27 deletions packages/kbn-es/src/cli_commands/build_snapshots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,35 +49,33 @@ export const buildSnapshots: Command = {
del.sync(outputDir);
Fs.mkdirSync(outputDir, { recursive: true });

for (const license of ['oss', 'trial']) {
for (const platform of ['darwin', 'win32', 'linux']) {
log.info('Building', platform, license === 'trial' ? 'default' : 'oss', 'snapshot');
await log.indent(4, async () => {
const snapshotPath = await buildSnapshot({
license,
sourcePath: options.sourcePath,
log,
platform,
});
for (const platform of ['darwin', 'win32', 'linux']) {
log.info('Building', platform, 'default snapshot');
await log.indent(4, async () => {
const snapshotPath = await buildSnapshot({
license: 'trial',
sourcePath: options.sourcePath,
log,
platform,
});

const filename = basename(snapshotPath);
const outputPath = resolve(outputDir, filename);
const hash = createHash('sha512');
await pipelineAsync(
Fs.createReadStream(snapshotPath),
new Transform({
transform(chunk, _, cb) {
hash.update(chunk);
cb(undefined, chunk);
},
}),
Fs.createWriteStream(outputPath)
);
const filename = basename(snapshotPath);
const outputPath = resolve(outputDir, filename);
const hash = createHash('sha512');
await pipelineAsync(
Fs.createReadStream(snapshotPath),
new Transform({
transform(chunk, _, cb) {
hash.update(chunk);
cb(undefined, chunk);
},
}),
Fs.createWriteStream(outputPath)
);

Fs.writeFileSync(`${outputPath}.sha512`, `${hash.digest('hex')} ${filename}`);
log.success('snapshot and shasum written to', outputPath);
});
}
Fs.writeFileSync(`${outputPath}.sha512`, `${hash.digest('hex')} ${filename}`);
log.success('snapshot and shasum written to', outputPath);
});
}
},
};
2 changes: 1 addition & 1 deletion packages/kbn-es/src/cli_commands/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const snapshot: Command = {
return dedent`
Options:
--license Run with a 'oss', 'basic', or 'trial' license [default: ${license}]
--license Run with a 'basic' or 'trial' license [default: ${license}]
--version Version of ES to download [default: ${defaults.version}]
--base-path Path containing cache/installations [default: ${basePath}]
--install-path Installation path, defaults to 'source' within base-path
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-es/src/cli_commands/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const source: Command = {
return dedent`
Options:
--license Run with a 'oss', 'basic', or 'trial' license [default: ${license}]
--license Run with a 'basic' or 'trial' license [default: ${license}]
--source-path Path to ES source [default: ${defaults['source-path']}]
--base-path Path containing cache/installations [default: ${basePath}]
--install-path Installation path, defaults to 'source' within base-path
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-es/src/custom_snapshots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function resolveCustomSnapshotUrl(

const ext = process.platform === 'win32' ? 'zip' : 'tar.gz';
const os = process.platform === 'win32' ? 'windows' : process.platform;
const name = license === 'oss' ? 'elasticsearch-oss' : 'elasticsearch';
const name = 'elasticsearch';
const overrideUrl = customSnapshotUrl
.replace('{name}', name)
.replace('{ext}', ext)
Expand Down
18 changes: 8 additions & 10 deletions packages/kbn-es/src/install/install_archive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,15 @@ export async function installArchive(archive: string, options?: InstallArchiveOp
fs.mkdirSync(tmpdir, { recursive: true });
log.info('created %s', chalk.bold(tmpdir));

if (license !== 'oss') {
// starting in 6.3, security is disabled by default. Since we bootstrap
// the keystore, we can enable security ourselves.
await appendToConfig(installPath, 'xpack.security.enabled', 'true');
// starting in 6.3, security is disabled by default. Since we bootstrap
// the keystore, we can enable security ourselves.
await appendToConfig(installPath, 'xpack.security.enabled', 'true');

await appendToConfig(installPath, 'xpack.license.self_generated.type', license);
await configureKeystore(installPath, log, [
['bootstrap.password', password],
...parseSettings(esArgs, { filter: SettingsFilter.SecureOnly }),
]);
}
await appendToConfig(installPath, 'xpack.license.self_generated.type', license);
await configureKeystore(installPath, log, [
['bootstrap.password', password],
...parseSettings(esArgs, { filter: SettingsFilter.SecureOnly }),
]);

return { installPath };
}
Expand Down
11 changes: 3 additions & 8 deletions packages/kbn-es/src/utils/build_snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ interface BuildSnapshotOptions {
* :distribution:archives:darwin-tar:assemble
* :distribution:archives:linux-tar:assemble
* :distribution:archives:windows-zip:assemble
* :distribution:archives:oss-darwin-tar:assemble
* :distribution:archives:oss-linux-tar:assemble
* :distribution:archives:oss-windows-zip:assemble
*/
export async function buildSnapshot({
license,
Expand Down Expand Up @@ -67,15 +64,13 @@ export async function buildSnapshot({
}

export function archiveForPlatform(platform: NodeJS.Platform, license: string) {
const taskPrefix = license === 'oss' ? 'oss-' : '';

switch (platform) {
case 'darwin':
return { format: 'tar', ext: 'tar.gz', task: `${taskPrefix}darwin-tar`, platform: 'darwin' };
return { format: 'tar', ext: 'tar.gz', task: 'darwin-tar', platform: 'darwin' };
case 'win32':
return { format: 'zip', ext: 'zip', task: `${taskPrefix}windows-zip`, platform: 'windows' };
return { format: 'zip', ext: 'zip', task: 'windows-zip', platform: 'windows' };
case 'linux':
return { format: 'tar', ext: 'tar.gz', task: `${taskPrefix}linux-tar`, platform: 'linux' };
return { format: 'tar', ext: 'tar.gz', task: 'linux-tar', platform: 'linux' };
default:
throw new Error(`unsupported platform: ${platform}`);
}
Expand Down

0 comments on commit 85d4522

Please sign in to comment.