Skip to content

Commit

Permalink
Implement recursive FindControlById in the oscal catalog
Browse files Browse the repository at this point in the history
  • Loading branch information
isimluk committed Sep 25, 2020
1 parent 46c5311 commit b93b9d9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions types/oscal/catalog/catalog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package catalog

func (c *Catalog) FindControlById(id string) *Control {
for i, ctrl := range c.Controls {
if ctrl.Id == id {
return &c.Controls[i]
}
}
for i, _ := range c.Groups {
ctrl := c.Groups[i].FindControlById(id)
if ctrl != nil {
return ctrl
}
}
return nil
}
16 changes: 16 additions & 0 deletions types/oscal/catalog/group.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package catalog

func (g *Group) FindControlById(id string) *Control {
for i, ctrl := range g.Controls {
if ctrl.Id == id {
return &g.Controls[i]
}
}
for i, _ := range g.Groups {
ctrl := g.Groups[i].FindControlById(id)
if ctrl != nil {
return ctrl
}
}
return nil
}

0 comments on commit b93b9d9

Please sign in to comment.