Skip to content

Commit

Permalink
Merge branch 'master' into tswast-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
tswast committed Sep 19, 2017
2 parents c367fd0 + 2ec36ec commit d00ca72
Show file tree
Hide file tree
Showing 26 changed files with 1,499 additions and 960 deletions.
2 changes: 1 addition & 1 deletion appengine-java8/endpoints-v2-backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>endpoints-framework-maven-plugin</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
<configuration>
<!-- plugin configuration -->
<hostname>${endpoints.project.id}.appspot.com</hostname>
Expand Down
6 changes: 4 additions & 2 deletions appengine-java8/endpoints-v2-guice/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ To add the project ID:
0. For `<endpoints.project.id>`, replace the value `YOUR_PROJECT_ID` with
your project ID.

0. Edit the file `src/main/java/com/example/echo/Echo.java`.
0. Edit the file `src/main/java/com/example/echo/Echo.java` and
`src/main/java/com/example/echo/EchoEndpointModule.java`.

0. Replace the value `YOUR-PROJECT-ID` with your project ID.

Expand Down Expand Up @@ -82,7 +83,8 @@ You will get a 200 response with the following data:
0. For `def projectId = 'YOUR_PROJECT_ID'`, replace the value `YOUR_PROJECT_ID`
with your project ID.

0. Edit the file `src/main/java/com/example/echo/Echo.java
0. Edit the file `src/main/java/com/example/echo/Echo.java` and
`src/main/java/com/example/echo/EchoEndpointModule.java`.

0. Replace the value `YOUR-PROJECT-ID` with your project ID.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,32 @@

package com.example.echo;

import com.google.api.control.ServiceManagementConfigFilter;
import com.google.api.control.extensions.appengine.GoogleAppEngineControlFilter;
import com.google.api.server.spi.EndpointsServlet;
import com.google.api.server.spi.guice.EndpointsModule;
import com.google.common.collect.ImmutableList;
import com.google.inject.servlet.GuiceFilter;
import java.util.HashMap;
import java.util.Map;
import javax.inject.Singleton;

// [START endpoints_module]
public class EchoEndpointModule extends EndpointsModule {
@Override
public void configureServlets() {
super.configureServlets();

bind(ServiceManagementConfigFilter.class).in(Singleton.class);
filter("/_ah/api/*").through(ServiceManagementConfigFilter.class);

Map<String, String> apiController = new HashMap<String, String>();
apiController.put("endpoints.projectId", "YOUR-PROJECT-ID");
apiController.put("endpoints.serviceName", "YOUR-PROJECT-ID.appspot.com");

bind(GoogleAppEngineControlFilter.class).in(Singleton.class);
filter("/_ah/api/*").through(GoogleAppEngineControlFilter.class, apiController);

bind(Echo.class).toInstance(new Echo());
configureEndpoints("/_ah/api/*", ImmutableList.of(Echo.class));
}
Expand Down
34 changes: 5 additions & 29 deletions appengine-java8/endpoints-v2-guice/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>

<!--
URL Pattern /_ah/api/* instead of /* because a legacy v1 servlet uses
the route /_ah/api/ and using /* will erronously use the legacy v1
servlet instead of routing to your API.
-->
<filter-mapping>
<filter-name>guiceFilter</filter-name>
<url-pattern>/_ah/api/*</url-pattern>
Expand All @@ -35,33 +40,4 @@
<welcome-file>index.html</welcome-file>
</welcome-file-list>

<!-- Add a filter that fetches the service config from service management. -->
<filter>
<filter-name>endpoints-api-configuration</filter-name>
<filter-class>com.google.api.control.ServiceManagementConfigFilter</filter-class>
</filter>

<!-- Add a filter that performs Endpoints logging and monitoring. -->
<filter>
<filter-name>endpoints-api-controller</filter-name>
<filter-class>com.google.api.control.extensions.appengine.GoogleAppEngineControlFilter</filter-class>
<init-param>
<param-name>endpoints.projectId</param-name>
<param-value>${endpoints.project.id}</param-value>
</init-param>
<init-param>
<param-name>endpoints.serviceName</param-name>
<param-value>${endpoints.project.id}.appspot.com</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>endpoints-api-configuration</filter-name>
<servlet-name>EndpointsServlet</servlet-name>
</filter-mapping>

<filter-mapping>
<filter-name>endpoints-api-controller</filter-name>
<servlet-name>EndpointsServlet</servlet-name>
</filter-mapping>
</web-app>
2 changes: 1 addition & 1 deletion appengine/endpoints-frameworks-v2/backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>endpoints-framework-maven-plugin</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
<configuration>
<!-- plugin configuration -->
<hostname>${endpoints.project.id}.appspot.com</hostname>
Expand Down
6 changes: 4 additions & 2 deletions appengine/endpoints-frameworks-v2/guice-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ To add the project ID:
0. For `<endpoints.project.id>`, replace the value `YOUR_PROJECT_ID` with
your project ID.

0. Edit the file `src/main/java/com/example/echo/Echo.java`.
0. Edit the file `src/main/java/com/example/echo/Echo.java` and
`src/main/java/com/example/echo/EchoEndpointModule.java`.

0. Replace the value `YOUR-PROJECT-ID` with your project ID.

Expand Down Expand Up @@ -82,7 +83,8 @@ You will get a 200 response with the following data:
0. For `def projectId = 'YOUR_PROJECT_ID'`, replace the value `YOUR_PROJECT_ID`
with your project ID.

0. Edit the file `src/main/java/com/example/echo/Echo.java
0. Edit the file `src/main/java/com/example/echo/Echo.java` and
`src/main/java/com/example/echo/EchoEndpointModule.java`

