Skip to content

Commit

Permalink
Merge branch 'dev' into add-retry-executor
Browse files Browse the repository at this point in the history
  • Loading branch information
omerzi authored Jul 28, 2024
2 parents 9499e27 + b8a73a1 commit ca16718
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 85 deletions.
27 changes: 8 additions & 19 deletions .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,19 @@ jobs:
- name: Checkout Source
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.22.x

- name: Static Code Analysis
uses: golangci/golangci-lint-action@v3
with:
args: |
--timeout 5m --out-${NO_FUTURE}format colored-line-number --enable errcheck,gosimple,govet,ineffassign,staticcheck,typecheck,unused,gocritic,asasalint,asciicheck,errchkjson,exportloopref,makezero,nilerr,unparam,unconvert,wastedassign,usestdlibvars
- name: Setup Go with cache
uses: jfrog/.github/actions/install-go-with-cache@main

- name: Run golangci lint
uses: jfrog/.github/actions/golangci-lint@main
Go-Sec:
runs-on: ubuntu-latest
steps:
- name: Checkout Source
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.22.x
- name: Setup Go with cache
uses: jfrog/.github/actions/install-go-with-cache@main

- name: Run Gosec Security Scanner
uses: securego/gosec@master
with:
args: -exclude G204,G304,G404,G401,G505 -tests -exclude-dir \.*test\.* ./...
- name: Run Go-Sec scanner
uses: jfrog/.github/actions/gosec-scanner@main
26 changes: 5 additions & 21 deletions .github/workflows/cla.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,10 @@ jobs:
CLAssistant:
runs-on: ubuntu-latest
steps:
- uses: actions-ecosystem/action-regex-match@v2
id: sign-or-recheck
- name: Run CLA Check
uses: jfrog/.github/actions/cla@main
with:
text: ${{ github.event.comment.body }}
regex: '\s*(I have read the CLA Document and I hereby sign the CLA)|(recheck)\s*'

