-
Notifications
You must be signed in to change notification settings - Fork 54
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
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 dbf8085
chore: Generate clients with IAM stubs
lqiu96 5bf473b
chore: Add IAM showcase tests
lqiu96 2fda5da
chore: Add samples
lqiu96 a1ccb3b
Merge branch 'main' into main-showcase_iam_tests
lqiu96 6c2f4ba
chore: Exclude httpjson tests
lqiu96 db735ab
chore: Use @Before to create the resource
lqiu96 d51e35f
chore: Use constant for policy
lqiu96 6b4255a
chore: Log resource name
lqiu96 6047046
chore: Test use setPolicyRequest's resourceName
lqiu96 6272824
chore: run mvn clean before showcase tests
lqiu96 39d3fe3
chore: Attempt again with cache deleted
lqiu96 105ccd7
Merge branch 'main' into main-showcase_iam_tests
lqiu96 c02c9ef
chore: Add logging for test
lqiu96 a165545
chore: Sleep for 1s
lqiu96 c119191
chore: Use resource from setPolicyRequest
lqiu96 8334663
Merge branch 'main' into main-showcase_iam_tests
lqiu96 d1ce001
chore: Ignore failing HttpJson test for now
lqiu96 42f1956
chore: Un-ignore test
lqiu96 3a6c3b3
chore: Fix lint issues
lqiu96 d150fdb
chore: Test with rooms/ prefix
lqiu96 6652d00
chore: Use Identity client for Users
lqiu96 0c7cb46
chore: Create user resource to assign policy to
lqiu96 0c4222f
chore: Use user's name as resource id
lqiu96 adfad68
chore: Change resource name before each test
lqiu96 5d8e25b
Merge branch 'main' into main-showcase_iam_tests
lqiu96 5346d43
chore: Add iam-grpc in pom
lqiu96 1682e0a
chore: Resolve sonar issues
lqiu96 a3fb65b
chore: Add comment for testIamPolicy
lqiu96 bf33627
chore: Address PR comments
lqiu96 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added since there are compilation issues for MockIAMPolicy and MockIAMPolicyImpl |
||
</dependencies> | ||
</project> |
53 changes: 53 additions & 0 deletions
53
.../src/main/java/com/google/showcase/v1beta1/compliance/getiampolicy/AsyncGetIamPolicy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
50 changes: 50 additions & 0 deletions
50
...d/src/main/java/com/google/showcase/v1beta1/compliance/getiampolicy/SyncGetIamPolicy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
54 changes: 54 additions & 0 deletions
54
.../src/main/java/com/google/showcase/v1beta1/compliance/setiampolicy/AsyncSetIamPolicy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
51 changes: 51 additions & 0 deletions
51
...d/src/main/java/com/google/showcase/v1beta1/compliance/setiampolicy/SyncSetIamPolicy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
54 changes: 54 additions & 0 deletions
54
...va/com/google/showcase/v1beta1/compliance/testiampermissions/AsyncTestIamPermissions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
50 changes: 50 additions & 0 deletions
50
...ava/com/google/showcase/v1beta1/compliance/testiampermissions/SyncTestIamPermissions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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.