Skip to content

feat(securitycenter): add securitycenter_update_finding_state_v2 sample and preserve existing IAM bindings - #14683

Open
iennae wants to merge 1 commit into
mainfrom
feat/scc-v2-update-finding-state
Open

iennae wants to merge 1 commit into
mainfrom
feat/scc-v2-update-finding-state

Conversation

@iennae

@iennae iennae commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds update_finding_state (region tag securitycenter_update_finding_state_v2) and its integration test test_update_finding_state in securitycenter/snippets_v2/snippets_findings_v2.py so the Security Command Center Updating a finding's state documentation can migrate from the decommissioned v1 API to v2.
  • Updates set_source_iam_policy (securitycenter_set_source_iam_v2) to append the new role binding to old_policy.bindings instead of replacing the bindings list with a single-element list, preventing accidental removal of existing IAM bindings on the source.

@iennae
iennae requested review from a team as code owners October 26, 2026 02:20
@snippet-bot

snippet-bot Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

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 api: securitycenter Issues related to the Security Command Center API. samples Issues that are directly related to samples. labels Oct 26, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates various generative AI examples to use newer model versions, transitions several default locations to 'global' or 'us-east5', refactors RAG examples to use the new Google GenAI SDK, and adds a new Security Command Center snippet for updating finding states. The review feedback highlights critical issues with non-existent model names (such as 'gemini-3.8-flash' and 'claude-sonnet-4-6') and points out that initializing the GenAI client with a 'global' location will cause RAG retrieval to fail since RAG is a regional service that must match the corpus region ('us-east5').

Comment thread generative_ai/chat_completions/chat_completions_credentials_refresher.py Outdated
Comment thread generative_ai/model_garden/claude_3_streaming_example.py Outdated
Comment thread generative_ai/rag/generate_content_example.py Outdated
Comment thread generative_ai/rag/quickstart_example.py Outdated
Comment thread generative_ai/rag/quickstart_example.py Outdated
@iennae
iennae force-pushed the feat/scc-v2-update-finding-state branch from ca9f06d to dddc245 Compare October 26, 2026 02:24
…le and fix source IAM binding append

Problem:
1. The Security Command Center 'Managing findings using the API' guide
   (how-to-api-create-manage-findings.md) has its Python sample for
   'Updating a finding's state' commented out with TODO(b/374152194)
   referencing the legacy v1 region tag securitycenter_update_finding_state
   because securitycenter/snippets_v2/snippets_findings_v2.py was missing
   a v2 sample for SecurityCenterClient.set_finding_state.
2. In securitycenter/snippets_v2/snippets_findings_v2.py,
   set_source_iam_policy (securitycenter_set_source_iam_v2) passed
   "policy": {"bindings": [binding]} to set_iam_policy, overwriting existing
   IAM bindings on the source instead of appending to old_policy.bindings
   (tracked in b/364943255).

Solution:
1. Add update_finding_state(organization_id: str, source_id: str,
   finding_id: str) -> None (# [START securitycenter_update_finding_state_v2])
   to securitycenter/snippets_v2/snippets_findings_v2.py and
   test_update_finding_state to snippets_findings_v2_test.py following the
   Google Cloud Python sample authoring standards (PEP 484 type annotations,
   -> None return contract, explicit SetFindingStateRequest, NotFound and
   GoogleAPICallError error handling to sys.stderr, and standardized stdout
   fields).
2. Update set_source_iam_policy in snippets_findings_v2.py to append the
   new Binding to old_policy.bindings and pass "policy": old_policy to
   client.set_iam_policy.
@iennae
iennae force-pushed the feat/scc-v2-update-finding-state branch from dddc245 to 5e02e31 Compare October 26, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: securitycenter Issues related to the Security Command Center API. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant