Skip to content

Commit 54f4f6e

Browse files
committed
Merge pull request GoogleCloudPlatform#42 from GoogleCloudPlatform/config-checking
Added user-friendly config checking.
2 parents 325fd9c + 2fe4f3b commit 54f4f6e

File tree

8 files changed

+129
-8
lines changed

8 files changed

+129
-8
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ cache:
3030
- 7-gce/node_modules/
3131

3232
env:
33-
- PATH=$PATH:$HOME/gcloud/google-cloud-sdk/bin GOOGLE_APPLICATION_CREDENTIALS=$TRAVIS_BUILD_DIR/test/encrypted/nodejs-docs-samples.json TEST_BUCKET_NAME=nodejs-docs-samples GCLOUD_PROJECT=nodejs-docs-samples #Other environment variables on same line
33+
- PATH=$PATH:$HOME/gcloud/google-cloud-sdk/bin GOOGLE_APPLICATION_CREDENTIALS=$TRAVIS_BUILD_DIR/test/encrypted/nodejs-docs-samples.json CLOUD_BUCKET=nodejs-docs-samples GCLOUD_PROJECT=nodejs-docs-samples OAUTH_CLIENT_ID=test-id OAUTH_CLIENT_SECRET=test-secret#Other environment variables on same line
3434

3535
before_install:
3636
- if [ ! -d $HOME/gcloud/google-cloud-sdk ]; then

2-structured-data/config.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
'use strict';
1515

