-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #547 from Swiddis/osints/main
Stub router for integrations project
- Loading branch information
Showing
8 changed files
with
453 additions
and
5 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,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 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 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 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'; | ||
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.