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

Allow the use of region selflinks in provider configs. #4219

Merged
merged 1 commit into from
Aug 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions google/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ func (c *Config) LoadAndValidate() error {
c.clientStorageTransfer.UserAgent = userAgent
c.clientStorageTransfer.BasePath = storageTransferClientBasePath

c.Region = GetRegionFromRegionSelfLink(c.Region)
return nil
}

Expand Down
5 changes: 1 addition & 4 deletions google/iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,7 @@ func mergeAuditConfigs(auditConfigs []*cloudresourcemanager.AuditConfig) []*clou
// Flattens AuditConfigs so each role has a single Binding with combined members\
func removeAllAuditConfigsWithService(ac []*cloudresourcemanager.AuditConfig, service string) []*cloudresourcemanager.AuditConfig {
acMap := createIamAuditConfigsMap(ac)
if _, ok := acMap[service]; ok {
delete(acMap, service)
}

delete(acMap, service)
return listFromIamAuditConfigMap(acMap)
}

Expand Down
12 changes: 12 additions & 0 deletions google/self_link_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,15 @@ func GetLocationalResourcePropertiesFromSelfLinkString(selfLink string) (string,
s := strings.Split(parsed.Path, "/")
return s[4], s[6], s[8], nil
}

// return the region a selfLink is referring to
func GetRegionFromRegionSelfLink(selfLink string) string {
re := regexp.MustCompile("/compute/[a-zA-Z0-9]*/projects/[a-zA-Z0-9-]*/regions/([a-zA-Z0-9-]*)")
switch {
case re.MatchString(selfLink):
if res := re.FindStringSubmatch(selfLink); len(res) == 2 && res[1] != "" {
return res[1]
}
}
return selfLink
}
12 changes: 12 additions & 0 deletions google/self_link_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,15 @@ func TestSelfLinkNameHash(t *testing.T) {
}
}
}

func TestGetRegionFromRegionSelfLink(t *testing.T) {
cases := map[string]string{
"https://www.googleapis.com/compute/v1/projects/test/regions/europe-west3": "europe-west3",
"europe-west3": "europe-west3",
}
for input, expected := range cases {
if result := GetRegionFromRegionSelfLink(input); result != expected {
t.Errorf("expected to get %q from %q, got %q", expected, input, result)
}
}
}