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

[Workspace] Add duplicate saved objects API #6288

Merged
merged 26 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d047607
Add copy saved objects API
gaobinlong Mar 28, 2024
317c565
Modify change log
gaobinlong Mar 28, 2024
bf4b53f
Add documents for all saved objects APIs
gaobinlong Mar 29, 2024
b38d1cf
merge main
gaobinlong Mar 29, 2024
d018404
Revert the yml file change
gaobinlong Apr 1, 2024
3423606
Move the duplicate api to workspace plugin
gaobinlong Apr 1, 2024
6df94c9
Modify change log
gaobinlong Apr 1, 2024
366565b
Modify api doc
gaobinlong Apr 1, 2024
0ecfe14
Check target workspace exists or not
gaobinlong Apr 2, 2024
d25ec21
Remove unused import
gaobinlong Apr 2, 2024
263a7d4
Fix test failure
gaobinlong Apr 2, 2024
4db87bb
merge main
gaobinlong Apr 3, 2024
70723bb
Merge remote-tracking branch 'upstream/main' into copy
gaobinlong Apr 7, 2024
62fcdef
Modify change log
gaobinlong Apr 7, 2024
3c64421
Modify workspace doc
gaobinlong Apr 7, 2024
7326a5f
Add more unit tests
gaobinlong Apr 8, 2024
23d5515
Some minor change
gaobinlong Apr 9, 2024
ac7afb8
Merge remote-tracking branch 'upstream/main' into copy
gaobinlong Apr 9, 2024
6e57d03
Fix test failure
gaobinlong Apr 9, 2024
55b902d
Modify test description
gaobinlong Apr 11, 2024
42242bb
Merge remote-tracking branch 'upstream/main' into copy
gaobinlong Apr 11, 2024
f172517
Optimize test description
gaobinlong Apr 11, 2024
8c9a08d
Modify test case
gaobinlong Apr 11, 2024
1df3d95
Merge remote-tracking branch 'upstream/main' into copy
gaobinlong Apr 11, 2024
5fda5a1
Merge remote-tracking branch 'upstream/main' into copy
gaobinlong Apr 11, 2024
7172f55
Minor change
gaobinlong Apr 11, 2024
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [Workspace] Add create workspace page ([#6179](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6179))
- [Multiple Datasource] Make sure customer always have a default datasource ([#6237](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6237))
- [Workspace] Add workspace list page ([#6182](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6182))
- [Workspace] Add copy saved objects API ([#6288](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6288))
- [Multiple Datasource] Add multi data source support to sample vega visualizations ([#6218](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6218))

### 🐛 Bug Fixes
Expand Down Expand Up @@ -1099,4 +1100,4 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

### 🔩 Tests

- Update caniuse to fix failed integration tests ([#2322](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2322))
- Update caniuse to fix failed integration tests ([#2322](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2322))
21 changes: 12 additions & 9 deletions config/opensearch_dashboards.yml
gaobinlong marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# OpenSearch Dashboards is served by a back end server. This setting specifies the port to use.
#server.port: 5601

#assistant.chat.enabled: true
# Specifies the address to which the OpenSearch Dashboards server will bind. IP addresses and host names are both valid values.
# The default is 'localhost', which usually means remote machines will not be able to connect.
# To allow connections from remote users, set this parameter to a non-loopback address.
#server.host: "localhost"
server.host: "0.0.0.0"

#workspace.enabled: true
#workspace.permission.enabled: true

# Enables you to specify a path to mount OpenSearch Dashboards at if you are running behind a proxy.
# Use the `server.rewriteBasePath` setting to tell OpenSearch Dashboards if it should remove the basePath
Expand All @@ -23,7 +26,7 @@
#server.name: "your-hostname"

# The URLs of the OpenSearch instances to use for all your queries.
#opensearch.hosts: ["http://localhost:9200"]
opensearch.hosts: ["http://localhost:9200"]

# OpenSearch Dashboards uses an index in OpenSearch to store saved searches, visualizations and
# dashboards. OpenSearch Dashboards creates a new index if the index doesn't already exist.
Expand Down Expand Up @@ -66,27 +69,27 @@
# the username and password that the OpenSearch Dashboards server uses to perform maintenance on the OpenSearch Dashboards
# index at startup. Your OpenSearch Dashboards users still need to authenticate with OpenSearch, which
# is proxied through the OpenSearch Dashboards server.
#opensearch.username: "opensearch_dashboards_system"
#opensearch.password: "pass"
opensearch.username: "admin"
opensearch.password: "admin"

# Enables SSL and paths to the PEM-format SSL certificate and SSL key files, respectively.
# These settings enable SSL for outgoing requests from the OpenSearch Dashboards server to the browser.
#server.ssl.enabled: false
#server.ssl.enabled: true
#server.ssl.certificate: none
#server.ssl.certificate: /path/to/your/server.crt
#server.ssl.key: /path/to/your/server.key

# Optional settings that provide the paths to the PEM-format SSL certificate and key files.
# These files are used to verify the identity of OpenSearch Dashboards to OpenSearch and are required when
# xpack.security.http.ssl.client_authentication in OpenSearch is set to required.
#opensearch.ssl.certificate: /path/to/your/client.crt
#opensearch.ssl.key: /path/to/your/client.key

# Optional setting that enables you to specify a path to the PEM file for the certificate
# authority for your OpenSearch instance.
#opensearch.ssl.certificateAuthorities: [ "/path/to/your/CA.pem" ]

# To disregard the validity of SSL certificates, change this setting's value to 'none'.
#opensearch.ssl.verificationMode: full
opensearch.ssl.verificationMode: none

# Time in milliseconds to wait for OpenSearch to respond to pings. Defaults to the value of
# the opensearch.requestTimeout setting.
Expand Down Expand Up @@ -312,4 +315,4 @@
# savedObjects.permission.enabled: true

# Set the value to true to enable workspace feature
# workspace.enabled: false
workspace.enabled: true
72 changes: 72 additions & 0 deletions src/core/server/saved_objects/routes/copy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

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

export const registerCopyRoute = (router: IRouter, config: SavedObjectConfig) => {
const { maxImportExportSize } = config;

router.post(
{
path: '/_copy',
bandinib-amzn marked this conversation as resolved.
Show resolved Hide resolved
validate: {
body: schema.object({
objects: schema.arrayOf(
schema.object({
type: schema.string(),
id: schema.string(),
})
),
includeReferencesDeep: schema.boolean({ defaultValue: false }),
targetWorkspace: schema.string(),
}),
},
},
router.handleLegacyErrors(async (context, req, res) => {
const savedObjectsClient = context.core.savedObjects.client;
const { objects, includeReferencesDeep, targetWorkspace } = req.body;

Check warning on line 33 in src/core/server/saved_objects/routes/copy.ts

View check run for this annotation

Codecov / codecov/patch

src/core/server/saved_objects/routes/copy.ts#L32-L33

Added lines #L32 - L33 were not covered by tests

// need to access the registry for type validation, can't use the schema for this
const supportedTypes = context.core.savedObjects.typeRegistry

Check warning on line 36 in src/core/server/saved_objects/routes/copy.ts

View check run for this annotation

Codecov / codecov/patch

src/core/server/saved_objects/routes/copy.ts#L36

Added line #L36 was not covered by tests
.getImportableAndExportableTypes()
.map((t) => t.name);

Check warning on line 38 in src/core/server/saved_objects/routes/copy.ts

View check run for this annotation

Codecov / codecov/patch

src/core/server/saved_objects/routes/copy.ts#L38

Added line #L38 was not covered by tests

const invalidObjects = objects.filter((obj) => !supportedTypes.includes(obj.type));

Check warning on line 40 in src/core/server/saved_objects/routes/copy.ts

View check run for this annotation

Codecov / codecov/patch

src/core/server/saved_objects/routes/copy.ts#L40

Added line #L40 was not covered by tests
if (invalidObjects.length) {
return res.badRequest({

Check warning on line 42 in src/core/server/saved_objects/routes/copy.ts

View check run for this annotation

Codecov / codecov/patch

src/core/server/saved_objects/routes/copy.ts#L42

Added line #L42 was not covered by tests
body: {
message: `Trying to copy object(s) with unsupported types: ${invalidObjects
.map((obj) => `${obj.type}:${obj.id}`)

Check warning on line 45 in src/core/server/saved_objects/routes/copy.ts

View check run for this annotation

Codecov / codecov/patch

src/core/server/saved_objects/routes/copy.ts#L45

Added line #L45 was not covered by tests
.join(', ')}`,
},
});
}

const objectsListStream = await exportSavedObjectsToStream({

Check warning on line 51 in src/core/server/saved_objects/routes/copy.ts

View check run for this annotation

Codecov / codecov/patch

src/core/server/saved_objects/routes/copy.ts#L51

Added line #L51 was not covered by tests
savedObjectsClient,
objects,
exportSizeLimit: maxImportExportSize,
includeReferencesDeep,
excludeExportDetails: true,
});

const result = await importSavedObjectsFromStream({

Check warning on line 59 in src/core/server/saved_objects/routes/copy.ts

View check run for this annotation

Codecov / codecov/patch

src/core/server/saved_objects/routes/copy.ts#L59

Added line #L59 was not covered by tests
savedObjectsClient: context.core.savedObjects.client,
typeRegistry: context.core.savedObjects.typeRegistry,
readStream: objectsListStream,
objectLimit: maxImportExportSize,
overwrite: false,
createNewCopies: true,
workspaces: [targetWorkspace],
});

return res.ok({ body: result });

Check warning on line 69 in src/core/server/saved_objects/routes/copy.ts

View check run for this annotation

Codecov / codecov/patch

src/core/server/saved_objects/routes/copy.ts#L69

Added line #L69 was not covered by tests
})
);
};
2 changes: 2 additions & 0 deletions src/core/server/saved_objects/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { registerExportRoute } from './export';
import { registerImportRoute } from './import';
import { registerResolveImportErrorsRoute } from './resolve_import_errors';
import { registerMigrateRoute } from './migrate';
import { registerCopyRoute } from './copy';

export function registerRoutes({
http,
Expand All @@ -71,6 +72,7 @@ export function registerRoutes({
registerExportRoute(router, config);
registerImportRoute(router, config);
registerResolveImportErrorsRoute(router, config);
registerCopyRoute(router, config);

const internalRouter = http.createRouter('/internal/saved_objects/');

Expand Down
Loading
Loading