Skip to content

Commit

Permalink
Merge pull request GoogleCloudPlatform#42 from GoogleCloudPlatform/co…
Browse files Browse the repository at this point in the history
…nfig-checking

Added user-friendly config checking.
  • Loading branch information
jmdobry committed Feb 5, 2016
2 parents 325fd9c + 2fe4f3b commit 54f4f6e
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ cache:
- 7-gce/node_modules/

env:
- 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
- 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

before_install:
- if [ ! -d $HOME/gcloud/google-cloud-sdk ]; then
Expand Down
9 changes: 8 additions & 1 deletion 2-structured-data/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

'use strict';

module.exports = {
var config = module.exports = {
port: process.env.PORT || 8080,

// dataBackend can be 'datastore', 'cloudsql', or 'mongodb'. Be sure to
Expand All @@ -38,3 +38,10 @@ module.exports = {
collection: process.env.MONGO_COLLECTION || 'books'
}
};

var projectId = config.gcloud.projectId;

if (!projectId || projectId === 'your-project-id') {
throw new Error('You must set the GCLOUD_PROJECT env var or add your ' +
'project id to config.js!');
}
16 changes: 14 additions & 2 deletions 3-binary-data/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@

'use strict';


module.exports = {
var config = module.exports = {
port: process.env.PORT || 8080,

// dataBackend can be 'datastore', 'cloudsql', or 'mongodb'. Be sure to
Expand Down Expand Up @@ -42,3 +41,16 @@ module.exports = {
collection: process.env.MONGO_COLLECTION || 'books'
}
};

var projectId = config.gcloud.projectId;
var cloudStorageBucket = config.cloudStorageBucket;

if (!projectId || projectId === 'your-project-id') {
throw new Error('You must set the GCLOUD_PROJECT env var or add your ' +
'project id to config.js!');
}

if (!cloudStorageBucket || cloudStorageBucket === 'your-bucket-name') {
throw new Error('You must set the CLOUD_BUCKET env var or add your ' +
'bucket name to config.js!');
}
27 changes: 26 additions & 1 deletion 4-auth/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
'use strict';


module.exports = {
var config = module.exports = {
port: process.env.PORT || 8080,

// Secret is used by sessions to encrypt the cookie.
Expand Down Expand Up @@ -55,3 +55,28 @@ module.exports = {
scopes: ['email', 'profile']
}
};

var projectId = config.gcloud.projectId;
var cloudStorageBucket = config.cloudStorageBucket;
var clientId = config.oauth2.clientId;
var clientSecret = config.oauth2.clientSecret;

if (!projectId || projectId === 'your-project-id') {
throw new Error('You must set the GCLOUD_PROJECT env var or add your ' +
'project id to config.js!');
}

if (!cloudStorageBucket || cloudStorageBucket === 'your-bucket-name') {
throw new Error('You must set the CLOUD_BUCKET env var or add your ' +
'bucket name to config.js!');
}

if (!clientId || clientId === 'your-client-id') {
throw new Error('You must set the OAUTH_CLIENT_ID env var or add your ' +
'client id to config.js!');
}

if (!clientSecret || clientSecret === 'your-client-secret') {
throw new Error('You must set the OAUTH_CLIENT_SECRET env var or add your ' +
'client secret config.js!');
}
27 changes: 26 additions & 1 deletion 5-logging/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
'use strict';


module.exports = {
var config = module.exports = {
port: process.env.PORT || 8080,

// Secret is used by sessions to encrypt the cookie.
Expand Down Expand Up @@ -55,3 +55,28 @@ module.exports = {
scopes: ['email', 'profile']
}
};

var projectId = config.gcloud.projectId;
var cloudStorageBucket = config.cloudStorageBucket;
var clientId = config.oauth2.clientId;
var clientSecret = config.oauth2.clientSecret;

if (!projectId || projectId === 'your-project-id') {
throw new Error('You must set the GCLOUD_PROJECT env var or add your ' +
'project id to config.js!');
}

if (!cloudStorageBucket || cloudStorageBucket === 'your-bucket-name') {
throw new Error('You must set the CLOUD_BUCKET env var or add your ' +
'bucket name to config.js!');
}

if (!clientId || clientId === 'your-client-id') {
throw new Error('You must set the OAUTH_CLIENT_ID env var or add your ' +
'client id to config.js!');
}

if (!clientSecret || clientSecret === 'your-client-secret') {
throw new Error('You must set the OAUTH_CLIENT_SECRET env var or add your ' +
'client secret config.js!');
}
27 changes: 26 additions & 1 deletion 6-pubsub/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
'use strict';


module.exports = {
var config = module.exports = {
port: process.env.PORT || 8080,

// Secret is used by sessions to encrypt the cookie.
Expand Down Expand Up @@ -55,3 +55,28 @@ module.exports = {
scopes: ['email', 'profile']
}
};

var projectId = config.gcloud.projectId;
var cloudStorageBucket = config.cloudStorageBucket;
var clientId = config.oauth2.clientId;
var clientSecret = config.oauth2.clientSecret;

if (!projectId || projectId === 'your-project-id') {
throw new Error('You must set the GCLOUD_PROJECT env var or add your ' +
'project id to config.js!');
}

if (!cloudStorageBucket || cloudStorageBucket === 'your-bucket-name') {
throw new Error('You must set the CLOUD_BUCKET env var or add your ' +
'bucket name to config.js!');
}

if (!clientId || clientId === 'your-client-id') {
throw new Error('You must set the OAUTH_CLIENT_ID env var or add your ' +
'client id to config.js!');
}

if (!clientSecret || clientSecret === 'your-client-secret') {
throw new Error('You must set the OAUTH_CLIENT_SECRET env var or add your ' +
'client secret config.js!');
}
27 changes: 26 additions & 1 deletion 7-gce/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
'use strict';


module.exports = {
var config = module.exports = {
port: process.env.PORT || 8080,

// Secret is used by sessions to encrypt the cookie.
Expand Down Expand Up @@ -55,3 +55,28 @@ module.exports = {
scopes: ['email', 'profile']
}
};

var projectId = config.gcloud.projectId;
var cloudStorageBucket = config.cloudStorageBucket;
var clientId = config.oauth2.clientId;
var clientSecret = config.oauth2.clientSecret;

if (!projectId || projectId === 'your-project-id') {
throw new Error('You must set the GCLOUD_PROJECT env var or add your ' +
'project id to config.js!');
}

if (!cloudStorageBucket || cloudStorageBucket === 'your-bucket-name') {
throw new Error('You must set the CLOUD_BUCKET env var or add your ' +
'bucket name to config.js!');
}

if (!clientId || clientId === 'your-client-id') {
throw new Error('You must set the OAUTH_CLIENT_ID env var or add your ' +
'client id to config.js!');
}

if (!clientSecret || clientSecret === 'your-client-secret') {
throw new Error('You must set the OAUTH_CLIENT_SECRET env var or add your ' +
'client secret config.js!');
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Tutorial | Folder

* Make sure you're authenticated with the gcloud sdk and your gcloud project
has enabled all the APIs used by these tutorials.
* Make sure you've got the required environment variables set. (Take a look at
the various config.js files.)
* `git clone [email protected]:GoogleCloudPlatform/nodejs-getting-started.git`
* `cd nodejs-getting-started`
* `npm install`
Expand Down

0 comments on commit 54f4f6e

Please sign in to comment.