-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.ts
50 lines (43 loc) · 1.28 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*!
* Copyright © 2023 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
import { services } from '@architect/functions'
import { Client } from '@opensearch-project/opensearch'
import { AwsSigv4Signer } from '@opensearch-project/opensearch/aws'
import memoizee from 'memoizee'
async function getServiceProps() {
const discoveredServices = await services()
return discoveredServices['nasa_gcn-architect_plugin_search']
}
/** Return the OpenSearch Service name. */
export async function name(): Promise<string | undefined> {
const props = await getServiceProps()
return props.name
}
export const search = memoizee(
async () => {
const props = await getServiceProps()
const node = props?.node
const service = props?.sig4service
if (!node) throw new Error('unknown endpoint')
const options = { node }
if (service) {
const region = process.env.AWS_REGION
if (!region)
throw new Error('environment variable AWS_REGION must be defined')
Object.assign(
options,
AwsSigv4Signer({
region,
service,
})
)
}
return new Client(options)
},
{ promise: true }
)