Skip to content

Commit

Permalink
Merge pull request #852 from GoogleCloudPlatform/iot-snippets
Browse files Browse the repository at this point in the history
Updates sample to work as commandline
  • Loading branch information
gguuss authored Sep 13, 2017
2 parents e0ffe50 + 29b51be commit bd89eb9
Show file tree
Hide file tree
Showing 7 changed files with 965 additions and 358 deletions.
121 changes: 107 additions & 14 deletions iot/api-client/manager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ PubSub topic for Cloud IoT as described in [the parent README](../README.md).
Manually install [the provided client library](https://cloud.google.com/iot/resources/java/cloud-iot-core-library.jar)
for Cloud IoT Core to Maven:

mvn install:install-file -Dfile=cloud-iot-core-library.jar -DgroupId=com.google.apis \
mvn install:install-file -Dfile=cloud-iot-core-library.jar -DgroupId=com.example.apis \
-DartifactId=google-api-services-cloudiot -Dversion=v1beta1-rev20170418-1.22.0-SNAPSHOT \
-Dpackaging=jar

Expand All @@ -21,23 +21,116 @@ mvn clean compile assembly:single

## Running the sample

The following command summarizes the sample usage:
The following description summarizes the sample usage:

mvn exec:java \
-Dexec.mainClass="com.google.cloud.iot.examples.DeviceRegistryExample" \
-Dexec.args="-project_id=my-project-id \
-pubsub_topic=projects/my-project-id/topics/my-topic-id \
-ec_public_key_file=/path/to/ec_public.pem \
-rsa_certificate_file=/path/to/rsa_cert.pem"
usage: DeviceRegistryExample [--cloud_region <arg>] --command <arg>
[--ec_public_key_file <arg>] --project_id <arg> --pubsub_topic
<arg> --registry_name <arg> [--rsa_certificate_file <arg>]

Cloud IoT Core Commandline Example (Device / Registry management):

--cloud_region <arg> GCP cloud region.
--command <arg> Command to run:
create-iot-topic
create-rsa
create-es
create-unauth
create-registry
delete-device
delete-registry
get-device
get-registry
list-devices
list-registries
patch-device-es
patch-device-rsa
--ec_public_key_file <arg> Path to ES256 public key file.
--project_id <arg> GCP cloud project name.
--pubsub_topic <arg> Pub/Sub topic to create registry in.
--registry_name <arg> Name for your Device Registry.
--rsa_certificate_file <arg> Path to RS256 certificate file.

https://cloud.google.com/iot-core

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:

mvn exec:java \
-Dexec.mainClass="com.google.cloud.iot.examples.DeviceRegistryExample" \
-Dexec.args="-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"

## Usage Examples

Create a PubSub topic, `hello-java`, for the project, `blue-jet-123`:

java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
com.example.cloud.iot.examples.DeviceRegistryExample \
-project_id=blue-jet-123 -pubsub_topic=hello-java
-command=create-iot-topic

Create an ES device:

java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
com.example.cloud.iot.examples.DeviceRegistryExample \
-project_id=blue-jet-123 -pubsub_topic=hello-java \
-registry_name=hello-java -ec_public_key_file ../ec_public.pem \
-device_id="java-device-0" -command=create-es

Create an RSA device:

java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
com.example.cloud.iot.examples.DeviceRegistryExample \
-project_id=blue-jet-123 -pubsub_topic=hello-java \
-registry_name=hello-java -rsa_certificate_file ../rsa_cert.pem \
-device_id="java-device-1" -command=create-rsa

Create a device without authorization:

java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
com.example.cloud.iot.examples.DeviceRegistryExample \
-project_id=blue-jet-123 -pubsub_topic=hello-java \
-registry_name=hello-java -device_id="java-device-3" \
-command=create-unauth

Create a device registry:

java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
com.example.cloud.iot.examples.DeviceRegistryExample \
-project_id=blue-jet-123 -pubsub_topic=hello-java \
-registry_name=hello-java -command=create-registry \

Get a device registry:

java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
com.example.cloud.iot.examples.DeviceRegistryExample \
-project_id=blue-jet-123 -pubsub_topic=hello-java \
-registry_name=hello-java -command=get-registry

List devices:

java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
com.example.cloud.iot.examples.DeviceRegistryExample \
-project_id=blue-jet-123 -pubsub_topic=hello-java \
-registry_name=hello-java -command=list-devices

List device registries:

java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
com.example.cloud.iot.examples.DeviceRegistryExample \
-project_id=blue-jet-123 -pubsub_topic=hello-java \
-registry_name=hello-java -command=list-registries

Patch a device with ES:

java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
com.example.cloud.iot.examples.DeviceRegistryExample \
-project_id=blue-jet-123 -pubsub_topic=hello-java \
-registry_name=hello-java -ec_public_key_file ../ec_public.pem \
-device_id="java-device-1" -command=patch-device-es

Patch a device with RSA:

java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
com.example.cloud.iot.examples.DeviceRegistryExample \
-project_id=blue-jet-123 -pubsub_topic=hello-java \
-registry_name=hello-java -rsa_certificate_file ../rsa_cert.pem \
-device_id="java-device-0" -command=patch-device-rsa
19 changes: 19 additions & 0 deletions iot/api-client/manager/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
<artifactId>google-api-services-cloudiot</artifactId>
<version>v1beta1-rev20170418-1.22.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-pubsub</artifactId>
<version>0.21.1-beta</version>
</dependency>
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client</artifactId>
Expand All @@ -57,6 +62,20 @@
<artifactId>commons-cli</artifactId>
<version>1.3</version>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<version>0.34</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Loading

0 comments on commit bd89eb9

Please sign in to comment.