Skip to content
Open
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/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ jobs:
needs: setup
steps:
- uses: actions/checkout@v4.2.2
with:
fetch-depth: 5
- name: Setup Go
uses: actions/setup-go@v5.5.0
with:
Expand All @@ -41,7 +43,6 @@ jobs:
- name: Setup bridger
id: setup
run: |
echo "gcli_ver=$(grep 'golangci-lint-version' .golangci.yml | awk '{print $2}')" >> $GITHUB_OUTPUT
echo "::group::godownload"
make download
echo "::endgroup::"
Expand All @@ -50,7 +51,6 @@ jobs:
with:
go_version_file: "go.mod"
reporter: github-pr-review
golangci_lint_version: "v${{ steps.setup.outputs.gcli_ver }}"
cache: false
fail_level: warning
filter_mode: added
Expand Down
56 changes: 56 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
version: "2"
linters:
enable:
- bodyclose
- depguard
- durationcheck
- funlen
- gocognit
- gocritic
- gocyclo
- godox
- goheader
- gosec
- misspell
- mnd
- nakedret
- revive
- unconvert
settings:
errcheck:
check-type-assertions: true
check-blank: false
exclude-functions:
- (io.Closer).Close
depguard:
rules:
main:
list-mode: lax
allow:
- $gostd
deny:
- pkg: github.com/docker/distribution
desc: use the distribution package from github.com/distribution/distribution instead
- pkg: golang.org/x/crypto/ssh/terminal
desc: use the terminal package from golang.org/x/term instead
formatters:
enable:
- gofmt
- goimports
output:
formats:
text:
print-linter-name: true
junit-xml:
output: "reports/golangci-lint.xml"
sort-order:
- severity
- linter
- file
issues:
new: true
run:
tests: false
modules-download-mode: readonly
allow-parallel-runners: true
31 changes: 0 additions & 31 deletions .golangci.yml

This file was deleted.

2 changes: 1 addition & 1 deletion cmd/bridgr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
if err != nil {
log.Error("Unable to open bridgr config \"%s\": %s", *configPtr, err)
if configFile != nil {
configFile.Close()
_ = configFile.Close()

Check warning on line 90 in cmd/bridgr/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/bridgr/main.go#L90

Added line #L90 was not covered by tests
}
exit(cfgErr)
}
Expand Down
1 change: 1 addition & 0 deletions internal/bridgr/asset/dev.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !dist
// +build !dist

package asset
Expand Down
3 changes: 1 addition & 2 deletions internal/bridgr/asset/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package asset

