Skip to content

Commit 2c51440

Browse files
committed
Added tests to adapter loader, cleaned up README, renamed to GCS_BUCKET from GCS_BUCKET_NAME
1 parent 0f00d65 commit 2c51440

File tree

4 files changed

+50
-22
lines changed

4 files changed

+50
-22
lines changed

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,14 @@ PARSE_SERVER_MAX_UPLOAD_SIZE
135135

136136
```
137137

138-
##### Configuring S3 Adapter
138+
##### Configuring File Adapters
139+
Parse Server allows developers to choose from several options when hosting files: the `GridStoreAdapter`, which backed by MongoDB; the `S3Adapter`, which is backed by [Amazon S3](https://aws.amazon.com/s3/); or the `GCSAdapter`, which is backed by [Google Cloud Storage](https://cloud.google.com/storage/).
139140

140-
You can use the following environment variable setup the S3 adapter
141+
`GridStoreAdapter` is used by default and requires no setup, but if you're interested in using S3 or GCS, additional configuration information is available below.
142+
143+
###### Configuring `S3Adapter`
144+
145+
You can use the following environment variable setup to enable the S3 adapter:
141146

142147
```js
143148
S3_ACCESS_KEY
@@ -149,6 +154,19 @@ S3_DIRECT_ACCESS
149154

