33 S3Client ,
44} from "@aws-sdk/client-s3" ;
55import { getSignedUrl } from "@aws-sdk/s3-request-presigner" ;
6+ import { AwsCredentialIdentity } from "@smithy/types" ;
67import { Nullable } from "@webui/common/utility-types" ;
78import fp from "fastify-plugin" ;
89
@@ -19,11 +20,17 @@ class S3Manager {
1920 /**
2021 * @param region
2122 * @param [profile]
23+ * @param [credentials]
2224 */
23- constructor ( region : string , profile : Nullable < string > ) {
25+ constructor (
26+ region : string ,
27+ profile : Nullable < string > ,
28+ credentials : Nullable < AwsCredentialIdentity >
29+ ) {
2430 this . #s3Client = new S3Client ( {
2531 region,
2632 ...( ( null !== profile ) && { profile} ) ,
33+ ...( ( null !== credentials ) && { credentials} ) ,
2734 } ) ;
2835 }
2936
@@ -60,25 +67,34 @@ class S3Manager {
6067
6168declare module "fastify" {
6269 interface FastifyInstance {
63- S3Manager ?: S3Manager ;
70+ StreamFilesS3Manager ?: S3Manager ;
6471 }
6572}
6673
6774export default fp (
6875 ( fastify ) => {
69- const region = settings . StreamFilesS3Region ;
70- const profile = settings . StreamFilesS3Profile ;
76+ const region = settings . StreamFilesS3Region as Nullable < string > ;
77+ const profile = settings . StreamFilesS3Profile as Nullable < string > ;
7178
7279 // Only decorate if the region is set (i.e. s3 support is configured in package)
73- // Disable no-unnecessary-condition since linter doesn't understand that settings
74- // values are not hardcoded.
75- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
7680 if ( null !== region && "" !== region ) {
81+ const {
82+ CLP_STREAM_OUTPUT_AWS_ACCESS_KEY_ID : accessKeyId ,
83+ CLP_STREAM_OUTPUT_AWS_SECRET_ACCESS_KEY : secretAccessKey ,
84+ } = fastify . config ;
85+
7786 fastify . log . info (
7887 { region, profile} ,
79- "Initializing S3Manager"
88+ "Initializing StreamFilesS3Manager"
89+ ) ;
90+ const credentials = ( accessKeyId && secretAccessKey ) ?
91+ { accessKeyId, secretAccessKey} :
92+ null ;
93+
94+ fastify . decorate (
95+ "StreamFilesS3Manager" ,
96+ new S3Manager ( region , profile , credentials )
8097 ) ;
81- fastify . decorate ( "S3Manager" , new S3Manager ( region , profile ) ) ;
8298 }
8399 } ,
84100) ;
0 commit comments