Skip to content
This repository was archived by the owner on Feb 11, 2025. It is now read-only.
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 Gemfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# frozen_string_literal: true

source 'https://rubygems.org'
ruby '~> 3.2.0'
ruby '~> 3.3.0'

gem 'bosh-template'
gem 'guard-rspec'
gem 'rake'
gem 'rspec'
gem 'rspec-its'
gem 'rubocop'
gem 'rubocop', '>=1.52.1'
gem 'rubocop-rake'
gem 'rubocop-rspec'
37 changes: 20 additions & 17 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ GEM
guard (~> 2.1)
guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0)
json (2.6.2)
json (2.8.2)
language_server-protocol (3.17.0.3)
listen (3.7.1)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
Expand All @@ -32,19 +33,20 @@ GEM
notiffany (0.1.3)
nenv (~> 0.1)
shellany (~> 0.0)
parallel (1.22.1)
parser (3.1.2.1)
parallel (1.26.3)
parser (3.3.6.0)
ast (~> 2.4.1)
racc
pry (0.14.1)
coderay (~> 1.1)
method_source (~> 1.0)
racc (1.8.1)
rainbow (3.1.1)
rake (13.0.6)
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
regexp_parser (2.6.0)
rexml (3.2.5)
regexp_parser (2.9.2)
rspec (3.11.0)
rspec-core (~> 3.11.0)
rspec-expectations (~> 3.11.0)
Expand All @@ -61,44 +63,45 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.11.0)
rspec-support (3.11.1)
rubocop (1.36.0)
rubocop (1.68.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.1.2.1)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.20.1, < 2.0)
regexp_parser (>= 2.4, < 3.0)
rubocop-ast (>= 1.32.2, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.22.0)
parser (>= 3.1.1.0)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.36.1)
parser (>= 3.3.1.0)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
rubocop-rspec (2.13.2)
rubocop (~> 1.33)
ruby-progressbar (1.11.0)
ruby-progressbar (1.13.0)
semi_semantic (1.2.0)
shellany (0.0.1)
thor (1.2.1)
unicode-display_width (2.3.0)
unicode-display_width (2.6.0)

PLATFORMS
universal-darwin-22
x86_64-darwin-21
x86_64-linux

DEPENDENCIES
bosh-template
guard-rspec
rake
rspec
rspec-its
rubocop
rubocop (>= 1.52.1)
rubocop-rake
rubocop-rspec

RUBY VERSION
ruby 3.2.2p53
ruby 3.3.6p108

BUNDLED WITH
2.3.22
4 changes: 3 additions & 1 deletion acceptance-tests/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module acceptance_tests

go 1.20
go 1.22

toolchain go1.22.3

