-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Implement gRPC and HttpJson showcase tests for IAM (#1789)
* 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
Showing
91 changed files
with
8,190 additions
and
21 deletions.
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
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.