From 5ee67042c1ed5dea7c729e7cf55216bcd390c460 Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Tue, 18 Jul 2017 15:52:02 -0700 Subject: [PATCH 1/4] Add example queries to samples --- bigquery/queries.js | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/bigquery/queries.js b/bigquery/queries.js index 89ce7475c2..9de2a6b46c 100644 --- a/bigquery/queries.js +++ b/bigquery/queries.js @@ -16,8 +16,8 @@ 'use strict'; // [START bigquery_simple_app_all] -// [START bigquery_simple_app_print] function printResult (rows) { + // [START bigquery_simple_app_print] console.log('Query Results:'); rows.forEach(function (row) { let str = ''; @@ -29,25 +29,26 @@ function printResult (rows) { } console.log(str); }); + // [END bigquery_simple_app_print] } -// [END bigquery_simple_app_print] - -// [START bigquery_simple_app_query] -const sqlQuery = `SELECT - corpus, COUNT(*) as unique_words -FROM publicdata.samples.shakespeare -GROUP BY - corpus -ORDER BY - unique_words DESC LIMIT 10;`; function queryShakespeare (projectId) { + // [START bigquery_simple_app_query] // Imports the Google Cloud client library const BigQuery = require('@google-cloud/bigquery'); // The project ID to use, e.g. "your-project-id" // const projectId = "your-project-id"; + // The SQL query to run + const sqlQuery = `SELECT + corpus, COUNT(*) as unique_words + FROM publicdata.samples.shakespeare + GROUP BY + corpus + ORDER BY + unique_words DESC LIMIT 10;`; + // Instantiates a client const bigquery = BigQuery({ projectId: projectId @@ -69,8 +70,8 @@ function queryShakespeare (projectId) { .catch((err) => { console.error('ERROR:', err); }); + // [END bigquery_simple_app_query] } -// [END bigquery_simple_app_query] // [END bigquery_simple_app_all] function syncQuery (sqlQuery, projectId) { @@ -81,6 +82,9 @@ function syncQuery (sqlQuery, projectId) { // The project ID to use, e.g. "your-project-id" // const projectId = "your-project-id"; + // The SQL query to run, e.g. "SELECT * FROM publicdata.samples.natality LIMIT 5;" + // const sqlQuery = "SELECT * FROM publicdata.samples.natality LIMIT 5;"; + // Instantiates a client const bigquery = BigQuery({ projectId: projectId @@ -115,6 +119,9 @@ function asyncQuery (sqlQuery, projectId) { // The project ID to use, e.g. "your-project-id" // const projectId = "your-project-id"; + // The SQL query to run, e.g. "SELECT * FROM publicdata.samples.natality LIMIT 5;" + // const sqlQuery = "SELECT * FROM publicdata.samples.natality LIMIT 5;"; + // Instantiates a client const bigquery = BigQuery({ projectId: projectId From 9d6306024800fd3c4c6b639ac9260a45b3c21cf8 Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Tue, 18 Jul 2017 16:20:31 -0700 Subject: [PATCH 2/4] Add more example parameters --- bigquery/tables.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bigquery/tables.js b/bigquery/tables.js index a282e0f4f0..653c5acd94 100644 --- a/bigquery/tables.js +++ b/bigquery/tables.js @@ -97,6 +97,9 @@ function listTables (datasetId, projectId) { // The project ID to use, e.g. "your-project-id" // const projectId = "your-project-id"; + // The ID of the dataset to list tables in, e.g. "my_dataset" + // const datasetId = "my_dataset"; + // Instantiates a client const bigquery = BigQuery({ projectId: projectId @@ -401,6 +404,10 @@ function insertRowsAsStream (datasetId, tableId, rows, projectId) { // The ID of the table into which data should be inserted, e.g. "my_table" // const tableId = "my_table"; + // The rows to insert into the table + // Customize this object to match your table's schema + // const rows = [{name: "Tom", age: 30}, {name: "Jane", age: 32}]; + // Instantiates a client const bigquery = BigQuery({ projectId: projectId From cdb89d9de24f334d8d176e1eb807a59af9fa39e3 Mon Sep 17 00:00:00 2001 From: Gus Class Date: Thu, 20 Jul 2017 20:25:24 -0400 Subject: [PATCH 3/4] Updates README and cleans up package.json (#431) --- iot/manager/README.md | 70 +++++++++++++++++++++++----------------- iot/manager/package.json | 23 +++++++++++-- 2 files changed, 61 insertions(+), 32 deletions(-) diff --git a/iot/manager/README.md b/iot/manager/README.md index bb9d5c4e17..f29821be08 100644 --- a/iot/manager/README.md +++ b/iot/manager/README.md @@ -15,33 +15,43 @@ Run the following command to install the library dependencies for NodeJS: # Running the sample -The following command summarizes the sample usage: - - Usage: cloudiot_device_manager_example [options] - - Example Google Cloud IoT device manager integration - - Options: - - -h, --help output usage information - --project_id GCP cloud project name. - --pubsub_topic Cloud Pub/Sub topic to use. - --api_key Your API key. - --ec_public_key_file Path to EC public key. - --rsa_certificate_file Path to RSA certificate file. - --cloud_region GCP cloud region. - --service_account_json Path to service account JSON file. - --registry_id Custom registry id. If not provided, a unique registry id will be generated. - -For example, if your project ID is `blue-jet-123`, your service account -credentials are stored in your home folder in creds.json and you have generated -your credentials using the shell script provided in the parent folder, you can -run the sample as: - - node cloudiot_device_manager_example.js \ - --service_account_json=$HOME/creds.json \ - --api_key=YOUR_CLIENT_ID \ - --project_id=blue-jet-123 \ - --pubsub_topic=projects/blue-jet-123/topics/device-events \ - --ec_public_key_file=../ec_public.pem \ - --rsa_certificate_file=../rsa_cert.pem +Commands: + createRsa256Device Creates an RSA256 device. + createEs256Device Creates an ES256 device. + createUnauthDevice Creates a device without authorization. + createRegistry Creates a device registry. + createIotTopic Creates and configures a PubSub topic for Cloud IoT Core. + setupIotTopic Configures the PubSub topic for Cloud IoT Core. + deleteDevice Deletes a device from the device registry. + clearRegistry !!Be careful! Removes all devices and then deletes a device + registry!! + deleteRegistry Deletes a device registry. + getDevice Retrieves device info given a device ID. + listDevices Lists the devices in a given registry. + patchEs256 Patches a device with ES256 authorization credentials. + patchRsa256 Patches a device with RSA256 authentication credentials. + +Options: + --apiKey, -a The API key used for discoverying the API. [string] + --projectId, -p The Project ID to use. Defaults to the value of the GCLOUD_PROJECT or GOOGLE_CLOUD_PROJECT + environment variables. [string] + --serviceAccount, -s The path to your service credentials JSON. [string] + --help Show help [boolean] + --cloudRegion, -c [string] [default: "us-central1"] + +Examples: + node manager.js createEs256Device my-es-device my-registry ../ec_public.pem --apiKey=abc123zz + node manager.js createRegistry my-registry my-iot-topic --service_account_json=$HOME/creds_iot.json + --api_key=abc123zz --project_id=my-project-id + node manager.js createRsa256Device my-rsa-device my-registry ../rsa_cert.pem --apiKey=abc123zz + node manager.js createUnauthDevice my-device my-registry + node manager.js deleteDevice my-device my-registry + node manager.js deleteRegistry my-device my-registry + node manager.js getDevice my-device my-registry + node manager.js listDevices my-node-registry + node manager.js patchRsa256 my-device my-registry ../rsa_cert.pem + node manager.js patchEs256 my-device my-registry ../ec_public.pem + node manager.js setupTopic my-iot-topic --service_account_json=$HOME/creds_iot.json --api_key=abc123zz + --project_id=my-project-id + +For more information, see https://cloud.google.com/iot-core/docs diff --git a/iot/manager/package.json b/iot/manager/package.json index 90200ce762..a5c7f3d903 100644 --- a/iot/manager/package.json +++ b/iot/manager/package.json @@ -2,12 +2,31 @@ "name": "nodejs-docs-samples-iot-manager", "version": "0.0.1", "description": "Example of Cloud IoT device administration", - "main": "cloudiot-device-manager-example.js", + "main": "manager.js", + "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", + "system-test": "ava -T 3m --verbose system-test/*.test.js", + "test": "npm run system-test" + }, "dependencies": { "@google-cloud/nodejs-repo-tools": "^1.4.15", "@google-cloud/pubsub": "0.12.0", - "ava": "^0.20.0", "googleapis": "19.0.0", "yargs": "^8.0.2" + }, + "devDependencies": { + "@google-cloud/nodejs-repo-tools": "1.4.15", + "ava": "0.20.0", + "uuid": "3.1.0" } } From 42e33283a0c506b8464dc29bea3ebca151f7c73a Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Fri, 21 Jul 2017 11:04:05 -0700 Subject: [PATCH 4/4] Add build client sample --- bigquery/queries.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bigquery/queries.js b/bigquery/queries.js index 9de2a6b46c..3bcfa8348c 100644 --- a/bigquery/queries.js +++ b/bigquery/queries.js @@ -113,19 +113,21 @@ function syncQuery (sqlQuery, projectId) { function asyncQuery (sqlQuery, projectId) { // [START bigquery_async_query] + // [START bigquery_build_client] // Imports the Google Cloud client library const BigQuery = require('@google-cloud/bigquery'); // The project ID to use, e.g. "your-project-id" // const projectId = "your-project-id"; - // The SQL query to run, e.g. "SELECT * FROM publicdata.samples.natality LIMIT 5;" - // const sqlQuery = "SELECT * FROM publicdata.samples.natality LIMIT 5;"; - // Instantiates a client const bigquery = BigQuery({ projectId: projectId }); + // [END bigquery_build_client] + + // The SQL query to run, e.g. "SELECT * FROM publicdata.samples.natality LIMIT 5;" + // const sqlQuery = "SELECT * FROM publicdata.samples.natality LIMIT 5;"; // Query options list: https://cloud.google.com/bigquery/docs/reference/v2/jobs/query const options = {