Skip to content

Commit

Permalink
Merge pull request #332 from ashmeet-kandhari/#1322_s3_use_iam_role_fix
Browse files Browse the repository at this point in the history
fixed oc-s3-storage-adapter to use IAM roles
  • Loading branch information
ricardo-devis-agullo authored Feb 24, 2023
2 parents 5cea04b + 0d46eb8 commit 59915ab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
3 changes: 2 additions & 1 deletion packages/oc-s3-storage-adapter/__test__/s3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const validOptions = {
region: 'region-test',
key: 'test-key',
secret: 'test-secret',
path: '/'
path: '/',
componentsDir: 'components'
};

test('should expose the correct methods', () => {
Expand Down
20 changes: 12 additions & 8 deletions packages/oc-s3-storage-adapter/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { S3 } from '@aws-sdk/client-s3';
import { S3, S3ClientConfig } from '@aws-sdk/client-s3';
import {
NodeHttpHandler,
NodeHttpHandlerOptions
Expand Down Expand Up @@ -95,19 +95,23 @@ export default function s3Adapter(conf: S3Config): StorageAdapter {
requestHandler = new NodeHttpHandler(handlerOptions);
}

const getClient = () =>
new S3({
const getClient = () => {
const configOpts: S3ClientConfig = {
logger: conf.debug ? (console.log as any) : undefined,
tls: sslEnabled,
credentials: {
accessKeyId: accessKeyId!,
secretAccessKey: secretAccessKey!
},
requestHandler,
endpoint: conf.endpoint,
region,
forcePathStyle: s3ForcePathStyle
});
}
if (accessKeyId && secretAccessKey) {
configOpts.credentials = {
accessKeyId,
secretAccessKey
};
}
return new S3(configOpts);
};

const getFile = async (filePath: string, force = false) => {
const getFromAws = async () => {
Expand Down

0 comments on commit 59915ab

Please sign in to comment.