Skip to content

Commit

Permalink
revert useless modifications
Browse files Browse the repository at this point in the history
Signed-off-by: yubonluo <yubonluo@amazon.com>
  • Loading branch information
yubonluo committed Mar 28, 2024
1 parent c0f62aa commit 4d5af83
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 27 deletions.
40 changes: 15 additions & 25 deletions src/core/server/saved_objects/routes/copy.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Any modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

import { schema } from '@osd/config-schema';
import { IRouter } from '../../http';
import { SavedObjectConfig } from '../saved_objects_config';
import { exportSavedObjectsToStream } from '../export';
import { validateObjects } from './utils';
import { importSavedObjectsFromStream } from '../import';

export const registerCopyRoute = (router: IRouter, config: SavedObjectConfig) => {
Expand All @@ -24,14 +17,11 @@ export const registerCopyRoute = (router: IRouter, config: SavedObjectConfig) =>
path: '/_copy',
validate: {
body: schema.object({
objects: schema.maybe(
schema.arrayOf(
schema.object({
type: schema.string(),
id: schema.string(),
}),
{ maxSize: maxImportExportSize }
)
objects: schema.arrayOf(
schema.object({
type: schema.string(),
id: schema.string(),
})
),
includeReferencesDeep: schema.boolean({ defaultValue: false }),
targetWorkspace: schema.string(),
Expand All @@ -47,15 +37,15 @@ export const registerCopyRoute = (router: IRouter, config: SavedObjectConfig) =>
.getImportableAndExportableTypes()
.map((t) => t.name);

if (objects) {
const validationError = validateObjects(objects, supportedTypes);
if (validationError) {
return res.badRequest({
body: {
message: validationError,
},
});
}
const invalidObjects = objects.filter((obj) => !supportedTypes.includes(obj.type));
if (invalidObjects.length) {
return res.badRequest({
body: {
message: `Trying to copy object(s) with unsupported types: ${invalidObjects
.map((obj) => `${obj.type}:${obj.id}`)
.join(', ')}`,
},
});
}

const objectsListStream = await exportSavedObjectsToStream({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe(`POST ${URL}`, () => {
const result = await supertest(httpSetup.server.listener).post(URL).send({}).expect(400);

expect(result.body.message).toMatchInlineSnapshot(
`"[request body.targetWorkspace]: expected value of type [string] but got [undefined]"`
`"[request body.objects]: expected value of type [array] but got [undefined]"`
);
});

Expand Down Expand Up @@ -157,7 +157,7 @@ describe(`POST ${URL}`, () => {
.expect(400);

expect(result.body.message).toMatchInlineSnapshot(
`"Trying to export object(s) with non-exportable types: unknown:my-pattern"`
`"Trying to copy object(s) with unsupported types: unknown:my-pattern"`
);
});

Expand Down

0 comments on commit 4d5af83

Please sign in to comment.