Skip to content

Commit aba9348

Browse files
authored
Sync main nov 24 feature branch resource identity (#15803)
2 parents 56ff575 + 41a39ce commit aba9348

File tree

326 files changed

+19262
-1525
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

326 files changed

+19262
-1525
lines changed

.ci/infra/terraform/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ After applying this configuration:
4848
- Enroll in Cloud Armor Managed Protection Plus tier
4949
- Add Cloud Identity Premium Plan to the Google Workspace domain
5050
- Perform the Privileged Access Manager set-up https://pantheon.corp.google.com/iam-admin/pam/setup
51-
- (Org only) Enroll the org in the Premium tier of Security Control Center
5251
- Upload a model with the name `tf-static-1` to the Vertex AI model registry
5352
- This should only be necessary until uploading new models is supported in the provider.
53+
- (Org only) Enroll the org in the Premium tier of Security Control Center
54+
- (Org only) Enable Compliance Manager https://cloud.google.com/security-command-center/docs/compliance-manager-enable
5455
5556
Quotas that will need to be adjusted to support all tests:
5657
- Project quota for the new service account

.ci/infra/terraform/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ module "project-services" {
249249
"cloudquotas.googleapis.com",
250250
"cloudresourcemanager.googleapis.com",
251251
"cloudscheduler.googleapis.com",
252+
"cloudsecuritycompliance.googleapis.com",
252253
"cloudtasks.googleapis.com",
253254
"cloudtrace.googleapis.com",
254255
"composer.googleapis.com",

.ci/magician/cmd/create_test_failure_ticket.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -523,10 +523,23 @@ func init() {
523523
var (
524524
// TODO: add all mismatch resource names
525525
resourceNameConverter = map[string]string{
526-
"google_iam3_projects_policy_binding": "google_iam_projects_policy_binding",
527-
"google_iam3_organizations_policy_binding": "google_iam_organizations_policy_binding",
528-
"google_cloud_backup_dr_data_source": "google_backup_dr_data_source",
529-
"google_cloud_backup_dr_backup": "google_backup_dr_backup",
530-
"google_security_posture_posture_deployment": "google_securityposture_posture_deployment",
526+
"google_iam3_projects_policy_binding": "google_iam_projects_policy_binding",
527+
"google_iam3_organizations_policy_binding": "google_iam_organizations_policy_binding",
528+
"google_cloud_backup_dr_data_source": "google_backup_dr_data_source",
529+
"google_cloud_backup_dr_backup": "google_backup_dr_backup",
530+
"google_security_posture_posture_deployment": "google_securityposture_posture_deployment",
531+
"google_container_cluster_custom_service_account": "google_container_cluster",
532+
"iap_client": "google_iap_client",
533+
"compute_node_types": "google_compute_node_types",
534+
"google_big_query_table": "google_bigquery_table",
535+
"google_sql_user_fw": "google_fw_sql_user",
536+
"google_resource_fw_pubsub_lite_reservation": "google_fwprovider_pubsub_lite_reservation",
537+
"google_compute_router_bgp_peer": "google_compute_router_peer",
538+
"google_resource_manager3_capability": "google_resource_manager_capability",
539+
"google_datafusion_instance": "google_data_fusion_instance",
540+
"google_iam_beta_workload_identity_pool_iam_policy": "google_iam_workload_identity_pool_iam_policy",
541+
"google_resource_google_project_default_service_accounts_disable": "google_project_default_service_accounts",
542+
"google_datasource_google_service_networking_peered_dns_domain": "google_service_networking_peered_dns_domain",
543+
"google_resource_google_project_default_service_accounts_delete": "google_project_default_service_accounts",
531544
}
532545
)

.ci/magician/cmd/parse_comment.go

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"regexp"
7+
"strings"
8+
9+
"magician/github"
10+
11+
"github.com/spf13/cobra"
12+
)
13+
14+
// This regex captures the entire line starting with @modular-magician
15+
// Example: "@modular-magician reassign-reviewer user1" or "@modular-magician assign review @user2"
16+
var magicianInvocationRegex = regexp.MustCompile(`@modular-magician\s+([^\n\r]+)`)
17+
18+
// Command patterns for reassign-reviewer with flexible syntax
19+
// Supports: assign-reviewer, reassign-reviewer, assign reviewer, reassign review, etc.
20+
// Captures only valid GitHub usernames: [a-zA-Z0-9-_]
21+
var reassignReviewerRegex = regexp.MustCompile(`^(?:re)?assign[- ]?review(?:er)?\s*@?([a-zA-Z0-9-_]*)`)
22+
23+
var parseCommentCmd = &cobra.Command{
24+
Use: "parse-comment PR_NUMBER COMMENT_AUTHOR",
25+
Short: "Parses a comment from the COMMENT_BODY env var to execute magician commands",
26+
Long: `This command parses GitHub PR comments for @modular-magician invocations.
27+
28+
It supports flexible command syntax including:
29+
- Commands with hyphens: reassign-reviewer
30+
- Commands with spaces: reassign reviewer
31+
- Optional prefixes and suffixes: assign-review, reassign-reviewer
32+
- Optional @ prefix for usernames
33+
34+
The command expects the comment body to be provided in the COMMENT_BODY environment variable and also requires:
35+
1. PR_NUMBER - The pull request number
36+
2. COMMENT_AUTHOR - The GitHub username who made the comment`,
37+
Args: cobra.ExactArgs(2),
38+
RunE: func(cmd *cobra.Command, args []string) error {
39+
prNumber := args[0]
40+
author := args[1]
41+
42+
githubToken, ok := os.LookupEnv("GITHUB_TOKEN")
43+
if !ok {
44+
return fmt.Errorf("did not provide GITHUB_TOKEN environment variable")
45+
}
46+
gh := github.NewClient(githubToken)
47+
48+
if gh.GetUserType(author) != github.CoreContributorUserType {
49+
return fmt.Errorf("comment author %s is not a core contributor", author)
50+
}
51+
52+
comment, ok := os.LookupEnv("COMMENT_BODY")
53+
if !ok {
54+
return fmt.Errorf("did not provide COMMENT_BODY environment variable")
55+
}
56+
if comment == "" {
57+
fmt.Println("COMMENT_BODY is empty. Ignoring.")
58+
return nil
59+
}
60+
61+
return execParseComment(prNumber, comment, gh)
62+
},
63+
}
64+
65+
// execParseComment is the main router that finds and executes the first command
66+
func execParseComment(prNumber, comment string, gh GithubClient) error {
67+
// Find the first @modular-magician invocation in the comment
68+
match := magicianInvocationRegex.FindStringSubmatch(comment)
69+
70+
if match == nil {
71+
fmt.Println("No @modular-magician invocation found. Ignoring comment.")
72+
return nil
73+
}
74+
75+
if len(match) < 2 {
76+
fmt.Printf("Invalid match structure. Ignoring.\n")
77+
return nil
78+
}
79+
80+
commandLine := strings.TrimSpace(match[1])
81+
if commandLine == "" {
82+
fmt.Printf("Empty command after @modular-magician. Ignoring.\n")
83+
return nil
84+
}
85+
86+
fmt.Printf("Processing command: %q\n", commandLine)
87+
88+
// Route to appropriate handler based on command pattern
89+
return routeCommand(prNumber, commandLine, gh)
90+
}
91+
92+
// routeCommand determines which command handler to call based on the command pattern
93+
func routeCommand(prNumber, commandLine string, gh GithubClient) error {
94+
// Check for reassign-reviewer command variants
95+
if matches := reassignReviewerRegex.FindStringSubmatch(commandLine); matches != nil {
96+
reviewer := strings.TrimSpace(matches[1])
97+
return handleReassignReviewer(prNumber, reviewer, gh)
98+
}
99+
100+
// Add more command patterns here as needed
101+
// Example for future commands:
102+
// if matches := cherryPickRegex.FindStringSubmatch(commandLine); matches != nil {
103+
// return handleCherryPick(prNumber, matches[1:], gh)
104+
// }
105+
106+
fmt.Printf("Unknown command format: %q\n", commandLine)
107+
return nil
108+
}
109+
110+
// handleReassignReviewer processes the reassign-reviewer command
111+
func handleReassignReviewer(prNumber, reviewer string, gh GithubClient) error {
112+
// The regex already extracted just the username without @
113+
// and only allows valid GitHub username characters [a-zA-Z0-9-_]
114+
115+
fmt.Printf("Reassigning reviewer for PR #%s", prNumber)
116+
if reviewer != "" {
117+
fmt.Printf(" to @%s", reviewer)
118+
} else {
119+
fmt.Printf(" (selecting random reviewer)")
120+
}
121+
fmt.Println()
122+
return execReassignReviewer(prNumber, reviewer, gh)
123+
}
124+
125+
func init() {
126+
rootCmd.AddCommand(parseCommentCmd)
127+
}

0 commit comments

Comments
 (0)