0. Replace the value `YOUR-PROJECT-ID` with your project ID.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,34 @@

package com.example.echo;

import com.google.api.control.ServiceManagementConfigFilter;
import com.google.api.control.extensions.appengine.GoogleAppEngineControlFilter;
import com.google.api.server.spi.EndpointsServlet;
import com.google.api.server.spi.guice.EndpointsModule;
import com.google.common.collect.ImmutableList;
import com.google.inject.servlet.GuiceFilter;
import java.util.HashMap;
import java.util.Map;
import javax.inject.Singleton;

// [START endpoints_module]
public class EchoEndpointModule extends EndpointsModule {
@Override
public void configureServlets() {
super.configureServlets();

bind(ServiceManagementConfigFilter.class).in(Singleton.class);
filter("/_ah/api/*").through(ServiceManagementConfigFilter.class);

Map<String, String> apiController = new HashMap<String, String>();
apiController.put("endpoints.projectId", "YOUR-PROJECT-ID");
apiController.put("endpoints.serviceName", "YOUR-PROJECT-ID.appspot.com");

bind(GoogleAppEngineControlFilter.class).in(Singleton.class);
filter("/_ah/api/*").through(GoogleAppEngineControlFilter.class, apiController);

bind(Echo.class).toInstance(new Echo());
configureEndpoints("/_ah/api/*", ImmutableList.of(Echo.class));
super.configureServlets();
}
}
// [END endpoints_module]

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>

<!--
URL Pattern /_ah/api/* instead of /* because a legacy v1 servlet uses
the route /_ah/api/ and using /* will erronously use the legacy v1
servlet instead of routing to your API.
-->
<filter-mapping>
<filter-name>guiceFilter</filter-name>
<url-pattern>/_ah/api/*</url-pattern>
Expand All @@ -35,33 +40,4 @@
<welcome-file>index.html</welcome-file>
</welcome-file-list>

<!-- Add a filter that fetches the service config from service management. -->
<filter>
<filter-name>endpoints-api-configuration</filter-name>
<filter-class>com.google.api.control.ServiceManagementConfigFilter</filter-class>
</filter>

<!-- Add a filter that performs Endpoints logging and monitoring. -->
<filter>
<filter-name>endpoints-api-controller</filter-name>
<filter-class>com.google.api.control.extensions.appengine.GoogleAppEngineControlFilter</filter-class>
<init-param>
<param-name>endpoints.projectId</param-name>
<param-value>${endpoints.project.id}</param-value>
</init-param>
<init-param>
<param-name>endpoints.serviceName</param-name>
<param-value>${endpoints.project.id}.appspot.com</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>endpoints-api-configuration</filter-name>
<servlet-name>EndpointsServlet</servlet-name>
</filter-mapping>

<filter-mapping>
<filter-name>endpoints-api-controller</filter-name>
<servlet-name>EndpointsServlet</servlet-name>
</filter-mapping>
</web-app>
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
Loading

0 comments on commit d00ca72

Please sign in to comment.