Skip to content

Commit 6d8aa0d

Browse files
authored
feat: accessapproval snippet migration (GoogleCloudPlatform#8401)
* feat: accessapproval snippet migration Moving the snippet from https://github.com/googleapis/java-accessapproval/tree/main/samples/snippets * header year * fixed overly permissive method signature * adding a line in codeowners file * default access * Renamed classes to reflect actions Renamed classes to reflect actions rather than QuickStart. Use assertWithMessage Use setUp() for BeforeClass Keep copyright year 2020 * Renamed listRequest to listAccessApprovalRequest
1 parent 65b52a5 commit 6d8aa0d

File tree

5 files changed

+158
-0
lines changed

5 files changed

+158
-0
lines changed

.github/CODEOWNERS

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
/workflows @GoogleCloudPlatform/java-samples-reviewers @yoshi-approver @GoogleCloudPlatform/torus-dpe
2828

2929
# Infrastructure
30+
/accessapproval @GoogleCloudPlatform/java-samples-reviewers @yoshi-approver @GoogleCloudPlatform/dee-infra
3031
/auth @GoogleCloudPlatform/java-samples-reviewers @yoshi-approver @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/googleapis-auth
3132
/batch @GoogleCloudPlatform/java-samples-reviewers @yoshi-approver @GoogleCloudPlatform/dee-infra
3233
/compute @GoogleCloudPlatform/java-samples-reviewers @yoshi-approver @GoogleCloudPlatform/dee-infra

.github/auto-label.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ path:
22
pullrequest: true
33
labelprefix: "api: "
44
paths:
5+
accessapproval: "accessapproval"
56
aiplatform: "aiplatform"
67
appengine-java8: "appengine"
78
appengine-java11: "appengine"

accessapproval/snippets/pom.xml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<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">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.example.accessapproval</groupId>
5+
<artifactId>accessapproval-snippets</artifactId>
6+
<packaging>jar</packaging>
7+
<name>Google Cloud Access Approval Snippets</name>
8+
9+
<!--
10+
The parent pom defines common style checks and testing strategies for our samples.
11+
Removing or replacing it should not affect the execution of the samples in anyway.
12+
-->
13+
<parent>
14+
<groupId>com.google.cloud.samples</groupId>
15+
<artifactId>shared-configuration</artifactId>
16+
<version>1.2.0</version>
17+
</parent>
18+
19+
<properties>
20+
<maven.compiler.target>1.8</maven.compiler.target>
21+
<maven.compiler.source>1.8</maven.compiler.source>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
</properties>
24+
25+
<dependencyManagement>
26+
<dependencies>
27+
<dependency>
28+
<groupId>com.google.cloud</groupId>
29+
<artifactId>libraries-bom</artifactId>
30+
<version>26.18.0</version>
31+
<type>pom</type>
32+
<scope>import</scope>
33+
</dependency>
34+
</dependencies>
35+
</dependencyManagement>
36+
37+
<dependencies>
38+
<dependency>
39+
<groupId>com.google.cloud</groupId>
40+
<artifactId>google-cloud-accessapproval</artifactId>
41+
</dependency>
42+
43+
<dependency>
44+
<groupId>junit</groupId>
45+
<artifactId>junit</artifactId>
46+
<version>4.13.2</version>
47+
<scope>test</scope>
48+
</dependency>
49+
<dependency>
50+
<groupId>com.google.truth</groupId>
51+
<artifactId>truth</artifactId>
52+
<version>1.1.3</version>
53+
<scope>test</scope>
54+
</dependency>
55+
<dependency>
56+
<groupId>com.google.cloud</groupId>
57+
<artifactId>google-cloud-core</artifactId>
58+
<version>2.8.20</version>
59+
<classifier>tests</classifier>
60+
</dependency>
61+
</dependencies>
62+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2020 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+
package accessapproval;
18+
19+
// [START accessapproval_quickstart]
20+
import com.google.cloud.accessapproval.v1.AccessApprovalAdminClient;
21+
import com.google.cloud.accessapproval.v1.ApprovalRequest;
22+
import java.io.IOException;
23+
24+
public class ListRequest {
25+
26+
public static void main(String[] arguments) throws IOException {
27+
// TODO(developer): Replace these variables before running the sample.
28+
String projectId = "your-project-id";
29+
listAccessApprovalRequest(projectId);
30+
}
31+
32+
static void listAccessApprovalRequest(String projectId) throws IOException {
33+
try (AccessApprovalAdminClient client = AccessApprovalAdminClient.create()) {
34+
String parent = "projects/" + projectId;
35+
AccessApprovalAdminClient.ListApprovalRequestsPagedResponse response =
36+
client.listApprovalRequests(parent);
37+
int total = 0;
38+
for (ApprovalRequest request : response.iterateAll()) {
39+
System.out.println(request.getName());
40+
total++;
41+
}
42+
if (total == 0) {
43+
System.out.println("No approval requests found");
44+
}
45+
}
46+
}
47+
}
48+
// [END accessapproval_quickstart]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2020 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+
package accessapproval;
18+
19+
import static com.google.common.truth.Truth.assertWithMessage;
20+
import static org.junit.Assert.assertEquals;
21+
22+
import com.google.cloud.testing.junit4.StdOutCaptureRule;
23+
import java.io.IOException;
24+
import org.junit.BeforeClass;
25+
import org.junit.Rule;
26+
import org.junit.Test;
27+
28+
public class ListRequestIT {
29+
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
30+
31+
@Rule public StdOutCaptureRule stdOutCap = new StdOutCaptureRule();
32+
33+
@BeforeClass
34+
public static void setUp() throws Exception {
35+
assertWithMessage("Missing environment variable 'GOOGLE_CLOUD_PROJECT'")
36+
.that(PROJECT_ID)
37+
.isNotEmpty();
38+
}
39+
40+
@Test
41+
public void testListRequest() throws IOException {
42+
ListRequest listRequest = new ListRequest();
43+
listRequest.listAccessApprovalRequest(PROJECT_ID);
44+
assertEquals("No approval requests found\n", stdOutCap.getCapturedOutputAsUtf8String());
45+
}
46+
}

0 commit comments

Comments
 (0)