Skip to content

Commit 86eba3b

Browse files
authored
feat: add functions_firebase_auth (#2050)
* feat: add functions_firebase_auth * Update FirebaseAuth.java * feat: add json parsing logic
1 parent ee7893d commit 86eba3b

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

functions/snippets/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@
6767
<version>1.19.0</version>
6868
<scope>test</scope>
6969
</dependency>
70+
71+
<!-- Required for Function primitives -->
72+
<dependency>
73+
<groupId>com.google.cloud.functions</groupId>
74+
<artifactId>functions-framework-api</artifactId>
75+
<version>1.0.0-alpha-2-rc3</version>
76+
<type>jar</type>
77+
</dependency>
7078
</dependencies>
7179

7280
<!-- Required for Java 8 (Alpha) functions in the inline editor -->
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
// [START functions_firebase_auth]
18+
import com.google.cloud.functions.Context;
19+
import com.google.cloud.functions.RawBackgroundFunction;
20+
import com.google.gson.Gson;
21+
import com.google.gson.JsonObject;
22+
import java.util.logging.Logger;
23+
24+
public class FirebaseAuth implements RawBackgroundFunction {
25+
26+
// Use GSON (https://github.com/google/gson) to parse JSON content.
27+
private Gson gsonParser = new Gson();
28+
29+
private static final Logger LOGGER = Logger.getLogger(FirebaseAuth.class.getName());
30+
31+
@Override
32+
public void accept(String json, Context context) {
33+
JsonObject body = gsonParser.fromJson(json, JsonObject.class);
34+
LOGGER.info("Function triggered by event: " + json);
35+
}
36+
}
37+
38+
// [END functions_firebase_auth]

functions/snippets/src/test/java/SnippetsTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,4 +217,9 @@ public void helloExecutionCount() throws IOException {
217217
new Concepts().executionCount(request, response);
218218
assertThat(responseOut.toString(), containsString("Instance execution count: 1"));
219219
}
220+
221+
@Test
222+
public void firebaseAuth() throws IOException {
223+
new FirebaseAuth().accept("{\"foo\": \"bar\"}", null);
224+
}
220225
}

0 commit comments

Comments
 (0)