Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Prev Previous commit
Next Next commit
feat(s3): configure from standard environment variables
  • Loading branch information
Antoine Monnet committed Feb 4, 2025
commit 5276b3d5f36a2c332070afa553c744a0e6d204d0
19 changes: 12 additions & 7 deletions src/drivers/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,28 @@ export default defineDriver((options: S3DriverOptions) => {
let _awsClient: AwsClient;
const getAwsClient = () => {
if (!_awsClient) {
if (!options.accessKeyId) {
const accessKeyId =
options.accessKeyId || globalThis.process?.env?.AWS_ACCESS_KEY_ID;
if (!accessKeyId) {
throw createRequiredError(DRIVER_NAME, "accessKeyId");
}
if (!options.secretAccessKey) {
const secretAccessKey =
options.secretAccessKey ||
globalThis.process?.env?.AWS_SECRET_ACCESS_KEY;
if (!secretAccessKey) {
throw createRequiredError(DRIVER_NAME, "secretAccessKey");
}
if (!options.endpoint) {
const region = options.region || globalThis.process?.env?.AWS_REGION;
throw createRequiredError(DRIVER_NAME, "endpoint");
}
if (!options.region) {
if (!region) {
throw createRequiredError(DRIVER_NAME, "region");
}
_awsClient = new AwsClient({
service: "s3",
accessKeyId: options.accessKeyId,
secretAccessKey: options.secretAccessKey,
region: options.region,
accessKeyId,
secretAccessKey,
region,
});
}
return _awsClient;
Expand Down