Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[kbnArchiver] convert archive names to root-relative paths #101839

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 2 additions & 21 deletions packages/kbn-test/src/kbn_archiver_cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,11 @@ export function runKbnArchiverCli() {
new RunWithCommands({
description: 'Import/export saved objects from archives, for testing',
globalFlags: {
string: ['config', 'space', 'kibana-url', 'dir'],
string: ['config', 'space', 'kibana-url'],
help: `
--space space id to operate on, defaults to the default space
--config optional path to an FTR config file that will be parsed and used for defaults
--kibana-url set the url that kibana can be reached at, uses the "servers.kibana" setting from --config by default
--dir directory that contains exports to be imported, or where exports will be saved, uses the "kbnArchiver.directory"
setting from --config by default
`,
},
async extendContext({ log, flags }) {
Expand Down Expand Up @@ -79,23 +77,6 @@ export function runKbnArchiverCli() {
);
}

let importExportDir;
if (flags.dir) {
if (typeof flags.dir !== 'string') {
throw createFlagError('expected --dir to be a string');
}

importExportDir = flags.dir;
} else if (config) {
importExportDir = config.get('kbnArchiver.directory');
}

if (!importExportDir) {
throw createFlagError(
'--config does not include a kbnArchiver.directory, specify it or include --dir flag'
);
}

const space = flags.space;
if (!(space === undefined || typeof space === 'string')) {
throw createFlagError('--space must be a string');
Expand All @@ -106,7 +87,7 @@ export function runKbnArchiverCli() {
kbnClient: new KbnClient({
log,
url: kibanaUrl,
importExportDir,
importExportBaseDir: process.cwd(),
}),
};
},
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-test/src/kbn_client/kbn_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface KbnClientOptions {
certificateAuthorities?: Buffer[];
log: ToolingLog;
uiSettingDefaults?: UiSettingValues;
importExportDir?: string;
importExportBaseDir?: string;
}

export class KbnClient {
Expand Down Expand Up @@ -67,7 +67,7 @@ export class KbnClient {
this.log,
this.requester,
this.savedObjects,
options.importExportDir
options.importExportBaseDir
);
}

Expand Down
12 changes: 7 additions & 5 deletions packages/kbn-test/src/kbn_client/kbn_client_import_export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

import { inspect } from 'util';
import Fs from 'fs/promises';
import { existsSync } from 'fs';
import Path from 'path';

import FormData from 'form-data';
import { ToolingLog, isAxiosResponseError, createFailError } from '@kbn/dev-utils';
import { ToolingLog, isAxiosResponseError, createFailError, REPO_ROOT } from '@kbn/dev-utils';

import { KbnClientRequester, uriencode, ReqOptions } from './kbn_client_requester';
import { KbnClientSavedObjects } from './kbn_client_saved_objects';
Expand Down Expand Up @@ -39,21 +40,22 @@ export class KbnClientImportExport {
public readonly log: ToolingLog,
public readonly requester: KbnClientRequester,
public readonly savedObjects: KbnClientSavedObjects,
public readonly dir?: string
public readonly baseDir: string = REPO_ROOT
) {}

private resolvePath(path: string) {
if (!Path.extname(path)) {
path = `${path}.json`;
}

if (!this.dir && !Path.isAbsolute(path)) {
const absolutePath = Path.resolve(this.baseDir, path);
if (existsSync(absolutePath)) {
throw new Error(
'unable to resolve relative path to import/export without a configured dir, either path absolute path or specify --dir'
`unable to resolve path [${path}] to import/export, resolved relative to [${this.baseDir}]`
);
}

return this.dir ? Path.resolve(this.dir, path) : path;
return absolutePath;
}

async load(name: string, options?: { space?: string }) {
Expand Down
12 changes: 10 additions & 2 deletions test/api_integration/apis/kql_telemetry/kql_telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@ export default function ({ getService }: FtrProviderContext) {
const es = getService('es');

describe('telemetry API', () => {
before(() => kibanaServer.importExport.load('saved_objects/basic'));
after(() => kibanaServer.importExport.unload('saved_objects/basic'));
before(() =>
kibanaServer.importExport.load(
'test/api_integration/fixtures/kbn_archiver/saved_objects/basic.json'
)
);
after(() =>
kibanaServer.importExport.unload(
'test/api_integration/fixtures/kbn_archiver/saved_objects/basic.json'
)
);

it('should increment the opt *in* counter in the .kibana/kql-telemetry document', async () => {
await supertest
Expand Down
5 changes: 4 additions & 1 deletion test/api_integration/apis/saved_objects/bulk_create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ export default function ({ getService }: FtrProviderContext) {
before(async () => {
KIBANA_VERSION = await getKibanaVersion(getService);
await kibanaServer.spaces.create({ id: SPACE_ID, name: SPACE_ID });
await kibanaServer.importExport.load('saved_objects/basic', { space: SPACE_ID });
await kibanaServer.importExport.load(
'test/api_integration/fixtures/kbn_archiver/saved_objects/basic.json',
{ space: SPACE_ID }
);
});

after(() => kibanaServer.spaces.delete(SPACE_ID));
Expand Down
10 changes: 8 additions & 2 deletions test/api_integration/apis/saved_objects/bulk_get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,16 @@ export default function ({ getService }: FtrProviderContext) {

before(async () => {
KIBANA_VERSION = await getKibanaVersion(getService);
await kibanaServer.importExport.load('saved_objects/basic');
await kibanaServer.importExport.load(
'test/api_integration/fixtures/kbn_archiver/saved_objects/basic.json'
);
});

after(() => kibanaServer.importExport.unload('saved_objects/basic'));
after(() =>
kibanaServer.importExport.unload(
'test/api_integration/fixtures/kbn_archiver/saved_objects/basic.json'
)
);

it('should return 200 with individual responses', async () =>
await supertest
Expand Down
12 changes: 10 additions & 2 deletions test/api_integration/apis/saved_objects/bulk_update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,16 @@ export default function ({ getService }: FtrProviderContext) {
const kibanaServer = getService('kibanaServer');

describe('bulkUpdate', () => {
before(() => kibanaServer.importExport.load('saved_objects/basic'));
after(() => kibanaServer.importExport.unload('saved_objects/basic'));
before(() =>
kibanaServer.importExport.load(
'test/api_integration/fixtures/kbn_archiver/saved_objects/basic.json'
)
);
after(() =>
kibanaServer.importExport.unload(
'test/api_integration/fixtures/kbn_archiver/saved_objects/basic.json'
)
);

it('should return 200', async () => {
const response = await supertest
Expand Down
10 changes: 8 additions & 2 deletions test/api_integration/apis/saved_objects/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@ export default function ({ getService }: FtrProviderContext) {

before(async () => {
KIBANA_VERSION = await getKibanaVersion(getService);
await kibanaServer.importExport.load('saved_objects/basic');
await kibanaServer.importExport.load(
'test/api_integration/fixtures/kbn_archiver/saved_objects/basic.json'
);
});

after(() => kibanaServer.importExport.unload('saved_objects/basic'));
after(() =>
kibanaServer.importExport.unload(
'test/api_integration/fixtures/kbn_archiver/saved_objects/basic.json'
)
);

it('should return 200', async () => {
await supertest
Expand Down
12 changes: 10 additions & 2 deletions test/api_integration/apis/saved_objects/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,16 @@ export default function ({ getService }: FtrProviderContext) {
const kibanaServer = getService('kibanaServer');

describe('delete', () => {
before(() => kibanaServer.importExport.load('saved_objects/basic'));
after(() => kibanaServer.importExport.unload('saved_objects/basic'));
before(() =>
kibanaServer.importExport.load(
'test/api_integration/fixtures/kbn_archiver/saved_objects/basic.json'
)
);
after(() =>
kibanaServer.importExport.unload(
'test/api_integration/fixtures/kbn_archiver/saved_objects/basic.json'
)
);

it('should return 200 when deleting a doc', async () =>
await supertest
Expand Down
5 changes: 4 additions & 1 deletion test/api_integration/apis/saved_objects/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ export default function ({ getService }: FtrProviderContext) {
before(async () => {
KIBANA_VERSION = await getKibanaVersion(getService);
await kibanaServer.spaces.create({ id: SPACE_ID, name: SPACE_ID });
await kibanaServer.importExport.load('saved_objects/basic', { space: SPACE_ID });
await kibanaServer.importExport.load(
'test/api_integration/fixtures/kbn_archiver/saved_objects/basic.json',
{ space: SPACE_ID }
);
});

after(() => kibanaServer.spaces.delete(SPACE_ID));
Expand Down
36 changes: 28 additions & 8 deletions test/api_integration/apis/saved_objects/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ export default function ({ getService }: FtrProviderContext) {
describe('find', () => {
before(async () => {
await kibanaServer.spaces.create({ id: SPACE_ID, name: SPACE_ID });
await kibanaServer.importExport.load('saved_objects/basic', { space: SPACE_ID });
await kibanaServer.importExport.load(
'test/api_integration/fixtures/kbn_archiver/saved_objects/basic.json',
{ space: SPACE_ID }
);

await kibanaServer.spaces.create({ id: `${SPACE_ID}-foo`, name: `${SPACE_ID}-foo` });
await kibanaServer.importExport.load('saved_objects/basic/foo-ns', {
space: `${SPACE_ID}-foo`,
});
await kibanaServer.importExport.load(
'test/api_integration/fixtures/kbn_archiver/saved_objects/basic/foo-ns.json',
{
space: `${SPACE_ID}-foo`,
}
);
});

after(async () => {
Expand Down Expand Up @@ -255,9 +261,17 @@ export default function ({ getService }: FtrProviderContext) {
});

describe('`has_reference` and `has_reference_operator` parameters', () => {
before(() => kibanaServer.importExport.load('saved_objects/references', { space: SPACE_ID }));
before(() =>
kibanaServer.importExport.load(
'test/api_integration/fixtures/kbn_archiver/saved_objects/references.json',
{ space: SPACE_ID }
)
);
after(() =>
kibanaServer.importExport.unload('saved_objects/references', { space: SPACE_ID })
kibanaServer.importExport.unload(
'test/api_integration/fixtures/kbn_archiver/saved_objects/references.json',
{ space: SPACE_ID }
)
);

it('search for a reference', async () => {
Expand Down Expand Up @@ -320,10 +334,16 @@ export default function ({ getService }: FtrProviderContext) {

describe('searching for special characters', () => {
before(() =>
kibanaServer.importExport.load('saved_objects/find_edgecases', { space: SPACE_ID })
kibanaServer.importExport.load(
'test/api_integration/fixtures/kbn_archiver/saved_objects/find_edgecases.json',
{ space: SPACE_ID }
)
);
after(() =>
kibanaServer.importExport.unload('saved_objects/find_edgecases', { space: SPACE_ID })
kibanaServer.importExport.unload(
'test/api_integration/fixtures/kbn_archiver/saved_objects/find_edgecases.json',
{ space: SPACE_ID }
)
);

it('can search for objects with dashes', async () =>
Expand Down
10 changes: 8 additions & 2 deletions test/api_integration/apis/saved_objects/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ export default function ({ getService }: FtrProviderContext) {

before(async () => {
KIBANA_VERSION = await getKibanaVersion(getService);
await kibanaServer.importExport.load('saved_objects/basic');
await kibanaServer.importExport.load(
'test/api_integration/fixtures/kbn_archiver/saved_objects/basic.json'
);
});
after(() => kibanaServer.importExport.unload('saved_objects/basic'));
after(() =>
kibanaServer.importExport.unload(
'test/api_integration/fixtures/kbn_archiver/saved_objects/basic.json'
)
);

it('should return 200', async () =>
await supertest
Expand Down
12 changes: 10 additions & 2 deletions test/api_integration/apis/saved_objects/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,16 @@ export default function ({ getService }: FtrProviderContext) {
};

describe('with basic data existing', () => {
before(() => kibanaServer.importExport.load('saved_objects/basic'));
after(() => kibanaServer.importExport.unload('saved_objects/basic'));
before(() =>
kibanaServer.importExport.load(
'test/api_integration/fixtures/kbn_archiver/saved_objects/basic.json'
)
);
after(() =>
kibanaServer.importExport.unload(
'test/api_integration/fixtures/kbn_archiver/saved_objects/basic.json'
)
);

it('should return 415 when no file passed in', async () => {
await supertest
Expand Down
12 changes: 10 additions & 2 deletions test/api_integration/apis/saved_objects/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,16 @@ export default function ({ getService }: FtrProviderContext) {
});

describe('with kibana index', () => {
before(() => kibanaServer.importExport.load('saved_objects/basic'));
after(() => kibanaServer.importExport.unload('saved_objects/basic'));
before(() =>
kibanaServer.importExport.load(
'test/api_integration/fixtures/kbn_archiver/saved_objects/basic.json'
)
);
after(() =>
kibanaServer.importExport.unload(
'test/api_integration/fixtures/kbn_archiver/saved_objects/basic.json'
)
);

it('should return 200', async () =>
await supertest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ export default function ({ getService }: FtrProviderContext) {
describe('with basic data existing', () => {
before(async () => {
await kibanaServer.spaces.create({ id: SPACE_ID, name: SPACE_ID });
await kibanaServer.importExport.load('saved_objects/basic', { space: SPACE_ID });
await kibanaServer.importExport.load(
'test/api_integration/fixtures/kbn_archiver/saved_objects/basic.json',
{ space: SPACE_ID }
);
});
after(() => kibanaServer.spaces.delete(SPACE_ID));

Expand Down
12 changes: 10 additions & 2 deletions test/api_integration/apis/saved_objects/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,16 @@ export default function ({ getService }: FtrProviderContext) {
const kibanaServer = getService('kibanaServer');

describe('update', () => {
before(() => kibanaServer.importExport.load('saved_objects/basic'));
after(() => kibanaServer.importExport.unload('saved_objects/basic'));
before(() =>
kibanaServer.importExport.load(
'test/api_integration/fixtures/kbn_archiver/saved_objects/basic.json'
)
);
after(() =>
kibanaServer.importExport.unload(
'test/api_integration/fixtures/kbn_archiver/saved_objects/basic.json'
)
);
it('should return 200', async () => {
await supertest
.put(`/api/saved_objects/visualization/dd7caf20-9efd-11e7-acb3-3dab96693fab`)
Expand Down
Loading