Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions scripts/subtests/lint
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@ set -o pipefail

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

set +e
golangci_lint_executable=$(which golangci-lint)
set -e
if [ -z "${golangci_lint_executable}" ] || [ ! -x "${golangci_lint_executable}" ]; then
if ! command -v golangci-lint &> /dev/null; then
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
fi

pushd "${SCRIPT_DIR}/../../src" > /dev/null
golangci-lint run ./...
popd > /dev/null

popd > /dev/null
5 changes: 1 addition & 4 deletions scripts/subtests/spec-test
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ set -o pipefail

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

set +e
bundler_executable=$(which bundle)
set -e
if [ -z "${bundler_executable}" ] || [ ! -x "${bundler_executable}" ]; then
if ! command -v bundle &> /dev/null; then
gem install bundler
fi

Expand Down
8 changes: 5 additions & 3 deletions scripts/subtests/unit-test
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ if [ "${CI:-false}" = 'false' ]; then
fi

pushd "${SCRIPT_DIR}/../../src" > /dev/null
go run github.com/onsi/ginkgo/v2/ginkgo $flags
popd > /dev/null

if ! command -v ginkgo &> /dev/null; then
go install github.com/onsi/ginkgo/v2/ginkgo@latest
fi
ginkgo $flags
popd > /dev/null
6 changes: 6 additions & 0 deletions src/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,19 @@ linters:
- third_party$
- builtin$
- examples$
rules:
# Exclude gosec from all test files
- path: _test\.go
linters:
- gosec

issues:
# Disable max issues per linter.
max-issues-per-linter: 0
# Disable max same issues.
max-same-issues: 0


