forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Setup workspace skeleton and implement basic CRUD API (open…
…search-project#130) * feature: setup workspace skeleton and implement basic CRUD API on workspace Signed-off-by: Zhou Su <suzhou@dev-dsk-suzhou-2a-8ce7a7a7.us-west-2.amazon.com> * feat: remove useless required plugins and logger typo Signed-off-by: SuZhou-Joe <suzhou@amazon.com> * feat: setup public side skeleton Signed-off-by: SuZhou-Joe <suzhou@amazon.com> --------- Signed-off-by: Zhou Su <suzhou@dev-dsk-suzhou-2a-8ce7a7a7.us-west-2.amazon.com> Signed-off-by: SuZhou-Joe <suzhou@amazon.com> Co-authored-by: Zhou Su <suzhou@dev-dsk-suzhou-2a-8ce7a7a7.us-west-2.amazon.com>
- Loading branch information
Showing
17 changed files
with
638 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export interface WorkspaceAttribute { | ||
id: string; | ||
name: string; | ||
description?: string; | ||
features?: string[]; | ||
color?: string; | ||
icon?: string; | ||
defaultVISTheme?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export const WORKSPACE_TYPE = 'workspace'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"id": "workspace", | ||
"version": "opensearchDashboards", | ||
"server": true, | ||
"ui": true, | ||
"requiredPlugins": [], | ||
"optionalPlugins": [], | ||
"requiredBundles": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { WorkspacePlugin } from './plugin'; | ||
|
||
export function plugin() { | ||
return new WorkspacePlugin(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
import { Plugin } from '../../../core/public'; | ||
|
||
export class WorkspacePlugin implements Plugin<{}, {}, {}> { | ||
public async setup() { | ||
return {}; | ||
} | ||
|
||
public start() { | ||
return {}; | ||
} | ||
|
||
public stop() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
import { PluginInitializerContext } from '../../../core/server'; | ||
import { WorkspacePlugin } from './plugin'; | ||
|
||
// This exports static code and TypeScript types, | ||
// as well as, OpenSearch Dashboards Platform `plugin()` initializer. | ||
|
||
export function plugin(initializerContext: PluginInitializerContext) { | ||
return new WorkspacePlugin(initializerContext); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
import { PluginInitializerContext, CoreSetup, Plugin, Logger } from '../../../core/server'; | ||
import { IWorkspaceDBImpl } from './types'; | ||
import { WorkspaceClientWithSavedObject } from './workspace_client'; | ||
import { registerRoutes } from './routes'; | ||
|
||
export class WorkspacePlugin implements Plugin<{}, {}> { | ||
private readonly logger: Logger; | ||
private client?: IWorkspaceDBImpl; | ||
|
||
constructor(initializerContext: PluginInitializerContext) { | ||
this.logger = initializerContext.logger.get('plugins', 'workspace'); | ||
} | ||
|
||
public async setup(core: CoreSetup) { | ||
this.logger.debug('Setting up Workspaces service'); | ||
|
||
this.client = new WorkspaceClientWithSavedObject(core); | ||
|
||
await this.client.setup(core); | ||
|
||
registerRoutes({ | ||
http: core.http, | ||
logger: this.logger, | ||
client: this.client as IWorkspaceDBImpl, | ||
}); | ||
|
||
return { | ||
client: this.client, | ||
}; | ||
} | ||
|
||
public start() { | ||
this.logger.debug('Starting Workspace service'); | ||
|
||
return { | ||
client: this.client as IWorkspaceDBImpl, | ||
}; | ||
} | ||
|
||
public stop() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
import { schema } from '@osd/config-schema'; | ||
|
||
import { CoreSetup, Logger } from '../../../../core/server'; | ||
import { IWorkspaceDBImpl } from '../types'; | ||
|
||
const WORKSPACES_API_BASE_URL = '/api/workspaces'; | ||
|
||
const workspaceAttributesSchema = schema.object({ | ||
description: schema.maybe(schema.string()), | ||
name: schema.string(), | ||
features: schema.maybe(schema.arrayOf(schema.string())), | ||
color: schema.maybe(schema.string()), | ||
icon: schema.maybe(schema.string()), | ||
defaultVISTheme: schema.maybe(schema.string()), | ||
}); | ||
|
||
export function registerRoutes({ | ||
client, | ||
logger, | ||
http, | ||
}: { | ||
client: IWorkspaceDBImpl; | ||
logger: Logger; | ||
http: CoreSetup['http']; | ||
}) { | ||
const router = http.createRouter(); | ||
router.post( | ||
{ | ||
path: `${WORKSPACES_API_BASE_URL}/_list`, | ||
validate: { | ||
body: schema.object({ | ||
search: schema.maybe(schema.string()), | ||
sortOrder: schema.maybe(schema.string()), | ||
perPage: schema.number({ min: 0, defaultValue: 20 }), | ||
page: schema.number({ min: 0, defaultValue: 1 }), | ||
sortField: schema.maybe(schema.string()), | ||
searchFields: schema.maybe(schema.arrayOf(schema.string())), | ||
}), | ||
}, | ||
}, | ||
router.handleLegacyErrors(async (context, req, res) => { | ||
const result = await client.list( | ||
{ | ||
context, | ||
request: req, | ||
logger, | ||
}, | ||
req.body | ||
); | ||
if (!result.success) { | ||
return res.ok({ body: result }); | ||
} | ||
return res.ok({ | ||
body: { | ||
...result, | ||
result: { | ||
...result.result, | ||
workspaces: result.result.workspaces.map((workspace) => ({ | ||
...workspace, | ||
})), | ||
}, | ||
}, | ||
}); | ||
}) | ||
); | ||
router.get( | ||
{ | ||
path: `${WORKSPACES_API_BASE_URL}/{id}`, | ||
validate: { | ||
params: schema.object({ | ||
id: schema.string(), | ||
}), | ||
}, | ||
}, | ||
router.handleLegacyErrors(async (context, req, res) => { | ||
const { id } = req.params; | ||
const result = await client.get( | ||
{ | ||
context, | ||
request: req, | ||
logger, | ||
}, | ||
id | ||
); | ||
if (!result.success) { | ||
return res.ok({ body: result }); | ||
} | ||
|
||
return res.ok({ | ||
body: { | ||
...result, | ||
result: { | ||
...result.result, | ||
}, | ||
}, | ||
}); | ||
}) | ||
); | ||
router.post( | ||
{ | ||
path: `${WORKSPACES_API_BASE_URL}`, | ||
validate: { | ||
body: schema.object({ | ||
attributes: workspaceAttributesSchema, | ||
}), | ||
}, | ||
}, | ||
router.handleLegacyErrors(async (context, req, res) => { | ||
const { attributes } = req.body; | ||
|
||
const result = await client.create( | ||
{ | ||
context, | ||
request: req, | ||
logger, | ||
}, | ||
{ | ||
...attributes, | ||
} | ||
); | ||
return res.ok({ body: result }); | ||
}) | ||
); | ||
router.put( | ||
{ | ||
path: `${WORKSPACES_API_BASE_URL}/{id?}`, | ||
validate: { | ||
params: schema.object({ | ||
id: schema.string(), | ||
}), | ||
body: schema.object({ | ||
attributes: workspaceAttributesSchema, | ||
}), | ||
}, | ||
}, | ||
router.handleLegacyErrors(async (context, req, res) => { | ||
const { id } = req.params; | ||
const { attributes } = req.body; | ||
|
||
const result = await client.update( | ||
{ | ||
context, | ||
request: req, | ||
logger, | ||
}, | ||
id, | ||
{ | ||
...attributes, | ||
} | ||
); | ||
return res.ok({ body: result }); | ||
}) | ||
); | ||
router.delete( | ||
{ | ||
path: `${WORKSPACES_API_BASE_URL}/{id?}`, | ||
validate: { | ||
params: schema.object({ | ||
id: schema.string(), | ||
}), | ||
}, | ||
}, | ||
router.handleLegacyErrors(async (context, req, res) => { | ||
const { id } = req.params; | ||
|
||
const result = await client.delete( | ||
{ | ||
context, | ||
request: req, | ||
logger, | ||
}, | ||
id | ||
); | ||
return res.ok({ body: result }); | ||
}) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export { workspace } from './workspace'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { SavedObjectsType, WORKSPACE_TYPE } from '../../../../core/server'; | ||
|
||
export const workspace: SavedObjectsType = { | ||
name: WORKSPACE_TYPE, | ||
namespaceType: 'agnostic', | ||
hidden: false, | ||
/** | ||
* workspace won't appear in management page. | ||
*/ | ||
mappings: { | ||
dynamic: false, | ||
properties: { | ||
name: { | ||
type: 'keyword', | ||
}, | ||
description: { | ||
type: 'text', | ||
}, | ||
/** | ||
* In opensearch, string[] is also mapped to text | ||
*/ | ||
features: { | ||
type: 'text', | ||
}, | ||
color: { | ||
type: 'text', | ||
}, | ||
icon: { | ||
type: 'text', | ||
}, | ||
defaultVISTheme: { | ||
type: 'text', | ||
}, | ||
}, | ||
}, | ||
}; |
Oops, something went wrong.