Skip to content

Commit 63a7c82

Browse files
committed
Improves loading of Push Adapter, fix loading of S3Adapter
- Adds environment variables to configure S3Adapter
1 parent ab11ef1 commit 63a7c82

File tree

3 files changed

+20
-25
lines changed

3 files changed

+20
-25
lines changed

src/Adapters/AdapterLoader.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@ export function loadAdapter(adapter, defaultAdapter, options) {
2828
return loadAdapter(adapter.class, undefined, adapter.options);
2929
} else if (adapter.adapter) {
3030
return loadAdapter(adapter.adapter, undefined, adapter.options);
31-
} else {
32-
// Try to load the defaultAdapter with the options
33-
// The default adapter should throw if the options are
34-
// incompatible
35-
try {
36-
return loadAdapter(defaultAdapter, undefined, adapter);
37-
} catch (e) {};
3831
}
3932
// return the adapter as is as it's unusable otherwise
4033
return adapter;

src/Adapters/Files/S3Adapter.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,33 @@ import requiredParameter from '../../requiredParameter';
88

99
const DEFAULT_S3_REGION = "us-east-1";
1010

11-
function parseS3AdapterOptions(...options) {
12-
if (options.length === 1 && typeof options[0] == "object") {
13-
return options;
11+
function requiredOrFromEnvironment(env, name) {
12+
let environmentVariable = process.env[env];
13+
if (!environmentVariable) {
14+
requiredParameter(`S3Adapter requires an ${name}`);
1415
}
15-
16-
const additionalOptions = options[3] || {};
17-
18-
return {
19-
accessKey: options[0],
20-
secretKey: options[1],
21-
bucket: options[2],
22-
region: additionalOptions.region
16+
return environmentVariable;
17+
}
18+
19+
function fromEnvironmentOrDefault(env, defaultValue) {
20+
let environmentVariable = process.env[env];
21+
if (environmentVariable) {
22+
return environmentVariable;
2323
}
24+
return defaultValue;
2425
}
2526

2627
export class S3Adapter extends FilesAdapter {
2728
// Creates an S3 session.
2829
// Providing AWS access and secret keys is mandatory
2930
// Region and bucket will use sane defaults if omitted
3031
constructor(
31-
accessKey = requiredParameter('S3Adapter requires an accessKey'),
32-
secretKey = requiredParameter('S3Adapter requires a secretKey'),
33-
bucket,
34-
{ region = DEFAULT_S3_REGION,
35-
bucketPrefix = '',
36-
directAccess = false } = {}) {
32+
accessKey = requiredOrFromEnvironment('S3_ACCESS_KEY', 'accessKey'),
33+
secretKey = requiredOrFromEnvironment('S3_SECRET_KEY', 'secretKey'),
34+
bucket = fromEnvironmentOrDefault('S3_BUCKET', undefined),
35+
{ region = fromEnvironmentOrDefault('S3_REGION', DEFAULT_S3_REGION),
36+
bucketPrefix = fromEnvironmentOrDefault('S3_BUCKET_PREFIX', ''),
37+
directAccess = fromEnvironmentOrDefault('S3_DIRECT_ACCESS', false) } = {}) {
3738
super();
3839

3940
this._region = region;

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ function ParseServer({
133133
const filesControllerAdapter = loadAdapter(filesAdapter, () => {
134134
return new GridStoreAdapter(databaseURI);
135135
});
136-
const pushControllerAdapter = loadAdapter(push, ParsePushAdapter);
136+
// Pass the push options too as it works with the default
137+
const pushControllerAdapter = loadAdapter(push && push.adapter, ParsePushAdapter, push);
137138
const loggerControllerAdapter = loadAdapter(loggerAdapter, FileLoggerAdapter);
138139
const emailControllerAdapter = loadAdapter(emailAdapter);
139140
// We pass the options and the base class for the adatper,

0 commit comments

Comments
 (0)