-
Notifications
You must be signed in to change notification settings - Fork 78
Stub router for integrations project #547
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5d08945
Copy minimal integrations router code from osints/dev
Swiddis 4084c76
Copy over osints/dev package
Swiddis ebecc31
Update yarn.lock
Swiddis 481bd72
Swap adaptor any to unknown
Swiddis 8f9a975
Clean up router tests
Swiddis 55f98e7
Add license header and clean constants
Swiddis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,32 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| export interface IntegrationsAdaptor { | ||
| getIntegrationTemplates: ( | ||
| query?: IntegrationTemplateQuery | ||
| ) => Promise<IntegrationTemplateSearchResult>; | ||
|
|
||
| getIntegrationInstances: ( | ||
| query?: IntegrationInstanceQuery | ||
| ) => Promise<IntegrationInstancesSearchResult>; | ||
|
|
||
| getIntegrationInstance: (query?: IntegrationInstanceQuery) => Promise<IntegrationInstanceResult>; | ||
|
|
||
| loadIntegrationInstance: ( | ||
| templateName: string, | ||
| name: string, | ||
| dataSource: string | ||
| ) => Promise<IntegrationInstance>; | ||
|
|
||
| deleteIntegrationInstance: (id: string) => Promise<unknown>; | ||
|
|
||
| getStatic: (templateName: string, path: string) => Promise<Buffer>; | ||
|
|
||
| getSchemas: ( | ||
| templateName: string | ||
| ) => Promise<{ mappings: { [key: string]: unknown }; schemas: { [key: string]: unknown } }>; | ||
|
|
||
| getAssets: (templateName: string) => Promise<{ savedObjects?: unknown }>; | ||
| } |
This file contains hidden or 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,84 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| interface IntegrationTemplate { | ||
| name: string; | ||
| version: string; | ||
| displayName?: string; | ||
| integrationType: string; | ||
| license: string; | ||
| type: string; | ||
| author?: string; | ||
| description?: string; | ||
| sourceUrl?: string; | ||
| statics?: { | ||
| logo?: StaticAsset; | ||
| gallery?: StaticAsset[]; | ||
| darkModeLogo?: StaticAsset; | ||
| darkModeGallery?: StaticAsset[]; | ||
| }; | ||
| components: IntegrationComponent[]; | ||
| assets: { | ||
| savedObjects?: { | ||
| name: string; | ||
| version: string; | ||
| }; | ||
| }; | ||
| } | ||
|
|
||
| interface StaticAsset { | ||
| annotation?: string; | ||
| path: string; | ||
| } | ||
|
|
||
| interface IntegrationComponent { | ||
| name: string; | ||
| version: string; | ||
| } | ||
|
|
||
| interface DisplayAsset { | ||
| body: string; | ||
| } | ||
|
|
||
| interface IntegrationTemplateSearchResult { | ||
| hits: IntegrationTemplate[]; | ||
| } | ||
|
|
||
| interface IntegrationTemplateQuery { | ||
| name?: string; | ||
| } | ||
|
|
||
| interface IntegrationInstance { | ||
| name: string; | ||
| templateName: string; | ||
| dataSource: { | ||
| sourceType: string; | ||
| dataset: string; | ||
| namespace: string; | ||
| }; | ||
| creationDate: string; | ||
| assets: AssetReference[]; | ||
| } | ||
|
|
||
| interface IntegrationInstanceResult extends IntegrationInstance { | ||
| id: string; | ||
| status: string; | ||
| } | ||
|
|
||
| interface AssetReference { | ||
| assetType: string; | ||
| assetId: string; | ||
| isDefaultAsset: boolean; | ||
| description: string; | ||
| } | ||
|
|
||
| interface IntegrationInstancesSearchResult { | ||
| hits: IntegrationInstanceResult[]; | ||
| } | ||
|
|
||
| interface IntegrationInstanceQuery { | ||
| added?: boolean; | ||
| id?: string; | ||
| } |
This file contains hidden or 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
53 changes: 53 additions & 0 deletions
53
server/routes/integrations/__tests__/integrations_router.test.ts
This file contains hidden or 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,53 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { OpenSearchDashboardsResponseFactory } from '../../../../../../src/core/server/http/router'; | ||
|
Swiddis marked this conversation as resolved.
|
||
| import { handleWithCallback } from '../integrations_router'; | ||
| import { IntegrationsAdaptor } from 'server/adaptors/integrations/integrations_adaptor'; | ||
|
|
||
| describe('handleWithCallback', () => { | ||
| let adaptorMock: jest.Mocked<IntegrationsAdaptor>; | ||
| let responseMock: jest.Mocked<OpenSearchDashboardsResponseFactory>; | ||
|
|
||
| beforeEach(() => { | ||
| adaptorMock = {} as any; | ||
| responseMock = { | ||
| custom: jest.fn((data) => data), | ||
| ok: jest.fn((data) => data), | ||
| } as any; | ||
| }); | ||
|
|
||
| it('retrieves data from the callback method', async () => { | ||
| const callback = jest.fn((_) => { | ||
| return { test: 'data' }; | ||
| }); | ||
|
|
||
| const result = await handleWithCallback( | ||
| adaptorMock as IntegrationsAdaptor, | ||
| responseMock as OpenSearchDashboardsResponseFactory, | ||
| callback | ||
| ); | ||
|
|
||
| expect(callback).toHaveBeenCalled(); | ||
| expect(responseMock.ok).toHaveBeenCalled(); | ||
| expect(result.body.data).toEqual({ test: 'data' }); | ||
| }); | ||
|
|
||
| it('passes callback errors through', async () => { | ||
| const callback = jest.fn((_) => { | ||
| throw new Error('test error'); | ||
| }); | ||
|
|
||
| const result = await handleWithCallback( | ||
| adaptorMock as IntegrationsAdaptor, | ||
| responseMock as OpenSearchDashboardsResponseFactory, | ||
| callback | ||
| ); | ||
|
|
||
| expect(callback).toHaveBeenCalled(); | ||
| expect(responseMock.custom).toHaveBeenCalled(); | ||
| expect(result.body).toEqual('test error'); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.