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

feat: Adding disable role snippet #9295

Merged
merged 8 commits into from
May 2, 2024
Merged

feat: Adding disable role snippet #9295

merged 8 commits into from
May 2, 2024

Conversation

msilc
Copy link
Contributor

@msilc msilc commented Apr 18, 2024

Description

Added a new disable role snippet

Checklist

  • I have followed Sample Format Guide
  • pom.xml parent set to latest shared-configuration
  • Appropriate changes to README are included in PR
  • These samples need a new API enabled in testing projects to pass (let us know which ones)
  • These samples need a new/updated env vars in testing projects set to pass (let us know which ones)
  • Tests pass: mvn clean verify required
  • Lint passes: mvn -P lint checkstyle:check required
  • Static Analysis: mvn -P lint clean compile pmd:cpd-check spotbugs:check advisory only
  • This sample adds a new sample directory, and I updated the CODEOWNERS file with the codeowners for this sample
  • This sample adds a new Product API, and I updated the Blunderbuss issue/PR auto-assigner with the codeowners for this sample
  • Please merge this PR for me once it is approved

@msilc msilc requested a review from Sita04 April 18, 2024 13:56
@msilc msilc requested review from yoshi-approver and a team as code owners April 18, 2024 13:56
Copy link

snippet-bot bot commented Apr 18, 2024

Here is the summary of changes.

You are about to add 1 region tag.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@product-auto-label product-auto-label bot added samples Issues that are directly related to samples. api: iam Issues related to the Identity and Access Management API. labels Apr 18, 2024
@msilc msilc changed the title Feat: Adding disable role snippet feat: Adding disable role snippet Apr 18, 2024
@kweinmeister kweinmeister added the kokoro:run Add this label to force Kokoro to re-run the tests. label Apr 22, 2024
@kokoro-team kokoro-team removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Apr 22, 2024
Copy link
Contributor

@Sita04 Sita04 left a comment

Choose a reason for hiding this comment

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

Thanks for the snippet!
Few minor comments.

UpdateRoleRequest updateRoleRequest =
UpdateRoleRequest.newBuilder()
.setName(roleName)
.setRole(roleBuilder)
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of the Role.Builder, can we use Role?

Comment on lines 39 to 42
Role.Builder roleBuilder =
Role.newBuilder()
.setName(roleName)
.setStage(Role.RoleLaunchStage.DISABLED);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we build this and get back the Role, like below?

Suggested change
Role.Builder roleBuilder =
Role.newBuilder()
.setName(roleName)
.setStage(Role.RoleLaunchStage.DISABLED);
Role role =
Role.newBuilder()
.setName(roleName)
.setStage(Role.RoleLaunchStage.DISABLED)
.build();

// once, and can be reused for multiple requests.
try (IAMClient iamClient = IAMClient.create()) {
Role result = iamClient.updateRole(updateRoleRequest);
System.out.println("Disabled role:\n" + result);
Copy link
Contributor

Choose a reason for hiding this comment

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

Kindly return the updated role to be used in test assert statements.

@@ -111,6 +111,10 @@ public void testRole() throws IOException {
ListRoles.listRoles(projectId);
assertThat(bout.toString().contains(roleId));

// Test disable role.
DisableRole.disableRole(projectId, roleId);
assertThat(bout.toString().contains("Stage: DISABLED"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of asserting from sysout, it's more robust to retrieve and verify the status from the updated role.

@Sita04 Sita04 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 23, 2024
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 23, 2024
@msilc msilc requested a review from Sita04 April 23, 2024 22:41
@Sita04 Sita04 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 24, 2024
Copy link
Contributor

@Sita04 Sita04 left a comment

Choose a reason for hiding this comment

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

LGTM

@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 24, 2024
@Sita04 Sita04 assigned Sita04 and unassigned kweinmeister Apr 25, 2024
@Sita04
Copy link
Contributor

Sita04 commented Apr 30, 2024

@msilc PTAL at the lint issues

@msilc msilc added the kokoro:run Add this label to force Kokoro to re-run the tests. label May 2, 2024
@kokoro-team kokoro-team removed the kokoro:run Add this label to force Kokoro to re-run the tests. label May 2, 2024
@msilc msilc merged commit f52fd74 into main May 2, 2024
11 checks passed
@msilc msilc deleted the disable_role_snippet branch May 2, 2024 13:24
rafaelMurata pushed a commit to rafaelMurata/java-docs-samples that referenced this pull request May 7, 2024
* Added the disable role snippet

* Refactoring

* Updated header

* PR fix

* Checkstyle fix

* Names reverted
rafaelMurata pushed a commit to rafaelMurata/java-docs-samples that referenced this pull request May 27, 2024
* Added the disable role snippet

* Refactoring

* Updated header

* PR fix

* Checkstyle fix

* Names reverted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: iam Issues related to the Identity and Access Management API. samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants