Skip to content

Commit

Permalink
Merge pull request #59 from inteon/fix_linters
Browse files Browse the repository at this point in the history
Fix gosec errors and enable gosec linter
  • Loading branch information
inteon committed May 13, 2024
2 parents ca879f2 + baddf17 commit 656eb61
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 14 deletions.
1 change: 0 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
issues:
exclude-rules:
- linters:
- gosec
- nilnil
text: ".*"
linters:
Expand Down
1 change: 1 addition & 0 deletions internal/util/signal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func testExitCode(
os.Exit(0)
}

// #nosec G204
cmd := exec.Command(os.Args[0], "-test.run="+t.Name())
cmd.Env = append(os.Environ(), "BE_CRASHER=1")
cmd.Stdout = os.Stdout
Expand Down
2 changes: 1 addition & 1 deletion internal/versionchecker/test/testdata/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func (inv *Inventory) write(manifestsPath string) error {
invBytes.WriteString("\n---\n")
}

if err := os.WriteFile(manifestsPath, invBytes.Bytes(), 0644); err != nil {
if err := os.WriteFile(manifestsPath, invBytes.Bytes(), 0600); err != nil {
return fmt.Errorf("failed to write inventory file: %v", err)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/create/certificaterequest/certificaterequest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ spec:

for name, test := range tests {
t.Run(name, func(t *testing.T) {
if err := os.WriteFile("testfile.yaml", []byte(test.inputFileContent), 0644); err != nil {
if err := os.WriteFile("testfile.yaml", []byte(test.inputFileContent), 0600); err != nil {
t.Fatalf("error creating test file %#v", err)
}
defer os.Remove("testfile.yaml")
Expand Down
3 changes: 1 addition & 2 deletions pkg/renew/renew.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,7 @@ func (o *Options) Run(ctx context.Context, args []string) error {
}

for _, crt := range crts {
// #nosec G601 -- False positive. See https://github.com/golang/go/discussions/56010
if err := o.renewCertificate(ctx, &crt); err != nil {
if err := o.renewCertificate(ctx, &crt); /* #nosec G601 -- Pointer does not outlive function scope */ err != nil {
return err
}
}
Expand Down
11 changes: 4 additions & 7 deletions pkg/status/certificate/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,8 @@ func findMatchingCR(cmClient cmclient.Interface, ctx context.Context, crt *cmapi
nextRevision = *crt.Status.Revision + 1
}
for _, req := range reqs.Items {
// #nosec G601 -- False positive. See https://github.com/golang/go/discussions/56010
if predicate.CertificateRequestRevision(nextRevision)(&req) &&
predicate.ResourceOwnedBy(crt)(&req) {
if predicate.CertificateRequestRevision(nextRevision)(&req) && /* #nosec G601 -- Pointer does not outlive function scope */
predicate.ResourceOwnedBy(crt)(&req) /* #nosec G601 -- Pointer does not outlive function scope */ {
possibleMatches = append(possibleMatches, req.DeepCopy())
}
}
Expand All @@ -338,8 +337,7 @@ func findMatchingOrder(cmClient cmclient.Interface, ctx context.Context, req *cm

possibleMatches := []*cmacme.Order{}
for _, order := range orders.Items {
// #nosec G601 -- False positive. See https://github.com/golang/go/discussions/56010
if predicate.ResourceOwnedBy(req)(&order) {
if predicate.ResourceOwnedBy(req)(&order) /* #nosec G601 -- Pointer does not outlive function scope */ {
possibleMatches = append(possibleMatches, order.DeepCopy())
}
}
Expand Down Expand Up @@ -391,8 +389,7 @@ func findMatchingChallenges(cmClient cmclient.Interface, ctx context.Context, or

possibleMatches := []*cmacme.Challenge{}
for _, challenge := range challenges.Items {
// #nosec G601 -- False positive. See https://github.com/golang/go/discussions/56010
if predicate.ResourceOwnedBy(order)(&challenge) {
if predicate.ResourceOwnedBy(order)(&challenge) /* #nosec G601 -- Pointer does not outlive function scope */ {
possibleMatches = append(possibleMatches, challenge.DeepCopy())
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/status/certificate/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ func (secretStatus *SecretStatus) String() string {
return secretStatus.Error.Error()
}

secretFormat := `Secret:
detailsFormat := `Secret:
Name: %s
Issuer Country: %s
Issuer Organisation: %s
Expand All @@ -363,7 +363,7 @@ func (secretStatus *SecretStatus) String() string {
if err != nil {
extKeyUsageString = err.Error()
}
output := fmt.Sprintf(secretFormat, secretStatus.Name, strings.Join(secretStatus.IssuerCountry, ", "),
output := fmt.Sprintf(detailsFormat, secretStatus.Name, strings.Join(secretStatus.IssuerCountry, ", "),
strings.Join(secretStatus.IssuerOrganisation, ", "),
secretStatus.IssuerCommonName, keyUsageToString(secretStatus.KeyUsage),
extKeyUsageString, secretStatus.PublicKeyAlgorithm, secretStatus.SignatureAlgorithm,
Expand Down

0 comments on commit 656eb61

Please sign in to comment.