Skip to content

Commit

Permalink
chore: Implement gRPC and HttpJson showcase tests for IAM (#1789)
Browse files Browse the repository at this point in the history
* chore: Add framework for iam showcase tests

* chore: Generate clients with IAM stubs

* chore: Add IAM showcase tests

* chore: Add samples

* chore: Exclude httpjson tests

* chore: Use @before to create the resource

* chore: Use constant for policy

* chore: Log resource name

* chore: Test use setPolicyRequest's resourceName

* chore: run mvn clean before showcase tests

* chore: Attempt again with cache deleted

* chore: Add logging for test

* chore: Sleep for 1s

* chore: Use resource from setPolicyRequest

* chore: Ignore failing HttpJson test for now

* chore: Un-ignore test

* chore: Fix lint issues

* chore: Test with rooms/ prefix

* chore: Use Identity client for Users

* chore: Create user resource to assign policy to

* chore: Use user's name as resource id

* chore: Change resource name before each test

* chore: Add iam-grpc in pom

* chore: Resolve sonar issues

* chore: Add comment for testIamPolicy

* chore: Address PR comments
  • Loading branch information
lqiu96 committed Jul 12, 2023
1 parent a6d9ef8 commit 1fe186a
Show file tree
Hide file tree
Showing 91 changed files with 8,196 additions and 21 deletions.
9 changes: 6 additions & 3 deletions showcase/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ proto_library_with_info(
"@com_google_gapic_showcase//schema/google/showcase/v1beta1:showcase_proto",
# "//showcase/gapic-showcase-extended/proto:showcase_proto_extended",
"@com_google_googleapis//google/cloud:common_resources_proto",
"@com_google_googleapis//google/cloud/location:location_proto"
"@com_google_googleapis//google/cloud/location:location_proto",
"@com_google_googleapis//google/iam/v1:iam_policy_proto"
],
)

Expand Down Expand Up @@ -57,13 +58,15 @@ java_gapic_library(
test_deps = [
":showcase_java_grpc",
# ":showcase_java_grpc_extended",
"@com_google_googleapis//google/cloud/location:location_java_grpc"
"@com_google_googleapis//google/cloud/location:location_java_grpc",
"@com_google_googleapis//google/iam/v1:iam_java_grpc"
],
transport = "grpc+rest",
deps = [
":showcase_java_proto",
"@com_google_googleapis//google/api:api_java_proto",
"@com_google_googleapis//google/cloud/location:location_java_proto"
"@com_google_googleapis//google/cloud/location:location_java_proto",
"@com_google_googleapis//google/iam/v1:iam_java_proto"
],
)

Expand Down
5 changes: 5 additions & 0 deletions showcase/gapic-showcase/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -237,5 +237,10 @@
<classifier>testlib</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>grpc-google-iam-v1</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2023 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
*
* https://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.google.showcase.v1beta1.samples;

// [START localhost7469_v1beta1_generated_Compliance_GetIamPolicy_async]
import com.google.api.core.ApiFuture;
import com.google.iam.v1.GetIamPolicyRequest;
import com.google.iam.v1.GetPolicyOptions;
import com.google.iam.v1.Policy;
import com.google.showcase.v1beta1.BlurbName;
import com.google.showcase.v1beta1.ComplianceClient;

public class AsyncGetIamPolicy {

public static void main(String[] args) throws Exception {
asyncGetIamPolicy();
}

public static void asyncGetIamPolicy() throws Exception {
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ComplianceClient complianceClient = ComplianceClient.create()) {
GetIamPolicyRequest request =
GetIamPolicyRequest.newBuilder()
.setResource(
BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
.toString())
.setOptions(GetPolicyOptions.newBuilder().build())
.build();
ApiFuture<Policy> future = complianceClient.getIamPolicyCallable().futureCall(request);
// Do something.
Policy response = future.get();
}
}
}
// [END localhost7469_v1beta1_generated_Compliance_GetIamPolicy_async]
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2023 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
*
* https://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.google.showcase.v1beta1.samples;

// [START localhost7469_v1beta1_generated_Compliance_GetIamPolicy_sync]
import com.google.iam.v1.GetIamPolicyRequest;
import com.google.iam.v1.GetPolicyOptions;
import com.google.iam.v1.Policy;
import com.google.showcase.v1beta1.BlurbName;
import com.google.showcase.v1beta1.ComplianceClient;

public class SyncGetIamPolicy {

public static void main(String[] args) throws Exception {
syncGetIamPolicy();
}

public static void syncGetIamPolicy() throws Exception {
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ComplianceClient complianceClient = ComplianceClient.create()) {
GetIamPolicyRequest request =
GetIamPolicyRequest.newBuilder()
.setResource(
BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
.toString())
.setOptions(GetPolicyOptions.newBuilder().build())
.build();
Policy response = complianceClient.getIamPolicy(request);
}
}
}
// [END localhost7469_v1beta1_generated_Compliance_GetIamPolicy_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2023 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
*
* https://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.google.showcase.v1beta1.samples;

