Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade dependencies #461

Merged
merged 2 commits into from
Apr 4, 2024
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
25 changes: 14 additions & 11 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ linters-settings:
# STxxxx checks in https://staticcheck.io/docs/configuration/options/#checks
# Default: ["*"]
checks: ["all", "-ST1000", "-ST1003"]
testifylint:
disable:
- go-require

linters:
enable:
Expand All @@ -31,12 +28,13 @@ linters:
- bidichk # Checks for dangerous unicode character sequences
- bodyclose # Checks whether HTTP response body is closed successfully
# - copyloopvar # Detects places where loop variables are copied
- decorder # check declaration order and count of types, constants, variables and functions
- decorder # Check declaration order and count of types, constants, variables and functions
- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
- dupl # Tool for code clone detection
- durationcheck # check for two durations multiplied together
- dupword # A linter that checks for duplicate words in the source code (usually miswritten)
- durationcheck # Check for two durations multiplied together
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases
- errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and optionally reports occations, where the check for the returned error can be omitted.
- errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted.
- errname # Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`.
- errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13.
- execinquery # Execinquery is a linter about query string checker in Query function which reads your Go src files and warning it finds.
Expand Down Expand Up @@ -68,12 +66,15 @@ linters:
- loggercheck # Checks key value pairs for common logger libraries (kitlog,klog,logr,zap).
- mirror # Reports wrong mirror patterns of bytes/strings usage
- misspell # Finds commonly misspelled English words in comments
- nakedret # Finds naked returns in functions greater than a specified function length
- nestif # Reports deeply nested if statements
- nilerr # Finds the code that returns nil even if it checks that the error is not nil.
- nilnil # Checks that there is no simultaneous return of `nil` error and an invalid value.
- noctx # noctx finds sending http request without context.Context
- nolintlint # Reports ill-formed or insufficient nolint directives
- nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL
- perfsprint # Checks that fmt.Sprintf can be replaced with a faster alternative.
- prealloc # Finds slice declarations that could potentially be preallocated
- predeclared # find code that shadows one of Go's predeclared identifiers
- protogetter # Reports direct reads from proto message fields when getters should be used.
- revive # golint replacement, finds style mistakes
Expand Down Expand Up @@ -114,18 +115,15 @@ linters:
- maintidx # maintidx measures the maintainability index of each function.
- makezero # Finds slice declarations with non-zero initial length
- maligned # Tool to detect Go structs that would take less memory if their fields were sorted
- nakedret # Finds naked returns in functions greater than a specified function length
- nestif # Reports deeply nested if statements
- nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity
- nonamedreturns # Reports all named returns
- paralleltest # paralleltest detects missing usage of t.Parallel() method in your Go test
- prealloc # Finds slice declarations that could potentially be preallocated
- promlinter # Check Prometheus metrics naming via promlint
- rowserrcheck # checks whether Err of rows is checked successfully
- sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed.
- structcheck # Finds unused struct fields
- tagalign # Check that struct tags are well aligned.
- tagliatelle # Checks the struct tags.
- testableexamples # linter checks if examples are testable (have an expected output)
- testpackage # linter that makes you use a separate _test package
- thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers
- varnamelen # checks that the length of a variable's name matches its scope
Expand All @@ -138,9 +136,10 @@ issues:
# Allow complex tests, better to be self contained
- path: _test\.go
linters:
- dupword
- forcetypeassert
- gocognit
- gocyclo
- gocyclo

# Allow complex main function and lower security in examples
- path: cmd/ocfclient/main\.go
Expand All @@ -149,6 +148,7 @@ issues:
- goconst
- gocyclo
- gosec
- nestif

- path: pkg/error
text: "package name error has same name as predeclared identifier"
Expand All @@ -161,3 +161,6 @@ issues:

# Fix found issues (if it's supported by the linter).
# fix: true

run:
go: "1.20"
2 changes: 1 addition & 1 deletion bridge/resources/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func (r *Resource) observerHandler(req *net.Request, createSubscription bool) (*
}