import (
"io"
"io/ioutil"
"strings"
"text/template"

Expand All @@ -20,7 +19,7 @@ func Load(name string) (string, error) {
return "", err
}
defer f.Close()
content, err := ioutil.ReadAll(f)
content, err := io.ReadAll(f)
if err != nil {
return "", err
}
Expand Down
11 changes: 11 additions & 0 deletions internal/bridgr/bridgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ import (
log "unknwon.dev/clog/v2"
)

const (
fileMode = 0644
dirMode = 0750
)

var (
// Verbose determines whether debug logging is printed
Verbose = false
Expand All @@ -28,6 +33,12 @@ var (

// FileTimeout is the duration used for HTTP/s file download overall timeout. Used in the transport object
FileTimeout = time.Second * 20

// DefaultFilePerms are the permissions for files created by Bridgr workers
DefaultFilePerms = os.FileMode(fileMode)

// DefaultDirPerms are the directory permissions for directories created by Bridgr workers
DefaultDirPerms = os.FileMode(dirMode)
)

// BaseDir gives the runtime absolute directory of the base "packages" directory
Expand Down
2 changes: 1 addition & 1 deletion internal/bridgr/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (b Bridgr) Execute(filter []string) error {
}

func contains(item string, list []string) bool {
if len(list) <= 0 || strings.ToLower(list[0]) == "all" {
if len(list) == 0 || strings.ToLower(list[0]) == "all" {
return true
}
for _, x := range list {
Expand Down
6 changes: 3 additions & 3 deletions internal/bridgr/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
} else {
re := regexp.MustCompile(`[:/]`)
outFile := re.ReplaceAllString(reference.Path(img), "_") + ".tar"
out, err := os.Create(path.Join(d.dir(), outFile))
out, err := os.Create(path.Join(d.dir(), outFile)) // #nosec G304, this is already rooted in the Docker worker's base directory

Check warning on line 123 in internal/bridgr/docker.go

View check run for this annotation

Codecov / codecov/patch

internal/bridgr/docker.go#L123

Added line #L123 was not covered by tests
if err != nil {
log.Info("error creating %s for saving Docker image %s - %s", outFile, img.String(), err)
continue
Expand All @@ -140,7 +140,7 @@
// Setup gets the environment ready to run the Docker worker
func (d *Docker) Setup() error {
log.Trace("Called Docker.Setup()")
_ = os.MkdirAll(d.dir(), os.ModePerm)
_ = os.MkdirAll(d.dir(), DefaultDirPerms)

Check warning on line 143 in internal/bridgr/docker.go

View check run for this annotation

Codecov / codecov/patch

internal/bridgr/docker.go#L143

Added line #L143 was not covered by tests

// filter nil images from parse errors
filtered := d.Images[:0]
Expand Down Expand Up @@ -198,7 +198,7 @@

func (d *Docker) tagForRemote(cli imageTagger, local reference.Named) string {
destReg := d.Destination
remoteTag := strings.Replace(local.String(), reference.Domain(local), destReg, -1)
remoteTag := strings.ReplaceAll(local.String(), reference.Domain(local), destReg)

_ = cli.ImageTag(context.Background(), local.String(), remoteTag)
return remoteTag
Expand Down
6 changes: 3 additions & 3 deletions internal/bridgr/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,15 @@
// Setup only does the setup step of the Files worker
func (f File) Setup() error {
log.Trace("Called Files.Setup()")
_ = os.MkdirAll(f.dir(), os.ModePerm)
_ = os.MkdirAll(f.dir(), DefaultDirPerms)

Check warning on line 155 in internal/bridgr/file.go

View check run for this annotation

Codecov / codecov/patch

internal/bridgr/file.go#L155

Added line #L155 was not covered by tests
for _, item := range f {
_ = item.Normalize(f.dir())
}
return nil
}

func (ff *fileFetcher) fileFetch(source string, out io.WriteCloser) error {
in, openErr := os.Open(source)
in, openErr := os.Open(source) // #nosec G304 this is intended behavior, we want to read local files
if openErr != nil {
return openErr
}
Expand Down Expand Up @@ -204,7 +204,7 @@
func (ff *fileFetcher) s3Fetch(client s3iface.S3API, source *url.URL, out io.WriteCloser) error {
defer out.Close()
if client == (*s3.S3)(nil) {
return errors.New("Invalid S3 client, unable to copy file")
return errors.New("invalid S3 client, unable to copy file")

Check warning on line 207 in internal/bridgr/file.go

View check run for this annotation

Codecov / codecov/patch

internal/bridgr/file.go#L207

Added line #L207 was not covered by tests
}
log.Trace("Downloading S3 file: %s", source.String())
resp, err := client.GetObject(&s3.GetObjectInput{
Expand Down
3 changes: 1 addition & 2 deletions internal/bridgr/file_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"errors"
"io"
"io/ioutil"
"net/http"
"net/url"
"reflect"
Expand All @@ -24,7 +23,7 @@ type httpMock struct {
func (m httpMock) RoundTrip(req *http.Request) (*http.Response, error) {
return &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewBufferString("OK")),
Body: io.NopCloser(bytes.NewBufferString("OK")),
Header: make(http.Header),
}, nil
}
Expand Down
12 changes: 6 additions & 6 deletions internal/bridgr/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@

// Setup does any initial setup for the Git worker
func (g *Git) Setup() error {
return os.MkdirAll(g.dir(), os.ModePerm)
return os.MkdirAll(g.dir(), DefaultDirPerms)

Check warning on line 111 in internal/bridgr/git.go

View check run for this annotation

Codecov / codecov/patch

internal/bridgr/git.go#L111

Added line #L111 was not covered by tests
}

// Run executes the Git worker to fetch artifacts
Expand All @@ -124,13 +124,13 @@
log.Info("Error cloning Git repository '%s': %s", item.URL.String(), err)
}
if item.Bare {
_ = os.MkdirAll(path.Join(dir, "info"), os.ModePerm)
_ = os.MkdirAll(path.Join(dir, "objects", "info"), os.ModePerm)
infoRefs, _ := os.Create(path.Join(dir, "info", "refs"))
_ = os.MkdirAll(path.Join(dir, "info"), DefaultDirPerms)
_ = os.MkdirAll(path.Join(dir, "objects", "info"), DefaultDirPerms)
infoRefs, _ := os.Create(path.Join(dir, "info", "refs")) // #nosec G304, this is already cleaned and rooted in the PrepDir function

Check warning on line 129 in internal/bridgr/git.go

View check run for this annotation

Codecov / codecov/patch

internal/bridgr/git.go#L127-L129

Added lines #L127 - L129 were not covered by tests
generateRefInfo(repo, infoRefs)
infoRefs.Close()

infoPack, _ := os.Create(path.Join(dir, "objects", "info", "packs"))
infoPack, _ := os.Create(path.Join(dir, "objects", "info", "packs")) // #nosec G304, this is already cleaned and rooted in the PrepDir function

Check warning on line 133 in internal/bridgr/git.go

View check run for this annotation

Codecov / codecov/patch

internal/bridgr/git.go#L133

Added line #L133 was not covered by tests
generatePackInfo(repo, infoPack)
infoPack.Close()
}
Expand All @@ -142,7 +142,7 @@
func (g *Git) prepDir(url *url.URL) string {
dir := path.Base(url.Path)
dir = strings.TrimSuffix(dir, git.GitDirName)
dir = path.Join(g.dir(), dir)
dir = path.Join(g.dir(), dir) // this roots the directory in the Git worker's base directory

if _, err := os.Stat(dir); !os.IsNotExist(err) {
log.Trace("%s exists, removing to allow new clone", dir)
Expand Down
2 changes: 1 addition & 1 deletion internal/bridgr/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
for _, chart := range h {
chart.Normalize(h.dir())
}
return os.MkdirAll(h.dir(), os.ModePerm)
return os.MkdirAll(h.dir(), DefaultDirPerms)

Check warning on line 41 in internal/bridgr/helm.go

View check run for this annotation

Codecov / codecov/patch

internal/bridgr/helm.go#L41

Added line #L41 was not covered by tests
}

// Run downloads the requested Helm charts, and creates an index for statically hosting them
Expand Down
4 changes: 2 additions & 2 deletions internal/bridgr/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@
// Setup creates the items that are needed to fetch artifacts for the Python worker. It does not actually fetch artifacts.
func (p Python) Setup() error {
log.Trace("Called Python Setup()")
_ = os.MkdirAll(p.dir(), os.ModePerm)
_ = os.MkdirAll(p.dir(), DefaultDirPerms)

Check warning on line 101 in internal/bridgr/python.go

View check run for this annotation

Codecov / codecov/patch

internal/bridgr/python.go#L101

Added line #L101 was not covered by tests
reqt, err := os.Create(path.Join(p.dir(), "requirements.txt"))
if err != nil {
return fmt.Errorf("Unable to create Python requirements file: %s", err)
return fmt.Errorf("unable to create Python requirements file: %s", err)

Check warning on line 104 in internal/bridgr/python.go

View check run for this annotation

Codecov / codecov/patch

internal/bridgr/python.go#L104

Added line #L104 was not covered by tests
}

return asset.RenderFile(pyReqt, p.Packages, reqt)
Expand Down
6 changes: 3 additions & 3 deletions internal/bridgr/ruby.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@
// Setup creates the items that are needed to fetch artifacts for the Python worker. It does not actually fetch artifacts.
func (r *Ruby) Setup() error {
log.Trace("Called Ruby.Setup()")
_ = os.MkdirAll(r.dir(), os.ModePerm)
_ = os.MkdirAll(r.dir(), DefaultDirPerms)

Check warning on line 114 in internal/bridgr/ruby.go

View check run for this annotation

Codecov / codecov/patch

internal/bridgr/ruby.go#L114

Added line #L114 was not covered by tests

gemfile, err := os.Create(path.Join(r.dir(), "Gemfile"))
if err != nil {
return fmt.Errorf("Unable to create Ruby Gemfile: %s", err)
return fmt.Errorf("unable to create Ruby Gemfile: %s", err)

Check warning on line 118 in internal/bridgr/ruby.go

View check run for this annotation

Codecov / codecov/patch

internal/bridgr/ruby.go#L118

Added line #L118 was not covered by tests
}

return asset.RenderFile(rbGems, r, gemfile)
Expand All @@ -128,7 +128,7 @@
return err
}

shell, err := asset.Load("ruby.sh") //no parsing needed, so just Load is fine here
shell, err := asset.Load("ruby.sh") // no parsing needed, so just Load is fine here

Check warning on line 131 in internal/bridgr/ruby.go

View check run for this annotation

Codecov / codecov/patch

internal/bridgr/ruby.go#L131

Added line #L131 was not covered by tests
if err != nil {
return err
}
Expand Down
8 changes: 6 additions & 2 deletions internal/bridgr/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"time"
)

const (
serverReadHeaderTimeout = 5 * time.Second
)

var (
logFmt = "2/Jan/2006:15:04:05 -0700"
shutdownTimeout = 10 * time.Second
Expand Down Expand Up @@ -54,7 +58,7 @@
fs := http.FileServer(root)
handlerChain := logMiddleware(customHeaders(fs))
http.Handle("/", handlerChain)
server := &http.Server{Addr: addr}
server := &http.Server{Addr: addr, ReadHeaderTimeout: serverReadHeaderTimeout, Handler: http.DefaultServeMux}

Check warning on line 61 in internal/bridgr/server.go

View check run for this annotation

Codecov / codecov/patch

internal/bridgr/server.go#L61

Added line #L61 was not covered by tests

signal.Notify(quit, os.Interrupt)
go shutdownHandler(server)
Expand Down Expand Up @@ -83,7 +87,7 @@
loggingRW := &loggingResponseWriter{
ResponseWriter: w,
}
next.ServeHTTP(loggingRW, r) //continue with the response
next.ServeHTTP(loggingRW, r) // continue with the response

// clog (used by the rest of bridgr) doesn't support changing the "prefix" of logging output
// so, we use direct Printf here instead so the logs aren't "double formatted" - first by clog and then in CLF form
Expand Down
4 changes: 2 additions & 2 deletions internal/bridgr/yum.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@
// Setup only does the setup step of the YUM worker
func (y Yum) Setup() error {
log.Trace("Called Yum Setup()")
_ = os.MkdirAll(y.dir(), os.ModePerm)
_ = os.MkdirAll(y.dir(), DefaultDirPerms)

Check warning on line 111 in internal/bridgr/yum.go

View check run for this annotation

Codecov / codecov/patch

internal/bridgr/yum.go#L111

Added line #L111 was not covered by tests

repoFile, err := os.Create(path.Join(y.dir(), "bridgr.repo"))
if err != nil {
return fmt.Errorf("Unable to create YUM repo file: %s", err)
return fmt.Errorf("unable to create YUM repo file: %s", err)

Check warning on line 115 in internal/bridgr/yum.go

View check run for this annotation

Codecov / codecov/patch

internal/bridgr/yum.go#L115

Added line #L115 was not covered by tests
}

err = asset.RenderFile(yumRepo, y.Repos, repoFile)
Expand Down
Loading