Skip to content

Commit a5b4a88

Browse files
comments + fmt
Signed-off-by: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com>
1 parent 4bf74f1 commit a5b4a88

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

internal/graphapi/controlhelpers.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ func normalizeFramework(framework *string) string {
280280
return customFramework
281281
}
282282

283+
// getControlMappings returns the controls and subcontrols mapped to a control based on the ref code and framework
283284
func getControlMappings(ctx context.Context, refCode string, framework *string, parentControlID *string) ([]*generated.MappedControl, error) {
284285
fullWhere, err := prepMappedControlQuery(ctx, refCode, framework, parentControlID)
285286
if err != nil {
@@ -299,6 +300,7 @@ func getControlMappings(ctx context.Context, refCode string, framework *string,
299300
return res, nil
300301
}
301302

303+
// getSubcontrolMappings returns the controls and subcontrols mapped to a subcontrol based on the ref code and framework
302304
func getSubcontrolMappings(ctx context.Context, refCode string, framework *string, parentControlID *string) ([]*generated.MappedControl, error) {
303305
fullWhere, err := prepMappedControlQuery(ctx, refCode, framework, parentControlID)
304306
if err != nil {
@@ -318,6 +320,7 @@ func getSubcontrolMappings(ctx context.Context, refCode string, framework *strin
318320
return res, nil
319321
}
320322

323+
// prepMappedControlQuery gets the predicate for the mapped control query
321324
func prepMappedControlQuery(ctx context.Context, refCode string, framework *string, parentControlID *string) ([]predicate.MappedControl, error) {
322325
// get orgs to filter, this will allow us to skip expensive authz checks
323326
orgIDs, err := auth.GetOrganizationIDsFromContext(ctx)
@@ -539,6 +542,7 @@ func findOrganizationSubcontrolForMapping(ctx context.Context, c *generated.Subc
539542
return mappedFromSystem, true
540543
}
541544

545+
// isSameControl determines if the ref code is the same as the mapped control being checked
542546
func isSameControl(refCode string, framework *string, mappedControl *generated.Control) bool {
543547
if refCode != mappedControl.RefCode {
544548
return false
@@ -555,6 +559,7 @@ func isSameControl(refCode string, framework *string, mappedControl *generated.C
555559
return currentFramework == mappedFramework
556560
}
557561

562+
// isSameSubcontrold etermines if the ref code is the same as the mapped subcontrol being checked
558563
func isSameSubcontrol(refCode string, framework *string, mappedControl *generated.Subcontrol) bool {
559564
if refCode != mappedControl.RefCode {
560565
return false

internal/graphapi/controlhelpers_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,11 @@ func TestGenerateMapControlKey(t *testing.T) {
200200

201201
func TestIsSameControl(t *testing.T) {
202202
tests := []struct {
203-
name string
204-
refCode string
205-
framework *string
206-
mappedCtrl *generated.Control
207-
expected bool
203+
name string
204+
refCode string
205+
framework *string
206+
mappedCtrl *generated.Control
207+
expected bool
208208
}{
209209
{
210210
name: "different ref codes returns false",
@@ -453,12 +453,12 @@ func TestPrepMappedControlQuery(t *testing.T) {
453453
wantPredicates int
454454
}{
455455
{
456-
name: "no auth context returns error",
457-
ctx: context.Background(),
458-
refCode: "CC1.1",
459-
framework: strPtr("SOC2"),
456+
name: "no auth context returns error",
457+
ctx: context.Background(),
458+
refCode: "CC1.1",
459+
framework: strPtr("SOC2"),
460460
parentControlID: nil,
461-
wantErr: true,
461+
wantErr: true,
462462
},
463463
{
464464
name: "control query with nil framework adds nil framework predicate",

0 commit comments

Comments
 (0)