func (r *Resource) HandleRequest(req *net.Request) (*pool.Message, error) {
if req.Code() == codes.GET && r.getHandler != nil {
if req.Code() == codes.GET && r.getHandler != nil { //nolint:nestif
var resp *pool.Message
var err error
if obs, errObs := req.Observe(); errObs == nil && r.createSubscription != nil && r.PolicyBitMask&schema.Observable != 0 {
Expand Down
3 changes: 2 additions & 1 deletion client/core/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ func DialDiscoveryAddresses(ctx context.Context, cfg DiscoveryConfiguration, err
return nil, errors.New("context has not set deadline")
}
timeout := time.Until(v)
var out []*DiscoveryClient

out := make([]*DiscoveryClient, 0, len(cfg.MulticastAddressUDP4)+len(cfg.MulticastAddressUDP6))

// We need to separate messageIDs for upd4 and udp6, because if any docker container has isolated network
// iotivity-lite gets error EINVAL(22) for sendmsg with UDP6 for some interfaces. If it happens, the device is
Expand Down
11 changes: 6 additions & 5 deletions client/core/getDevice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/plgd-dev/device/v2/client/core/otm"
"github.com/plgd-dev/device/v2/schema/platform"
"github.com/plgd-dev/device/v2/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -75,15 +76,15 @@ func TestClientGetDeviceParallel(t *testing.T) {
go func() {
defer wg.Done()
got, err := c.GetDeviceByIP(ctx, ip)
require.NoError(t, err)
require.NotEmpty(t, got)
assert.NoError(t, err)
Danielius1922 marked this conversation as resolved.
Show resolved Hide resolved
assert.NotEmpty(t, got)
Danielius1922 marked this conversation as resolved.
Show resolved Hide resolved
links, err := got.GetResourceLinks(ctx, got.GetEndpoints())
require.NoError(t, err)
assert.NoError(t, err)
Danielius1922 marked this conversation as resolved.
Show resolved Hide resolved
link, ok := links.GetResourceLink(platform.ResourceURI)
require.True(t, ok)
assert.True(t, ok)
Danielius1922 marked this conversation as resolved.
Show resolved Hide resolved
var v interface{}
err = got.GetResource(ctx, link, &v)
require.NoError(t, err)
assert.NoError(t, err)
Danielius1922 marked this conversation as resolved.
Show resolved Hide resolved
}()
}
wg.Wait()
Expand Down
2 changes: 1 addition & 1 deletion client/getDevice.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (c *Client) getDeviceByIPWithUpdateCache(ctx context.Context, ip string, ex
if err != nil {
return nil, err
}
var devs []*core.Device
devs := make([]*core.Device, 0, len(newDevices))
oldDevs := make(map[string]*core.Device)
if expectedDeviceID != "" {
d, ok := c.deviceCache.GetDevice(expectedDeviceID)
Expand Down
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,27 @@ require (
github.com/karrick/tparse/v2 v2.8.2
github.com/pion/dtls/v2 v2.2.8-0.20240327211025-8244c4570c01
github.com/pion/logging v0.2.2
github.com/plgd-dev/go-coap/v3 v3.3.4-0.20240403064319-6ed2ef2c4664
github.com/plgd-dev/go-coap/v3 v3.3.4-0.20240404104253-8d54d1cdfc79
github.com/plgd-dev/kit/v2 v2.0.0-20211006190727-057b33161b90
github.com/stretchr/testify v1.9.0
github.com/ugorji/go/codec v1.2.12
go.uber.org/atomic v1.11.0
golang.org/x/sync v0.6.0
google.golang.org/grpc v1.62.1
google.golang.org/grpc v1.63.0
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dsnet/golib/memfile v1.0.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pion/transport/v3 v3.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sys v0.18.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect
google.golang.org/protobuf v1.33.0 // indirect
Expand Down
13 changes: 6 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrU
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
Expand Down Expand Up @@ -98,8 +96,8 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/plgd-dev/go-coap/v2 v2.0.4-0.20200819112225-8eb712b901bc/go.mod h1:+tCi9Q78H/orWRtpVWyBgrr4vKFo2zYtbbxUllerBp4=
github.com/plgd-dev/go-coap/v2 v2.4.1-0.20210517130748-95c37ac8e1fa/go.mod h1:rA7fc7ar+B/qa+Q0hRqv7yj/EMtIlmo1l7vkQGSrHPU=
github.com/plgd-dev/go-coap/v3 v3.3.4-0.20240403064319-6ed2ef2c4664 h1:iMMYyd666v1oHmR642hYFoRgRyrN/qMoCoY0X/Cj6RE=
github.com/plgd-dev/go-coap/v3 v3.3.4-0.20240403064319-6ed2ef2c4664/go.mod h1:flkLrn0JqGJyW25Uybwg0g0PZUt+pZ1O7aaPeIhEEbs=
github.com/plgd-dev/go-coap/v3 v3.3.4-0.20240404104253-8d54d1cdfc79 h1:Kaf/67M7+UVsRbNHQx3DDOLzpDI6RE/oYZz2v+a4csg=
github.com/plgd-dev/go-coap/v3 v3.3.4-0.20240404104253-8d54d1cdfc79/go.mod h1:UKObEIXVvPfdNGv7QoKegxPwT12UBy26tNUEOebFkls=
github.com/plgd-dev/kit v0.0.0-20200819113605-d5fcf3e94f63/go.mod h1:Yl9zisyXfPdtP9hTWlJqjJYXmgU/jtSDKttz9/CeD90=
github.com/plgd-dev/kit/v2 v2.0.0-20211006190727-057b33161b90 h1:TC1HJ/UbyflJFPvaOdGmNZ5TeFGex1/dyr9urNGLy7M=
github.com/plgd-dev/kit/v2 v2.0.0-20211006190727-057b33161b90/go.mod h1:Z7oKFLSGQjdi8eInxwFCs0tSApuEM1o0qNck+sJYp4M=
Expand Down Expand Up @@ -182,8 +180,9 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down Expand Up @@ -257,8 +256,8 @@ google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyac
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk=
google.golang.org/grpc v1.62.1 h1:B4n+nfKzOICUXMgyrNd19h/I9oH0L1pizfk1d4zSgTk=
google.golang.org/grpc v1.62.1/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE=
google.golang.org/grpc v1.63.0 h1:WjKe+dnvABXyPJMD7KDNLxtoGk5tgk+YFWN6cBWjZE8=
google.golang.org/grpc v1.63.0/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
Expand Down
9 changes: 5 additions & 4 deletions pkg/eventloop/eventloop_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"sync"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -67,7 +68,7 @@ func TestEventLoopAddThreadSafety(t *testing.T) {
startedCh := make(chan struct{})
wg.Add(1)
loop.Add(NewReadHandler(reflect.ValueOf(startedCh), func(_ reflect.Value, closed bool) {
require.True(t, closed, "Channel should be closed")
assert.True(t, closed, "Channel should be closed")
Danielius1922 marked this conversation as resolved.
Show resolved Hide resolved
wg.Done()
}))
close(startedCh)
Expand All @@ -79,7 +80,7 @@ func TestEventLoopAddThreadSafety(t *testing.T) {
ch := make(chan struct{})
loop.Add(NewReadHandler(reflect.ValueOf(ch), func(_ reflect.Value, closed bool) {
// Simulate task processing
require.True(t, closed, "Channel should be closed")
assert.True(t, closed, "Channel should be closed")
Danielius1922 marked this conversation as resolved.
Show resolved Hide resolved
wg.Done()
}))
close(ch)
Expand All @@ -105,7 +106,7 @@ func TestEventLoopRemoveThreadSafety(t *testing.T) {
startedCh := make(chan struct{})
wg.Add(1)
loop.Add(NewReadHandler(reflect.ValueOf(startedCh), func(_ reflect.Value, closed bool) {
require.True(t, closed, "Channel should be closed")
assert.True(t, closed, "Channel should be closed")
Danielius1922 marked this conversation as resolved.
Show resolved Hide resolved
wg.Done()
}))
close(startedCh)
Expand All @@ -118,7 +119,7 @@ func TestEventLoopRemoveThreadSafety(t *testing.T) {
// Simulate adding a task
ch := make(chan struct{})
loop.Add(NewReadHandler(reflect.ValueOf(ch), func(reflect.Value, bool) {
require.Fail(t, "Task should not be processed")
assert.Fail(t, "Task should not be processed")
Danielius1922 marked this conversation as resolved.
Show resolved Hide resolved
}))
go func() {
defer wg.Done()
Expand Down
2 changes: 1 addition & 1 deletion pkg/security/generateCertificate/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func (cfg Configuration) AsnExtensionKeyUsages() ([]asn1.ObjectIdentifier, error
}

func (cfg Configuration) ToIPAddresses() ([]net.IP, error) {
var ips []net.IP
ips := make([]net.IP, 0, len(cfg.SubjectAlternativeName.IPAddresses))
for _, ip := range cfg.SubjectAlternativeName.IPAddresses {
v := net.ParseIP(ip)
if v == nil {
Expand Down
15 changes: 7 additions & 8 deletions pkg/security/signer/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func NewOCFIdentityCertificate(caCert []*x509.Certificate, caKey crypto.PrivateK
return &OCFIdentityCertificate{caCert: caCert, caKey: caKey, validNotBefore: validNotBefore, validNotAfter: validNotAfter}
}

func (s *OCFIdentityCertificate) Sign(_ context.Context, csr []byte) (signedCsr []byte, err error) {
func (s *OCFIdentityCertificate) Sign(_ context.Context, csr []byte) ([]byte, error) {
now := time.Now()
notBefore := s.validNotBefore
notAfter := s.validNotAfter
Expand All @@ -67,24 +67,23 @@ func (s *OCFIdentityCertificate) Sign(_ context.Context, csr []byte) (signedCsr

csrBlock, _ := pem.Decode(csr)
if csrBlock == nil {
err = errors.New("pem not found")
return
return nil, errors.New("pem not found")
}

certificateRequest, err := x509.ParseCertificateRequest(csrBlock.Bytes)
if err != nil {
return
return nil, err
}

err = certificateRequest.CheckSignature()
if err != nil {
return
return nil, err
}

serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
if err != nil {
return
return nil, err
}

template := x509.Certificate{
Expand All @@ -102,9 +101,9 @@ func (s *OCFIdentityCertificate) Sign(_ context.Context, csr []byte) (signedCsr
if len(s.caCert) == 0 {
return nil, errors.New("cannot sign with empty signer CA certificates")
}
signedCsr, err = x509.CreateCertificate(rand.Reader, &template, s.caCert[0], certificateRequest.PublicKey, s.caKey)
signedCsr, err := x509.CreateCertificate(rand.Reader, &template, s.caCert[0], certificateRequest.PublicKey, s.caKey)
if err != nil {
return
return nil, err
}
return pkgX509.CreatePemChain(s.caCert, signedCsr)
}
Loading