Skip to content

Commit

Permalink
Fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielius1922 committed Aug 21, 2024
1 parent 1db2b3e commit 50a78f7
Show file tree
Hide file tree
Showing 30 changed files with 59 additions and 58 deletions.
3 changes: 1 addition & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ linters:
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
- bidichk # Checks for dangerous unicode character sequences
- bodyclose # Checks whether HTTP response body is closed successfully
# - copyloopvar # Detects places where loop variables are copied
- copyloopvar # Detects places where loop variables are copied
- 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
Expand All @@ -35,7 +35,6 @@ linters:
- 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.
- exportloopref # checks for pointers to enclosing loop variables
# - forcetypeassert # finds forced type assertions
- gci # Gci control golang package import order and make it always deterministic.
- gocheckcompilerdirectives # Checks that go compiler directive comments (//go:) are valid.
Expand Down
4 changes: 2 additions & 2 deletions bundle/client/coap/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func updateResource(co *client.Conn, href string, contentFormat int) {
if err != nil {
updateError(err)
}
resp, err := co.Post(context.Background(), href, message.MediaType(contentFormat), bytes.NewReader(b.Bytes()))
resp, err := co.Post(context.Background(), href, message.MediaType(contentFormat), bytes.NewReader(b.Bytes())) //nolint:gosec
if err != nil {
updateError(err)
}
Expand All @@ -210,7 +210,7 @@ func createResource(co *client.Conn, href string, contentFormat int) {
if err != nil {
createError(err)
}
req, err := co.NewPostRequest(context.Background(), href, message.MediaType(contentFormat), os.Stdin)
req, err := co.NewPostRequest(context.Background(), href, message.MediaType(contentFormat), os.Stdin) //nolint:gosec
if err != nil {
createError(err)
}
Expand Down
4 changes: 2 additions & 2 deletions bundle/client/grpc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func updateResource(ctx context.Context, client pbGW.GrpcGatewayClient, deviceID
resp, err := client.UpdateResource(ctx, &pbGW.UpdateResourceRequest{
ResourceId: commands.NewResourceID(deviceID, href),
Content: &pbGW.Content{
ContentType: message.MediaType(contentFormat).String(),
ContentType: message.MediaType(contentFormat).String(), //nolint:gosec
Data: data,
},
})
Expand All @@ -133,7 +133,7 @@ func createResource(ctx context.Context, client pbGW.GrpcGatewayClient, deviceID
resp, err := client.CreateResource(ctx, &pbGW.CreateResourceRequest{
ResourceId: commands.NewResourceID(deviceID, href),
Content: &pbGW.Content{
ContentType: message.MediaType(contentFormat).String(),
ContentType: message.MediaType(contentFormat).String(), //nolint:gosec
Data: data,
},
})
Expand Down
4 changes: 2 additions & 2 deletions cloud2cloud-connector/service/deviceSubscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (s *SubscriptionManager) handleResourcesPublished(ctx context.Context, d Su
for _, endpoint := range link.GetEndpoints() {
endpoints = append(endpoints, &commands.EndpointInformation{
Endpoint: endpoint.URI,
Priority: int64(endpoint.Priority),
Priority: endpoint.Priority,
})
}
href := pkgHttpUri.CanonicalHref(trimDeviceIDFromHref(link.DeviceID, link.Href))
Expand All @@ -120,7 +120,7 @@ func (s *SubscriptionManager) handleResourcesPublished(ctx context.Context, d Su
Interfaces: link.Interfaces,
DeviceId: link.DeviceID,
Anchor: link.Anchor,
Policy: &commands.Policy{BitFlags: int32(link.Policy.BitMask)},
Policy: &commands.Policy{BitFlags: commands.ToPolicyBitFlags(link.Policy.BitMask)},
Title: link.Title,
SupportedContentTypes: link.SupportedContentTypes,
EndpointInformations: endpoints,
Expand Down
4 changes: 2 additions & 2 deletions cloud2cloud-connector/service/publishResource.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func publishResource(ctx context.Context, raClient raService.ResourceAggregateCl
for _, endpoint := range link.GetEndpoints() {
endpoints = append(endpoints, &commands.EndpointInformation{
Endpoint: endpoint.URI,
Priority: int64(endpoint.Priority),
Priority: endpoint.Priority,
})
}
href := pkgHttpUri.CanonicalHref(trimDeviceIDFromHref(link.DeviceID, link.Href))
Expand All @@ -26,7 +26,7 @@ func publishResource(ctx context.Context, raClient raService.ResourceAggregateCl
Interfaces: link.Interfaces,
DeviceId: link.DeviceID,
Anchor: link.Anchor,
Policy: &commands.Policy{BitFlags: int32(link.Policy.BitMask)},
Policy: &commands.Policy{BitFlags: commands.ToPolicyBitFlags(link.Policy.BitMask)},
Title: link.Title,
SupportedContentTypes: link.SupportedContentTypes,
EndpointInformations: endpoints,
Expand Down
11 changes: 5 additions & 6 deletions coap-gateway/coapconv/coapconv.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func CoapCodeToStatus(code codes.Code, operation Operation) commands.Status {

func MakeMediaType(coapContentFormat int32, contentType string) (message.MediaType, error) {
if coapContentFormat >= 0 {
return message.MediaType(coapContentFormat), nil
return message.MediaType(coapContentFormat), nil //nolint:gosec
}
switch contentType {
case message.TextPlain.String():
Expand Down Expand Up @@ -174,7 +174,7 @@ func NewContent(opts message.Options, body io.Reader) *commands.Content {
data, coapContentFormat := GetContentData(opts, body)

return &commands.Content{
ContentType: getContentFormatString(coapContentFormat),
ContentType: GetContentFormatString(coapContentFormat),
CoapContentFormat: coapContentFormat,
Data: data,
}
Expand All @@ -192,10 +192,9 @@ func GetContentData(opts message.Options, body io.Reader) (data []byte, contentF
return data, contentFormat
}

func getContentFormatString(coapContentFormat int32) string {
func GetContentFormatString(coapContentFormat int32) string {
if coapContentFormat != -1 {
mt := message.MediaType(coapContentFormat)
return mt.String()
return message.MediaType(coapContentFormat).String() //nolint:gosec
}
return ""
}
Expand Down Expand Up @@ -416,7 +415,7 @@ func NewNotifyResourceChangedRequestsFromBatchResourceDiscovery(deviceID, connec
resourceChangedReq := &commands.NotifyResourceChangedRequest{
ResourceId: commands.NewResourceID(deviceID, r.Href()),
Content: &commands.Content{
ContentType: getContentFormatString(ct),
ContentType: GetContentFormatString(ct),
CoapContentFormat: ct,
Data: data,
},
Expand Down
2 changes: 1 addition & 1 deletion coap-gateway/coapconv/getEncoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func GetAccept(opts message.Options) message.MediaType {
if err != nil {
return message.AppOcfCbor
}
return message.MediaType(ct)
return message.MediaType(ct) //nolint:gosec
}

// GetEncoder returns encoder by accept
Expand Down
2 changes: 1 addition & 1 deletion coap-gateway/service/observation/deviceObserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ func createDiscoveryResourceObserver(ctx context.Context, deviceID string, coapC
err := resourcesObserver.addResource(ctx, &commands.Resource{
DeviceId: resourcesObserver.deviceID,
Href: resources.ResourceURI,
Policy: &commands.Policy{BitFlags: int32(schema.Observable)},
Policy: &commands.Policy{BitFlags: commands.ToPolicyBitFlags(schema.Observable)},
}, interfaces.OC_IF_B, etags)
if err != nil {
resourcesObserver.CleanObservedResources(ctx)
Expand Down
4 changes: 2 additions & 2 deletions coap-gateway/service/observation/deviceObserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func testValidateResourceLinks(ctx context.Context, t *testing.T, deviceID strin
ResourceTypes: []string{device.ResourceType},
Interfaces: []string{interfaces.OC_IF_BASELINE},
Policy: &commands.Policy{
BitFlags: int32(schema.Observable | schema.Discoverable),
BitFlags: commands.ToPolicyBitFlags(schema.Observable | schema.Discoverable),
},
},
{
Expand All @@ -330,7 +330,7 @@ func testValidateResourceLinks(ctx context.Context, t *testing.T, deviceID strin
ResourceTypes: []string{platform.ResourceType},
Interfaces: []string{interfaces.OC_IF_BASELINE},
Policy: &commands.Policy{
BitFlags: int32(schema.Observable | schema.Discoverable),
BitFlags: commands.ToPolicyBitFlags(schema.Observable | schema.Discoverable),
},
},
}
Expand Down
4 changes: 2 additions & 2 deletions coap-gateway/service/resourceDirectory.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func parsePublishedResources(data io.ReadSeeker, deviceID string) (wkRd, error)
return w, nil
}

func PublishResourceLinks(ctx context.Context, raClient raService.ResourceAggregateClient, links schema.ResourceLinks, deviceID string, ttl int32, connectionID string, sequence uint64) ([]*commands.Resource, error) {
func PublishResourceLinks(ctx context.Context, raClient raService.ResourceAggregateClient, links schema.ResourceLinks, deviceID string, ttl int, connectionID string, sequence uint64) ([]*commands.Resource, error) {
var validUntil time.Time
if ttl > 0 {
validUntil = time.Now().Add(time.Second * time.Duration(ttl))
Expand All @@ -118,7 +118,7 @@ func PublishResourceLinks(ctx context.Context, raClient raService.ResourceAggreg
}

func observeResources(ctx context.Context, client *session, w wkRd, sequenceNumber uint64) (coapCodes.Code, error) {
publishedResources, err := PublishResourceLinks(ctx, client.server.raClient, w.Links, w.DeviceID, int32(w.TimeToLive), client.RemoteAddr().String(), sequenceNumber)
publishedResources, err := PublishResourceLinks(ctx, client.server.raClient, w.Links, w.DeviceID, w.TimeToLive, client.RemoteAddr().String(), sequenceNumber)
if err != nil {
return coapCodes.BadRequest, fmt.Errorf("unable to publish resources for device %v: %w", w.DeviceID, err)
}
Expand Down
2 changes: 1 addition & 1 deletion coap-gateway/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func New(ctx context.Context, config Config, fileWatcher *fsnotify.Watcher, logg

ownerCache: ownerCache,
subscriptionsCache: subscriptionsCache,
messagePool: pool.New(uint32(config.APIs.COAP.MessagePoolSize), 1024),
messagePool: pool.New(config.APIs.COAP.MessagePoolSize, 1024),
logger: logger,
tracerProvider: tracerProvider,
}
Expand Down
2 changes: 1 addition & 1 deletion device-provisioning-service/service/cloudConfiguration.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (RequestHandle) ProcessCloudConfiguration(ctx context.Context, req *mux.Mes
},
Gateways: coapGateways,
ProviderName: cloudCfg.AuthorizationProvider,
SelectedGateway: int32(selectedGateway),
SelectedGateway: int32(selectedGateway), //nolint:gosec
},
})
return msg, err
Expand Down
6 changes: 3 additions & 3 deletions device-provisioning-service/service/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,9 @@ func HTTPConfigToProto(cfg pkgHttpClient.Config) (*pb.HttpConfig, error) {
}

return &pb.HttpConfig{
MaxIdleConns: uint32(cfg.MaxIdleConns),
MaxConnsPerHost: uint32(cfg.MaxConnsPerHost),
MaxIdleConnsPerHost: uint32(cfg.MaxIdleConnsPerHost),
MaxIdleConns: uint32(cfg.MaxIdleConns), //nolint:gosec
MaxConnsPerHost: uint32(cfg.MaxConnsPerHost), //nolint:gosec
MaxIdleConnsPerHost: uint32(cfg.MaxIdleConnsPerHost), //nolint:gosec
IdleConnTimeout: cfg.IdleConnTimeout.Nanoseconds(),
Timeout: cfg.Timeout.Nanoseconds(),
Tls: tls,
Expand Down
2 changes: 1 addition & 1 deletion device-provisioning-service/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func New(ctx context.Context, config Config, fileWatcher *fsnotify.Watcher, logg
ctx: ctx,
cancel: cancel,

messagePool: pool.New(uint32(config.APIs.COAP.MessagePoolSize), 1024),
messagePool: pool.New(config.APIs.COAP.MessagePoolSize, 1024),
store: store,
logger: logger,
authHandler: optCfg.authHandler,
Expand Down
2 changes: 1 addition & 1 deletion grpc-gateway/pb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,7 @@ If true - show UI element, if false - hide UI element
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| endpoint | [string](#string) | | |
| priority | [int64](#int64) | | |
| priority | [uint64](#uint64) | | |



Expand Down
2 changes: 1 addition & 1 deletion grpc-gateway/pb/doc.html
Original file line number Diff line number Diff line change
Expand Up @@ -3621,7 +3621,7 @@ <h3 id="resourceaggregate.pb.EndpointInformation">EndpointInformation</h3>

<tr>
<td>priority</td>
<td><a href="#int64">int64</a></td>
<td><a href="#uint64">uint64</a></td>
<td></td>
<td><p> </p></td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion grpc-gateway/pb/service.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1637,7 +1637,7 @@
},
"priority": {
"type": "string",
"format": "int64"
"format": "uint64"
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion grpc-gateway/service/createAndDeleteResource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func createSwitchResourceExpectedEvents(t *testing.T, deviceID, subID, correlati
ResourceTypes: []string{types.BINARY_SWITCH},
Interfaces: []string{interfaces.OC_IF_A, interfaces.OC_IF_BASELINE},
Policy: &commands.Policy{
BitFlags: int32(schema.Discoverable | schema.Observable),
BitFlags: commands.ToPolicyBitFlags(schema.Discoverable | schema.Observable),
},
},
},
Expand Down
5 changes: 1 addition & 4 deletions pkg/net/coap/service/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Config struct {
Addr string `yaml:"address" json:"address"`
Protocols []Protocol `yaml:"protocols" json:"protocols"`
MaxMessageSize uint32 `yaml:"maxMessageSize" json:"maxMessageSize"`
MessagePoolSize int `yaml:"messagePoolSize" json:"messagePoolSize"`
MessagePoolSize uint32 `yaml:"messagePoolSize" json:"messagePoolSize"`
MessageQueueSize int `yaml:"messageQueueSize" json:"messageQueueSize"`
BlockwiseTransfer BlockwiseTransferConfig `yaml:"blockwiseTransfer" json:"blockwiseTransfer"`
TLS TLSConfig `yaml:"tls" json:"tls"`
Expand Down Expand Up @@ -61,9 +61,6 @@ func (c *Config) Validate() error {
if c.MaxMessageSize <= 64 {
return fmt.Errorf("maxMessageSize('%v')", c.MaxMessageSize)
}
if c.MessagePoolSize < 0 {
return fmt.Errorf("messagePoolSize('%v')", c.MessagePoolSize)
}
if len(c.Protocols) == 0 {
return fmt.Errorf("protocols('%v')", c.Protocols)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/net/coap/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func New(ctx context.Context, config Config, router *mux.Router, fileWatcher *fs
return nil, err
}
serviceOpts := Options{
MessagePool: pool.New(uint32(config.MessagePoolSize), 1024),
MessagePool: pool.New(config.MessagePoolSize, 1024),
OnInactivityConnection: makeOnInactivityConnection(logger),
}
for _, o := range opt {
Expand Down
2 changes: 1 addition & 1 deletion pkg/net/grpc/server/makeDefaultOptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func defaultMessageProducer(ctx context.Context, ctxLogger context.Context, msg
}
tags := grpc_ctxtags.Extract(ctx)
newTags := grpc_ctxtags.NewTags()
newTags.Set(log.DurationMSKey, math.Float32frombits(uint32(duration.Integer)))
newTags.Set(log.DurationMSKey, math.Float32frombits(uint32(duration.Integer))) //nolint:gosec
newTags.Set(log.ProtocolKey, "GRPC")
for k, v := range tags.Values() {
if strings.EqualFold(k, grpcPrefixKey+"."+requestKey+"."+log.StartTimeKey) {
Expand Down
6 changes: 3 additions & 3 deletions pkg/security/certManager/general/certManager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,18 +178,18 @@ func TestCertManagerWithExpiredCA(t *testing.T) {
defer mng.Close()
pool := mng.GetCertificateAuthorities()
require.NotNil(t, pool)
require.Len(t, pool.Subjects(), 1)
require.Len(t, pool.Subjects(), 1) //nolint:staticcheck
time.Sleep(time.Second * 2)
pool = mng.GetCertificateAuthorities()
require.NotNil(t, pool)
require.Empty(t, pool.Subjects())
require.Empty(t, pool.Subjects()) //nolint:staticcheck
caPem, _ = getCA(t, time.Now(), time.Second*100)
err = os.WriteFile(caFile.Name(), caPem, os.FileMode(os.O_RDWR))
require.NoError(t, err)
time.Sleep(time.Second * 1)
pool = mng.GetCertificateAuthorities()
require.NotNil(t, pool)
require.Len(t, pool.Subjects(), 1)
require.Len(t, pool.Subjects(), 1) //nolint:staticcheck
}

// Check when cert expires
Expand Down
2 changes: 1 addition & 1 deletion resource-aggregate/commands/eventContentToContent.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func EventContentToContent(ec EventContent) (*Content, error) {
if c != nil {
contentType := c.GetContentType()
if contentType == "" && c.GetCoapContentFormat() >= 0 {
contentType = message.MediaType(c.GetCoapContentFormat()).String()
contentType = message.MediaType(c.GetCoapContentFormat()).String() //nolint:gosec
}
content = &Content{
Data: c.GetData(),
Expand Down
6 changes: 6 additions & 0 deletions resource-aggregate/commands/resouces.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package commands

import "github.com/plgd-dev/device/v2/schema"

func (c *Content) Clone() *Content {
if c == nil {
return nil
Expand Down Expand Up @@ -74,3 +76,7 @@ func CloneResourcesMap(resources map[string]*Resource) map[string]*Resource {
}
return c
}

func ToPolicyBitFlags(bm schema.BitMask) int32 {
return int32(bm) //nolint:gosec
}
6 changes: 3 additions & 3 deletions resource-aggregate/commands/resourceconv.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func (e *EndpointInformation) ToSchema() schema.Endpoint {
return schema.Endpoint{
URI: e.GetEndpoint(),
Priority: uint64(e.GetPriority()),
Priority: e.GetPriority(),
}
}

Expand Down Expand Up @@ -67,7 +67,7 @@ func SchemaEndpointsToRAEndpointInformations(ra []schema.Endpoint) []*EndpointIn
for _, e := range ra {
r = append(r, &EndpointInformation{
Endpoint: e.URI,
Priority: int64(e.Priority),
Priority: e.Priority,
})
}
return r
Expand All @@ -78,7 +78,7 @@ func SchemaPolicyToRAPolicy(ra *schema.Policy) *Policy {
return nil
}
return &Policy{
BitFlags: int32(ra.BitMask),
BitFlags: ToPolicyBitFlags(ra.BitMask),
}
}

Expand Down
6 changes: 3 additions & 3 deletions resource-aggregate/commands/resources.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 50a78f7

Please sign in to comment.