Skip to content

Commit

Permalink
Merge branch 'main' into listen_socket
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurenceJJones authored Apr 22, 2024
2 parents 3106b05 + 83ff2b5 commit fe73b75
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 37 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build-binary-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ jobs:
steps:

- name: Check out repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: 1.21.5
go-version: 1.21.7

- name: Build all platforms
run: |
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ jobs:
steps:

- name: Check out code into the Go module directory
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: 1.21.5
go-version: 1.21.7

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: go, python

Expand All @@ -37,9 +37,9 @@ jobs:
make build
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v4
with:
version: v1.55
version: v1.56
args: --issues-exit-code=1 --timeout 10m
only-new-issues: false
# the cache is already managed above, enabling it here
Expand All @@ -48,4 +48,4 @@ jobs:
skip-build-cache: true

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
2 changes: 1 addition & 1 deletion .github/workflows/publish-docker-doc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
steps:
-
name: Check out the repo
uses: actions/checkout@v3
uses: actions/checkout@v4
-
name: Update docker hub README
uses: ms-jpq/sync-dockerhub-readme@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
name: Update the release draft
steps:
# Drafts your next Release notes as Pull Requests are merged into "main"
- uses: release-drafter/release-drafter@v5
- uses: release-drafter/release-drafter@v6
with:
config-name: release-drafter.yml
# (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/release_publish_docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
steps:
-
name: Check out the repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
-
Expand All @@ -43,27 +43,27 @@ jobs:
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
-
name: Login to DockerHub
if: github.event_name == 'release'
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v1.12.0
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build and push
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ jobs:
steps:

- name: Check out code into the Go module directory
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: 1.21.5
go-version: 1.21.7

- name: Build
run: |
Expand All @@ -40,7 +40,7 @@ jobs:

- name: Cache virtualenvs
id: cache-pipenv
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.local/share/virtualenvs
key: ${{ runner.os }}-pipenv-${{ hashFiles('**/Pipfile.lock') }}
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/tests_deb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ jobs:
steps:

- name: Check out code into the Go module directory
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: 1.21.5
go-version: 1.21.7

- name: Cache virtualenvs
id: cache-pipenv
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.local/share/virtualenvs
key: ${{ runner.os }}-pipenv-${{ hashFiles('**/Pipfile.lock') }}
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG GOVERSION=1.21.5
ARG GOVERSION=1.21.7

FROM golang:${GOVERSION}-alpine AS build

Expand Down
14 changes: 9 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"bytes"
"context"
"errors"
"flag"
"fmt"
"os"
Expand Down Expand Up @@ -33,9 +34,9 @@ func HandleSignals(ctx context.Context) error {
case s := <-signalChan:
switch s {
case syscall.SIGTERM:
return fmt.Errorf("received SIGTERM")
return errors.New("received SIGTERM")
case os.Interrupt: // cross-platform SIGINT
return fmt.Errorf("received interrupt")
return errors.New("received interrupt")
}
case <-ctx.Done():
return ctx.Err()
Expand All @@ -60,7 +61,7 @@ func Execute() error {
}

if configPath == nil || *configPath == "" {
return fmt.Errorf("configuration file is required")
return errors.New("configuration file is required")
}

configBytes, err := cfg.MergedConfig(*configPath)
Expand Down Expand Up @@ -100,8 +101,9 @@ func Execute() error {
ScenariosContaining: strings.Join(config.CrowdsecConfig.IncludeScenariosContaining, ","),
ScenariosNotContaining: strings.Join(config.CrowdsecConfig.ExcludeScenariosContaining, ","),
Origins: strings.Join(config.CrowdsecConfig.OnlyIncludeDecisionsFrom, ","),
Scopes: strings.Join(config.CrowdsecConfig.Scopes, ","),
},
UserAgent: fmt.Sprintf("crowdsec-blocklist-mirror/%s", version.String()),
UserAgent: "crowdsec-blocklist-mirror/" + version.String(),
CertPath: config.CrowdsecConfig.CertPath,
KeyPath: config.CrowdsecConfig.KeyPath,
CAPath: config.CrowdsecConfig.CAPath,
Expand All @@ -121,7 +123,7 @@ func Execute() error {

g.Go(func() error {
decisionStreamer.Run(ctx)
return fmt.Errorf("bouncer stream halted")
return errors.New("bouncer stream halted")
})

g.Go(func() error {
Expand All @@ -148,10 +150,12 @@ func Execute() error {
if decisions == nil {
continue
}

if len(decisions.New) > 0 {
log.Infof("received %d new decisions", len(decisions.New))
registry.GlobalDecisionRegistry.AddDecisions(decisions.New)
}

if len(decisions.Deleted) > 0 {
log.Infof("received %d expired decisions", len(decisions.Deleted))
registry.GlobalDecisionRegistry.DeleteDecisions(decisions.Deleted)
Expand Down
6 changes: 4 additions & 2 deletions pkg/cfg/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cfg

import (
"errors"
"fmt"
"io"
"net"
Expand Down Expand Up @@ -30,6 +31,7 @@ type CrowdsecConfig struct {
IncludeScenariosContaining []string `yaml:"include_scenarios_containing"`
ExcludeScenariosContaining []string `yaml:"exclude_scenarios_containing"`
OnlyIncludeDecisionsFrom []string `yaml:"only_include_decisions_from"`
Scopes []string `yaml:"scopes,omitempty"`
}

type BlockListConfig struct {
Expand Down Expand Up @@ -71,11 +73,11 @@ type Config struct {

func (cfg *Config) ValidateAndSetDefaults() error {
if cfg.CrowdsecConfig.LapiKey == "" && cfg.CrowdsecConfig.CertPath == "" {
return fmt.Errorf("one of lapi_key or cert_path is required")
return errors.New("one of lapi_key or cert_path is required")
}

if cfg.CrowdsecConfig.LapiURL == "" {
return fmt.Errorf("lapi_url is required")
return errors.New("lapi_url is required")
}

if !strings.HasSuffix(cfg.CrowdsecConfig.LapiURL, "/") {
Expand Down
4 changes: 2 additions & 2 deletions pkg/cfg/logging.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cfg

import (
"fmt"
"errors"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -75,7 +75,7 @@ func (c *LoggingConfig) setDefaults() {

func (c *LoggingConfig) validate() error {
if c.LogMedia != "stdout" && c.LogMedia != "file" {
return fmt.Errorf("log_media should be either 'stdout' or 'file'")
return errors.New("log_media should be either 'stdout' or 'file'")
}

return nil
Expand Down
2 changes: 2 additions & 0 deletions pkg/server/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,14 @@ func appendQuoted(buf []byte, s string) []byte {
if r == rune('"') || r == '\\' { // always backslashed
buf = append(buf, '\\')
buf = append(buf, byte(r))

continue
}

if strconv.IsPrint(r) {
n := utf8.EncodeRune(runeTmp[:], r)
buf = append(buf, runeTmp[:n]...)

continue
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func satisfiesBasicAuth(r *http.Request, user, password string) bool {
return false
}

expectedVal := fmt.Sprintf("Basic %s", basicAuth(user, password))
expectedVal := "Basic " + basicAuth(user, password)
foundVal := r.Header[http.CanonicalHeaderKey("Authorization")][0]
log.WithFields(log.Fields{
"expected": expectedVal,
Expand Down

0 comments on commit fe73b75

Please sign in to comment.