Skip to content

Commit

Permalink
GetProjectFromRegionalSelfLink: Accept projects with a colon in the n…
Browse files Browse the repository at this point in the history
…ame (#12628)

Signed-off-by: Norbert Kamiński <[email protected]>

[upstream:f5e373575e0c43293f7f4a2402e90bc960c5d03b]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician committed Dec 26, 2024
1 parent 9c9f5b7 commit c4b3d84
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .changelog/12628.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
compute: GetProjectFromRegionalSelfLink accepts projects with a colon in the name
```
2 changes: 1 addition & 1 deletion google/tpgresource/self_link_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func GetRegionFromRegionalSelfLink(selfLink string) string {
}

func GetProjectFromRegionalSelfLink(selfLink string) string {
re := regexp.MustCompile("projects/([a-zA-Z0-9-]*)/(?:locations|regions)/[a-zA-Z0-9-]*")
re := regexp.MustCompile("projects/([a-zA-Z0-9-:]*)/(?:locations|regions)/[a-zA-Z0-9-:]*")
switch {
case re.MatchString(selfLink):
if res := re.FindStringSubmatch(selfLink); len(res) == 2 && res[1] != "" {
Expand Down
5 changes: 3 additions & 2 deletions google/tpgresource/self_link_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ func TestGetRegionFromRegionalSelfLink(t *testing.T) {

func TestGetProjectFromRegionalSelfLink(t *testing.T) {
cases := map[string]string{
"projects/foo/locations/europe-north1/datasets/bar/operations/foobar": "foo",
"projects/REDACTED/regions/europe-north1/subnetworks/tf-test-net-xbwhsmlfm8": "REDACTED",
"projects/foo/locations/europe-north1/datasets/bar/operations/foobar": "foo",
"projects/REDACTED/regions/europe-north1/subnetworks/tf-test-net-xbwhsmlfm8": "REDACTED",
"projects/REDA:CT-ED09/regions/europe-north1/subnetworks/tf-test-net-xbwhsmlfm8": "REDA:CT-ED09",
}
for input, expected := range cases {
if result := GetProjectFromRegionalSelfLink(input); result != expected {
Expand Down

0 comments on commit c4b3d84

Please sign in to comment.