Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate code from googleapis/java-webrisk #7415

Merged
merged 82 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
0600c63
samples: scaffold pom.xml files (#88)
yoshi-automation Mar 17, 2020
1475ec1
chore(deps): update dependency com.google.cloud:libraries-bom to v4.3…
renovate-bot Mar 23, 2020
2fd77bc
deps: update dependency com.google.cloud.samples:shared-configuration…
renovate-bot Mar 26, 2020
a9889a7
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Mar 30, 2020
6a706b1
chore(deps): update dependency com.google.cloud:libraries-bom to v4.4…
renovate-bot Apr 1, 2020
123710a
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Apr 6, 2020
98096be
chore(deps): update dependency com.google.cloud:libraries-bom to v4.4…
renovate-bot Apr 6, 2020
5efb41a
chore(deps): update dependency com.google.cloud:libraries-bom to v5 (…
renovate-bot Apr 14, 2020
1f3cdd0
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Apr 16, 2020
67a83b0
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Apr 17, 2020
7b45dbe
chore(deps): update dependency com.google.cloud:libraries-bom to v5.2…
renovate-bot Apr 23, 2020
040bb5a
chore(deps): update dependency com.google.cloud:libraries-bom to v5.3…
renovate-bot Apr 28, 2020
b73e6b7
chore(deps): update dependency com.google.cloud:libraries-bom to v5.4…
renovate-bot May 19, 2020
354c8e2
chore(deps): update dependency com.google.cloud:libraries-bom to v5.5…
renovate-bot May 29, 2020
8281972
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Jun 10, 2020
7abac32
chore(deps): update dependency com.google.cloud:libraries-bom to v5.7…
renovate-bot Jun 10, 2020
ecd1a8f
chore(deps): update dependency com.google.cloud:libraries-bom to v6 (…
renovate-bot Jun 16, 2020
eb15e43
chore(deps): update dependency com.google.cloud:libraries-bom to v7 (…
renovate-bot Jun 17, 2020
4f398d3
chore(deps): update dependency com.google.cloud:libraries-bom to v7.0…
renovate-bot Jun 22, 2020
f172583
chore(deps): update dependency com.google.cloud:libraries-bom to v8 (…
renovate-bot Jun 26, 2020
fc7025d
chore(deps): update dependency com.google.cloud:libraries-bom to v8.1…
renovate-bot Jul 16, 2020
d3bffc7
chore(deps): update dependency com.google.cloud:libraries-bom to v9
renovate-bot Aug 14, 2020
0b47fd7
chore(deps): update dependency com.google.cloud:libraries-bom to v9.1.0
renovate-bot Aug 17, 2020
d0f2bf5
chore(deps): update dependency com.google.cloud:libraries-bom to v10 …
renovate-bot Sep 22, 2020
d104ea2
test(deps): update dependency com.google.truth:truth to v1.1 (#257)
renovate-bot Oct 22, 2020
35e6839
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Oct 22, 2020
79d3184
chore(deps): update dependency com.google.cloud:libraries-bom to v13 …
renovate-bot Oct 22, 2020
3c26455
chore(deps): update dependency com.google.cloud:libraries-bom to v13.…
renovate-bot Oct 27, 2020
4d09371
chore(deps): update dependency com.google.cloud:libraries-bom to v13.…
renovate-bot Oct 28, 2020
e9a44de
test(deps): update dependency junit:junit to v4.13.1 (#258)
renovate-bot Oct 28, 2020
54c1aa7
chore(deps): update dependency com.google.cloud:libraries-bom to v13.…
renovate-bot Oct 30, 2020
3c5a4c0
chore(deps): update dependency com.google.cloud:libraries-bom to v16 …
renovate-bot Nov 19, 2020
32025b6
samples: create Java sample for Search API and Submit API in Webrisk …
Neenu1995 Dec 15, 2020
025c57a
chore(deps): update dependency com.google.cloud:libraries-bom to v16.…
renovate-bot Dec 15, 2020
f0c83fe
chore(deps): update dependency com.google.cloud:libraries-bom to v16.…
renovate-bot Jan 7, 2021
d376aa2
chore(deps): update dependency com.google.cloud:libraries-bom to v16.…
renovate-bot Jan 20, 2021
742a76c
test(deps): update dependency com.google.truth:truth to v1.1.2 (#328)
renovate-bot Jan 25, 2021
46656a1
chore(deps): update dependency com.google.cloud:libraries-bom to v16.…
renovate-bot Feb 11, 2021
e330f31
test(deps): update dependency junit:junit to v4.13.2 (#349)
renovate-bot Feb 16, 2021
7e2d8b9
chore(deps): update dependency com.google.cloud:libraries-bom to v17 …
renovate-bot Feb 24, 2021
5a86e6d
chore(deps): update dependency com.google.cloud:libraries-bom to v18 …
renovate-bot Feb 25, 2021
e43f691
chore(deps): update dependency com.google.cloud:libraries-bom to v18.…
renovate-bot Mar 3, 2021
5b0571e
chore(deps): update dependency com.google.cloud:libraries-bom to v19 …
renovate-bot Mar 4, 2021
4c96ab5
chore(deps): update dependency com.google.cloud:libraries-bom to v19.…
renovate-bot Mar 29, 2021
51d5045
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Apr 9, 2021
322a4bc
chore(deps): update dependency com.google.cloud:libraries-bom to v20 …
renovate-bot Apr 12, 2021
9483cf7
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot Apr 19, 2021
20f6ef7
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot Apr 29, 2021
5581bb8
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot May 13, 2021
bb707b1
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot May 17, 2021
ed87b12
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot May 25, 2021
8cf4052
test(deps): update dependency com.google.truth:truth to v1.1.3 (#450)
renovate-bot May 26, 2021
68830b3
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot Jun 7, 2021
cab1317
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Jun 7, 2021
8888c86
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot Jun 23, 2021
f436e0f
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot Jul 9, 2021
28b9e83
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot Jul 26, 2021
2f2bf38
chore(deps): update dependency com.google.cloud:libraries-bom to v21 …
renovate-bot Aug 19, 2021
ea81f59
chore(deps): update dependency com.google.cloud:libraries-bom to v22 …
renovate-bot Aug 27, 2021
46904b9
chore: migrate to owlbot (#525)
Neenu1995 Sep 5, 2021
2934c39
chore(deps): update dependency com.google.cloud:libraries-bom to v23 …
renovate-bot Sep 13, 2021
176500d
chore(deps): update dependency com.google.cloud:libraries-bom to v23.…
renovate-bot Oct 1, 2021
6b1ffbb
chore(deps): update dependency com.google.cloud:libraries-bom to v24 …
renovate-bot Oct 27, 2021
3944e8a
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Dec 6, 2021
c03f5f5
chore(deps): update dependency com.google.cloud:libraries-bom to v24.…
renovate-bot Dec 8, 2021
2186ccc
chore(deps): update dependency com.google.cloud:libraries-bom to v24.…
renovate-bot Dec 28, 2021
6651b1b
chore(deps): update dependency com.google.cloud:libraries-bom to v24.…
renovate-bot Jan 7, 2022
2259b6c
chore(deps): update dependency com.google.cloud:libraries-bom to v24.…
renovate-bot Jan 18, 2022
843a9f7
chore(deps): update dependency com.google.cloud:libraries-bom to v24.…
renovate-bot Feb 8, 2022
5b29e9a
chore(deps): update dependency com.google.cloud:libraries-bom to v24.…
renovate-bot Mar 3, 2022
5b2c5e6
chore(deps): update dependency com.google.cloud:libraries-bom to v25 …
renovate-bot Mar 14, 2022
e162528
chore(deps): update dependency com.google.cloud:libraries-bom to v25.…
renovate-bot Apr 1, 2022
9664e90
chore(deps): update dependency com.google.cloud:libraries-bom to v25.…
renovate-bot Apr 27, 2022
a418f72
chore(deps): update dependency com.google.cloud:libraries-bom to v25.…
renovate-bot May 16, 2022
8fb24b4
chore(deps): update dependency com.google.cloud:libraries-bom to v25.…
renovate-bot Jun 6, 2022
9a7ef48
chore(deps): update dependency com.google.cloud:libraries-bom to v26 …
renovate-bot Jul 11, 2022
59810a9
chore(deps): update dependency com.google.cloud:libraries-bom to v26.…
renovate-bot Aug 16, 2022
272e8a8
chore(deps): update dependency com.google.cloud:libraries-bom to v26.…
renovate-bot Aug 31, 2022
35f2ba2
chore(deps): update dependency com.google.cloud:libraries-bom to v26.…
renovate-bot Sep 20, 2022
af5fda6
chore(deps): update dependency com.google.cloud:libraries-bom to v26.…
renovate-bot Oct 7, 2022
e23f3cf
chore(deps): update dependency com.google.cloud:libraries-bom to v26.…
renovate-bot Nov 8, 2022
6ec3938
Merge remote-tracking branch 'migration/main' into java-webrisk-migra…
Sita04 Nov 11, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions webrisk/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version='1.0' encoding='UTF-8'?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.google.cloud</groupId>
<artifactId>webrisk-snippets</artifactId>
<packaging>jar</packaging>
<name>Google Web Risk Snippets</name>
<url>https://github.com/googleapis/java-webrisk</url>

<!--
The parent pom defines common style checks and testing strategies for our samples.
Removing or replacing it should not affect the execution of the samples in anyway.
-->
<parent>
<groupId>com.google.cloud.samples</groupId>
<artifactId>shared-configuration</artifactId>
<version>1.2.0</version>
</parent>

<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>


<!-- [START webrisk_install_with_bom] -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>libraries-bom</artifactId>
<version>26.1.4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-webrisk</artifactId>
</dependency>
<!-- [END webrisk_install_with_bom] -->

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<version>1.1.3</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
53 changes: 53 additions & 0 deletions webrisk/src/main/java/webrisk/SearchUriExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2020 Google LLC
*
* 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 webrisk;

import com.google.cloud.webrisk.v1.WebRiskServiceClient;
import com.google.webrisk.v1.SearchUrisRequest;
import com.google.webrisk.v1.SearchUrisResponse;
import com.google.webrisk.v1.ThreatType;
import java.io.IOException;

public class SearchUriExample {

public static void searchUriExample() throws IOException {
// The URL to be searched
String uri = "http://testsafebrowsing.appspot.com/s/malware.html";
SearchUrisResponse response = searchUriExample(uri);
}

// [START webrisk_search_uri]
public static SearchUrisResponse searchUriExample(String uri) throws IOException {
// create-webrisk-client
try (WebRiskServiceClient webRiskServiceClient = WebRiskServiceClient.create()) {
// Query the url for a specific threat type
SearchUrisRequest searchUrisRequest =
SearchUrisRequest.newBuilder().addThreatTypes(ThreatType.MALWARE).setUri(uri).build();
SearchUrisResponse searchUrisResponse = webRiskServiceClient.searchUris(searchUrisRequest);
webRiskServiceClient.shutdownNow();
if (!searchUrisResponse.getThreat().getThreatTypesList().isEmpty()) {
System.out.println("The URL has the following threat : ");
System.out.println(searchUrisResponse);
} else {
System.out.println("The URL is safe!");
}

return searchUrisResponse;
}
}
// [END webrisk_search_uri]
}
49 changes: 49 additions & 0 deletions webrisk/src/main/java/webrisk/SubmitUriExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2020 Google LLC
*
* 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 webrisk;

import com.google.cloud.webrisk.v1.WebRiskServiceClient;
import com.google.webrisk.v1.CreateSubmissionRequest;
import com.google.webrisk.v1.Submission;
import java.io.IOException;

public class SubmitUriExample {

public static void submitUriExample() throws IOException {
// The URL to be submitted
String uri = "http://testsafebrowsing.appspot.com/s/malware.html";
Submission response = submitUriExample(uri);
}

// [START webrisk_submit_uri]
public static Submission submitUriExample(String uri) throws IOException {
// create-webrisk-client
try (WebRiskServiceClient webRiskServiceClient = WebRiskServiceClient.create()) {
Submission submission = Submission.newBuilder().setUri(uri).build();
CreateSubmissionRequest submissionRequest =
CreateSubmissionRequest.newBuilder()
.setParent("projects/your-project-id")
.setSubmission(submission)
.build();
Submission submissionResponse = webRiskServiceClient.createSubmission(submissionRequest);
webRiskServiceClient.shutdownNow();
System.out.println("The submitted " + submissionResponse);
return submissionResponse;
}
}
// [END webrisk_submit_uri]
}
47 changes: 47 additions & 0 deletions webrisk/src/test/java/webrisk/SearchUriExampleTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2020 Google LLC
*
* 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 webrisk;

import com.google.common.truth.Truth;
import com.google.webrisk.v1.SearchUrisResponse;
import com.google.webrisk.v1.ThreatType;
import java.io.IOException;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class SearchUriExampleTest {
@Test
public void testSearchWithThreat() throws IOException {
// The URL to be searched
String uri = "http://testsafebrowsing.appspot.com/s/malware.html";
SearchUrisResponse actualResponse = SearchUriExample.searchUriExample(uri);
List<ThreatType> type = actualResponse.getThreat().getThreatTypesList();
Truth.assertThat(type).contains(ThreatType.MALWARE);
}

@Test
public void testSearchWithoutThreat() throws IOException {
// The URL to be searched
String uri = "http://testsafebrowsing.appspot.com/malware.html";
SearchUrisResponse actualResponse = SearchUriExample.searchUriExample(uri);
List<ThreatType> type = actualResponse.getThreat().getThreatTypesList();
Truth.assertThat(type).isEmpty();
}
}
31 changes: 31 additions & 0 deletions webrisk/src/test/java/webrisk/SubmitUriExampleTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2020 Google LLC
*
* 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 webrisk;

import com.google.common.truth.Truth;
import com.google.webrisk.v1.Submission;
import java.io.IOException;
import org.junit.Test;

public class SubmitUriExampleTest {
@Test
public void testSumbitUriExample() throws IOException {
String testUri = "http://testsafebrowsing.appspot.com/s/malware.html";
Submission actualSubmission = SubmitUriExample.submitUriExample(testUri);
Truth.assertThat(actualSubmission.getUri()).isEqualTo(testUri);
}
}