formatters:
exclusions:
generated: lax
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/cf-auth-proxy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type CAPI struct {

type UAA struct {
ClientID string `env:"UAA_CLIENT_ID,"`
ClientSecret string `env:"UAA_CLIENT_SECRET,"`
ClientSecret string `env:"UAA_CLIENT_SECRET,"` //#nosec G117
Addr string `env:"UAA_ADDR, required, report"`
CAPath string `env:"UAA_CA_PATH, report"`
}
Expand Down
4 changes: 2 additions & 2 deletions src/internal/auth/capi_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (c *CAPIClient) IsAuthorized(sourceId string, clientToken string) bool {
}

func (c *CAPIClient) HasApp(sourceID, authToken string) bool {
req, err := http.NewRequest(http.MethodGet, c.addr+"/v3/apps/"+sourceID, nil)
req, err := http.NewRequest(http.MethodGet, c.addr+"/v3/apps/"+sourceID, nil) //#nosec G704
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use //nolint:gosec instead of #nosec as we are using gosec via golang and not directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. There are several instances where there nosec is already used in this code base. Do you want me to change those as well?

if err != nil {
c.log.Printf("failed to build authorize log access request: %s", err)
return false
Expand Down Expand Up @@ -130,7 +130,7 @@ func (c *CAPIClient) GetRelatedSourceIds(appNames []string, authToken string) ma
return map[string][]string{}
}

req, err := http.NewRequest(http.MethodGet, c.addr+"/v3/apps", nil)
req, err := http.NewRequest(http.MethodGet, c.addr+"/v3/apps", nil) //#nosec G704
if err != nil {
c.log.Printf("failed to build app list request: %s", err)
return map[string][]string{}
Expand Down
2 changes: 1 addition & 1 deletion src/internal/cache/log_cache.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cache

import (
"context"
"log"
"net"
"strconv"
Expand All @@ -9,7 +10,6 @@ import (

metrics "code.cloudfoundry.org/go-metric-registry"

"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

Expand Down
2 changes: 1 addition & 1 deletion src/internal/gateway/gateway.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gateway

import (
"context"
"fmt"
"io"
"log"
Expand All @@ -10,7 +11,6 @@ import (

"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/shirou/gopsutil/v4/host"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/encoding/protojson"
Expand Down
6 changes: 4 additions & 2 deletions src/internal/nozzle/nozzle.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nozzle

import (
"context"
"log"
"runtime"
"time"
Expand All @@ -11,7 +12,6 @@ import (
diodes "code.cloudfoundry.org/go-diodes"
"code.cloudfoundry.org/go-log-cache/v3/rpc/logcache_v1"
"code.cloudfoundry.org/go-loggregator/v10/rpc/loggregator_v2"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
Expand Down Expand Up @@ -177,7 +177,7 @@ func (n *Nozzle) envelopeWriter(ch chan []*loggregator_v2.Envelope, client logca
for {
envelopes := <-ch

ctx, _ := context.WithTimeout(context.Background(), 3*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
_, err := client.Send(ctx, &logcache_v1.SendRequest{
Envelopes: &loggregator_v2.EnvelopeBatch{
Batch: envelopes,
Expand All @@ -186,10 +186,12 @@ func (n *Nozzle) envelopeWriter(ch chan []*loggregator_v2.Envelope, client logca

if err != nil {
n.errCounter.Add(1)
cancel()
continue
}

n.egressCounter.Add(float64(len(envelopes)))
cancel()
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/internal/nozzle/nozzle_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nozzle_test

import (
"context"
"log"
"sync"

Expand All @@ -9,7 +10,6 @@ import (
"code.cloudfoundry.org/go-loggregator/v10"
"code.cloudfoundry.org/go-loggregator/v10/rpc/loggregator_v2"
. "code.cloudfoundry.org/log-cache/internal/nozzle"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
Expand Down
5 changes: 3 additions & 2 deletions src/internal/routing/batched_ingress_client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package routing

import (
"context"
"log"
"time"

Expand All @@ -10,7 +11,6 @@ import (
diodes "code.cloudfoundry.org/go-diodes"
rpc "code.cloudfoundry.org/go-log-cache/v3/rpc/logcache_v1"
"code.cloudfoundry.org/go-loggregator/v10/rpc/loggregator_v2"
"golang.org/x/net/context"
"google.golang.org/grpc"
)

Expand Down Expand Up @@ -96,7 +96,8 @@ func (b *BatchedIngressClient) write(batch []interface{}) {
e = append(e, i.(*loggregator_v2.Envelope))
}

ctx, _ := context.WithTimeout(context.Background(), 3*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
_, err := b.c.Send(ctx, &rpc.SendRequest{
LocalOnly: b.localOnly,
Envelopes: &loggregator_v2.EnvelopeBatch{Batch: e},
Expand Down
2 changes: 1 addition & 1 deletion src/internal/routing/batched_ingress_client_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package routing_test

import (
"context"
"io"
"log"
"time"
Expand All @@ -11,7 +12,6 @@ import (
"code.cloudfoundry.org/go-loggregator/v10/rpc/loggregator_v2"
metrics "code.cloudfoundry.org/go-metric-registry"
"code.cloudfoundry.org/log-cache/internal/routing"
"golang.org/x/net/context"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down
2 changes: 1 addition & 1 deletion src/internal/routing/local_store_reader.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package routing

import (
"context"
"fmt"
"regexp"
"time"

"code.cloudfoundry.org/go-log-cache/v3/rpc/logcache_v1"
"code.cloudfoundry.org/go-loggregator/v10/rpc/loggregator_v2"
"golang.org/x/net/context"
"google.golang.org/grpc"
)

Expand Down
2 changes: 1 addition & 1 deletion src/internal/routing/local_store_reader_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package routing_test

import (
"context"
"regexp"
"time"

"code.cloudfoundry.org/go-log-cache/v3/rpc/logcache_v1"
"code.cloudfoundry.org/go-loggregator/v10/rpc/loggregator_v2"
"code.cloudfoundry.org/log-cache/internal/routing"
"golang.org/x/net/context"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down
4 changes: 2 additions & 2 deletions src/internal/routing/static_lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ func NewStaticLookup(numOfRoutes int, hasher func(string) uint64) *StaticLookup

// NOTE: 18446744073709551615 is 0xFFFFFFFFFFFFFFFF or the max value of a
// uint64.
x := (18446744073709551615 / uint64(numOfRoutes))
for i := uint64(0); i < uint64(numOfRoutes); i++ {
x := (18446744073709551615 / uint64(numOfRoutes)) //#nosec G115
for i := uint64(0); i < uint64(numOfRoutes); i++ { //#nosec G115
t.Put(i*x, i)
}

Expand Down
12 changes: 5 additions & 7 deletions src/internal/syslog/server.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package syslog

import (
"context"
"crypto/tls"
"errors"
"fmt"
"log"
"net"
"strconv"
"strings"
"sync"
"time"

"code.cloudfoundry.org/go-loggregator/v10"
Expand All @@ -15,13 +20,6 @@ import (
"github.com/leodido/go-syslog/v4/nontransparent"
"github.com/leodido/go-syslog/v4/octetcounting"
"github.com/leodido/go-syslog/v4/rfc5424"

"net"
"strconv"
"strings"
"sync"

"golang.org/x/net/context"
)

type Server struct {
Expand Down
Loading