150155
```
151156

157+
###### Configuring `GCSAdapter`
158+
159+
You can use the following environment variable setup to enable the GCS adapter:
160+
161+
```js
162+
GCP_PROJECT_ID
163+
GCP_KEYFILE_PATH
164+
GCS_BUCKET
165+
GCS_BUCKET_PREFIX
166+
GCS_DIRECT_ACCESS
167+
168+
```
169+
152170
## Contributing
153171

154172
We really want Parse to be yours, to see it grow and thrive in the open source community. Please see the [Contributing to Parse Server guide](CONTRIBUTING.md).

spec/AdapterLoader.spec.js

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,72 +3,73 @@ var loadAdapter = require("../src/Adapters/AdapterLoader").loadAdapter;
33
var FilesAdapter = require("../src/Adapters/Files/FilesAdapter").default;
44
var ParsePushAdapter = require("../src/Adapters/Push/ParsePushAdapter");
55
var S3Adapter = require("../src/Adapters/Files/S3Adapter").default;
6+
var GCSAdapter = require("../src/Adapters/Files/GCSAdapter").default;
67

78
describe("AdapterLoader", ()=>{
8-
9+
910
it("should instantiate an adapter from string in object", (done) => {
1011
var adapterPath = require('path').resolve("./spec/MockAdapter");
1112

1213
var adapter = loadAdapter({
1314
adapter: adapterPath,
1415
options: {
15-
key: "value",
16+
key: "value",
1617
foo: "bar"
1718
}
1819
});
19-
20+
2021
expect(adapter instanceof Object).toBe(true);
2122
expect(adapter.options.key).toBe("value");
2223
expect(adapter.options.foo).toBe("bar");
2324
done();
2425
});
25-
26+
2627
it("should instantiate an adapter from string", (done) => {
2728
var adapterPath = require('path').resolve("./spec/MockAdapter");
2829
var adapter = loadAdapter(adapterPath);
29-
30+
3031
expect(adapter instanceof Object).toBe(true);
3132
done();
3233
});
33-
34+
3435
it("should instantiate an adapter from string that is module", (done) => {
3536
var adapterPath = require('path').resolve("./src/Adapters/Files/FilesAdapter");
3637
var adapter = loadAdapter({
3738
adapter: adapterPath
3839
});
39-
40+
4041
expect(adapter instanceof FilesAdapter).toBe(true);
4142
done();
4243
});
43-
44+
4445
it("should instantiate an adapter from function/Class", (done) => {
4546
var adapter = loadAdapter({
4647
adapter: FilesAdapter
4748
});
4849
expect(adapter instanceof FilesAdapter).toBe(true);
4950
done();
5051
});
51-
52+
5253
it("should instantiate the default adapter from Class", (done) => {
5354
var adapter = loadAdapter(null, FilesAdapter);
5455
expect(adapter instanceof FilesAdapter).toBe(true);
5556
done();
5657
});
57-
58+
5859
it("should use the default adapter", (done) => {
5960
var defaultAdapter = new FilesAdapter();
6061
var adapter = loadAdapter(null, defaultAdapter);
6162
expect(adapter instanceof FilesAdapter).toBe(true);
6263
done();
6364
});
64-
65+
6566
it("should use the provided adapter", (done) => {
6667
var originalAdapter = new FilesAdapter();
6768
var adapter = loadAdapter(originalAdapter);
6869
expect(adapter).toBe(originalAdapter);
6970
done();
7071
});
71-
72+
7273
it("should fail loading an improperly configured adapter", (done) => {
7374
var Adapter = function(options) {
7475
if (!options.foo) {
@@ -79,14 +80,14 @@ describe("AdapterLoader", ()=>{
7980
param: "key",
8081
doSomething: function() {}
8182
};
82-
83+
8384
expect(() => {
8485
var adapter = loadAdapter(adapterOptions, Adapter);
8586
expect(adapter).toEqual(adapterOptions);
8687
}).not.toThrow("foo is required for that adapter");
8788
done();
8889
});
89-
90+
9091
it("should load push adapter from options", (done) => {
9192
var options = {
9293
ios: {
@@ -100,7 +101,7 @@ describe("AdapterLoader", ()=>{
100101
}).not.toThrow();
101102
done();
102103
});
103-
104+
104105
it("should load S3Adapter from direct passing", (done) => {
105106
var s3Adapter = new S3Adapter("key", "secret", "bucket")
106107
expect(() => {
@@ -109,4 +110,13 @@ describe("AdapterLoader", ()=>{
109110
}).not.toThrow();
110111
done();
111112
})
113+
114+
it("should load GCSAdapter from direct passing", (done) => {
115+
var gcsAdapter = new GCSAdapter("projectId", "path/to/keyfile", "bucket")
116+
expect(() => {
117+
var adapter = loadAdapter(gcsAdapter, FilesAdapter);
118+
expect(adapter).toBe(gcsAdapter);
119+
}).not.toThrow();
120+
done();
121+
})
112122
});

spec/FilesController.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,21 @@ describe("FilesController",()=>{
3232
console.log("set S3_ACCESS_KEY and S3_SECRET_KEY to test S3Adapter")
3333
}
3434

35-
if (process.env.GCP_PROJECT_ID && process.env.GCP_KEYFILE_PATH && process.env.GCS_BUCKET_NAME) {
35+
if (process.env.GCP_PROJECT_ID && process.env.GCP_KEYFILE_PATH && process.env.GCS_BUCKET) {
3636

3737
// Test the GCS Adapter
38-
var gcsAdapter = new GCSAdapter(process.env.GCP_PROJECT_ID, process.env.GCP_KEYFILE_PATH, process.env.GCS_BUCKET_NAME);
38+
var gcsAdapter = new GCSAdapter(process.env.GCP_PROJECT_ID, process.env.GCP_KEYFILE_PATH, process.env.GCS_BUCKET);
3939

4040
FCTestFactory.testAdapter("GCSAdapter", gcsAdapter);
4141

4242
// Test GCS with direct access
43-
var gcsDirectAccessAdapter = new GCSAdapter(process.env.GCP_PROJECT_ID, process.env.GCP_KEYFILE_PATH, process.env.GCS_BUCKET_NAME, {
43+
var gcsDirectAccessAdapter = new GCSAdapter(process.env.GCP_PROJECT_ID, process.env.GCP_KEYFILE_PATH, process.env.GCS_BUCKET, {
4444
directAccess: true
4545
});
4646

4747
FCTestFactory.testAdapter("GCSAdapterDirect", gcsDirectAccessAdapter);
4848

4949
} else if (!process.env.TRAVIS) {
50-
console.log("set GCP_PROJECT_ID, GCP_KEYFILE_PATH, and GCS_BUCKET_NAME to test GCSAdapter")
50+
console.log("set GCP_PROJECT_ID, GCP_KEYFILE_PATH, and GCS_BUCKET to test GCSAdapter")
5151
}
5252
});

src/Adapters/Files/GCSAdapter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class GCSAdapter extends FilesAdapter {
2828
constructor(
2929
projectId = requiredOrFromEnvironment('GCP_PROJECT_ID', 'projectId'),
3030
keyFilename = requiredOrFromEnvironment('GCP_KEYFILE_PATH', 'keyfile path'),
31-
bucket = requiredOrFromEnvironment('GCS_BUCKET_NAME', 'bucket name'),
31+
bucket = requiredOrFromEnvironment('GCS_BUCKET', 'bucket name'),
3232
{ bucketPrefix = fromEnvironmentOrDefault('GCS_BUCKET_PREFIX', ''),
3333
directAccess = fromEnvironmentOrDefault('GCS_DIRECT_ACCESS', false) } = {}) {
3434
super();

0 commit comments

Comments
 (0)