Skip to content
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

Improve OpenSearchURL credential storing user and password in separate fields from the URL #2549

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion packages/components/credentials/OpenSearchUrl.credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
{
HenryHengZJ marked this conversation as resolved.
Show resolved Hide resolved
label: 'Password',
name: 'password',
type: 'password',
placeholder: '<OPENSEARCH_PASSWORD>',
optional: true
}
]
}
Expand Down
29 changes: 21 additions & 8 deletions packages/components/nodes/vectorstores/OpenSearch/OpenSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 = []
Expand All @@ -96,10 +100,6 @@ class OpenSearch_VectorStores implements INode {
}
}

const client = new Client({
nodes: [opensearchURL]
})

try {
await OpenSearchVectorStore.fromDocuments(finalDocs, embeddings, {
client,
Expand All @@ -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,
Expand All @@ -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