Skip to content

Commit bb5cd08

Browse files
committed
Merge branch 'master' into patch-1
2 parents 5b1cf98 + 21444b0 commit bb5cd08

35 files changed

+993
-552
lines changed

.DS_Store

-8 KB
Binary file not shown.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,6 @@ lib/
4040

4141
# cache folder
4242
.cache
43+
44+
# Mac DS_Store files
45+
.DS_Store

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).

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"commander": "^2.9.0",
2929
"deepcopy": "^0.6.1",
3030
"express": "^4.13.4",
31+
"gcloud": "^0.28.0",
3132
"mailgun-js": "^0.7.7",
3233
"mime": "^1.3.4",
3334
"mongodb": "~2.1.0",

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: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,52 @@
11
var FilesController = require('../src/Controllers/FilesController').FilesController;
22
var GridStoreAdapter = require("../src/Adapters/Files/GridStoreAdapter").GridStoreAdapter;
33
var S3Adapter = require("../src/Adapters/Files/S3Adapter").S3Adapter;
4+
var GCSAdapter = require("../src/Adapters/Files/GCSAdapter").GCSAdapter;
45
var Config = require("../src/Config");
56

67
var FCTestFactory = require("./FilesControllerTestFactory");
78

89

910
// Small additional tests to improve overall coverage
1011
describe("FilesController",()=>{
11-
12+
1213
// Test the grid store adapter
1314
var gridStoreAdapter = new GridStoreAdapter('mongodb://localhost:27017/parse');
1415
FCTestFactory.testAdapter("GridStoreAdapter", gridStoreAdapter);
15-
16+
1617
if (process.env.S3_ACCESS_KEY && process.env.S3_SECRET_KEY) {
17-
18+
1819
// Test the S3 Adapter
1920
var s3Adapter = new S3Adapter(process.env.S3_ACCESS_KEY, process.env.S3_SECRET_KEY, 'parse.server.tests');
20-
21+
2122
FCTestFactory.testAdapter("S3Adapter",s3Adapter);
22-
23+
2324
// Test S3 with direct access
2425
var s3DirectAccessAdapter = new S3Adapter(process.env.S3_ACCESS_KEY, process.env.S3_SECRET_KEY, 'parse.server.tests', {
2526
directAccess: true
2627
});
27-
28+
2829
FCTestFactory.testAdapter("S3AdapterDirect", s3DirectAccessAdapter);
29-
30+
3031
} else if (!process.env.TRAVIS) {
3132
console.log("set S3_ACCESS_KEY and S3_SECRET_KEY to test S3Adapter")
3233
}
34+
35+
if (process.env.GCP_PROJECT_ID && process.env.GCP_KEYFILE_PATH && process.env.GCS_BUCKET) {
36+
37+
// Test the GCS Adapter
38+
var gcsAdapter = new GCSAdapter(process.env.GCP_PROJECT_ID, process.env.GCP_KEYFILE_PATH, process.env.GCS_BUCKET);
39+
40+
FCTestFactory.testAdapter("GCSAdapter", gcsAdapter);
41+
42+
// Test GCS with direct access
43+
var gcsDirectAccessAdapter = new GCSAdapter(process.env.GCP_PROJECT_ID, process.env.GCP_KEYFILE_PATH, process.env.GCS_BUCKET, {
44+
directAccess: true
45+
});
46+
47+
FCTestFactory.testAdapter("GCSAdapterDirect", gcsDirectAccessAdapter);
48+
49+
} else if (!process.env.TRAVIS) {
50+
console.log("set GCP_PROJECT_ID, GCP_KEYFILE_PATH, and GCS_BUCKET to test GCSAdapter")
51+
}
3352
});

spec/FilesControllerTestFactory.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
1-
21
var FilesController = require('../src/Controllers/FilesController').FilesController;
32
var Config = require("../src/Config");
43

54
var testAdapter = function(name, adapter) {
65
// Small additional tests to improve overall coverage
7-
6+
87
var config = new Config(Parse.applicationId);
98
var filesController = new FilesController(adapter);
109

1110
describe("FilesController with "+name,()=>{
12-
11+
1312
it("should properly expand objects", (done) => {
14-
13+
1514
var result = filesController.expandFilesInObject(config, function(){});
16-
15+
1716
expect(result).toBeUndefined();
18-
17+
1918
var fullFile = {
2019
type: '__type',
2120
url: "http://an.url"
2221
}
23-
22+
2423
var anObject = {
2524
aFile: fullFile
2625
}
2726
filesController.expandFilesInObject(config, anObject);
2827
expect(anObject.aFile.url).toEqual("http://an.url");
29-
28+
3029
done();
31-
})
32-
30+
})
31+
3332
it("should properly create, read, delete files", (done) => {
3433
var filename;
3534
filesController.createFile(config, "file.txt", "hello world").then( (result) => {
@@ -51,14 +50,14 @@ var testAdapter = function(name, adapter) {
5150
console.error(err);
5251
done();
5352
}).then((result) => {
54-
53+
5554
filesController.getFileData(config, filename).then((res) => {
5655
fail("the file should be deleted");
5756
done();
5857
}, (err) => {
59-
done();
58+
done();
6059
});
61-
60+
6261
}, (err) => {
6362
fail("The adapter should delete the file");
6463
console.error(err);

spec/HTTPRequest.spec.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ app.get("/301", function(req, res){
2424

2525
app.post('/echo', function(req, res){
2626
res.json(req.body);
27-
})
27+
});
28+
29+
app.get('/qs', function(req, res){
30+
res.json(req.query);
31+
});
2832

2933
app.listen(13371);
3034

@@ -193,4 +197,35 @@ describe("httpRequest", () => {
193197
}
194198
});
195199
})
200+
201+
it("should params object to query string", (done) => {
202+
httpRequest({
203+
url: httpRequestServer+"/qs",
204+
params: {
205+
foo: "bar"
206+
}
207+
}).then(function(httpResponse){
208+
expect(httpResponse.status).toBe(200);
209+
expect(httpResponse.data).toEqual({foo: "bar"});
210+
done();
211+
}, function(){
212+
fail("should not fail");
213+
done();
214+
})
215+
});
216+
217+
it("should params string to query string", (done) => {
218+
httpRequest({
219+
url: httpRequestServer+"/qs",
220+
params: "foo=bar&foo2=bar2"
221+
}).then(function(httpResponse){
222+
expect(httpResponse.status).toBe(200);
223+
expect(httpResponse.data).toEqual({foo: "bar", foo2: 'bar2'});
224+
done();
225+
}, function(){
226+
fail("should not fail");
227+
done();
228+
})
229+
});
230+
196231
});

0 commit comments

Comments
 (0)