require (
github.com/bramvdbogaerde/go-scp v1.5.0
Expand Down
5 changes: 5 additions & 0 deletions acceptance-tests/go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
github.com/bramvdbogaerde/go-scp v1.5.0 h1:a9BinAjTfQh273eh7vd3qUgmBC+bx+3TRDtkZWmIpzM=
github.com/bramvdbogaerde/go-scp v1.5.0/go.mod h1:on2aH5AxaFb2G0N5Vsdy6B0Ml7k9HuHSwfo1y0QzAbQ=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
Expand All @@ -14,7 +15,9 @@ github.com/onsi/ginkgo/v2 v2.20.2/go.mod h1:K9gyxPIlb+aIvnZ8bd9Ak+YP18w3APlR+5co
github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k=
github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8=
Expand All @@ -24,11 +27,13 @@ golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.24.0 h1:Mh5cbb+Zk2hqqXNO7S1iTjEphVL+jb8ZWaqh/g+JWkM=
golang.org/x/term v0.24.0/go.mod h1:lOBK/LVxemqiMij05LGJ0tzNr8xlmwBRJ81PX6wVLH8=
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24=
golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
7 changes: 3 additions & 4 deletions src/pcap/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ linters-settings:
# Default: true
skipRecvDeref: false

gomnd:
mnd:
# List of function patterns to exclude from analysis.
# Values always ignored: `time.Date`,
# `strconv.FormatInt`, `strconv.FormatUint`, `strconv.FormatFloat`,
Expand Down Expand Up @@ -184,9 +184,8 @@ linters:
- durationcheck # checks for two durations multiplied together
- errname # checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error
- errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13
- execinquery # checks query string in Query function which reads your Go src files and warning it finds
- exhaustive # checks exhaustiveness of enum switch statements
- exportloopref # checks for pointers to enclosing loop variables
- copyloopvar # checks for pointers to enclosing loop variables
- forbidigo # forbids identifiers
- funlen # tool for detection of long functions
- gci # controls golang package import order and makes it always deterministic
Expand All @@ -197,7 +196,7 @@ linters:
- godot # checks if comments end in a period
- gofmt # checks whether code was gofmt-ed
- goimports # in addition to fixing imports, goimports also formats your code in the same style as gofmt
- gomnd # detects magic numbers
- mnd # detects magic numbers
- gomoddirectives # manages the use of 'replace', 'retract', and 'excludes' directives in go.mod
- gomodguard # allow and block lists linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations
- goprintffuncname # checks that printf-like functions are named with f at the end
Expand Down
4 changes: 2 additions & 2 deletions src/pcap/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (a *Agent) Capture(stream Agent_CaptureServer) (err error) {
return errorf(codes.InvalidArgument, "%w", err)
}

opts := req.Payload.(*AgentRequest_Start).Start.Capture
opts := req.Payload.(*AgentRequest_Start).Start.Capture //nolint:errcheck //this only returns one value
log.Info("starting capture", zap.String("device", opts.Device), zap.Uint32("snapLen", opts.SnapLen), zap.String("filter", opts.Filter))

handle, err := openHandle(opts)
Expand Down Expand Up @@ -196,7 +196,7 @@ func validateAgentStartRequest(req *AgentRequest) error {
// openHandle is a helper function to open the packet capturing handle that reads from the
// network interface and returns the data. Puts the network interface into promiscuous mode.
func openHandle(opts *CaptureOptions) (*pcap.Handle, error) {
handle, err := pcap.OpenLive(opts.Device, int32(opts.SnapLen), true, readPacketTimeout)
handle, err := pcap.OpenLive(opts.Device, int32(opts.SnapLen), true, readPacketTimeout) //nolint:gosec //size in relation to packets, well within int32
if err != nil {
return nil, errorf(codes.Internal, "open handle: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion src/pcap/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func TestCapture(t *testing.T) {
t.Errorf("capture() unexpected error during api creation: %v", err)
}

var connectToTargetFn = func(ctx context.Context, req *CaptureOptions, target AgentEndpoint, creds credentials.TransportCredentials, log *zap.Logger) (captureStream, error) {
var connectToTargetFn = func(ctx context.Context, req *CaptureOptions, target AgentEndpoint, creds credentials.TransportCredentials, log *zap.Logger) (captureStream, error) { //nolint:revive //keep vars even if unused for better context
return tt.stream, tt.err
}

Expand Down
6 changes: 3 additions & 3 deletions src/pcap/bosh.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func (br *BoshResolver) Validate(endpointRequest *EndpointRequest) error {
func (br *BoshResolver) setup() error {
br.logger.Debug("setting up BoshResolver", zap.Any("resolver-config", br.Config))

timeout := 500 * time.Millisecond //nolint:gomnd // reasonable value.
timeout := 500 * time.Millisecond //nolint:mnd // reasonable value.

br.client = &http.Client{
Transport: &http.Transport{
Expand Down Expand Up @@ -385,7 +385,7 @@ func (br *BoshResolver) verifyJWT(tokenString string) error {
scopes, ok := claims["scope"].([]interface{})
if ok {
for _, scope := range scopes {
if scope.(string) == br.Config.TokenScope {
if scope.(string) == br.Config.TokenScope { //nolint:errcheck //fine to panic if not string
return nil
}
}
Expand All @@ -406,7 +406,7 @@ func (br *BoshResolver) parseKey(token *jwt.Token) (interface{}, error) {
return nil, fmt.Errorf("header 'jku' missing from token, cannot verify signature: %w", ErrTokenUnsupported)
}

jkuURL, err := url.Parse(jku.(string))
jkuURL, err := url.Parse(jku.(string)) //nolint:errcheck //fine to panic if not string
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion src/pcap/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func (c *Client) logProgress(ctx context.Context, logger *zap.Logger) {
logger.Debug("could not inspect output file", zap.Error(err))
return
}
logger.Debug(fmt.Sprintf("%s bytes written to disk (total).", bytefmt.ByteSize(uint64(info.Size()))))
logger.Debug(fmt.Sprintf("%s bytes written to disk (total).", bytefmt.ByteSize(uint64(info.Size())))) //nolint:gosec //file size is non negative
case <-ctx.Done():
return
}
Expand Down
8 changes: 4 additions & 4 deletions src/pcap/cmd/pcap-agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (

var DefaultConfig = Config{
pcap.NodeConfig{
Listen: pcap.Listen{Port: 9494}, //nolint:gomnd // default value used for testing
Listen: pcap.Listen{Port: 9494}, //nolint:mnd // default value used for testing
Buffer: pcap.BufferConf{
Size: 1000, //nolint:gomnd // default value used for testing
UpperLimit: 995, //nolint:gomnd // default value used for testing
LowerLimit: 900, //nolint:gomnd // default value used for testing
Size: 1000, //nolint:mnd // default value used for testing
UpperLimit: 995, //nolint:mnd // default value used for testing
LowerLimit: 900, //nolint:mnd // default value used for testing
},
LogLevel: "debug",
ID: "test-agent",
Expand Down
2 changes: 1 addition & 1 deletion src/pcap/cmd/pcap-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func main() {
switch len(os.Args) {
case 1:
config = DefaultConfig
case 2: //nolint:gomnd // two arguments mean parse the config.
case 2: //nolint:mnd // two arguments mean parse the config.
config, err = parseConfig(os.Args[1])
default:
err = fmt.Errorf("invalid number of arguments, expected 1 or 2 but got %d", len(os.Args))
Expand Down
12 changes: 6 additions & 6 deletions src/pcap/cmd/pcap-api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ import (

var DefaultAPIConfig = APIConfig{
NodeConfig: pcap.NodeConfig{
Listen: pcap.Listen{Port: 8080}, //nolint:gomnd // default port
Listen: pcap.Listen{Port: 8080}, //nolint:mnd // default port
Buffer: pcap.BufferConf{
Size: 100, //nolint:gomnd // default size
UpperLimit: 95, //nolint:gomnd // default size
LowerLimit: 60, //nolint:gomnd // default size
Size: 100, //nolint:mnd // default size
UpperLimit: 95, //nolint:mnd // default size
LowerLimit: 60, //nolint:mnd // default size
},
LogLevel: "debug",
ID: "test-api",
},
AgentsMTLS: nil,
DrainTimeout: 10 * time.Second, //nolint:gomnd // default configuration
ConcurrentCaptures: 5, //nolint:gomnd // default configuration
DrainTimeout: 10 * time.Second, //nolint:mnd // default configuration
ConcurrentCaptures: 5, //nolint:mnd // default configuration
}

type APIConfig struct {
Expand Down
2 changes: 1 addition & 1 deletion src/pcap/cmd/pcap-api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func main() {
switch len(os.Args) {
case 1:
config = DefaultAPIConfig
case 2: //nolint:gomnd // two arguments mean parse the config.
case 2: //nolint:mnd // two arguments mean parse the config.
config, err = parseAPIConfig(os.Args[1])
default:
err = fmt.Errorf("invalid number of arguments, expected 1 or 2 but got %d", len(os.Args))
Expand Down
4 changes: 2 additions & 2 deletions src/pcap/cmd/pcap-bosh-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type options struct {
BoshEnvironment string `short:"e" long:"bosh-environment" description:"The BOSH environment to use for retrieving the BOSH UAA token from the BOSH config file" env:"BOSH_ENVIRONMENT" required:"true"`
Deployment string `short:"d" long:"deployment" description:"The name of the deployment in which you would like to capture." required:"true"`
InstanceGroups []string `short:"g" long:"instance-group" description:"The name of an instance group in the deployment in which you would like to capture. Can be defined multiple times." required:"true"`
InstanceIds []string `positional-arg-name:"ids" description:"The instance IDs of the deployment to capture." required:"false"`
InstanceIds []string `positional-arg-name:"ids" description:"The instance IDs of the deployment to capture." required:"false"` //nolint:revive //keep InstanceIds name (not IDs)
SnapLength uint16 `short:"l" long:"snaplen" description:"Snap Length, defining the captured length of the packet, with the remainder truncated. The real packet length is recorded." default:"65535"`
Verbose bool `short:"v" long:"verbose" description:"Show verbose debug information"`
Insecure bool `short:"k" long:"insecure" description:"Allow insecure server connections" required:"false"`
Expand Down Expand Up @@ -433,7 +433,7 @@ func (e *Environment) setup() error {
return nil
}
logger.Info("using TLS-encrypted connection to bosh-director", zap.String("bosh-director-url", e.DirectorURL.String()))
transport := http.DefaultTransport.(*http.Transport).Clone()
transport := http.DefaultTransport.(*http.Transport).Clone() //nolint:errcheck //Clone returns only one value

if e.CaCert != "" {
boshCA := x509.NewCertPool()
Expand Down
2 changes: 1 addition & 1 deletion src/pcap/cmd/pcap-bosh-cli/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestParseAPIURL(t *testing.T) {

func TestEnvironment_Connect(t *testing.T) {
mux := http.NewServeMux()
mux.HandleFunc("/info", func(writer http.ResponseWriter, request *http.Request) {
mux.HandleFunc("/info", func(writer http.ResponseWriter, _ *http.Request) {
info := pcap.BoshInfo{}
info.UserAuthentication.Type = BoshAuthTypeUAA
info.UserAuthentication.Options.URL = "https://uaa.fakebosh.com"
Expand Down
6 changes: 3 additions & 3 deletions src/pcap/devtools/pcap-agent-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func main() {
Capture: &pcap.CaptureOptions{
Device: "en0",
Filter: "",
SnapLen: 65000, //nolint:gomnd // default value used for testing
SnapLen: 65000, //nolint:mnd // default value used for testing
},
},
},
Expand All @@ -80,7 +80,7 @@ func main() {
return
}

devtools.ReadN(10, stream) //nolint:gomnd // default value used for testing
devtools.ReadN(10, stream) //nolint:mnd // default value used for testing

err = stream.Send(&pcap.AgentRequest{
Payload: &pcap.AgentRequest_Stop{},
Expand All @@ -90,5 +90,5 @@ func main() {
return
}

devtools.ReadN(10_000, stream) //nolint:gomnd // default value used for testing
devtools.ReadN(10_000, stream) //nolint:mnd // default value used for testing
}
8 changes: 4 additions & 4 deletions src/pcap/devtools/pcap-api-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func main() {
Options: &pcap.CaptureOptions{
Device: "en0",
Filter: "",
SnapLen: 65000, //nolint:gomnd // default value used for testing
SnapLen: 65000, //nolint:mnd // default value used for testing
},
},
},
Expand All @@ -88,8 +88,8 @@ func main() {

// keep receiving some data long enough to start a manual drain
for i := 0; i < 10000; i++ {
devtools.ReadN(1000, stream) //nolint:gomnd // default value used for testing
time.Sleep(200 * time.Millisecond) //nolint:gomnd // default value used for testing
devtools.ReadN(1000, stream) //nolint:mnd // default value used for testing
time.Sleep(200 * time.Millisecond) //nolint:mnd // default value used for testing
}

err = stream.Send(pcap.MakeStopRequest())
Expand All @@ -98,5 +98,5 @@ func main() {
return
}

devtools.ReadN(10_000, stream) //nolint:gomnd // default value used for testing
devtools.ReadN(10_000, stream) //nolint:mnd // default value used for testing
}
2 changes: 1 addition & 1 deletion src/pcap/pcap.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func newPacketResponse(data []byte, captureInfo gopacket.CaptureInfo) *CaptureRe
Packet: &Packet{
Data: data,
Timestamp: timestamppb.New(captureInfo.Timestamp),
Length: int32(captureInfo.Length),
Length: int32(captureInfo.Length), //nolint:gosec //this is a size of network packet, well within int32
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion src/pcap/test/bosh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestNewBoshResolver(t *testing.T) {
func TestAuthenticate(t *testing.T) {
bar, _, _, err := mock.NewResolverWithMockBoshAPI(nil)
if err != nil {
t.Errorf(err.Error())
t.Error(err)
}

validToken, err := mock.GetValidToken(bar.UaaURLs[0])
Expand Down
Loading