Skip to content
Merged
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
2 changes: 1 addition & 1 deletion scripts/subtests/lint
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ set +e
golangci_lint_executable=$(which golangci-lint)
set -e
if [ -z "${golangci_lint_executable}" ] || [ ! -x "${golangci_lint_executable}" ]; then
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
fi

pushd "${SCRIPT_DIR}/../../src" > /dev/null
Expand Down
21 changes: 21 additions & 0 deletions src/.golangci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
version: "2"

run:
# Timeout for analysis, e.g. 30s, 5m.
# Default: 1m
Expand All @@ -11,9 +13,28 @@ linters:
- gocyclo
# Inspects source code for security problems.
- gosec
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$

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

formatters:
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
2 changes: 1 addition & 1 deletion src/integration_tests/fakes/doppler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"code.cloudfoundry.org/loggregator-release/src/testservers"
"google.golang.org/grpc"

. "github.com/onsi/gomega"
. "github.com/onsi/gomega" //nolint:staticcheck
)

func DopplerEgressV1Client(addr string) (func(), plumbing.DopplerClient) {
Expand Down
4 changes: 2 additions & 2 deletions src/integration_tests/router/router_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ func primePumpV2(ingressClient loggregator_v2.Ingress_SenderClient, subscribeCli
Expect(err).ToNot(HaveOccurred())
}

var ErrorMissingOrigin = errors.New("Event not emitted due to missing origin information")
var ErrorUnknownEventType = errors.New("Cannot create envelope for unknown event type")
var ErrorMissingOrigin = errors.New("event not emitted due to missing origin information")
var ErrorUnknownEventType = errors.New("cannot create envelope for unknown event type")

func Wrap(event events.Event, origin string) (*events.Envelope, error) {
if origin == "" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ func (h *FakeUaaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {

token := r.FormValue("token")

if token == "iAmAnAdmin" {
switch token {
case "iAmAnAdmin":
authData := map[string]interface{}{
"scope": []string{
"doppler.firehose",
Expand All @@ -31,7 +32,7 @@ func (h *FakeUaaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {

marshaled, _ := json.Marshal(authData)
_, _ = w.Write(marshaled)
} else if token == "iAmNotAnAdmin" {
case "iAmNotAnAdmin":
authData := map[string]interface{}{
"scope": []string{
"uaa.not-admin",
Expand All @@ -40,13 +41,13 @@ func (h *FakeUaaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {

marshaled, _ := json.Marshal(authData)
_, _ = w.Write(marshaled)
} else if token == "expiredToken" {
case "expiredToken":
w.WriteHeader(http.StatusBadRequest)
_, _ = w.Write([]byte("{\"error\":\"invalid_token\",\"error_description\":\"Token has expired\"}"))
} else if token == "invalidToken" {
case "invalidToken":
w.WriteHeader(http.StatusBadRequest)
_, _ = w.Write([]byte("{\"invalidToken\":\"invalid_token\",\"error_description\":\"Invalid token (could not decode): invalidToken\"}"))
} else {
default:
w.WriteHeader(http.StatusInternalServerError)
}

Expand Down
2 changes: 1 addition & 1 deletion src/metricemitter/counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func NewCounter(name, sourceID string, opts ...MetricOption) *Counter {
name: name,
sourceID: sourceID,
}
m.Tagged.tags = make(map[string]*loggregator_v2.Value)
m.tags = make(map[string]*loggregator_v2.Value)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please revert this. The Tagged struct is used to unify the format of the tags among counters and gauges

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I've taken another look at this, This doesn't make any difference in the usage of the fields. As long as we keep and use the Tagged struct everywhere, there will be no problems.


for _, opt := range opts {
opt(m.Tagged)
Expand Down
2 changes: 1 addition & 1 deletion src/metricemitter/gauge.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func NewGauge(name, unit, sourceID string, opts ...MetricOption) *Gauge {
unit: unit,
sourceID: sourceID,
}
m.Tagged.tags = make(map[string]*loggregator_v2.Value)
m.tags = make(map[string]*loggregator_v2.Value)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same as above


for _, opt := range opts {
opt(m.Tagged)
Expand Down
6 changes: 1 addition & 5 deletions src/router/internal/server/v1/doppler_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,7 @@ func (m *DopplerServer) sendData(req *plumbing.SubscriptionRequest, sender sende
var done int64
go m.monitorContext(sender.Context(), &done)

for {
if atomic.LoadInt64(&done) > 0 {
break
}

for atomic.LoadInt64(&done) <= 0 {
data, ok := d.TryNext()
if !ok {
time.Sleep(10 * time.Millisecond)
Expand Down
4 changes: 2 additions & 2 deletions src/router/internal/sinks/message_router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ var _ = Describe("Message Router", func() {
})
})

var errorMissingOrigin = errors.New("Event not emitted due to missing origin information")
var errorUnknownEventType = errors.New("Cannot create envelope for unknown event type")
var errorMissingOrigin = errors.New("event not emitted due to missing origin information")
var errorUnknownEventType = errors.New("cannot create envelope for unknown event type")

func wrap(event events.Event, origin string) (*events.Envelope, error) {
if origin == "" {
Expand Down
4 changes: 2 additions & 2 deletions src/testservers/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
envstruct "code.cloudfoundry.org/go-envstruct"
"code.cloudfoundry.org/loggregator-release/src/router/app"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/ginkgo/v2" //nolint:staticcheck
. "github.com/onsi/gomega" //nolint:staticcheck
"github.com/onsi/gomega/gexec"
)

Expand Down
4 changes: 2 additions & 2 deletions src/testservers/traffic_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"os"
"os/exec"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/ginkgo/v2" //nolint:staticcheck
. "github.com/onsi/gomega" //nolint:staticcheck
"github.com/onsi/gomega/gexec"

envstruct "code.cloudfoundry.org/go-envstruct"
Expand Down
4 changes: 2 additions & 2 deletions src/trafficcontroller/app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ func LoadConfig() (*Config, error) {

func (c *Config) validate() error {
if c.SystemDomain == "" {
return errors.New("Need system domain in order to create the proxies")
return errors.New("need system domain in order to create the proxies")
}

if c.IP == "" {
return errors.New("Need IP address for access logging")
return errors.New("need IP address for access logging")
}

if len(c.GRPC.CAFile) == 0 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
)

var (
ErrNoAuthTokenProvided = errors.New("Error: Authorization not provided")
ErrInvalidAuthToken = errors.New("Error: Invalid authorization")
ErrNoAuthTokenProvided = errors.New("authorization not provided")
ErrInvalidAuthToken = errors.New("invalid authorization")
)

// TODO: We don't need to return an error and a status code. One will suffice.
Expand All @@ -25,7 +25,7 @@ func NewLogAccessAuthorizer(c *http.Client, disableAccessControl bool, apiHost s

return LogAccessAuthorizer(func(authToken string, target string) (int, error) {
if authToken == "" {
log.Println(ErrNoAuthTokenProvided)
log.Println("Error:", ErrNoAuthTokenProvided)
return http.StatusUnauthorized, ErrNoAuthTokenProvided
}

Expand Down
4 changes: 2 additions & 2 deletions src/trafficcontroller/internal/auth/uaa_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (c *uaaClient) GetAuthData(token string) (*AuthData, error) {
defer response.Body.Close()

if response.StatusCode == http.StatusUnauthorized {
return nil, errors.New("Invalid username/password")
return nil, errors.New("invalid username/password")
}

if response.StatusCode == http.StatusNotFound {
Expand All @@ -66,7 +66,7 @@ func (c *uaaClient) GetAuthData(token string) (*AuthData, error) {
}

if response.StatusCode != http.StatusOK {
return nil, errors.New("Unknown error occurred")
return nil, errors.New("unknown error occurred")
}

var aData AuthData
Expand Down
17 changes: 9 additions & 8 deletions src/trafficcontroller/internal/auth/uaa_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ var _ = Describe("UaaClient", func() {

_, err := uaaClient.GetAuthData("500Please")
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("Unknown error occurred"))
Expect(err.Error()).To(Equal("unknown error occurred"))
})
})

Expand All @@ -102,7 +102,7 @@ var _ = Describe("UaaClient", func() {

_, err := uaaClient.GetAuthData("iAmAnAdmin")
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("Invalid username/password"))
Expect(err.Error()).To(Equal("invalid username/password"))
})
})

Expand Down Expand Up @@ -149,7 +149,8 @@ func (h *FakeUaaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {

token := r.FormValue("token")

if token == "iAmAnAdmin" {
switch token {
case "iAmAnAdmin":
authData := map[string]interface{}{
"scope": []string{
"doppler.firehose",
Expand All @@ -161,7 +162,7 @@ func (h *FakeUaaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {

_, err = w.Write(marshaled)
Expect(err).ToNot(HaveOccurred())
} else if token == "iAmNotAnAdmin" {
case "iAmNotAnAdmin":
authData := map[string]interface{}{
"scope": []string{
"uaa.not-admin",
Expand All @@ -173,19 +174,19 @@ func (h *FakeUaaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {

_, err = w.Write(marshaled)
Expect(err).ToNot(HaveOccurred())
} else if token == "expiredToken" {
case "expiredToken":
w.WriteHeader(http.StatusBadRequest)
_, err := w.Write([]byte("{\"error\":\"invalid_token\",\"error_description\":\"Token has expired\"}"))
Expect(err).ToNot(HaveOccurred())
} else if token == "invalidToken" {
case "invalidToken":
w.WriteHeader(http.StatusBadRequest)
_, err := w.Write([]byte("{\"invalidToken\":\"invalid_token\",\"error_description\":\"Invalid token (could not decode): invalidToken\"}"))
Expect(err).ToNot(HaveOccurred())
} else if token == "invalidTokenWithBadResponse" {
case "invalidTokenWithBadResponse":
w.WriteHeader(http.StatusBadRequest)
_, err := w.Write([]byte("{"))
Expect(err).ToNot(HaveOccurred())
} else {
default:
w.WriteHeader(http.StatusInternalServerError)
}
}
Loading