From a98baceb397a1d65b04e0393cb017ab25cdc5a1b Mon Sep 17 00:00:00 2001 From: navinger Date: Mon, 3 Dec 2018 14:44:34 -0800 Subject: [PATCH] Removed old endpoints sample. (#1272) --- flexible/endpoints/README.md | 20 ---- flexible/endpoints/pom.xml | 76 ------------- .../endpoints/src/main/appengine/Dockerfile | 4 - .../endpoints/src/main/appengine/app.yaml | 12 -- .../endpoints/src/main/appengine/openapi.yaml | 106 ------------------ .../example/endpoints/AuthInfoServlet.java | 58 ---------- .../com/example/endpoints/EchoServlet.java | 56 --------- 7 files changed, 332 deletions(-) delete mode 100644 flexible/endpoints/README.md delete mode 100644 flexible/endpoints/pom.xml delete mode 100644 flexible/endpoints/src/main/appengine/Dockerfile delete mode 100644 flexible/endpoints/src/main/appengine/app.yaml delete mode 100644 flexible/endpoints/src/main/appengine/openapi.yaml delete mode 100644 flexible/endpoints/src/main/java/com/example/endpoints/AuthInfoServlet.java delete mode 100644 flexible/endpoints/src/main/java/com/example/endpoints/EchoServlet.java diff --git a/flexible/endpoints/README.md b/flexible/endpoints/README.md deleted file mode 100644 index 4f86b4b247a..00000000000 --- a/flexible/endpoints/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# Google Cloud Endpoints on App Engine flexible environment - - -Open in Cloud Shell - -This sample demonstrates how to use Google Cloud Endpoints on Google App Engine Flexible Environment using Java. - -## Edit the Open API specification - -Open the [src/main/appengine/openapi.yaml](src/main/appengine/openapi.yaml) file in your favorite editor, and replace the YOUR-PROJECT-ID `host` line with your actual Google Cloud Platform project Id. - -## Running locally - $ mvn jetty:run - -## Deploying - $ mvn gcloud:deploy - -## Calling your API - -Please refer to the Google Cloud Endpoints [documentation](https://cloud.google.com/endpoints/docs/app-engine/) for App Engine Flexible Environment to learn about creating an API Key and calling your API. diff --git a/flexible/endpoints/pom.xml b/flexible/endpoints/pom.xml deleted file mode 100644 index 3d0ddae2dbc..00000000000 --- a/flexible/endpoints/pom.xml +++ /dev/null @@ -1,76 +0,0 @@ - - - - 4.0.0 - war - 1.0-SNAPSHOT - com.example.flexible - flexible-endpoints - - - - com.google.cloud.samples - shared-configuration - 1.0.9 - - - - 1.8 - 1.8 - - false - - 1.3.0 - 9.4.4.v20170414 - - - - - javax.servlet - javax.servlet-api - 3.1.0 - jar - provided - - - - com.google.code.gson - gson - 2.6.2 - compile - - - - - - ${project.build.directory}/${project.build.finalName}/WEB-INF/classes - - - com.google.appengine - gcloud-maven-plugin - 2.0.9.121.v20160815 - - beta - - - - - com.google.cloud.tools - appengine-maven-plugin - ${appengine.maven.plugin} - - - - - - org.eclipse.jetty - jetty-maven-plugin - ${jetty} - - - - diff --git a/flexible/endpoints/src/main/appengine/Dockerfile b/flexible/endpoints/src/main/appengine/Dockerfile deleted file mode 100644 index 93d48abcd16..00000000000 --- a/flexible/endpoints/src/main/appengine/Dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM gcr.io/google_appengine/jetty9 - -ADD flexible-endpoints-1.0-SNAPSHOT.war $JETTY_BASE/webapps/root.war -ADD . /app diff --git a/flexible/endpoints/src/main/appengine/app.yaml b/flexible/endpoints/src/main/appengine/app.yaml deleted file mode 100644 index a3f52eb360f..00000000000 --- a/flexible/endpoints/src/main/appengine/app.yaml +++ /dev/null @@ -1,12 +0,0 @@ -runtime: custom -env: flex - -handlers: -- url: /.* - script: this field is required, but ignored - -beta_settings: - # Enable Google Cloud Endpoints API management. - use_endpoints_api_management: true - # Specify the Open API specification. - endpoints_swagger_spec_file: openapi.yaml diff --git a/flexible/endpoints/src/main/appengine/openapi.yaml b/flexible/endpoints/src/main/appengine/openapi.yaml deleted file mode 100644 index 71bac9ce62f..00000000000 --- a/flexible/endpoints/src/main/appengine/openapi.yaml +++ /dev/null @@ -1,106 +0,0 @@ -swagger: "2.0" -info: - description: "A simple Google Cloud Endpoints API example." - title: "Endpoints Example" - version: "1.0.0" -host: "YOUR-PROJECT-ID.appspot.com" -basePath: "/" -consumes: -- "application/json" -produces: -- "application/json" -schemes: -- "https" -paths: - "/echo": - post: - description: "Echo back a given message." - operationId: "echo" - produces: - - "application/json" - responses: - 200: - description: "Echo" - schema: - $ref: "#/definitions/echoMessage" - parameters: - - description: "Message to echo" - in: body - name: message - required: true - schema: - $ref: "#/definitions/echoMessage" - "/auth/info/googlejwt": - get: - description: "Returns the requests' authentication information." - operationId: "auth_info_google_jwt" - produces: - - "application/json" - responses: - 200: - description: "Authenication info." - schema: - $ref: "#/definitions/authInfoResponse" - x-security: - - google_jwt: - audiences: - # This must match the "aud" field in the JWT. You can add multiple - # audiences to accept JWTs from multiple clients. - - "echo.endpoints.sample.google.com" - "/auth/info/googleidtoken": - get: - description: "Returns the requests' authentication information." - operationId: "authInfoGoogleIdToken" - produces: - - "application/json" - responses: - 200: - description: "Authenication info." - schema: - $ref: "#/definitions/authInfoResponse" - x-security: - - google_id_token: - audiences: - # Your OAuth2 client's Client ID must be added here. You can add - # multiple client IDs to accept tokens from multiple clients. - - "YOUR-CLIENT-ID" -definitions: - echoMessage: - properties: - message: - type: "string" - authInfoResponse: - properties: - id: - type: "string" - email: - type: "string" -# This section requires all requests to any path to require an API key. -security: -- api_key: [] -securityDefinitions: - # This section configures basic authentication with an API key. - api_key: - type: "apiKey" - name: "key" - in: "query" - # This section configures authentication using Google API Service Accounts - # to sign a json web token. This is mostly used for server-to-server - # communication. - google_jwt: - authorizationUrl: "" - flow: "implicit" - type: "oauth2" - # This must match the 'iss' field in the JWT. - x-issuer: "jwt-client.endpoints.sample.google.com" - # Update this with your service account's email address. - x-jwks_uri: "https://www.googleapis.com/service_accounts/v1/jwk/YOUR-SERVICE-ACCOUNT-EMAIL" - # This section configures authentication using Google OAuth2 ID Tokens. - # ID Tokens can be obtained using OAuth2 clients, and can be used to access - # your API on behalf of a particular user. - google_id_token: - authorizationUrl: "" - flow: "implicit" - type: "oauth2" - x-issuer: "accounts.google.com" - x-jwks_uri: "https://www.googleapis.com/oauth2/v1/certs" diff --git a/flexible/endpoints/src/main/java/com/example/endpoints/AuthInfoServlet.java b/flexible/endpoints/src/main/java/com/example/endpoints/AuthInfoServlet.java deleted file mode 100644 index f51088b9209..00000000000 --- a/flexible/endpoints/src/main/java/com/example/endpoints/AuthInfoServlet.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2015 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. - */ - -package com.example.endpoints; - -import com.google.gson.Gson; -import com.google.gson.JsonObject; - -import java.io.IOException; -import java.util.Base64; - -import javax.servlet.annotation.WebServlet; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * A servlet that returns authentication information. - * See openapi.yaml for authentication mechanisms (e.g. JWT tokens, Google ID token). - */ -@WebServlet("/auth/info/*") -public class AuthInfoServlet extends HttpServlet { - - @Override - public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { - String encodedInfo = req.getHeader("X-Endpoint-API-UserInfo"); - if (encodedInfo == null || encodedInfo == "") { - JsonObject anon = new JsonObject(); - anon.addProperty("id", "anonymous"); - new Gson().toJson(anon, resp.getWriter()); - return; - } - - try { - byte[] authInfo = Base64.getDecoder().decode(encodedInfo); - resp.getOutputStream().write(authInfo); - } catch (IllegalArgumentException iae) { - resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); - JsonObject error = new JsonObject(); - error.addProperty("code", HttpServletResponse.SC_BAD_REQUEST); - error.addProperty("message", "Could not decode auth info."); - new Gson().toJson(error, resp.getWriter()); - } - } -} diff --git a/flexible/endpoints/src/main/java/com/example/endpoints/EchoServlet.java b/flexible/endpoints/src/main/java/com/example/endpoints/EchoServlet.java deleted file mode 100644 index 84e3152f404..00000000000 --- a/flexible/endpoints/src/main/java/com/example/endpoints/EchoServlet.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2015 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. - */ - -package com.example.endpoints; - -import com.google.gson.Gson; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.stream.JsonReader; - -import java.io.IOException; -import java.util.Map; - -import javax.servlet.annotation.WebServlet; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * A servlet that echoes JSON message bodies. - */ -@WebServlet("/echo") -public class EchoServlet extends HttpServlet { - - @Override - public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { - resp.addHeader("Content-Encoding", "application/json"); - - Object responseBody; - try { - JsonReader jsonReader = new JsonReader(req.getReader()); - responseBody = new Gson().fromJson(jsonReader, Map.class); - } catch (JsonParseException je) { - resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); - JsonObject error = new JsonObject(); - error.addProperty("code", HttpServletResponse.SC_BAD_REQUEST); - error.addProperty("message", "Body was not valid JSON."); - responseBody = error; - } - - new Gson().toJson(responseBody, resp.getWriter()); - } -}