// [START localhost7469_v1beta1_generated_Compliance_SetIamPolicy_async]
import com.google.api.core.ApiFuture;
import com.google.iam.v1.Policy;
import com.google.iam.v1.SetIamPolicyRequest;
import com.google.protobuf.FieldMask;
import com.google.showcase.v1beta1.BlurbName;
import com.google.showcase.v1beta1.ComplianceClient;

public class AsyncSetIamPolicy {

public static void main(String[] args) throws Exception {
asyncSetIamPolicy();
}

public static void asyncSetIamPolicy() throws Exception {
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ComplianceClient complianceClient = ComplianceClient.create()) {
SetIamPolicyRequest request =
SetIamPolicyRequest.newBuilder()
.setResource(
BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
.toString())
.setPolicy(Policy.newBuilder().build())
.setUpdateMask(FieldMask.newBuilder().build())
.build();
ApiFuture<Policy> future = complianceClient.setIamPolicyCallable().futureCall(request);
// Do something.
Policy response = future.get();
}
}
}
// [END localhost7469_v1beta1_generated_Compliance_SetIamPolicy_async]
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2023 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
*
* https://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.google.showcase.v1beta1.samples;

// [START localhost7469_v1beta1_generated_Compliance_SetIamPolicy_sync]
import com.google.iam.v1.Policy;
import com.google.iam.v1.SetIamPolicyRequest;
import com.google.protobuf.FieldMask;
import com.google.showcase.v1beta1.BlurbName;
import com.google.showcase.v1beta1.ComplianceClient;

public class SyncSetIamPolicy {

public static void main(String[] args) throws Exception {
syncSetIamPolicy();
}

public static void syncSetIamPolicy() throws Exception {
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ComplianceClient complianceClient = ComplianceClient.create()) {
SetIamPolicyRequest request =
SetIamPolicyRequest.newBuilder()
.setResource(
BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
.toString())
.setPolicy(Policy.newBuilder().build())
.setUpdateMask(FieldMask.newBuilder().build())
.build();
Policy response = complianceClient.setIamPolicy(request);
}
}
}
// [END localhost7469_v1beta1_generated_Compliance_SetIamPolicy_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2023 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
*
* https://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.google.showcase.v1beta1.samples;

// [START localhost7469_v1beta1_generated_Compliance_TestIamPermissions_async]
import com.google.api.core.ApiFuture;
import com.google.iam.v1.TestIamPermissionsRequest;
import com.google.iam.v1.TestIamPermissionsResponse;
import com.google.showcase.v1beta1.BlurbName;
import com.google.showcase.v1beta1.ComplianceClient;
import java.util.ArrayList;

public class AsyncTestIamPermissions {

public static void main(String[] args) throws Exception {
asyncTestIamPermissions();
}

public static void asyncTestIamPermissions() throws Exception {
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ComplianceClient complianceClient = ComplianceClient.create()) {
TestIamPermissionsRequest request =
TestIamPermissionsRequest.newBuilder()
.setResource(
BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
.toString())
.addAllPermissions(new ArrayList<String>())
.build();
ApiFuture<TestIamPermissionsResponse> future =
complianceClient.testIamPermissionsCallable().futureCall(request);
// Do something.
TestIamPermissionsResponse response = future.get();
}
}
}
// [END localhost7469_v1beta1_generated_Compliance_TestIamPermissions_async]
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2023 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
*
* https://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.google.showcase.v1beta1.samples;

// [START localhost7469_v1beta1_generated_Compliance_TestIamPermissions_sync]
import com.google.iam.v1.TestIamPermissionsRequest;
import com.google.iam.v1.TestIamPermissionsResponse;
import com.google.showcase.v1beta1.BlurbName;
import com.google.showcase.v1beta1.ComplianceClient;
import java.util.ArrayList;

public class SyncTestIamPermissions {

public static void main(String[] args) throws Exception {
syncTestIamPermissions();
}

public static void syncTestIamPermissions() throws Exception {
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ComplianceClient complianceClient = ComplianceClient.create()) {
TestIamPermissionsRequest request =
TestIamPermissionsRequest.newBuilder()
.setResource(
BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
.toString())
.addAllPermissions(new ArrayList<String>())
.build();
TestIamPermissionsResponse response = complianceClient.testIamPermissions(request);
}
}
}
// [END localhost7469_v1beta1_generated_Compliance_TestIamPermissions_sync]
Loading

0 comments on commit 1fe186a

Please sign in to comment.