16-
module.exports = {
16+
var config = module.exports = {
1717
port: process.env.PORT || 8080,
1818

1919
// dataBackend can be 'datastore', 'cloudsql', or 'mongodb'. Be sure to
@@ -38,3 +38,10 @@ module.exports = {
3838
collection: process.env.MONGO_COLLECTION || 'books'
3939
}
4040
};
41+
42+
var projectId = config.gcloud.projectId;
43+
44+
if (!projectId || projectId === 'your-project-id') {
45+
throw new Error('You must set the GCLOUD_PROJECT env var or add your ' +
46+
'project id to config.js!');
47+
}

3-binary-data/config.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313

1414
'use strict';
1515

16-
17-
module.exports = {
16+
var config = module.exports = {
1817
port: process.env.PORT || 8080,
1918

2019
// dataBackend can be 'datastore', 'cloudsql', or 'mongodb'. Be sure to
@@ -42,3 +41,16 @@ module.exports = {
4241
collection: process.env.MONGO_COLLECTION || 'books'
4342
}
4443
};
44+
45+
var projectId = config.gcloud.projectId;
46+
var cloudStorageBucket = config.cloudStorageBucket;
47+
48+
if (!projectId || projectId === 'your-project-id') {
49+
throw new Error('You must set the GCLOUD_PROJECT env var or add your ' +
50+
'project id to config.js!');
51+
}
52+
53+
if (!cloudStorageBucket || cloudStorageBucket === 'your-bucket-name') {
54+
throw new Error('You must set the CLOUD_BUCKET env var or add your ' +
55+
'bucket name to config.js!');
56+
}

4-auth/config.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
'use strict';
1515

1616

17-
module.exports = {
17+
var config = module.exports = {
1818
port: process.env.PORT || 8080,
1919

2020
// Secret is used by sessions to encrypt the cookie.
@@ -55,3 +55,28 @@ module.exports = {
5555
scopes: ['email', 'profile']
5656
}
5757
};
58+
59+
var projectId = config.gcloud.projectId;
60+
var cloudStorageBucket = config.cloudStorageBucket;
61+
var clientId = config.oauth2.clientId;
62+
var clientSecret = config.oauth2.clientSecret;
63+
64+
if (!projectId || projectId === 'your-project-id') {
65+
throw new Error('You must set the GCLOUD_PROJECT env var or add your ' +
66+
'project id to config.js!');
67+
}
68+
69+
if (!cloudStorageBucket || cloudStorageBucket === 'your-bucket-name') {
70+
throw new Error('You must set the CLOUD_BUCKET env var or add your ' +
71+
'bucket name to config.js!');
72+
}
73+
74+
if (!clientId || clientId === 'your-client-id') {
75+
throw new Error('You must set the OAUTH_CLIENT_ID env var or add your ' +
76+
'client id to config.js!');
77+
}
78+
79+
if (!clientSecret || clientSecret === 'your-client-secret') {
80+
throw new Error('You must set the OAUTH_CLIENT_SECRET env var or add your ' +
81+
'client secret config.js!');
82+
}

5-logging/config.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
'use strict';
1515

1616

17-
module.exports = {
17+
var config = module.exports = {
1818
port: process.env.PORT || 8080,
1919

2020
// Secret is used by sessions to encrypt the cookie.
@@ -55,3 +55,28 @@ module.exports = {
5555
scopes: ['email', 'profile']
5656
}
5757
};
58+
59+
var projectId = config.gcloud.projectId;
60+
var cloudStorageBucket = config.cloudStorageBucket;
61+
var clientId = config.oauth2.clientId;
62+
var clientSecret = config.oauth2.clientSecret;
63+
64+
if (!projectId || projectId === 'your-project-id') {
65+
throw new Error('You must set the GCLOUD_PROJECT env var or add your ' +
66+
'project id to config.js!');
67+
}
68+
69+
if (!cloudStorageBucket || cloudStorageBucket === 'your-bucket-name') {
70+
throw new Error('You must set the CLOUD_BUCKET env var or add your ' +
71+
'bucket name to config.js!');
72+
}
73+
74+
if (!clientId || clientId === 'your-client-id') {
75+
throw new Error('You must set the OAUTH_CLIENT_ID env var or add your ' +
76+
'client id to config.js!');
77+
}
78+
79+
if (!clientSecret || clientSecret === 'your-client-secret') {
80+
throw new Error('You must set the OAUTH_CLIENT_SECRET env var or add your ' +
81+
'client secret config.js!');
82+
}

6-pubsub/config.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
'use strict';
1515

1616

17-
module.exports = {
17+
var config = module.exports = {
1818
port: process.env.PORT || 8080,
1919

2020
// Secret is used by sessions to encrypt the cookie.
@@ -55,3 +55,28 @@ module.exports = {
5555
scopes: ['email', 'profile']
5656
}
5757
};
58+
59+
var projectId = config.gcloud.projectId;
60+
var cloudStorageBucket = config.cloudStorageBucket;
61+
var clientId = config.oauth2.clientId;
62+
var clientSecret = config.oauth2.clientSecret;
63+
64+
if (!projectId || projectId === 'your-project-id') {
65+
throw new Error('You must set the GCLOUD_PROJECT env var or add your ' +
66+
'project id to config.js!');
67+
}
68+
69+
if (!cloudStorageBucket || cloudStorageBucket === 'your-bucket-name') {
70+
throw new Error('You must set the CLOUD_BUCKET env var or add your ' +
71+
'bucket name to config.js!');
72+
}
73+
74+
if (!clientId || clientId === 'your-client-id') {
75+
throw new Error('You must set the OAUTH_CLIENT_ID env var or add your ' +
76+
'client id to config.js!');
77+
}
78+
79+
if (!clientSecret || clientSecret === 'your-client-secret') {
80+
throw new Error('You must set the OAUTH_CLIENT_SECRET env var or add your ' +
81+
'client secret config.js!');
82+
}

7-gce/config.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
'use strict';
1515

1616

17-
module.exports = {
17+
var config = module.exports = {
1818
port: process.env.PORT || 8080,
1919

2020
// Secret is used by sessions to encrypt the cookie.
@@ -55,3 +55,28 @@ module.exports = {
5555
scopes: ['email', 'profile']
5656
}
5757
};
58+
59+
var projectId = config.gcloud.projectId;
60+
var cloudStorageBucket = config.cloudStorageBucket;
61+
var clientId = config.oauth2.clientId;
62+
var clientSecret = config.oauth2.clientSecret;
63+
64+
if (!projectId || projectId === 'your-project-id') {
65+
throw new Error('You must set the GCLOUD_PROJECT env var or add your ' +
66+
'project id to config.js!');
67+
}
68+
69+
if (!cloudStorageBucket || cloudStorageBucket === 'your-bucket-name') {
70+
throw new Error('You must set the CLOUD_BUCKET env var or add your ' +
71+
'bucket name to config.js!');
72+
}
73+
74+
if (!clientId || clientId === 'your-client-id') {
75+
throw new Error('You must set the OAUTH_CLIENT_ID env var or add your ' +
76+
'client id to config.js!');
77+
}
78+
79+
if (!clientSecret || clientSecret === 'your-client-secret') {
80+
throw new Error('You must set the OAUTH_CLIENT_SECRET env var or add your ' +
81+
'client secret config.js!');
82+
}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Tutorial | Folder
2727

2828
* Make sure you're authenticated with the gcloud sdk and your gcloud project
2929
has enabled all the APIs used by these tutorials.
30+
* Make sure you've got the required environment variables set. (Take a look at
31+
the various config.js files.)
3032
* `git clone git@github.com:GoogleCloudPlatform/nodejs-getting-started.git`
3133
* `cd nodejs-getting-started`
3234
* `npm install`

0 commit comments

Comments
 (0)