Skip to content

Commit

Permalink
resource account: fix --stacks target
Browse files Browse the repository at this point in the history
Now we don't reuse the Stack when we match on a target to avoid losing
information like the Workspace or Role when a target is matched
  • Loading branch information
dschofie committed Apr 23, 2024
1 parent a27774b commit 6874efc
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions resource/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,49 +148,34 @@ func (a Account) FilterBaselineStacks(stackNames string) ([]Stack, error) {
return nil, err
}

for _, stack := range baselineStacks {
for i, stack := range baselineStacks {
acctStackNames := strings.Split(stack.Name, ",")
var matchingStackNames []string
for _, name := range acctStackNames {
for _, targetName := range targetStackNames {
if strings.TrimSpace(name) == strings.TrimSpace(targetName) {
matchingStackNames = append(matchingStackNames, name)
matchingStacks = append(matchingStacks, baselineStacks[i])
break
}
}
}
if len(matchingStackNames) > 0 {
matchingStacks = append(matchingStacks, Stack{
Path: stack.Path,
Type: stack.Type,
Name: strings.Join(matchingStackNames, ","),
})
}
}
return matchingStacks, nil
}

func (a Account) FilterServiceControlPolicies(stackNames string) []Stack {
var matchingStacks []Stack
targetStackNames := strings.Split(stackNames, ",")
for _, stack := range a.ServiceControlPolicies {
for i, stack := range a.ServiceControlPolicies {
acctStackNames := strings.Split(stack.Name, ",")
var matchingStackNames []string
for _, name := range acctStackNames {
for _, targetName := range targetStackNames {
if strings.TrimSpace(name) == strings.TrimSpace(targetName) {
matchingStackNames = append(matchingStackNames, name)
matchingStacks = append(matchingStacks, a.ServiceControlPolicies[i])
break
}
}
}
if len(matchingStackNames) > 0 {
matchingStacks = append(matchingStacks, Stack{
Path: stack.Path,
Type: stack.Type,
Name: strings.Join(matchingStackNames, ","),
})
}
}

return matchingStacks
}

0 comments on commit 6874efc

Please sign in to comment.