Skip to content

Commit

Permalink
fix: Removing args condition checking certificates
Browse files Browse the repository at this point in the history
  • Loading branch information
gsanchezgavier committed Aug 22, 2023
1 parent 60abbfd commit 18920ff
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 87 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## 2.7.1 (2023-08-22)
# Fixed
- Removes config validation that prevents to run the integration without a custom CA certificates

## 2.7.0 (2023-06-06)
# Changed
- Upgrade Go version to 1.20
Expand Down
13 changes: 7 additions & 6 deletions src/arguments/arguments.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import (
sdkArgs "github.com/newrelic/infra-integrations-sdk/args"
)

var (
ErrMissingUserOrPass = errors.New("both username and password must be provided")
ErrNegativeMaxConcurrentRequests = errors.New("max_concurrent_requests must be a positive integer")
)

// ArgumentList contains all the arguments available for the F5 integration
type ArgumentList struct {
sdkArgs.DefaultArgumentList
Expand All @@ -27,11 +32,11 @@ type ArgumentList struct {
// Parse validates and parses out regex patterns from the input arguments
func (al *ArgumentList) Parse() (*PathMatcher, error) {
if al.Username == "" || al.Password == "" {
return nil, errors.New("both username and password must be provided")
return nil, ErrMissingUserOrPass
}

if al.MaxConcurrentRequests <= 0 {
return nil, errors.New("max_concurrent_requests must be a positive integer")
return nil, ErrNegativeMaxConcurrentRequests
}

var partitions []string
Expand All @@ -40,10 +45,6 @@ func (al *ArgumentList) Parse() (*PathMatcher, error) {
return nil, err
}

if al.CABundleFile == "" && al.CABundleDir == "" {
return nil, errors.New("CABundleFile or CABundleDir must be specified")
}

return &PathMatcher{partitions}, nil

}
Expand Down
101 changes: 20 additions & 81 deletions src/arguments/arguments_test.go
Original file line number Diff line number Diff line change
@@ -1,103 +1,42 @@
package arguments
package arguments_test

import (
"testing"

"github.com/newrelic/nri-f5/src/arguments"
"github.com/stretchr/testify/assert"
)

func TestParseError(t *testing.T) {
testCases := []struct {
argumentList ArgumentList
expectError bool
name string
argumentList arguments.ArgumentList
expectError error
}{
{
ArgumentList{
Username: "",
Password: "",
CABundleFile: "test",
PartitionFilter: "[]",
MaxConcurrentRequests: 1,
},
true,
},
{
ArgumentList{
Username: "test",
Password: "",
CABundleFile: "test",
PartitionFilter: "[]",
MaxConcurrentRequests: 1,
},
true,
},
{
ArgumentList{
Username: "test",
Password: "test",
CABundleFile: "test",
PartitionFilter: "[]",
MaxConcurrentRequests: 1,
},
false,
},
{
ArgumentList{
Username: "test",
Password: "test",
CABundleFile: "test",
PartitionFilter: `["test2"]`,
MaxConcurrentRequests: 1,
},
false,
},
{
ArgumentList{
Username: "test",
Password: "test",
CABundleFile: "test",
PartitionFilter: `["test2]`,
MaxConcurrentRequests: 1,
},
true,
},
{
ArgumentList{
Username: "test",
Password: "test",
CABundleFile: "test",
PartitionFilter: `["test2"`,
MaxConcurrentRequests: 1,
},
true,
},
{
ArgumentList{
Username: "test",
Password: "test",
PartitionFilter: `["test2"]`,
MaxConcurrentRequests: 1,
},
true,
name: "user name or pass must be specified",
argumentList: arguments.ArgumentList{},
expectError: arguments.ErrMissingUserOrPass,
},
{
ArgumentList{
name: "max concurrent request must be positive",
argumentList: arguments.ArgumentList{
Username: "test",
Password: "test",
CABundleFile: "test",
PartitionFilter: `["test2"]`,
MaxConcurrentRequests: 0,
MaxConcurrentRequests: -1,
},
true,
expectError: arguments.ErrNegativeMaxConcurrentRequests,
},
}

for _, tc := range testCases {
_, err := tc.argumentList.Parse()
if tc.expectError {
assert.Error(t, err)
} else {
assert.Nil(t, err)
}
tc := tc

t.Run(tc.name, func(t *testing.T) {
t.Parallel()

_, err := tc.argumentList.Parse()
assert.ErrorIs(t, err, tc.expectError)
})
}
}

0 comments on commit 18920ff

Please sign in to comment.