Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentsimon committed Nov 24, 2022
1 parent fb07860 commit bfd5411
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions checks/evaluation/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ func applyScorePolicy(results *checker.TokenPermissionsData, c *checker.CheckReq
hm := make(map[string]permissions)
dl := c.Dlogger
//nolint:errcheck
remediaitonMetadata, _ := remediation.New(c)
remediationMetadata, _ := remediation.New(c)

for _, r := range results.TokenPermissions {
var msg checker.LogMessage

var rem *checker.Remediation
if r.File != nil {
msg.Path = r.File.Path
msg.Offset = r.File.Offset
msg.Type = r.File.Type
msg.Snippet = r.File.Snippet

if msg.Path != "" {
msg.Remediation = remediaitonMetadata.CreateWorkflowPermissionRemediation(r.File.Path)
rem = remediationMetadata.CreateWorkflowPermissionRemediation(r.File.Path)
}
}

Expand All @@ -92,7 +92,7 @@ func applyScorePolicy(results *checker.TokenPermissionsData, c *checker.CheckReq

// We warn only for top-level.
if *r.LocationType == checker.PermissionLocationTop {
dl.Warn(&msg)
warnWithRemediation(dl, &msg, rem)
} else {
dl.Debug(&msg)
}
Expand All @@ -103,7 +103,7 @@ func applyScorePolicy(results *checker.TokenPermissionsData, c *checker.CheckReq
}

case checker.PermissionLevelWrite:
dl.Warn(&msg)
warnWithRemediation(dl, &msg, rem)

// Group results by workflow name for score computation.
if err := updateWorkflowHashMap(hm, r); err != nil {
Expand All @@ -115,6 +115,11 @@ func applyScorePolicy(results *checker.TokenPermissionsData, c *checker.CheckReq
return calculateScore(hm), nil
}

func warnWithRemediation(logger checker.DetailLogger, msg *checker.LogMessage, rem *checker.Remediation) {
msg.Remediation = rem
logger.Warn(msg)
}

func recordPermissionWrite(hm map[string]permissions, path string,
locType checker.PermissionLocation, permName *string,
) {
Expand Down

0 comments on commit bfd5411

Please sign in to comment.