Skip to content

Commit

Permalink
Repo Migration (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukesneeringer authored and Ace Nassri committed Nov 21, 2022
1 parent b4d56c1 commit 7c7fb62
Show file tree
Hide file tree
Showing 13 changed files with 163 additions and 100 deletions.
3 changes: 3 additions & 0 deletions compute/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
rules:
no-console: off
43 changes: 24 additions & 19 deletions compute/mailjet.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,30 @@
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 || '<your-mailjet-api-key',
pass: process.env.MAILJET_API_SECRET || '<your-mailjet-api-secret>'
}
}));
var transport = mailer.createTransport(
smtp({
host: 'in.mailjet.com',
port: 2525,
auth: {
user: process.env.MAILJET_API_KEY || '<your-mailjet-api-key',
pass: process.env.MAILJET_API_SECRET || '<your-mailjet-api-secret>',
},
})
);

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);
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]
25 changes: 8 additions & 17 deletions compute/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,26 @@
"private": true,
"license": "Apache-2.0",
"author": "Google Inc.",
"repository": {
"type": "git",
"url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
},
"repository": "googleapis/nodejs-compute",
"engines": {
"node": ">=4.3.2"
"node": ">=4.0.0"
},
"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"
"test": "repo-tools test run --cmd npm -- run all-test"
},
"dependencies": {
"@google-cloud/compute": "0.8.0",
"googleapis": "20.1.0",
"nodemailer": "4.0.1",
"googleapis": "22.2.0",
"nodemailer": "4.3.1",
"nodemailer-smtp-transport": "2.7.4",
"sendgrid": "5.2.2"
"sendgrid": "5.2.3"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "1.4.17",
"ava": "0.21.0",
"@google-cloud/nodejs-repo-tools": "2.1.0",
"ava": "0.23.0",
"proxyquire": "1.8.0"
},
"cloud-repo-tools": {
"requiresKeyFile": true,
"requiresProjectId": true
}
}
42 changes: 42 additions & 0 deletions compute/quickstart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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.

/* eslint-disable no-unused-vars */

'use strict';

// [START compute_engine_quickstart]
// Imports the Google Cloud client library
const Compute = require('@google-cloud/compute');

// Creates a client
const compute = new Compute();

// Create a new VM using the latest OS image of your choice.
const zone = compute.zone('us-central1-a');
const name = 'ubuntu-http';

zone
.createVM(name, {os: 'ubuntu'}, data => {
// `operation` lets you check the status of long-running tasks.
const vm = data[0];
const operation = data[1];
return operation.promise();
})
.then(() => {
// Virtual machine created!
})
.catch(err => {
console.error('ERROR:', err);
});
// [END compute_engine_quickstart]
27 changes: 16 additions & 11 deletions compute/sendgrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,24 @@ 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.'
}]
}
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) {
Sendgrid.API(request, function(error, response) {
if (error) {
console.log('Mail not sent; see error message below.');
} else {
Expand Down
5 changes: 5 additions & 0 deletions compute/system-test/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
rules:
node/no-unpublished-require: off
node/no-unsupported-features: off
no-empty: off
2 changes: 1 addition & 1 deletion compute/system-test/vms.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test.before(tools.checkCredentials);
test.beforeEach(tools.stubConsole);
test.afterEach.always(tools.restoreConsole);

test.cb(`should retrieve vms`, (t) => {
test.cb(`should retrieve vms`, t => {
vmsExample.main((err, result) => {
t.ifError(err);
t.truthy(result);
Expand Down
2 changes: 1 addition & 1 deletion compute/system-test/vms_api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test.before(tools.checkCredentials);
test.beforeEach(tools.stubConsole);
test.afterEach.always(tools.restoreConsole);

test.cb('should retrieve vms', (t) => {
test.cb('should retrieve vms', t => {
vmsExample.main((err, result) => {
t.ifError(err);
t.truthy(result);
Expand Down
5 changes: 5 additions & 0 deletions compute/test/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
rules:
node/no-unpublished-require: off
node/no-unsupported-features: off
no-empty: off
18 changes: 9 additions & 9 deletions compute/test/mailjet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,35 @@ process.env.MAILJET_API_SECRET = `bar`;
test.beforeEach(tools.stubConsole);
test.afterEach.always(tools.restoreConsole);

test.cb(`should send an email`, (t) => {
test.cb(`should send an email`, t => {
proxyquire(`../mailjet`, {
nodemailer: {
createTransport: (arg) => {
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.`
text: `Hello!\n\nThis a test email from Node.js.`,
});
cb(null, `done`);
t.end();
}
},
};
}
},
},
'nodemailer-smtp-transport': (options) => {
'nodemailer-smtp-transport': options => {
t.deepEqual(options, {
host: `in.mailjet.com`,
port: 2525,
auth: {
user: `foo`,
pass: `bar`
}
pass: `bar`,
},
});
return `test`;
}
},
});
});
36 changes: 20 additions & 16 deletions compute/test/sendgrid.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,35 @@ process.env.SENDGRID_API_KEY = `foo`;
test.beforeEach(tools.stubConsole);
test.afterEach.always(tools.restoreConsole);

test.cb(`should send an email`, (t) => {
test.cb(`should send an email`, t => {
proxyquire(`../sendgrid`, {
sendgrid: (key) => {
sendgrid: key => {
t.is(key, `foo`);
return {
emptyRequest: (x) => x,
API: (request, cb) => {
emptyRequest: x => x,
API: request => {
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.`
}]
}
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();
}
},
};
}
},
});
});
16 changes: 8 additions & 8 deletions compute/vms.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@
// 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');
const Compute = require('@google-cloud/compute');
// [END auth]

// [START initialize]
// Instantiate a compute client
var compute = Compute();
// Creates a client
const compute = new Compute();
// [END initialize]

// [START list]
/**
* @param {Function} callback Callback function.
*/
function getVmsExample (callback) {
function getVmsExample(callback) {
// In this example we only want one VM per page
var options = {
maxResults: 1
const options = {
maxResults: 1,
};
compute.getVMs(options, function (err, vms) {
compute.getVMs(options, (err, vms) => {
if (err) {
return callback(err);
}
Expand All @@ -51,7 +51,7 @@ function getVmsExample (callback) {
// [END complete]

// Run the examples
exports.main = function (cb) {
exports.main = cb => {
getVmsExample(cb);
};

Expand Down
Loading

0 comments on commit 7c7fb62

Please sign in to comment.