Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checkshttp #230

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
22 changes: 22 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Build

on:
push:
pull_request:

jobs:
build:
runs-on: ubuntu-24.04

steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: '>=1.19'

- name: Install tests deps
run: sudo apt install nmap -y

- name: Go test
run: go test -v ./... -count 1
11 changes: 0 additions & 11 deletions .travis.yml

This file was deleted.

18 changes: 18 additions & 0 deletions bootstrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/adevinta/vulcan-check-sdk/agent"
"github.com/adevinta/vulcan-check-sdk/config"
"github.com/adevinta/vulcan-check-sdk/internal/http"
"github.com/adevinta/vulcan-check-sdk/internal/local"
"github.com/adevinta/vulcan-check-sdk/internal/logging"
"github.com/adevinta/vulcan-check-sdk/internal/push"
Expand Down Expand Up @@ -130,10 +131,19 @@ func NewCheck(name string, checker Checker) Check {
conf.Check.Target = runTarget
conf.Check.Opts = options
c = newLocalCheck(name, checker, logger, conf, json)
} else if conf.Port != nil {
logger.Debug("Http mode")
l := logging.BuildLoggerWithConfigAndFields(conf.Log, log.Fields{
// "checkTypeName": "TODO",
// "checkTypeVersion": "TODO",
// "component": "checks",
})
c = http.NewCheck(name, checker, l, conf)
} else {
logger.Debug("Push mode")
c = push.NewCheckWithConfig(name, checker, logger, conf)
}

cachedConfig = conf
return c
}
Expand All @@ -149,6 +159,14 @@ func NewCheckLog(name string) *log.Entry {
return (l)
}

// NewCheckLogFromContext retrieves the logger from the context or creates a new one.
func NewCheckLogFromContext(ctx context.Context, name string) *log.Entry {
if l, ok := ctx.Value("logger").(*log.Entry); ok {
return l
}
return NewCheckLog(name)
}

// NewCheckFromHandlerWithConfig creates a new check from run and abort handlers using provided config.
func NewCheckFromHandlerWithConfig(name string, conf *config.Config, run CheckerHandleRun) Check {
checkerAdapter := struct {
Expand Down
11 changes: 11 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const (
pushAgentAddr = "VULCAN_AGENT_ADDRESS"
pushMsgBufferLen = "VULCAN_CHECK_MSG_BUFF_LEN"

httpPort = "VULCAN_HTTP_PORT"

// Allows scanning private / reserved IP addresses.
allowPrivateIPs = "VULCAN_ALLOW_PRIVATE_IPS"

Expand Down Expand Up @@ -63,6 +65,7 @@ type Config struct {
Log LogConfig `toml:"Log"`
CommMode string `toml:"CommMode"`
Push rest.PusherConfig `toml:"Push"`
Port *int `toml:"Port"`
AllowPrivateIPs *bool `toml:"AllowPrivateIps"`
RequiredVars map[string]string `toml:"RequiredVars"`
}
Expand Down Expand Up @@ -121,6 +124,14 @@ func overrideCommConfigEnvVars(c *Config) {
c.Push.AgentAddr = pushEndPoint
}

port := os.Getenv(httpPort)
if port != "" {
p, err := strconv.Atoi(port)
if err == nil {
c.Port = &p
}
}

msgBuffLen := os.Getenv(pushMsgBufferLen)
len, err := strconv.ParseInt(msgBuffLen, 0, 32)
if err != nil {
Expand Down
3 changes: 0 additions & 3 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,6 @@ func setEnvVars(envVars map[string]string) error {
}

func TestLoadConfigFromFile(t *testing.T) {
type args struct {
filePath string
}
tests := []struct {
name string
filepath string
Expand Down
25 changes: 13 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,31 @@ require (
github.com/BurntSushi/toml v1.2.1
github.com/adevinta/vulcan-report v1.0.0
github.com/adevinta/vulcan-types v1.2.11
github.com/aws/aws-sdk-go v1.51.0
github.com/go-git/go-git/v5 v5.6.1
github.com/aws/aws-sdk-go v1.55.5

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dependency is already vulnerable

github.com/go-git/go-git/v5 v5.12.0
github.com/google/go-cmp v0.6.0
github.com/kr/pretty v0.3.1
github.com/lair-framework/go-nmap v0.0.0-20191202052157-3507e0b03523
github.com/sirupsen/logrus v1.9.0
go.uber.org/goleak v1.3.0
google.golang.org/api v0.171.0
gopkg.in/resty.v1 v1.12.0
)

require (
cloud.google.com/go/compute v1.23.4 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230411080316-8b3893ee7fca // indirect
github.com/acomagu/bufpipe v1.0.4 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
dario.cat/mergo v1.0.0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v1.0.0 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/docker/distribution v2.8.3+incompatible // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-git/gcfg v1.5.0 // indirect
github.com/go-git/go-billy/v5 v5.4.1 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
Expand All @@ -37,16 +39,15 @@ require (
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.3 // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/miekg/dns v1.1.58 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
github.com/skeema/knownhosts v1.1.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/skeema/knownhosts v1.2.2 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
Expand Down
Loading