Feature: Support role-based authentication for AWS (#2470)
* Storage, DynamoDBChatMemory - Make AWS credentials optional to support role-based authentication * Lint fix
This commit is contained in:
parent
48ac815f8e
commit
912c8f3d5b
|
|
@ -46,7 +46,8 @@ class DynamoDb_Memory implements INode {
|
||||||
label: 'Connect Credential',
|
label: 'Connect Credential',
|
||||||
name: 'credential',
|
name: 'credential',
|
||||||
type: 'credential',
|
type: 'credential',
|
||||||
credentialNames: ['dynamodbMemoryApi']
|
credentialNames: ['dynamodbMemoryApi'],
|
||||||
|
optional: true
|
||||||
}
|
}
|
||||||
this.inputs = [
|
this.inputs = [
|
||||||
{
|
{
|
||||||
|
|
@ -102,14 +103,19 @@ const initializeDynamoDB = async (nodeData: INodeData, options: ICommonObject):
|
||||||
const accessKeyId = getCredentialParam('accessKey', credentialData, nodeData)
|
const accessKeyId = getCredentialParam('accessKey', credentialData, nodeData)
|
||||||
const secretAccessKey = getCredentialParam('secretAccessKey', credentialData, nodeData)
|
const secretAccessKey = getCredentialParam('secretAccessKey', credentialData, nodeData)
|
||||||
|
|
||||||
const config: DynamoDBClientConfig = {
|
let credentials: DynamoDBClientConfig['credentials'] | undefined
|
||||||
region,
|
if (accessKeyId && secretAccessKey) {
|
||||||
credentials: {
|
credentials = {
|
||||||
accessKeyId,
|
accessKeyId,
|
||||||
secretAccessKey
|
secretAccessKey
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const config: DynamoDBClientConfig = {
|
||||||
|
region,
|
||||||
|
credentials
|
||||||
|
}
|
||||||
|
|
||||||
const client = new DynamoDBClient(config ?? {})
|
const client = new DynamoDBClient(config ?? {})
|
||||||
|
|
||||||
const dynamoDb = new DynamoDBChatMessageHistory({
|
const dynamoDb = new DynamoDBChatMessageHistory({
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,13 @@
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import { DeleteObjectsCommand, GetObjectCommand, ListObjectsV2Command, PutObjectCommand, S3Client } from '@aws-sdk/client-s3'
|
import {
|
||||||
|
DeleteObjectsCommand,
|
||||||
|
GetObjectCommand,
|
||||||
|
ListObjectsV2Command,
|
||||||
|
PutObjectCommand,
|
||||||
|
S3Client,
|
||||||
|
S3ClientConfig
|
||||||
|
} from '@aws-sdk/client-s3'
|
||||||
import { Readable } from 'node:stream'
|
import { Readable } from 'node:stream'
|
||||||
import { getUserHome } from './utils'
|
import { getUserHome } from './utils'
|
||||||
|
|
||||||
|
|
@ -311,14 +318,20 @@ export const getS3Config = () => {
|
||||||
const secretAccessKey = process.env.S3_STORAGE_SECRET_ACCESS_KEY
|
const secretAccessKey = process.env.S3_STORAGE_SECRET_ACCESS_KEY
|
||||||
const region = process.env.S3_STORAGE_REGION
|
const region = process.env.S3_STORAGE_REGION
|
||||||
const Bucket = process.env.S3_STORAGE_BUCKET_NAME
|
const Bucket = process.env.S3_STORAGE_BUCKET_NAME
|
||||||
if (!accessKeyId || !secretAccessKey || !region || !Bucket) {
|
if (!region || !Bucket) {
|
||||||
throw new Error('S3 storage configuration is missing')
|
throw new Error('S3 storage configuration is missing')
|
||||||
}
|
}
|
||||||
const s3Client = new S3Client({
|
|
||||||
credentials: {
|
let credentials: S3ClientConfig['credentials'] | undefined
|
||||||
|
if (accessKeyId && secretAccessKey) {
|
||||||
|
credentials = {
|
||||||
accessKeyId,
|
accessKeyId,
|
||||||
secretAccessKey
|
secretAccessKey
|
||||||
},
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const s3Client = new S3Client({
|
||||||
|
credentials,
|
||||||
region
|
region
|
||||||
})
|
})
|
||||||
return { s3Client, Bucket }
|
return { s3Client, Bucket }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue