diff --git a/README.md b/README.md index 96e1fe43615..343bcb17ddb 100644 --- a/README.md +++ b/README.md @@ -202,7 +202,7 @@ Google infrastructure. View the [Compute Engine Node.js samples][compute_samples]. [compute_docs]: https://cloud.google.com/compute/docs/ -[compute_samples]: computeengine +[compute_samples]: https://github.com/googleapis/nodejs-compute/tree/master/samples #### Google Container Engine diff --git a/circle.yml b/circle.yml index bdd2194d095..ffda52610ee 100644 --- a/circle.yml +++ b/circle.yml @@ -88,7 +88,6 @@ deployment: - node scripts/build "auth" - node scripts/build "appengine/pubsub" - node scripts/build "bigquery" - - node scripts/build "computeengine" - node scripts/build "containerengine/hello-world" - node scripts/build "datastore" - node scripts/build "debugger" diff --git a/computeengine/README.md b/computeengine/README.md index 3328f78d1ee..4ec37efab2b 100644 --- a/computeengine/README.md +++ b/computeengine/README.md @@ -1,115 +1,5 @@ -Google Cloud Platform logo +Samples for the [Google Compute Engine API Node.js Client][client] have moved to +[github.com/googleapis/nodejs-compute/tree/master/samples/][samples]. -# Google Compute Engine Node.js Samples - -[Compute Engine][compute_docs] lets you create and run virtual machines on -Google infrastructure. - -[compute_docs]: https://cloud.google.com/compute/docs/ - -## Table of Contents - -* [Setup](#setup) -* [Samples](#samples) - * [Sending mail with Sendgrid](#sending-mail-with-sendgrid) - * [Sending mail with Mailjet](#sending-mail-with-mailjet) - * [Listing instances (recommended)](#listing-instances-recommended) - * [Listing instances](#listing-instances) -* [Running the tests](#running-the-tests) - -## Setup - -1. Read [Prerequisites][prereq] and [How to run a sample][run] first. -1. Install dependencies: - - With `npm`: - - npm install - - With `yarn`: - - yarn install - -[prereq]: ../README.md#prerequisities -[run]: ../README.md#how-to-run-a-sample - -## Samples - -### Sending mail with Sendgrid - -View the [documentation][sendgrid_docs] or the [source code][sendgrid_code]. - -__Run the sample:__ - -1. Set the `SENDGRID_API_KEY` environment variable: - - export SENDGRID_API_KEY= - -1. Start the server: - - node sendgrid - -1. Open http://localhost:8080 in your browser - -[sendgrid_docs]: https://cloud.google.com/compute/docs/tutorials/sending-mail/using-sendgrid -[sendgrid_code]: sendgrid.js - -### Sending mail with Mailjet - -View the [documentation][mailjet_docs] or the [source code][mailjet_code]. - -__Run the sample:__ - -1. Set the `MAILJET_API_KEY` environment variable: - - export MAILJET_API_KEY= - -1. Set the `MAILJET_API_SECRET` environment variable: - - export MAILJET_API_SECRET= - -1. Start the server: - - node mailjet - -1. Open http://localhost:8080 in your browser - -[mailjet_docs]: https://cloud.google.com/compute/docs/tutorials/sending-mail/using-mailjet -[mailjet_code]: mailjet.js - -### Listing instances (recommended) - -View the [documentation][vms_docs] or the [source code][vms_code]. - -__Run the sample:__ - - node vms - -[vms_docs]: https://cloud.google.com/compute/docs/tutorials/nodejs-guide -[vms_code]: vms.js - -### Listing instances - -View the [documentation][vms_api_docs] or the [source code][vms_api_code]. - -__Run the sample:__ - - node vms_api - -[vms_api_docs]: https://cloud.google.com/compute/docs/tutorials/nodejs-guide -[vms_api_code]: vms_api.js - -## Running the tests - -1. Set the `GCLOUD_PROJECT` and `GOOGLE_APPLICATION_CREDENTIALS` environment - variables. - -1. Run the tests: - - With `npm`: - - npm test - - With `yarn`: - - yarn test +[client]: https://github.com/googleapis/nodejs-compute +[samples]: https://github.com/googleapis/nodejs-compute/tree/master/samples diff --git a/computeengine/mailjet.js b/computeengine/mailjet.js deleted file mode 100644 index 8fc796009e1..00000000000 --- a/computeengine/mailjet.js +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright 2017, Google, Inc. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict'; - -// [START send] -var mailer = require('nodemailer'); -var smtp = require('nodemailer-smtp-transport'); - -var transport = mailer.createTransport(smtp({ - host: 'in.mailjet.com', - port: 2525, - auth: { - user: process.env.MAILJET_API_KEY || '' - } -})); - -transport.sendMail({ - from: 'ANOTHER_EMAIL@ANOTHER_EXAMPLE.COM', // From address - to: 'EMAIL@EXAMPLE.COM', // To address - subject: 'test email from Node.js on Google Cloud Platform', // Subject - text: 'Hello!\n\nThis a test email from Node.js.' // Content -}, function (err, json) { - if (err) { - console.log(err); - } else { - console.log(json); - } -}); -// [END send] diff --git a/computeengine/package.json b/computeengine/package.json deleted file mode 100644 index 8703aae31e8..00000000000 --- a/computeengine/package.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "name": "nodejs-docs-samples-computeengine", - "version": "0.0.1", - "private": true, - "license": "Apache-2.0", - "author": "Google Inc.", - "repository": { - "type": "git", - "url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git" - }, - "engines": { - "node": ">=4.3.2" - }, - "scripts": { - "lint": "samples lint", - "pretest": "npm run lint", - "unit-test": "ava -T 20s --verbose test/*.test.js", - "system-test": "ava -T 20s --verbose system-test/*.test.js", - "all-test": "npm run unit-test && npm run system-test", - "test": "samples test run --cmd npm -- run all-test" - }, - "dependencies": { - "@google-cloud/compute": "0.8.0", - "googleapis": "20.1.0", - "nodemailer": "4.0.1", - "nodemailer-smtp-transport": "2.7.4", - "sendgrid": "5.2.2" - }, - "devDependencies": { - "@google-cloud/nodejs-repo-tools": "1.4.17", - "ava": "0.21.0", - "proxyquire": "1.8.0" - }, - "cloud-repo-tools": { - "requiresKeyFile": true, - "requiresProjectId": true - } -} diff --git a/computeengine/sendgrid.js b/computeengine/sendgrid.js deleted file mode 100644 index c2202e9ea2e..00000000000 --- a/computeengine/sendgrid.js +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2015-2016, Google, Inc. -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -// [START send] -// This sample is based off of https://www.npmjs.com/package/sendgrid#without-mail-helper-class -var Sendgrid = require('sendgrid')( - process.env.SENDGRID_API_KEY || '' -); - -var request = Sendgrid.emptyRequest({ - method: 'POST', - path: '/v3/mail/send', - body: { - personalizations: [{ - to: [{ email: 'to_email@example.com' }], - subject: 'Sendgrid test email from Node.js on Google Cloud Platform' - }], - from: { email: 'from_email@example.com' }, - content: [{ - type: 'text/plain', - value: 'Hello!\n\nThis a Sendgrid test email from Node.js on Google Cloud Platform.' - }] - } -}); - -Sendgrid.API(request, function (error, response) { - if (error) { - console.log('Mail not sent; see error message below.'); - } else { - console.log('Mail sent successfully!'); - } - console.log(response); -}); -// [END send] diff --git a/computeengine/system-test/vms.test.js b/computeengine/system-test/vms.test.js deleted file mode 100644 index 4b93ac1fd97..00000000000 --- a/computeengine/system-test/vms.test.js +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Copyright 2017, Google, Inc. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict'; - -const test = require(`ava`); -const tools = require(`@google-cloud/nodejs-repo-tools`); - -const vmsExample = require(`../vms`); - -test.before(tools.checkCredentials); -test.beforeEach(tools.stubConsole); -test.afterEach.always(tools.restoreConsole); - -test.cb(`should retrieve vms`, (t) => { - vmsExample.main((err, result) => { - t.ifError(err); - t.truthy(result); - t.true(Array.isArray(result)); - t.end(); - }); -}); diff --git a/computeengine/system-test/vms_api.test.js b/computeengine/system-test/vms_api.test.js deleted file mode 100644 index 44ac723a989..00000000000 --- a/computeengine/system-test/vms_api.test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright 2017, Google, Inc. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict'; - -const test = require(`ava`); -const tools = require(`@google-cloud/nodejs-repo-tools`); - -const vmsExample = require(`../vms_api`); - -test.before(tools.checkCredentials); -test.beforeEach(tools.stubConsole); -test.afterEach.always(tools.restoreConsole); - -test.cb('should retrieve vms', (t) => { - vmsExample.main((err, result) => { - t.ifError(err); - t.truthy(result); - t.end(); - }); -}); diff --git a/computeengine/test/mailjet.test.js b/computeengine/test/mailjet.test.js deleted file mode 100644 index 1ccbc0f30f9..00000000000 --- a/computeengine/test/mailjet.test.js +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Copyright 2017, Google, Inc. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict'; - -const proxyquire = require(`proxyquire`).noPreserveCache(); -const test = require(`ava`); -const tools = require(`@google-cloud/nodejs-repo-tools`); - -process.env.MAILJET_API_KEY = `foo`; -process.env.MAILJET_API_SECRET = `bar`; - -test.beforeEach(tools.stubConsole); -test.afterEach.always(tools.restoreConsole); - -test.cb(`should send an email`, (t) => { - proxyquire(`../mailjet`, { - nodemailer: { - createTransport: (arg) => { - t.is(arg, `test`); - return { - sendMail: (payload, cb) => { - t.deepEqual(payload, { - from: `ANOTHER_EMAIL@ANOTHER_EXAMPLE.COM`, - to: `EMAIL@EXAMPLE.COM`, - subject: `test email from Node.js on Google Cloud Platform`, - text: `Hello!\n\nThis a test email from Node.js.` - }); - cb(null, `done`); - t.end(); - } - }; - } - }, - 'nodemailer-smtp-transport': (options) => { - t.deepEqual(options, { - host: `in.mailjet.com`, - port: 2525, - auth: { - user: `foo`, - pass: `bar` - } - }); - return `test`; - } - }); -}); diff --git a/computeengine/test/sendgrid.test.js b/computeengine/test/sendgrid.test.js deleted file mode 100644 index df3aacc2298..00000000000 --- a/computeengine/test/sendgrid.test.js +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Copyright 2017, Google, Inc. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict'; - -const proxyquire = require(`proxyquire`).noPreserveCache(); -const test = require(`ava`); -const tools = require(`@google-cloud/nodejs-repo-tools`); - -process.env.SENDGRID_API_KEY = `foo`; - -test.beforeEach(tools.stubConsole); -test.afterEach.always(tools.restoreConsole); - -test.cb(`should send an email`, (t) => { - proxyquire(`../sendgrid`, { - sendgrid: (key) => { - t.is(key, `foo`); - return { - emptyRequest: (x) => x, - API: (request, cb) => { - t.deepEqual(request, { - method: `POST`, - path: `/v3/mail/send`, - body: { - personalizations: [{ - to: [{ email: `to_email@example.com` }], - subject: `Sendgrid test email from Node.js on Google Cloud Platform` - }], - from: { email: `from_email@example.com` }, - content: [{ - type: `text/plain`, - value: `Hello!\n\nThis a Sendgrid test email from Node.js on Google Cloud Platform.` - }] - } - }); - t.end(); - } - }; - } - }); -}); diff --git a/computeengine/vms.js b/computeengine/vms.js deleted file mode 100644 index 85ff8caf742..00000000000 --- a/computeengine/vms.js +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Copyright 2017, Google, Inc. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [START complete] -'use strict'; - -// [START auth] -// By default, the client will authenticate using the service account file -// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use -// the project specified by the GCLOUD_PROJECT environment variable. See -// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication -var Compute = require('@google-cloud/compute'); -// [END auth] - -// [START initialize] -// Instantiate a compute client -var compute = Compute(); -// [END initialize] - -// [START list] -/** - * @param {Function} callback Callback function. - */ -function getVmsExample (callback) { - // In this example we only want one VM per page - var options = { - maxResults: 1 - }; - compute.getVMs(options, function (err, vms) { - if (err) { - return callback(err); - } - - console.log('VMs:', vms); - callback(null, vms); - }); -} -// [END list] -// [END complete] - -// Run the examples -exports.main = function (cb) { - getVmsExample(cb); -}; - -if (module === require.main) { - exports.main(console.log); -} diff --git a/computeengine/vms_api.js b/computeengine/vms_api.js deleted file mode 100644 index cc89289b818..00000000000 --- a/computeengine/vms_api.js +++ /dev/null @@ -1,86 +0,0 @@ -/** - * Copyright 2017, Google, Inc. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict'; - -// [START complete] -// [START initialize] -var google = require('googleapis'); -var compute = google.compute('v1'); -// [END initialize] - -// [START auth] -function auth (callback) { - google.auth.getApplicationDefault(function (err, authClient) { - if (err) { - return callback(err); - } - - // The createScopedRequired method returns true when running on GAE or a - // local developer machine. In that case, the desired scopes must be passed - // in manually. When the code is running in GCE or GAE Flexible, the scopes - // are pulled from the GCE metadata server. - // See https://cloud.google.com/compute/docs/authentication for more - // information. - if (authClient.createScopedRequired && authClient.createScopedRequired()) { - // Scopes can be specified either as an array or as a single, - // space-delimited string. - authClient = authClient.createScoped([ - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/compute', - 'https://www.googleapis.com/auth/compute.readonly' - ]); - } - callback(null, authClient); - }); -} -// [END auth] - -// [START list] -/** - * @param {Function} callback Callback function. - */ -function getVmsExample (callback) { - auth(function (err, authClient) { - if (err) { - return callback(err); - } - // Retrieve the vms - compute.instances.aggregatedList({ - auth: authClient, - project: process.env.GCLOUD_PROJECT, - // In this example we only want one VM per page - maxResults: 1 - }, function (err, vms) { - if (err) { - return callback(err); - } - - console.log('VMs:', vms); - callback(null, vms); - }); - }); -} -// [END list] -// [END complete] - -// Run the examples -exports.main = function (cb) { - getVmsExample(cb); -}; - -if (module === require.main) { - exports.main(console.log); -}