Improve OpenSearchURL credential storing user and password in separate fields from the URL (#2549)
OpenSearch - Improve OpenSearchURL credential storing user and password in separate fields from the URL
This commit is contained in:
parent
76abd20e85
commit
a799ac8087
|
|
@ -10,12 +10,26 @@ class OpenSearchUrl implements INodeCredential {
|
|||
constructor() {
|
||||
this.label = 'OpenSearch'
|
||||
this.name = 'openSearchUrl'
|
||||
this.version = 1.0
|
||||
this.version = 2.0
|
||||
this.inputs = [
|
||||
{
|
||||
label: 'OpenSearch Url',
|
||||
name: 'openSearchUrl',
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
label: 'User',
|
||||
name: 'user',
|
||||
type: 'string',
|
||||
placeholder: '<OPENSEARCH_USERNAME>',
|
||||
optional: true
|
||||
},
|
||||
{
|
||||
label: 'Password',
|
||||
name: 'password',
|
||||
type: 'password',
|
||||
placeholder: '<OPENSEARCH_PASSWORD>',
|
||||
optional: true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class OpenSearch_VectorStores implements INode {
|
|||
constructor() {
|
||||
this.label = 'OpenSearch'
|
||||
this.name = 'openSearch'
|
||||
this.version = 2.0
|
||||
this.version = 3.0
|
||||
this.type = 'OpenSearch'
|
||||
this.icon = 'opensearch.svg'
|
||||
this.category = 'Vector Stores'
|
||||
|
|
@ -87,6 +87,10 @@ class OpenSearch_VectorStores implements INode {
|
|||
|
||||
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
|
||||
const opensearchURL = getCredentialParam('openSearchUrl', credentialData, nodeData)
|
||||
const user = getCredentialParam('user', credentialData, nodeData)
|
||||
const password = getCredentialParam('password', credentialData, nodeData)
|
||||
|
||||
const client = getOpenSearchClient(opensearchURL, user, password)
|
||||
|
||||
const flattenDocs = docs && docs.length ? flatten(docs) : []
|
||||
const finalDocs = []
|
||||
|
|
@ -96,10 +100,6 @@ class OpenSearch_VectorStores implements INode {
|
|||
}
|
||||
}
|
||||
|
||||
const client = new Client({
|
||||
nodes: [opensearchURL]
|
||||
})
|
||||
|
||||
try {
|
||||
await OpenSearchVectorStore.fromDocuments(finalDocs, embeddings, {
|
||||
client,
|
||||
|
|
@ -121,10 +121,10 @@ class OpenSearch_VectorStores implements INode {
|
|||
|
||||
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
|
||||
const opensearchURL = getCredentialParam('openSearchUrl', credentialData, nodeData)
|
||||
const user = getCredentialParam('user', credentialData, nodeData)
|
||||
const password = getCredentialParam('password', credentialData, nodeData)
|
||||
|
||||
const client = new Client({
|
||||
nodes: [opensearchURL]
|
||||
})
|
||||
const client = getOpenSearchClient(opensearchURL, user, password)
|
||||
|
||||
const vectorStore = new OpenSearchVectorStore(embeddings, {
|
||||
client,
|
||||
|
|
@ -142,4 +142,17 @@ class OpenSearch_VectorStores implements INode {
|
|||
}
|
||||
}
|
||||
|
||||
const getOpenSearchClient = (url: string, user?: string, password?: string): Client => {
|
||||
if (user && password) {
|
||||
const urlObj = new URL(url)
|
||||
urlObj.username = user
|
||||
urlObj.password = password
|
||||
url = urlObj.toString()
|
||||
}
|
||||
|
||||
return new Client({
|
||||
nodes: [url]
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = { nodeClass: OpenSearch_VectorStores }
|
||||
|
|
|
|||
Loading…
Reference in New Issue