Skip to content

Commit

Permalink
Applying new linter rules
Browse files Browse the repository at this point in the history
Signed-off-by: Elena Kolevska <[email protected]>
  • Loading branch information
elena-kolevska committed Oct 24, 2024
1 parent eac51d6 commit 46facb8
Show file tree
Hide file tree
Showing 34 changed files with 44 additions and 37 deletions.
1 change: 1 addition & 0 deletions bindings/alicloud/sls/sls.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func (s *AliCloudSlsLogstorage) parseLog(req *bindings.InvokeRequest) (*sls.Log,
if err != nil {
return nil, err
}
//nolint:gosec
return producer.GenerateLog(uint32(time.Now().Unix()), logInfo), nil
}

Expand Down
2 changes: 1 addition & 1 deletion bindings/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func (h *HTTPSource) Invoke(parentCtx context.Context, req *bindings.InvokeReque
}

// Create an error for non-200 status codes unless suppressed.
if errorIfNot2XX && resp.StatusCode/100 != 2 { //nolint:usestdlibvars
if errorIfNot2XX && resp.StatusCode/100 != 2 {
err = fmt.Errorf("received status code %d", resp.StatusCode)
}

Expand Down
2 changes: 1 addition & 1 deletion bindings/mqtt3/mqtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func (m *MQTT) handleMessage() func(client mqtt.Client, mqttMsg mqtt.Message) {
return func(client mqtt.Client, mqttMsg mqtt.Message) {
bo := m.backOff
if m.metadata.BackOffMaxRetries >= 0 {
bo = backoff.WithMaxRetries(bo, uint64(m.metadata.BackOffMaxRetries))
bo = backoff.WithMaxRetries(bo, uint64(m.metadata.BackOffMaxRetries)) //nolint:gosec
}

err := retry.NotifyRecover(
Expand Down
2 changes: 1 addition & 1 deletion common/authentication/postgresql/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (m *PostgresAuthMetadata) GetPgxPoolConfig() (*pgxpool.Config, error) {
config.MaxConnIdleTime = m.ConnectionMaxIdleTime
}
if m.MaxConns > 1 {
config.MaxConns = int32(m.MaxConns)
config.MaxConns = int32(m.MaxConns) //nolint:gosec
}

if m.QueryExecMode != "" {
Expand Down
2 changes: 1 addition & 1 deletion common/authentication/sqlite/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func ValidIdentifier(v string) bool {

// Loop through the string as byte slice as we only care about ASCII characters
b := []byte(v)
for i := range len(b) {
for i := range b {
if (b[i] >= '0' && b[i] <= '9') ||
(b[i] >= 'a' && b[i] <= 'z') ||
(b[i] >= 'A' && b[i] <= 'Z') ||
Expand Down
2 changes: 1 addition & 1 deletion common/component/azure/servicebus/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (c *Client) PublishBinding(ctx context.Context, req *bindings.InvokeRequest
func (c *Client) publishBackOff(ctx context.Context) (bo backoff.BackOff) {
ebo := backoff.NewExponentialBackOff()
ebo.InitialInterval = time.Duration(c.metadata.PublishInitialRetryIntervalInMs) * time.Millisecond
bo = backoff.WithMaxRetries(ebo, uint64(c.metadata.PublishMaxRetries))
bo = backoff.WithMaxRetries(ebo, uint64(c.metadata.PublishMaxRetries)) //nolint:gosec
bo = backoff.WithContext(bo, ctx)
return bo
}
2 changes: 1 addition & 1 deletion common/component/kafka/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ func (k *Kafka) SerializeValue(topic string, data []byte, metadata map[string]st
return nil, err
}
schemaIDBytes := make([]byte, 4)
binary.BigEndian.PutUint32(schemaIDBytes, uint32(schema.ID()))
binary.BigEndian.PutUint32(schemaIDBytes, uint32(schema.ID())) //nolint:gosec

recordValue := make([]byte, 0, len(schemaIDBytes)+len(valueBytes)+1)
recordValue = append(recordValue, byte(0))
Expand Down
2 changes: 1 addition & 1 deletion common/component/kafka/kafka_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestDeserializeValue(t *testing.T) {
}

schemaIDBytes := make([]byte, 4)
binary.BigEndian.PutUint32(schemaIDBytes, uint32(schema.ID()))
binary.BigEndian.PutUint32(schemaIDBytes, uint32(schema.ID())) //nolint:gosec

valJSON, _ := json.Marshal(testValue1)
codec, _ := goavro.NewCodecForStandardJSONFull(testSchema1)
Expand Down
2 changes: 1 addition & 1 deletion common/component/kafka/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func (k *Kafka) getKafkaMetadata(meta map[string]string) (*KafkaMetadata, error)
if err != nil {
return nil, fmt.Errorf("kafka error: invalid value for '%s' attribute: %w", consumeRetryInterval, err)
}
m.ConsumeRetryInterval = time.Duration(intVal) * time.Millisecond
m.ConsumeRetryInterval = time.Duration(intVal) * time.Millisecond //nolint:gosec
}
}

Expand Down
4 changes: 2 additions & 2 deletions common/component/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func ParseClientFromProperties(properties map[string]string, componentType metad
if processingTimeoutMs, parseErr := strconv.ParseUint(val, 10, 64); parseErr == nil {
// because of legacy reasons, we need to interpret a number as milliseconds
// the library would default to seconds otherwise
settings.ProcessingTimeout = time.Duration(processingTimeoutMs) * time.Millisecond
settings.ProcessingTimeout = time.Duration(processingTimeoutMs) * time.Millisecond //nolint:gosec
}
// if there was an error we would try to interpret it as a duration string, which was already done in Decode()
}
Expand All @@ -160,7 +160,7 @@ func ParseClientFromProperties(properties map[string]string, componentType metad
if redeliverIntervalMs, parseErr := strconv.ParseUint(val, 10, 64); parseErr == nil {
// because of legacy reasons, we need to interpret a number as milliseconds
// the library would default to seconds otherwise
settings.RedeliverInterval = time.Duration(redeliverIntervalMs) * time.Millisecond
settings.RedeliverInterval = time.Duration(redeliverIntervalMs) * time.Millisecond //nolint:gosec
}
// if there was an error we would try to interpret it as a duration string, which was already done in Decode()
}
Expand Down
4 changes: 2 additions & 2 deletions common/component/redis/v8client.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ func newV8Client(s *Settings) (RedisClient, error) {
/* #nosec */
if s.EnableTLS {
options.TLSConfig = &tls.Config{
InsecureSkipVerify: s.EnableTLS, //nolint:gosec
InsecureSkipVerify: s.EnableTLS,
}
err := s.SetCertificate(func(cert *tls.Certificate) {
options.TLSConfig.Certificates = []tls.Certificate{*cert}
Expand Down Expand Up @@ -440,7 +440,7 @@ func newV8Client(s *Settings) (RedisClient, error) {
/* #nosec */
if s.EnableTLS {
options.TLSConfig = &tls.Config{
InsecureSkipVerify: s.EnableTLS, //nolint:gosec
InsecureSkipVerify: s.EnableTLS,
}
err := s.SetCertificate(func(cert *tls.Certificate) {
options.TLSConfig.Certificates = []tls.Certificate{*cert}
Expand Down
6 changes: 3 additions & 3 deletions common/component/redis/v9client.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func newV9FailoverClient(s *Settings) (RedisClient, error) {
/* #nosec */
if s.EnableTLS {
opts.TLSConfig = &tls.Config{
InsecureSkipVerify: s.EnableTLS, //nolint:gosec
InsecureSkipVerify: s.EnableTLS,
}
err := s.SetCertificate(func(cert *tls.Certificate) {
opts.TLSConfig.Certificates = []tls.Certificate{*cert}
Expand Down Expand Up @@ -404,7 +404,7 @@ func newV9Client(s *Settings) (RedisClient, error) {
if s.EnableTLS {
/* #nosec */
options.TLSConfig = &tls.Config{
InsecureSkipVerify: s.EnableTLS, //nolint:gosec
InsecureSkipVerify: s.EnableTLS,
}
err := s.SetCertificate(func(cert *tls.Certificate) {
options.TLSConfig.Certificates = []tls.Certificate{*cert}
Expand Down Expand Up @@ -444,7 +444,7 @@ func newV9Client(s *Settings) (RedisClient, error) {
if s.EnableTLS {
/* #nosec */
options.TLSConfig = &tls.Config{
InsecureSkipVerify: s.EnableTLS, //nolint:gosec
InsecureSkipVerify: s.EnableTLS,
}
err := s.SetCertificate(func(cert *tls.Certificate) {
options.TLSConfig.Certificates = []tls.Certificate{*cert}
Expand Down
2 changes: 1 addition & 1 deletion common/wasm/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,6 @@ func newFakeWalltime() sys.Walltime {
t := time.Now().Unix() * int64(time.Second)
return func() (sec int64, nsec int32) {
wt := atomic.AddInt64(&t, int64(time.Millisecond))
return wt / 1e9, int32(wt % 1e9)
return wt / 1e9, int32(wt % 1e9) //nolint:gosec
}
}
2 changes: 1 addition & 1 deletion configuration/azure/appconfig/appconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (r *ConfigurationStore) Init(_ context.Context, md configuration.Metadata)
ApplicationID: "dapr-" + logger.DaprVersion,
},
Retry: policy.RetryOptions{
MaxRetries: int32(r.metadata.MaxRetries),
MaxRetries: int32(r.metadata.MaxRetries), //nolint:gosec
RetryDelay: r.metadata.MaxRetryDelay,
MaxRetryDelay: r.metadata.MaxRetryDelay,
},
Expand Down
2 changes: 1 addition & 1 deletion configuration/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (r *ConfigurationStore) parseConnectedSlaves(res string) int {
for _, info := range infos {
if strings.Contains(info, connectedSlavesReplicas) {
parsedReplicas, _ := strconv.ParseUint(info[len(connectedSlavesReplicas):], 10, 32)
return int(parsedReplicas)
return int(parsedReplicas) //nolint:gosec
}
}

Expand Down
2 changes: 1 addition & 1 deletion crypto/azure/keyvault/jwk.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (key JSONWebKey) publicRSA() (*rsa.PublicKey, error) {
if len(key.E) == 0 {
return nil, errors.New("property e is empty")
}
res.E = int(big.NewInt(0).SetBytes(key.E).Uint64())
res.E = int(big.NewInt(0).SetBytes(key.E).Uint64()) //nolint:gosec

return res, nil
}
Expand Down
2 changes: 2 additions & 0 deletions crypto/subtlecrypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
)

// SubtleCrypto offers an interface to perform low-level ("subtle") cryptographic operations with keys stored in a vault.
//
//nolint:interfacebloat
type SubtleCrypto interface {
metadata.ComponentWithMetadata

Expand Down
1 change: 1 addition & 0 deletions metadata/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func TryGetPriority(props map[string]string) (uint8, bool, error) {
return 0, false, fmt.Errorf("%s value must be a valid integer: actual is '%s'", PriorityMetadataKey, val)
}

//nolint:gosec
priority := uint8(intVal)
if intVal < 0 {
priority = 0
Expand Down
6 changes: 3 additions & 3 deletions nameresolution/consul/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func mapChecks(config []*AgentServiceCheck) []*consul.AgentServiceCheck {

mapped := []*consul.AgentServiceCheck{}

for i := range len(config) {
for i := range config {
mapped = append(mapped, mapCheck(config[i]))
}

Expand Down Expand Up @@ -232,7 +232,7 @@ func mapAdvancedRegistration(config *AgentServiceRegistration) *consul.AgentServ

mapped := []consul.Upstream{}

for i := range len(config) {
for i := range config {
tmp := consul.Upstream{
DestinationType: consul.UpstreamDestType(config[i].DestinationType),
DestinationNamespace: config[i].DestinationNamespace,
Expand Down Expand Up @@ -273,7 +273,7 @@ func mapAdvancedRegistration(config *AgentServiceRegistration) *consul.AgentServ

mapped := consul.AgentServiceChecks{}

for i := range len(config) {
for i := range config {
mapped = append(mapped, mapCheck(config[i]))
}

Expand Down
2 changes: 1 addition & 1 deletion nameresolution/consul/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ watchLoop:

// generate set of keys
serviceKeys := make(map[string]any)
for i := range len(services) {
for i := range services {
serviceKeys[services[i]] = nil
}

Expand Down
3 changes: 2 additions & 1 deletion nameresolution/mdns/mdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ func (a *addressList) next() *string {
a.mu.RLock()
defer a.mu.RUnlock()

//nolint:gosec
l := uint32(len(a.addresses))
if l == 0 {
return nil
Expand Down Expand Up @@ -299,7 +300,7 @@ func (m *Resolver) getZeroconfResolver() (resolver *zeroconf.Resolver, err error
zeroconf.SelectIPTraffic(zeroconf.IPv4),
zeroconf.SelectIPTraffic(zeroconf.IPv6),
}
for i := range len(opts) {
for i := range opts {
resolver, err = zeroconf.NewResolver(opts[i])
if err == nil {
break
Expand Down
2 changes: 1 addition & 1 deletion pubsub/envelope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ func TestCreateFromCloudEventsProtobufPayload(t *testing.T) {

contenttypes := []string{contribContenttype.CloudEventProtobufContentType, contribContenttype.ProtobufContentType}

for i := range len(contenttypes) {
for i := range contenttypes {
envelope := NewCloudEventsEnvelope("", "", "", "", "", "",
contenttypes[i], ceProtoBytes, "trace", "")

Expand Down
2 changes: 1 addition & 1 deletion pubsub/jetstream/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func parseMetadata(psm pubsub.Metadata) (metadata, error) {
}

if m.StartTime != nil {
m.internalStartTime = time.Unix(int64(*m.StartTime), 0)
m.internalStartTime = time.Unix(int64(*m.StartTime), 0) //nolint:gosec
}

switch m.DeliverPolicy {
Expand Down
2 changes: 1 addition & 1 deletion pubsub/rabbitmq/rabbitmq.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ func (r *rabbitMQ) prepareSubscription(channel rabbitMQChannelBroker, req pubsub
metadataRoutingKey = val
}
routingKeys := strings.Split(metadataRoutingKey, ",")
for i := range len(routingKeys) {
for i := range routingKeys {
routingKey := routingKeys[i]
r.logger.Debugf("%s binding queue '%s' to exchange '%s' with routing key '%s'", logMessagePrefix, q.Name, req.Topic, routingKey)
err = channel.QueueBind(q.Name, routingKey, req.Topic, false, nil)
Expand Down
5 changes: 3 additions & 2 deletions pubsub/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (r *redisStreams) Init(ctx context.Context, metadata pubsub.Metadata) error
if _, err = r.client.PingResult(ctx); err != nil {
return fmt.Errorf("redis streams: error connecting to redis at %s: %s", r.clientSettings.Host, err)
}
r.queue = make(chan redisMessageWrapper, int(r.clientSettings.QueueDepth))
r.queue = make(chan redisMessageWrapper, int(r.clientSettings.QueueDepth)) //nolint:gosec

for range r.clientSettings.Concurrency {
r.wg.Add(1)
Expand Down Expand Up @@ -268,6 +268,7 @@ func (r *redisStreams) pollNewMessagesLoop(ctx context.Context, stream string, h
}

// Read messages
//nolint:gosec
streams, err := r.client.XReadGroupResult(ctx, r.clientSettings.ConsumerID, r.clientSettings.ConsumerID, []string{stream, ">"}, int64(r.clientSettings.QueueDepth), time.Duration(r.clientSettings.ReadTimeout))
if err != nil {
if !errors.Is(err, r.client.GetNilValueError()) && err != context.Canceled {
Expand Down Expand Up @@ -323,7 +324,7 @@ func (r *redisStreams) reclaimPendingMessages(ctx context.Context, stream string
r.clientSettings.ConsumerID,
"-",
"+",
int64(r.clientSettings.QueueDepth),
int64(r.clientSettings.QueueDepth), //nolint:gosec
)
if err != nil && !errors.Is(err, r.client.GetNilValueError()) {
r.logger.Errorf("error retrieving pending Redis messages: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion pubsub/rocketmq/rocketmq.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func (r *rocketMQ) setUpConsumer() (mq.PushConsumer, error) {
if r.metadata.PullBatchSize > 0 {
opts = append(opts, mqc.WithPullBatchSize(r.metadata.PullBatchSize))
} else if r.metadata.ConsumerBatchSize > 0 {
r.metadata.PullBatchSize = int32(r.metadata.ConsumerBatchSize)
r.metadata.PullBatchSize = int32(r.metadata.ConsumerBatchSize) //nolint:gosec
opts = append(opts, mqc.WithPullBatchSize(r.metadata.PullBatchSize))
r.logger.Warn("set the number of msg pulled from the broker at a time, " +
"please use pullBatchSize instead of consumerBatchSize")
Expand Down
2 changes: 1 addition & 1 deletion secretstores/local/file/filestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (j *localSecretStore) visitPrimitive(context string) error {
}

func (j *localSecretStore) visitArray(array []interface{}) error {
for i := range len(array) {
for i := range array {
j.enterContext(strconv.Itoa(i))
err := j.visitProperty(array[i])
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions state/aerospike/aerospike.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ func parseHosts(hostsMeta string) ([]*as.Host, error) {
if err != nil {
return nil, errInvalidHosts
}
//nolint:gosec
hostPorts = append(hostPorts, as.NewHost(host, int(port)))
}

Expand Down
2 changes: 1 addition & 1 deletion state/bulk.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func DoBulkSetDelete[T stateRequestConstraint](ctx context.Context, req []T, met
}

errs := make([]error, len(req))
for i := range len(req) {
for i := range req {
errs[i] = <-errCh
}

Expand Down
2 changes: 1 addition & 1 deletion state/memcached/memcached.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (m *Memcached) parseTTL(req *state.SetRequest) (*int32, error) {
// If ttl is more than 30 days, convert it to unix timestamp.
// https://github.com/memcached/memcached/wiki/Commands#standard-protocol
if parsedInt >= 60*60*24*30 {
parsedInt = int32(m.clock.Now().Unix()) + parsedInt
parsedInt = int32(m.clock.Now().Unix()) + parsedInt //nolint:gosec
}

// Notice that for Dapr, -1 means "persist with no TTL".
Expand Down
2 changes: 1 addition & 1 deletion state/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ func validIdentifier(v string) bool {

// Loop through the string as byte slice as we only care about ASCII characters
b := []byte(v)
for i := range len(b) {
for i := range b {
if (b[i] >= '0' && b[i] <= '9') ||
(b[i] >= 'a' && b[i] <= 'z') ||
(b[i] >= 'A' && b[i] <= 'Z') ||
Expand Down
1 change: 1 addition & 0 deletions state/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ func (r *StateStore) parseConnectedSlaves(res string) int {
if strings.Contains(info, connectedSlavesReplicas) {
parsedReplicas, _ := strconv.ParseUint(info[len(connectedSlavesReplicas):], 10, 32)

//nolint:gosec
return int(parsedReplicas)
}
}
Expand Down
2 changes: 1 addition & 1 deletion state/redis/redis_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func parseQueryResponsePost28(ret any) ([]state.QueryItem, bool, error) {
if len(arr) == 0 {
return nil, false, errors.New("invalid output")
}
for i := range len(arr) {
for i := range arr {
inner, ok := arr[i].(map[any]any)
if !ok {
return nil, false, errors.New("invalid output")
Expand Down
3 changes: 1 addition & 2 deletions state/zookeeper/zk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package zookeeper

import (
"context"
"fmt"
"testing"
"time"

Expand All @@ -38,7 +37,7 @@ func TestNewConfig(t *testing.T) {
"sessionTimeout": "5s",
}
cp, err := newConfig(properties)
require.NoError(t, err, fmt.Sprintf("Unexpected error: %v", err))
require.NoError(t, err, "Unexpected error: %v", err)
assert.NotNil(t, cp, "failed to respond to missing data field")
assert.Equal(t, []string{
"127.0.0.1:3000", "127.0.0.1:3001", "127.0.0.1:3002",
Expand Down

0 comments on commit 46facb8

Please sign in to comment.