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
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ jobs:
uses: GeoNet/Actions/.github/workflows/reusable-go-apps.yml@main
with:
testSetup: |
docker run --name localstack -d --rm -p 4566:4566 -p 4510-4559:4510-4559 docker.io/localstack/localstack:3.2.0
docker run --name localstack -d --rm -p 4566:4566 -p 4510-4559:4510-4559 docker.io/localstack/localstack:4.0.3
echo "waiting for localstack to be ready"
until curl -v localhost:4566; do
sleep 1s
done
echo "waiting for localstack service status to be ready"
until docker exec localstack /opt/code/localstack/bin/localstack status services; do
until [[ "$(curl -s localhost:4566/_localstack/init | jq -r .completed.READY)" == "true" ]]; do
sleep 1s
done
goTestExtraArgs: -p 1 --tags localstack
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/GeoNet/kit

go 1.21
go 1.23

require (
github.com/aws/aws-sdk-go-v2 v1.25.3
Expand Down
2 changes: 1 addition & 1 deletion metrics/counters.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,5 @@ func StatusServiceUnavailable() {

// Written increments the bytes sent counter by n.
func Written(n int64) {
atomic.AddUint64(&httpCounters[7], uint64(n))
atomic.AddUint64(&httpCounters[7], uint64(n)) //nolint:gosec
}
2 changes: 1 addition & 1 deletion metrics/ddog_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func dogHttp(apiKey, hostName, appName string, m runtime.MemStats, t []TimerStat
}
}
// non nil connection error, sleep and try again
time.Sleep(time.Second << uint(tries))
time.Sleep(time.Second << uint(tries)) //nolint:gosec
}
if res != nil {
res.Body.Close()
Expand Down
2 changes: 1 addition & 1 deletion metrics/ddog_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func dogMsg(apiKey, hostName, appName string, m runtime.MemStats, t []TimerStats
}
}
// non nil connection error, sleep and try again
time.Sleep(time.Second << uint(tries))
time.Sleep(time.Second << uint(tries)) //nolint:gosec
}
if res != nil {
res.Body.Close()
Expand Down
2 changes: 1 addition & 1 deletion seis/dl/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func packetToBytes(dlp Packet) ([]byte, error) {

dlp.Preheader = Preheader{
DL: [2]byte{'D', 'L'},
HeaderLength: uint8(len(dlp.Header)),
HeaderLength: uint8(len(dlp.Header)), //nolint:gosec
}

out := make([]byte, 0, PreheaderSize+len(dlp.Header)+len(dlp.Body))
Expand Down
2 changes: 1 addition & 1 deletion seis/ms/blockette.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func EncodeBlockette1001(blk Blockette1001) []byte {
var b [Blockette1001Size]byte

b[0] = blk.TimingQuality
b[1] = uint8(blk.MicroSec)
b[1] = uint8(blk.MicroSec) //nolint:gosec
b[2] = blk.Reserved
b[3] = blk.FrameCount

Expand Down
12 changes: 6 additions & 6 deletions seis/ms/btime.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ func (b BTime) Time() time.Time {
// NewBTime builds a BTime from a time.Time.
func NewBTime(t time.Time) BTime {
return BTime{
Year: uint16(t.Year()),
Doy: uint16(t.YearDay()),
Hour: uint8(t.Hour()),
Minute: uint8(t.Minute()),
Second: uint8(t.Second()),
S0001: uint16(t.Nanosecond() / 100000),
Year: uint16(t.Year()), //nolint:gosec
Doy: uint16(t.YearDay()), //nolint:gosec
Hour: uint8(t.Hour()), //nolint:gosec
Minute: uint8(t.Minute()), //nolint:gosec
Second: uint8(t.Second()), //nolint:gosec
S0001: uint16(t.Nanosecond() / 100000), //nolint:gosec
}
}

Expand Down
5 changes: 4 additions & 1 deletion seis/ms/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
)

func decodeInt32(data []byte, order uint8, samples uint16) ([]int32, error) {
//nolint:gosec
if n := uint16(len(data) / 4); n < samples {
return nil, fmt.Errorf("invalid data length: %d", n)
}
Expand All @@ -20,13 +21,14 @@ func decodeInt32(data []byte, order uint8, samples uint16) ([]int32, error) {
default:
b = binary.BigEndian.Uint32(data[i:])
}
values = append(values, int32(b))
values = append(values, int32(b)) //nolint:gosec
}

return values, nil
}

func decodeFloat32(data []byte, order uint8, samples uint16) ([]float32, error) {
//nolint:gosec
if n := uint16(len(data) / 4); n < samples {
return nil, fmt.Errorf("invalid data length: %d", n)
}
Expand All @@ -45,6 +47,7 @@ func decodeFloat32(data []byte, order uint8, samples uint16) ([]float32, error)
}

func decodeFloat64(data []byte, order uint8, samples uint16) ([]float64, error) {
//nolint:gosec
if n := uint16(len(data) / 8); n < samples {
return nil, fmt.Errorf("invalid data length: %d", n)
}
Expand Down
19 changes: 9 additions & 10 deletions seis/ms/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (h *RecordHeader) SetCorrection(correction time.Duration, applied bool) {
default:
h.ActivityFlags = clearBit(h.ActivityFlags, 1)
}
h.TimeCorrection = int32(correction / (100 * time.Microsecond))
h.TimeCorrection = int32(correction / (100 * time.Microsecond)) //nolint:gosec
}

func (h RecordHeader) Correction() time.Duration {
Expand Down Expand Up @@ -260,18 +260,17 @@ func DecodeRecordHeader(data []byte) RecordHeader {

RecordStartTime: DecodeBTime(h[20:30]),
NumberOfSamples: binary.BigEndian.Uint16(h[30:32]),
SampleRateFactor: int16(binary.BigEndian.Uint16(h[32:34])),
SampleRateMultiplier: int16(binary.BigEndian.Uint16(h[34:36])),
SampleRateFactor: int16(binary.BigEndian.Uint16(h[32:34])), //nolint:gosec
SampleRateMultiplier: int16(binary.BigEndian.Uint16(h[34:36])), //nolint:gosec

ActivityFlags: h[36],
IOAndClockFlags: h[37],
DataQualityFlags: h[38],

NumberOfBlockettesThatFollow: h[39],

TimeCorrection: int32(binary.BigEndian.Uint32(h[40:44])),
BeginningOfData: binary.BigEndian.Uint16(h[44:46]),
FirstBlockette: binary.BigEndian.Uint16(h[46:48]),
TimeCorrection: int32(binary.BigEndian.Uint32(h[40:44])), //nolint:gosec
BeginningOfData: binary.BigEndian.Uint16(h[44:46]),
FirstBlockette: binary.BigEndian.Uint16(h[46:48]),
}
}

Expand All @@ -290,15 +289,15 @@ func EncodeRecordHeader(hdr RecordHeader) []byte {

copy(b[20:30], EncodeBTime(hdr.RecordStartTime))
binary.BigEndian.PutUint16(b[30:32], hdr.NumberOfSamples)
binary.BigEndian.PutUint16(b[32:34], uint16(hdr.SampleRateFactor))
binary.BigEndian.PutUint16(b[34:36], uint16(hdr.SampleRateMultiplier))
binary.BigEndian.PutUint16(b[32:34], uint16(hdr.SampleRateFactor)) //nolint:gosec
binary.BigEndian.PutUint16(b[34:36], uint16(hdr.SampleRateMultiplier)) //nolint:gosec

b[36] = hdr.ActivityFlags
b[37] = hdr.IOAndClockFlags
b[38] = hdr.DataQualityFlags

b[39] = hdr.NumberOfBlockettesThatFollow
binary.BigEndian.PutUint32(b[40:44], uint32(hdr.TimeCorrection))
binary.BigEndian.PutUint32(b[40:44], uint32(hdr.TimeCorrection)) //nolint:gosec
binary.BigEndian.PutUint16(b[44:46], hdr.BeginningOfData)
binary.BigEndian.PutUint16(b[46:48], hdr.FirstBlockette)

Expand Down
10 changes: 10 additions & 0 deletions seis/ms/header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,41 +269,51 @@ func TestBits(t *testing.T) {
for i := 0; i < 8; i++ {
r := byte(0x01 << i)

//nolint:gosec
if v := setBit(0, uint8(i)); v != r {
t.Errorf("invalid bit set: expected %v but got %v for %d", r, v, i)
}
}

for i := 0; i < 8; i++ {
//nolint:gosec
v := setBit(0, uint8(i))

//nolint:gosec
if !isBitSet(v, uint8(i)) {
t.Errorf("invalid bit test: expected bit to be set %d", i)
}

//nolint:gosec
v = clearBit(v, uint8(i))

//nolint:gosec
if isBitSet(v, uint8(i)) {
t.Errorf("invalid bit test: expected bit to not be set %d", i)
}
}

for i := 0; i < 8; i++ {
//nolint:gosec
v := setBit(0xff, uint8(i))

//nolint:gosec
if !isBitSet(v, uint8(i)) {
t.Errorf("invalid bit test: expected bit to be set %d", i)
}

//nolint:gosec
v = clearBit(v, uint8(i))

for j := 0; j < i; j++ {
//nolint:gosec
if !isBitSet(v, uint8(j)) {
t.Errorf("invalid bit test: expected bit to be set %d/%d", i, j)
}
}

for j := i + 1; j < 8; j++ {
//nolint:gosec
if !isBitSet(v, uint8(j)) {
t.Errorf("invalid bit test: expected bit to be set %d/%d", i, j)
}
Expand Down
25 changes: 15 additions & 10 deletions seis/ms/steim.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@ import (
)

func getNibble(word []byte, index int) uint8 {
b := word[index/4] //Which byte we want from within the word (4 bytes per word)
var res uint8 //value
i := index % 4 //which nibble we want from within the byte (4 nibbles per byte)
b := word[index/4] //Which byte we want from within the word (4 bytes per word)
var res uint8 //value
i := index % 4 //which nibble we want from within the byte (4 nibbles per byte)
//nolint:gosec
res = b & (0x3 << uint8((3-i)*2)) //0x3=00000011 create and apply the correct mask e.g. i=1 mask=00110000
res = res >> uint8((3-i)*2) //shift the masked value fully to the right
//nolint:gosec
res = res >> uint8((3-i)*2) //shift the masked value fully to the right
return res
}

// value must be 0, 1, 2 or 3, the nibble must not have been previously set
func writeNibble(word []byte, index int, value uint8) {
b := word[index/4]
i := index % 4
//nolint:gosec
b = b ^ (value << uint8((3-i)*2)) //set the bits
word[index/4] = b
}
Expand All @@ -32,7 +35,7 @@ func uintVarToInt32(v uint32, numbits uint8) int32 {
v = v + 1 //add 1 - positive nbit number
v = -v //get the negative - this gives us a proper negative int32
}
return int32(v)
return int32(v) //nolint:gosec
}

func int32ToUintVar(i int32, numbits uint8) uint32 {
Expand All @@ -42,17 +45,19 @@ func int32ToUintVar(i int32, numbits uint8) uint32 {
i = i - 1
i = i ^ ((1 << (numbits)) - 1) //flip all the bits
}
return uint32(i)
return uint32(i) //nolint:gosec
}

func applyDifferencesFromWord(w []byte, numdiffs int, diffbits uint32, d []int32) []int32 {
mask := (1 << diffbits) - 1
wint := binary.BigEndian.Uint32(w)

for i := numdiffs - 1; i >= 0; i-- {
//nolint:gosec
intn := wint & uint32(mask<<(uint32(i)*diffbits)) //apply a mask over the correct bits
intn = intn >> (uint32(i) * diffbits) //shift the masked value fully to the right

//nolint:gosec
intn = intn >> (uint32(i) * diffbits) //shift the masked value fully to the right
//nolint:gosec
diff := uintVarToInt32(intn, uint8(diffbits)) //convert diffbits bit int to int32

d = append(d, d[len(d)-1]+diff)
Expand All @@ -70,8 +75,8 @@ func decodeSteim(version int, raw []byte, wordOrder, frameCount uint8, expectedS

//Word 1 and 2 contain x0 and xn: the uncompressed initial and final quantities (word 0 contains nibs)
frame0 := raw[0:64]
start := int32(binary.BigEndian.Uint32(frame0[4:8]))
end := int32(binary.BigEndian.Uint32(frame0[8:12]))
start := int32(binary.BigEndian.Uint32(frame0[4:8])) //nolint:gosec
end := int32(binary.BigEndian.Uint32(frame0[8:12])) //nolint:gosec

d = append(d, start)

Expand Down
4 changes: 2 additions & 2 deletions seis/ms/unpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (m Record) Int32s() ([]int32, error) {
case EncodingInt32:
return decodeInt32(m.Data, m.B1000.WordOrder, m.RecordHeader.NumberOfSamples)
case EncodingSTEIM1:
framecount := uint8(len(m.Data) / 64)
framecount := uint8(len(m.Data) / 64) //nolint:gosec
if m.B1001.FrameCount != 0 {
framecount = m.B1001.FrameCount
}
Expand All @@ -94,7 +94,7 @@ func (m Record) Int32s() ([]int32, error) {
}
return decodeSteim(1, m.Data, m.B1000.WordOrder, framecount, m.RecordHeader.NumberOfSamples)
case EncodingSTEIM2: //STEIM2
framecount := uint8(len(m.Data) / 64)
framecount := uint8(len(m.Data) / 64) //nolint:gosec
if m.B1001.FrameCount != 0 {
framecount = m.B1001.FrameCount
}
Expand Down