Skip to content

Commit e493032

Browse files
simonfaltumclaude
andauthored
Refactor FindResourceByConfigKey to use AllResources loop (#4519)
## Summary - Replace 21 hand-written copy-paste blocks in `FindResourceByConfigKey()` with a loop over `AllResources()`, reducing ~130 lines of boilerplate - New resource types added to `AllResources()` are now automatically findable via `FindResourceByConfigKey()` with no additional edit - No behavioral change — same return values for all inputs ## Test plan - [x] All `bundle/config/` tests pass - [x] All caller tests (`cmd/bundle/deployment/`, `cmd/apps/`) pass - [x] Build succeeds 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f31a1c2 commit e493032

File tree

1 file changed

+4
-123
lines changed

1 file changed

+4
-123
lines changed

bundle/config/resources.go

Lines changed: 4 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -109,131 +109,12 @@ func (r *Resources) AllResources() []ResourceGroup {
109109
}
110110
}
111111

112+
// FindResourceByConfigKey searches all resource maps for a resource with the given key.
112113
func (r *Resources) FindResourceByConfigKey(key string) (ConfigResource, error) {
113114
var found []ConfigResource
114-
for k := range r.Jobs {
115-
if k == key {
116-
found = append(found, r.Jobs[k])
117-
}
118-
}
119-
120-
for k := range r.Pipelines {
121-
if k == key {
122-
found = append(found, r.Pipelines[k])
123-
}
124-
}
125-
126-
for k := range r.Apps {
127-
if k == key {
128-
found = append(found, r.Apps[k])
129-
}
130-
}
131-
132-
for k := range r.Catalogs {
133-
if k == key {
134-
found = append(found, r.Catalogs[k])
135-
}
136-
}
137-
138-
for k := range r.Schemas {
139-
if k == key {
140-
found = append(found, r.Schemas[k])
141-
}
142-
}
143-
144-
for k := range r.Experiments {
145-
if k == key {
146-
found = append(found, r.Experiments[k])
147-
}
148-
}
149-
150-
for k := range r.Clusters {
151-
if k == key {
152-
found = append(found, r.Clusters[k])
153-
}
154-
}
155-
156-
for k := range r.Volumes {
157-
if k == key {
158-
found = append(found, r.Volumes[k])
159-
}
160-
}
161-
162-
for k := range r.Dashboards {
163-
if k == key {
164-
found = append(found, r.Dashboards[k])
165-
}
166-
}
167-
168-
for k := range r.RegisteredModels {
169-
if k == key {
170-
found = append(found, r.RegisteredModels[k])
171-
}
172-
}
173-
174-
for k := range r.QualityMonitors {
175-
if k == key {
176-
found = append(found, r.QualityMonitors[k])
177-
}
178-
}
179-
180-
for k := range r.ModelServingEndpoints {
181-
if k == key {
182-
found = append(found, r.ModelServingEndpoints[k])
183-
}
184-
}
185-
186-
for k := range r.SecretScopes {
187-
if k == key {
188-
found = append(found, r.SecretScopes[k])
189-
}
190-
}
191-
192-
for k := range r.Alerts {
193-
if k == key {
194-
found = append(found, r.Alerts[k])
195-
}
196-
}
197-
198-
for k := range r.SqlWarehouses {
199-
if k == key {
200-
found = append(found, r.SqlWarehouses[k])
201-
}
202-
}
203-
204-
for k := range r.DatabaseInstances {
205-
if k == key {
206-
found = append(found, r.DatabaseInstances[k])
207-
}
208-
}
209-
210-
for k := range r.DatabaseCatalogs {
211-
if k == key {
212-
found = append(found, r.DatabaseCatalogs[k])
213-
}
214-
}
215-
216-
for k := range r.SyncedDatabaseTables {
217-
if k == key {
218-
found = append(found, r.SyncedDatabaseTables[k])
219-
}
220-
}
221-
222-
for k := range r.PostgresProjects {
223-
if k == key {
224-
found = append(found, r.PostgresProjects[k])
225-
}
226-
}
227-
228-
for k := range r.PostgresBranches {
229-
if k == key {
230-
found = append(found, r.PostgresBranches[k])
231-
}
232-
}
233-
234-
for k := range r.PostgresEndpoints {
235-
if k == key {
236-
found = append(found, r.PostgresEndpoints[k])
115+
for _, group := range r.AllResources() {
116+
if res, ok := group.Resources[key]; ok {
117+
found = append(found, res)
237118
}
238119
}
239120

0 commit comments

Comments
 (0)