Skip to content

Commit

Permalink
remove protected values from probes
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Korczynski <adam@adalogics.com>
  • Loading branch information
AdamKorcz committed Feb 24, 2024
1 parent d34ae27 commit 5c98388
Show file tree
Hide file tree
Showing 8 changed files with 3 additions and 70 deletions.
8 changes: 0 additions & 8 deletions probes/blocksDeleteOnBranches/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@ func Run(raw *checker.RawResults) ([]finding.Finding, string, error) {
for i := range r.Branches {
branch := &r.Branches[i]

protected := !(branch.Protected != nil && !*branch.Protected)
var protectedValue int
if protected {
protectedValue = 1
} else {
protectedValue = 0
}

var text string
var outcome finding.Outcome
switch {
Expand Down
8 changes: 0 additions & 8 deletions probes/blocksForcePushOnBranches/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@ func Run(raw *checker.RawResults) ([]finding.Finding, string, error) {
for i := range r.Branches {
branch := &r.Branches[i]

protected := !(branch.Protected != nil && !*branch.Protected)
var protectedValue int
if protected {
protectedValue = 1
} else {
protectedValue = 0
}

var text string
var outcome finding.Outcome
switch {
Expand Down
8 changes: 0 additions & 8 deletions probes/branchProtectionAppliesToAdmins/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,6 @@ func Run(raw *checker.RawResults) ([]finding.Finding, string, error) {
for i := range r.Branches {
branch := &r.Branches[i]

protected := !(branch.Protected != nil && !*branch.Protected)
var protectedValue int
if protected {
protectedValue = 1
} else {
protectedValue = 0
}

p := branch.BranchProtectionRule.EnforceAdmins
text, outcome, err := branchprotection.GetTextOutcomeFromBool(p,
"branch protection settings apply to administrators",
Expand Down
8 changes: 0 additions & 8 deletions probes/requiresApproversForPullRequests/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,6 @@ func Run(raw *checker.RawResults) ([]finding.Finding, string, error) {
for i := range r.Branches {
branch := &r.Branches[i]

protected := !(branch.Protected != nil && !*branch.Protected)
var protectedValue int
if protected {
protectedValue = 1
} else {
protectedValue = 0
}

nilMsg := fmt.Sprintf("could not determine whether branch '%s' has required approving review count", *branch.Name)
trueMsg := fmt.Sprintf("required approving review count on branch '%s'", *branch.Name)
falseMsg := fmt.Sprintf("branch '%s' does not require approvers", *branch.Name)
Expand Down
8 changes: 0 additions & 8 deletions probes/requiresLastPushApproval/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,6 @@ func Run(raw *checker.RawResults) ([]finding.Finding, string, error) {
for i := range r.Branches {
branch := &r.Branches[i]

protected := !(branch.Protected != nil && !*branch.Protected)
var protectedValue int
if protected {
protectedValue = 1
} else {
protectedValue = 0
}

p := branch.BranchProtectionRule.RequireLastPushApproval
text, outcome, err := branchprotection.GetTextOutcomeFromBool(p, "last push approval", *branch.Name)
if err != nil {
Expand Down
17 changes: 3 additions & 14 deletions probes/requiresPRsToChangeCode/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@ func Run(raw *checker.RawResults) ([]finding.Finding, string, error) {
for i := range r.Branches {
branch := &r.Branches[i]

protected := !(branch.Protected != nil && !*branch.Protected)
var protectedValue int
if protected {
protectedValue = 1
} else {
protectedValue = 0
}

nilMsg := fmt.Sprintf("could not determine whether branch '%s' requires PRs to change code", *branch.Name)
trueMsg := fmt.Sprintf("PRs are required in order to make changes on branch '%s'", *branch.Name)
falseMsg := fmt.Sprintf("PRs are not required to make changes on branch '%s'; ", *branch.Name) +
Expand All @@ -78,20 +70,17 @@ func Run(raw *checker.RawResults) ([]finding.Finding, string, error) {
case p == nil:
f = f.WithMessage(nilMsg).WithOutcome(finding.OutcomeNotAvailable)
f = f.WithValues(map[string]int{
*branch.Name: 1,
"branchProtected": protectedValue,
*branch.Name: 1,
})
case *p:
f = f.WithMessage(trueMsg).WithOutcome(finding.OutcomePositive)
f = f.WithValues(map[string]int{
*branch.Name: 1,
"branchProtected": protectedValue,
*branch.Name: 1,
})
case !*p:
f = f.WithMessage(falseMsg).WithOutcome(finding.OutcomeNegative)
f = f.WithValues(map[string]int{
*branch.Name: 1,
"branchProtected": protectedValue,
*branch.Name: 1,
})
default:
return nil, Probe, fmt.Errorf("create finding: %w", errWrongValue)
Expand Down
8 changes: 0 additions & 8 deletions probes/requiresUpToDateBranches/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,6 @@ func Run(raw *checker.RawResults) ([]finding.Finding, string, error) {
for i := range r.Branches {
branch := &r.Branches[i]

protected := !(branch.Protected != nil && !*branch.Protected)
var protectedValue int
if protected {
protectedValue = 1
} else {
protectedValue = 0
}

p := branch.BranchProtectionRule.CheckRules.UpToDateBeforeMerge
text, outcome, err := branchprotection.GetTextOutcomeFromBool(p,
"up-to-date branches",
Expand Down
8 changes: 0 additions & 8 deletions probes/runsStatusChecksBeforeMerging/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@ func Run(raw *checker.RawResults) ([]finding.Finding, string, error) {
for i := range r.Branches {
branch := &r.Branches[i]

protected := !(branch.Protected != nil && !*branch.Protected)
var protectedValue int
if protected {
protectedValue = 1
} else {
protectedValue = 0
}

switch {
case len(branch.BranchProtectionRule.CheckRules.Contexts) > 0:
f, err := finding.NewWith(fs, Probe,
Expand Down

0 comments on commit 5c98388

Please sign in to comment.