forked from opensearch-project/dashboards-flow-framework
-
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.
Signed-off-by: Tyler Ohlsen <[email protected]>
- Loading branch information
Showing
11 changed files
with
252 additions
and
84 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,26 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { FLOW_FRAMEWORK_WORKFLOW_ROUTE_PREFIX } from '../utils'; | ||
|
||
export function flowFrameworkPlugin(Client: any, config: any, components: any) { | ||
const ca = components.clientAction.factory; | ||
|
||
Client.prototype.flowFramework = components.clientAction.namespaceFactory(); | ||
const flowFramework = Client.prototype.flowFramework.prototype; | ||
|
||
flowFramework.deleteDetector = ca({ | ||
url: { | ||
fmt: `${FLOW_FRAMEWORK_WORKFLOW_ROUTE_PREFIX}/<%=workflow_id%>`, | ||
req: { | ||
workflow_id: { | ||
type: 'string', | ||
required: true, | ||
}, | ||
}, | ||
}, | ||
method: 'GET', | ||
}); | ||
} |
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 * from './flow_framework_plugin'; |
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,60 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { schema } from '@osd/config-schema'; | ||
import { | ||
IRouter, | ||
IOpenSearchDashboardsResponse, | ||
RequestHandlerContext, | ||
OpenSearchDashboardsRequest, | ||
OpenSearchDashboardsResponseFactory, | ||
} from '../../../../src/core/server'; | ||
import { GET_WORKFLOW_PATH } from '../../common'; | ||
import { generateCustomError } from './helpers'; | ||
|
||
export function registerFlowFrameworkRoutes( | ||
router: IRouter, | ||
flowFrameworkRoutesService: FlowFrameworkRoutesService | ||
): void { | ||
router.post( | ||
{ | ||
path: `${GET_WORKFLOW_PATH}/{workflow_id}`, | ||
validate: { | ||
params: schema.object({ | ||
index_name: schema.string(), | ||
}), | ||
body: schema.any(), | ||
}, | ||
}, | ||
flowFrameworkRoutesService.getWorkflow | ||
); | ||
} | ||
|
||
export class FlowFrameworkRoutesService { | ||
private client: any; | ||
|
||
constructor(client: any) { | ||
this.client = client; | ||
} | ||
|
||
getWorkflow = async ( | ||
context: RequestHandlerContext, | ||
req: OpenSearchDashboardsRequest, | ||
res: OpenSearchDashboardsResponseFactory | ||
): Promise<IOpenSearchDashboardsResponse<any>> => { | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
const { workflow_id } = req.params; | ||
|
||
try { | ||
const response = await this.client | ||
.asScoped(req) | ||
.callAsCurrentUser('flowFramework.getWorkflow', { workflow_id }); | ||
console.log('response from get workflow: ', response); | ||
return res.ok({ body: response }); | ||
} catch (err: any) { | ||
return generateCustomError(res, err); | ||
} | ||
}; | ||
} |
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 was deleted.
Oops, something went wrong.
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,105 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { schema } from '@osd/config-schema'; | ||
import { SearchRequest } from '@opensearch-project/opensearch/api/types'; | ||
import { | ||
IRouter, | ||
IOpenSearchDashboardsResponse, | ||
RequestHandlerContext, | ||
OpenSearchDashboardsRequest, | ||
OpenSearchDashboardsResponseFactory, | ||
} from '../../../../src/core/server'; | ||
import { SEARCH_INDICES_PATH, FETCH_INDICES_PATH, Index } from '../../common'; | ||
import { generateCustomError } from './helpers'; | ||
|
||
export function registerOpenSearchRoutes( | ||
router: IRouter, | ||
opensearchRoutesService: OpenSearchRoutesService | ||
): void { | ||
router.post( | ||
{ | ||
path: `${SEARCH_INDICES_PATH}/{index_name}`, | ||
validate: { | ||
params: schema.object({ | ||
index_name: schema.string(), | ||
}), | ||
body: schema.any(), | ||
}, | ||
}, | ||
opensearchRoutesService.searchIndex | ||
); | ||
|
||
router.post( | ||
{ | ||
path: `${FETCH_INDICES_PATH}/{pattern}`, | ||
validate: { | ||
params: schema.object({ | ||
pattern: schema.string(), | ||
}), | ||
}, | ||
}, | ||
opensearchRoutesService.catIndices | ||
); | ||
} | ||
|
||
export class OpenSearchRoutesService { | ||
private client: any; | ||
|
||
constructor(client: any) { | ||
this.client = client; | ||
} | ||
|
||
searchIndex = async ( | ||
context: RequestHandlerContext, | ||
req: OpenSearchDashboardsRequest, | ||
res: OpenSearchDashboardsResponseFactory | ||
): Promise<IOpenSearchDashboardsResponse<any>> => { | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
const { index_name } = req.params; | ||
const body = req.body; | ||
|
||
const params = { | ||
index: index_name, | ||
body, | ||
} as SearchRequest; | ||
|
||
try { | ||
const response = await this.client | ||
.asScoped(req) | ||
.callAsCurrentUser.search(params); | ||
return res.ok({ body: response }); | ||
} catch (err: any) { | ||
return generateCustomError(res, err); | ||
} | ||
}; | ||
|
||
catIndices = async ( | ||
context: RequestHandlerContext, | ||
req: OpenSearchDashboardsRequest, | ||
res: OpenSearchDashboardsResponseFactory | ||
): Promise<IOpenSearchDashboardsResponse<any>> => { | ||
const { pattern } = req.params; | ||
try { | ||
const response = await this.client | ||
.asScoped(req) | ||
.callAsCurrentUser.cat.indices({ | ||
index: pattern, | ||
format: 'json', | ||
h: 'health,index', | ||
}); | ||
|
||
// re-formatting the index results to match Index | ||
const cleanedIndices = response.body.map((index) => ({ | ||
name: index.index, | ||
health: index.health, | ||
})) as Index[]; | ||
|
||
return res.ok({ body: cleanedIndices }); | ||
} catch (err: any) { | ||
return generateCustomError(res, err); | ||
} | ||
}; | ||
} |
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,7 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export const FLOW_FRAMEWORK_API_ROUTE_PREFIX = '/_plugins/_flow_framework'; | ||
export const FLOW_FRAMEWORK_WORKFLOW_ROUTE_PREFIX = `${FLOW_FRAMEWORK_API_ROUTE_PREFIX}/workflow`; |
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 * from './constants'; |