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

chore: Implement gRPC and HttpJson showcase tests for IAM #1789

Merged
merged 30 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
285d90c
chore: Add framework for iam showcase tests
lqiu96 Jun 13, 2023
dbf8085
chore: Generate clients with IAM stubs
lqiu96 Jun 13, 2023
5bf473b
chore: Add IAM showcase tests
lqiu96 Jun 20, 2023
2fda5da
chore: Add samples
lqiu96 Jun 20, 2023
a1ccb3b
Merge branch 'main' into main-showcase_iam_tests
lqiu96 Jun 20, 2023
6c2f4ba
chore: Exclude httpjson tests
lqiu96 Jun 20, 2023
db735ab
chore: Use @Before to create the resource
lqiu96 Jun 20, 2023
d51e35f
chore: Use constant for policy
lqiu96 Jun 21, 2023
6b4255a
chore: Log resource name
lqiu96 Jun 21, 2023
6047046
chore: Test use setPolicyRequest's resourceName
lqiu96 Jun 21, 2023
6272824
chore: run mvn clean before showcase tests
lqiu96 Jun 21, 2023
39d3fe3
chore: Attempt again with cache deleted
lqiu96 Jun 21, 2023
105ccd7
Merge branch 'main' into main-showcase_iam_tests
lqiu96 Jun 21, 2023
c02c9ef
chore: Add logging for test
lqiu96 Jun 21, 2023
a165545
chore: Sleep for 1s
lqiu96 Jun 21, 2023
c119191
chore: Use resource from setPolicyRequest
lqiu96 Jun 21, 2023
8334663
Merge branch 'main' into main-showcase_iam_tests
lqiu96 Jun 21, 2023
d1ce001
chore: Ignore failing HttpJson test for now
lqiu96 Jun 21, 2023
42f1956
chore: Un-ignore test
lqiu96 Jun 21, 2023
3a6c3b3
chore: Fix lint issues
lqiu96 Jun 21, 2023
d150fdb
chore: Test with rooms/ prefix
lqiu96 Jun 21, 2023
6652d00
chore: Use Identity client for Users
lqiu96 Jun 21, 2023
0c7cb46
chore: Create user resource to assign policy to
lqiu96 Jun 22, 2023
0c4222f
chore: Use user's name as resource id
lqiu96 Jun 22, 2023
adfad68
chore: Change resource name before each test
lqiu96 Jun 22, 2023
5d8e25b
Merge branch 'main' into main-showcase_iam_tests
lqiu96 Jul 5, 2023
5346d43
chore: Add iam-grpc in pom
lqiu96 Jul 5, 2023
1682e0a
chore: Resolve sonar issues
lqiu96 Jul 5, 2023
a3fb65b
chore: Add comment for testIamPolicy
lqiu96 Jul 5, 2023
bf33627
chore: Address PR comments
lqiu96 Jul 7, 2023
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
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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So adding this iam_policy_proto implicitly enables IAM feature? Is this how we are suppose to enable IAM?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe having this in the bazel rule enables it: https://github.com/googleapis/gapic-showcase/blob/b146f892d98ea0d733c45a2315941e8e6ab69c90/schema/google/showcase/v1beta1/showcase_v1beta1.yaml#L29

But this was to generate the Java related Mixin code.

],
)

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>
Comment on lines +240 to +244
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added since there are compilation issues for MockIAMPolicy and MockIAMPolicyImpl

</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