Skip to content

Commit

Permalink
Merge pull request #56 from GoogleCloudPlatform/pubsub2
Browse files Browse the repository at this point in the history
Added Pub/Sub samples.
  • Loading branch information
jmdobry committed Jan 26, 2016
2 parents 29ff2aa + 5a6ecef commit f105cc8
Show file tree
Hide file tree
Showing 20 changed files with 621 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ services:
- docker

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 TEST_PROJECT_ID=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 TEST_BUCKET_NAME=nodejs-docs-samples GCLOUD_PROJECT=nodejs-docs-samples #Other environment variables on same line

before_install:
- if [ ! -d $HOME/gcloud/google-cloud-sdk ]; then
Expand Down
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This repository holds Node.js samples used throughout [cloud.google.com]().

* [Google App Engine](#google-app-engine)
* [Google Cloud Logging](#google-cloud-logging)
* [Google Cloud Pub/Sub](#google-cloud-pubsub)
* [Google Cloud Storage](#google-cloud-storage)
* [Google Prediction API](#google-prediction-api)
* [Other Example Apps](#other-example-apps)
Expand Down Expand Up @@ -75,6 +76,11 @@ __Other Examples__
- Writing logs sample - [Source code][logging_write_1] | [Documentation][logging_write_2]
- Exporting logs sample - [Source code][logging_export_1] | [Documentation][logging_export_2]

## Google Cloud Pub/Sub

- Subscriber/Publisher sample - [Source code][pubsub_subscriber_1] | [Documentation][pubsub_subscriber_2]
- IAM sample - [Source code][pubsub_iam_1] | [Documentation][pubsub_iam_2]

## Google Cloud Storage

- Auth sample - [Source code][storage_1] | [Documentation][storage_2]
Expand Down Expand Up @@ -110,7 +116,7 @@ See [CONTRIBUTING.md](https://github.com/GoogleCloudPlatform/nodejs-docs-samples
1. `npm install`
1. Start Redis
1. Start Memcached
1. Set the `TEST_PROJECT_ID` environment variable to id of your project
1. Set the `GCLOUD_PROJECT` environment variable to id of your project
1. Set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to the path to
a service account file. You can download one from your Google project's
"permissions" page.
Expand Down Expand Up @@ -240,15 +246,20 @@ See [LICENSE](https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/ma
[aestaticfiles_1]: https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/master/appengine/static-files

[datastore_1]: https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/master/datastore/tasks.js
[datastore_2]: https://cloud-dot-devsite.googleplex.com/datastore/docs/concepts/overview
[datastore_2]: https://cloud.google.com/datastore/docs/concepts/overview

[logging_read_1]: https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/master/logging/list.js
[logging_read_2]: https://cloud-dot-devsite.googleplex.com/logging/docs/api/tasks/authorization
[logging_read_2]: https://cloud.google.com/logging/docs/api/tasks/authorization
[logging_write_1]: https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/master/logging/write.js
[logging_write_2]: https://cloud.google.com/logging/docs/api/tasks/creating-logs
[logging_export_1]: https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/master/logging/export.js
[logging_export_2]: https://cloud.google.com/logging/docs/api/tasks/exporting-logs

[pubsub_subscriber_1]: https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/master/pubsub/subscription.js
[pubsub_subscriber_2]: https://cloud.google.com/pubsub/subscriber
[pubsub_iam_1]: https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/master/pubsub/iam.js
[pubsub_iam_2]: https://cloud.google.com/pubsub/access_control

[storage_1]: https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/master/storage/authSample.js
[storage_2]: https://cloud.google.com/storage/docs/authentication#acd-examples

Expand Down
2 changes: 1 addition & 1 deletion appengine/datastore/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ app.enable('trust proxy');
var dataset = gcloud.datastore.dataset({
// This environment variable is set by app.yaml when running on GAE, but will
// need to be manually set when running locally.
projectId: process.env.GCLOUD_PROJECT || process.env.TEST_PROJECT_ID
projectId: process.env.GCLOUD_PROJECT
});

app.get('/', function(req, res, next) {
Expand Down
2 changes: 1 addition & 1 deletion appengine/pubsub/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var messages = [];
var PUBSUB_VERIFICATION_TOKEN = process.env.PUBSUB_VERIFICATION_TOKEN;

var pubsub = gcloud.pubsub({
projectId: process.env.GCLOUD_PROJECT || process.env.TEST_PROJECT_ID
projectId: process.env.GCLOUD_PROJECT
});

var topic = pubsub.topic(process.env.PUBSUB_TOPIC);
Expand Down
2 changes: 1 addition & 1 deletion appengine/storage/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var multer = require('multer')({
// but will need to be manually set when running locally.
// The storage client is used to communicate with Google Cloud Storage
var storage = gcloud.storage({
projectId: process.env.GCLOUD_PROJECT || process.env.TEST_PROJECT_ID
projectId: process.env.GCLOUD_PROJECT
});

// A bucket is a container for objects (files).
Expand Down
2 changes: 1 addition & 1 deletion datastore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ These samples require two environment variables to be set:

- `GOOGLE_APPLICATION_CREDENTIALS` - Path to a service account file. You can
download one from your Google project's "permissions" page.
- `TEST_PROJECT_ID` - Id of your Google project.
- `GCLOUD_PROJECT` - Id of your Google project.

## Run a sample

Expand Down
4 changes: 2 additions & 2 deletions datastore/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
var input = process.argv.splice(2);
var command = input.shift();

var projectId = process.env.DATASTORE_PROJECT_ID || process.env.TEST_PROJECT_ID;
var projectId = process.env.DATASTORE_PROJECT_ID || process.env.GCLOUD_PROJECT;
if (!projectId) {
throw new Error('TEST_PROJECT_ID environment variable required.');
throw new Error('GCLOUD_PROJECT environment variable required.');
}
var keyFile = process.env.DATASTORE_KEYFILE ||
process.env.GOOGLE_APPLICATION_CREDENTIALS;
Expand Down
2 changes: 1 addition & 1 deletion logging/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ These samples require two environment variables to be set:

- `GOOGLE_APPLICATION_CREDENTIALS` - Path to a service account file. You can
download one from your Google project's "permissions" page.
- `TEST_PROJECT_ID` - Id of your Google project.
- `GCLOUD_PROJECT` - Id of your Google project.

## Run a sample

Expand Down
16 changes: 5 additions & 11 deletions logging/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,13 @@
'use strict';

// [START setup]
// You must set these environment variables to run this sample
var projectId = process.env.TEST_PROJECT_ID;
var keyFilename = process.env.GOOGLE_APPLICATION_CREDENTIALS;
// You must set the GOOGLE_APPLICATION_CREDENTIALS and GCLOUD_PROJECT
// environment variables to run this sample
var projectId = process.env.GCLOUD_PROJECT;

// If you don't set the environment variables, then you can modify this file
// to set the values
projectId = projectId || '<your-project-id>';
keyFilename = keyFilename || '/path/to/keyfile.json';

// Provide projectId and authentication to gcloud
// Initialize gcloud
var gcloud = require('gcloud')({
projectId: projectId,
keyFilename: keyFilename
projectId: projectId
});

// Get a reference to the logging component
Expand Down
16 changes: 5 additions & 11 deletions logging/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,14 @@

// [START list]
// [START auth]
// You must set these environment variables to run this sample
var projectId = process.env.TEST_PROJECT_ID;
var keyFilename = process.env.GOOGLE_APPLICATION_CREDENTIALS;

// If you don't set the environment variables, then you can modify this file
// to set the values
projectId = projectId || '<your-project-id>';
keyFilename = keyFilename || '/path/to/keyfile.json';
// You must set the GOOGLE_APPLICATION_CREDENTIALS and GCLOUD_PROJECT
// environment variables to run this sample
var projectId = process.env.GCLOUD_PROJECT;

// [START require]
// Provide projectId and authentication to gcloud
// Initialize gcloud
var gcloud = require('gcloud')({
projectId: projectId,
keyFilename: keyFilename
projectId: projectId
});
// [END require]
// [END auth]
Expand Down
16 changes: 5 additions & 11 deletions logging/write.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,13 @@

// [START write]
// [START setup]
// You must set these environment variables to run this sample
var projectId = process.env.TEST_PROJECT_ID;
var keyFilename = process.env.GOOGLE_APPLICATION_CREDENTIALS;
// You must set the GOOGLE_APPLICATION_CREDENTIALS and GCLOUD_PROJECT
// environment variables to run this sample
var projectId = process.env.GCLOUD_PROJECT;

// If you don't set the environment variables, then you can modify this file
// to set the values
projectId = projectId || '<your-project-id>';
keyFilename = keyFilename || '/path/to/keyfile.json';

// Provide projectId and authentication to gcloud
// Initialize gcloud
var gcloud = require('gcloud')({
projectId: projectId,
keyFilename: keyFilename
projectId: projectId
});

// Get a reference to the logging component
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@
"cover": "istanbul cover --hook-run-in-context node_modules/mocha/bin/_mocha -- --timeout 10000 --recursive",
"coveralls": "cat ./coverage/lcov.info | node_modules/.bin/coveralls",
"deps_datastore": "cd datastore; npm i; cd ../..",
"deps_pubsub": "cd pubsub; npm i; cd ../..",
"deps_storage": "cd storage; npm i; cd ../..",
"deps_prediction": "cd prediction; npm i; cd ../..",
"deps_logging": "cd logging; npm i; cd ../..",
"deps_express": "cd appengine/express; npm i; cd ../..",
"deps_sendgrid": "cd appengine/sendgrid; npm i; cd ../..; cd computeengine/sendgrid; npm i; cd ../..",
"deps_memcached": "cd appengine/express-memcached-session && npm i && cd ../..",
"pretest_geddy": "cd appengine/geddy; npm i geddy; GEDDY_SECRET=config/secrets.json; [[ -f $GEDDY_SECRET ]] || echo '{}' > $GEDDY_SECRET && node node_modules/.bin/geddy gen secret; cd ../..;",
"pretest": "npm run deps_datastore; npm run deps_storage; npm run deps_prediction; npm run deps_logging; npm run deps_memcached; npm run deps_express; npm run deps_sendgrid; npm run pretest_geddy",
"pretest": "npm run deps_datastore; npm run deps_storage; npm run deps_pubsub; npm run deps_prediction; npm run deps_logging; npm run deps_memcached; npm run deps_express; npm run deps_sendgrid; npm run pretest_geddy",
"test": "npm run jshint && npm run cover"
},
"devDependencies": {
Expand Down
25 changes: 25 additions & 0 deletions pubsub/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## Pub/Sub Samples

These samples require two environment variables to be set:

- `GOOGLE_APPLICATION_CREDENTIALS` - Path to a service account file. You can
download one from your Google project's "permissions" page.
- `GCLOUD_PROJECT` - Id of your Google project.

## Run a sample

Install dependencies:

npm install

To print available commands:

npm run

Execute a sample:

npm run <sample>

Example:

npm run subscription
Loading

0 comments on commit f105cc8

Please sign in to comment.