- name: "CLA Assistant"
if: ${{ steps.sign-or-recheck.outputs.match != '' || github.event_name == 'pull_request_target' }}
# Alpha Release
uses: cla-assistant/github-action@v2.3.0
env:
# Generated and maintained by GitHub
event_comment_body: ${{ github.event.comment.body }}
event_name: ${{ github.event_name }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# JFrog's organization secret
PERSONAL_ACCESS_TOKEN : ${{ secrets.CLA_SIGN_TOKEN }}
with:
path-to-signatures: 'signed_clas.json'
path-to-document: 'https://jfrog.com/cla/'
remote-organization-name: 'jfrog'
remote-repository-name: 'jfrog-signed-clas'
# branch should not be protected
branch: 'master'
allowlist: bot*
CLA_SIGN_TOKEN: ${{ secrets.CLA_SIGN_TOKEN }}
3 changes: 3 additions & 0 deletions .github/workflows/frogbot-scan-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ jobs:
# "frogbot" GitHub environment can approve the pull request to be scanned.
environment: frogbot
steps:
- name: Setup Go with cache
uses: jfrog/.github/actions/install-go-with-cache@main

- uses: jfrog/frogbot@v2
env:
JFROG_CLI_LOG_LEVEL: "DEBUG"
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/frogbot-scan-repository.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ jobs:
# The repository scanning will be triggered periodically on the following branches.
branch: [ "master" ]
steps:
- name: Setup Go with cache
uses: jfrog/.github/actions/install-go-with-cache@main

- uses: jfrog/frogbot@v2
env:
JFROG_CLI_LOG_LEVEL: "DEBUG"
Expand Down
15 changes: 2 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,8 @@ jobs:
- name: Checkout Source
uses: actions/checkout@v4

- name: Go Cache
uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.22.x
cache: false
- name: Setup Go with cache
uses: jfrog/.github/actions/install-go-with-cache@main

- name: Tests
run: go test -v -race -covermode atomic -coverprofile=covprofile ./...
3 changes: 2 additions & 1 deletion crypto/checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const (

var algorithmFunc = map[Algorithm]func() hash.Hash{
// Go native crypto algorithms:
MD5: md5.New,
MD5: md5.New,
//#nosec G401 -- Sha1 is supported by Artifactory.
SHA1: sha1.New,
// sha256-simd algorithm:
SHA256: sha256.New,
Expand Down
4 changes: 3 additions & 1 deletion fanout/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fanout

import (
"bytes"
//#nosec G505 -- Sha1 is supported by Artifactory.
"crypto/sha1"
"crypto/sha256"
"encoding/hex"
Expand Down Expand Up @@ -66,6 +67,7 @@ func TestFanoutRead(t *testing.T) {
}

func TestFanoutProgressiveRead(t *testing.T) {
//#nosec G401 -- Sha1 is supported by Artifactory.
hash1 := sha1.New()
proc1 := func(p []byte) (err error) {
if _, err := hash1.Write(p); err != nil {
Expand Down Expand Up @@ -104,7 +106,7 @@ func TestFanoutProgressiveRead(t *testing.T) {

func TestFanoutProgressiveReadError(t *testing.T) {
const errmsg = "ERRSHA1"

//#nosec G401 -- Sha1 is supported by Artifactory.
hash1 := sha1.New()
proc1 := func(p []byte) (err error) {
return errors.New(errmsg)
Expand Down
20 changes: 10 additions & 10 deletions io/fileutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package io

import (
"bufio"
"crypto/rand"
cr "crypto/rand"
"encoding/json"
"errors"
"fmt"
"io"
"math/rand"
"math/big"
"net/http"
"os"
"path"
Expand Down Expand Up @@ -35,16 +36,15 @@ type RandFile struct {

const buflen = 4096

var src = rand.NewSource(time.Now().UnixNano())

// #nosec G404 - No cryptographic level encryption is needed in random file
var rnd = rand.New(src)

// Create a temp file with the requested prefix at the provided dir. File length and contents are random, up to the requested max length.
func CreateRandomLenFile(maxLen int, filesDir string, prefix string) string {
file, _ := os.CreateTemp(filesDir, prefix)
fname := file.Name()
len := rnd.Intn(maxLen)
n, err := rand.Int(rand.Reader, big.NewInt(int64(maxLen)))
if err != nil {
panic(fmt.Errorf("failed to generate random number: %w", err))
}
len := int(n.Int64())
created, err := CreateRandFile(fname, len)
if err != nil {
panic(err)
Expand Down Expand Up @@ -127,7 +127,7 @@ func walk(path string, info os.FileInfo, walkFn WalkFunc, visitedDirSymlinks map
}
err = walkFn(path, info, nil)
if err != nil {
if info.IsDir() && err == ErrSkipDir {
if info.IsDir() && errors.Is(err, ErrSkipDir) {
return nil
}
return err
Expand Down Expand Up @@ -161,13 +161,13 @@ func walk(path string, info os.FileInfo, walkFn WalkFunc, visitedDirSymlinks map
}
fileInfo, err := fileHandler(filename)
if err != nil {
if err := walkFn(filename, fileInfo, err); err != nil && err != ErrSkipDir {
if err := walkFn(filename, fileInfo, err); err != nil && !errors.Is(err, ErrSkipDir) {
return err
}
} else {
err = walk(filename, fileInfo, walkFn, visitedDirSymlinks, walkIntoDirSymlink)
if err != nil {
if !fileInfo.IsDir() || err != ErrSkipDir {
if !fileInfo.IsDir() || !errors.Is(err, ErrSkipDir) {
return err
}
}
Expand Down
38 changes: 24 additions & 14 deletions lru/lru_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,28 @@ func (c *cacheBase) Get(key string) (value interface{}, ok bool) {
if c.Expiry != time.Duration(0) {
unixNow := time.Now().UnixNano() / int64(time.Millisecond)
unixExpiry := int64(c.Expiry / time.Millisecond)
if (unixNow - ele.Value.(*entry).timeInsert) > unixExpiry {
c.removeElement(ele)
return nil, false
if ent, ok := ele.Value.(*entry); ok {
if (unixNow - ent.timeInsert) > unixExpiry {
c.removeElement(ele)
return nil, false
}
}
}
c.ll.MoveToFront(ele)
return ele.Value.(*entry).value, true
if ent, ok := ele.Value.(*entry); ok {
return ent.value, true
}
}
return nil, false
}

// Updates element's value without updating its "Least-Recently-Used" status
func (c *cacheBase) UpdateElement(key string, value interface{}) {
if ee, ok := c.cache[key]; ok {
ee.Value.(*entry).value = value
return
if ent, ok := ee.Value.(*entry); ok {
ent.value = value
return
}
}
}

Expand All @@ -90,10 +96,12 @@ func (c *cacheBase) RemoveOldest() {

func (c *cacheBase) removeElement(e *list.Element) {
c.ll.Remove(e)
kv := e.Value.(*entry)
delete(c.cache, kv.key)
if c.OnEvicted != nil {
c.OnEvicted(kv.key, kv.value)
kv, ok := e.Value.(*entry)
if ok {
delete(c.cache, kv.key)
if c.OnEvicted != nil {
c.OnEvicted(kv.key, kv.value)
}
}
}

Expand All @@ -105,11 +113,13 @@ func (c *cacheBase) Len() int {
// Clear purges all stored items from the cache.
func (c *cacheBase) Clear() {
for _, e := range c.cache {
kv := e.Value.(*entry)
if c.OnEvicted != nil {
c.OnEvicted(kv.key, kv.value)
kv, ok := e.Value.(*entry)
if ok {
if c.OnEvicted != nil {
c.OnEvicted(kv.key, kv.value)
}
delete(c.cache, kv.key)
}
delete(c.cache, kv.key)
}
c.ll.Init()
}
21 changes: 17 additions & 4 deletions parallel/bounded_runner_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package parallel

import (
"crypto/rand"
"fmt"
"math/rand"
"math/big"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -199,7 +200,11 @@ func produceTasks(runner *runner, results chan int, errorsQueue *ErrorsQueue, ta
func createSuccessfulFlowTaskFunc(num int, result chan int) TaskFunc {
return func(threadId int) error {
result <- num
time.Sleep(time.Millisecond * time.Duration(rand.Intn(50)))
n, err := rand.Int(rand.Reader, big.NewInt(50))
if err != nil {
return err
}
time.Sleep(time.Millisecond * time.Duration(n.Int64()))
return nil
}
}
Expand All @@ -210,7 +215,11 @@ func createTaskWithErrorFunc(num int, result chan int) TaskFunc {
return fmt.Errorf("num: %d, above 50 going to stop", num)
}
result <- num
time.Sleep(time.Millisecond * time.Duration(rand.Intn(50)))
n, err := rand.Int(rand.Reader, big.NewInt(50))
if err != nil {
return err
}
time.Sleep(time.Millisecond * time.Duration(n.Int64()))
return nil
}
}
Expand All @@ -221,7 +230,11 @@ func createTaskWithIntAsErrorFunc(num int, result chan int) TaskFunc {
return fmt.Errorf("%d", num)
}
result <- num
time.Sleep(time.Millisecond * time.Duration(rand.Intn(50)))
n, err := rand.Int(rand.Reader, big.NewInt(50))
if err != nil {
return err
}
time.Sleep(time.Millisecond * time.Duration(n.Int64()))
return nil
}
}
Expand Down
7 changes: 5 additions & 2 deletions parallel/runner_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package parallel

import (
"crypto/rand"
"errors"
"fmt"
"math/rand"
"math/big"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -40,7 +41,9 @@ func TestAddTask(t *testing.T) {
x := i
_, err := runner.AddTask(func(int) error {
results <- x
time.Sleep(time.Millisecond * time.Duration(rand.Intn(50)))
n, err := rand.Int(rand.Reader, big.NewInt(50))
assert.NoError(t, err)
time.Sleep(time.Millisecond * time.Duration(n.Int64()))
if float64(x) > float64(count)/2 {
return fmt.Errorf("second half value %d not counted", x)
}
Expand Down

0 comments on commit ca16718

Please sign in to comment.