Skip to content

Commit

Permalink
go lint fix
Browse files Browse the repository at this point in the history
Signed-off-by: Benji Visser <benji@093b.org>
  • Loading branch information
noqcks committed Jul 16, 2023
1 parent e5b1327 commit 231a871
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 28 deletions.
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func isVerbose() (result bool) {
return appConfig.CliOptions.Verbosity > 0 || isPipedInput
}

//nolint:funlen
//nolint:funlen,gocognit
func startWorker(userInput string, failOnEolFound bool, eolMatchDate time.Time) <-chan error {
errs := make(chan error)
go func() {
Expand Down
4 changes: 2 additions & 2 deletions internal/config/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type defaultValueLoader interface {
loadDefaultValues(*viper.Viper)
}

const DEFAULT_PRO_LOOKAHEAD = "now+3y"
const DefaultProLookahead = "now+3y"

type parser interface {
parseConfigValues() error
Expand Down Expand Up @@ -212,7 +212,7 @@ func (cfg *Application) parseLookaheadOption() error {
// if the user has specified an API key and is posting results to xeol.io, then we
// set a default lookahead value to 3 years from now
if cfg.APIKey != "" {
cfg.EolMatchDate, err = tparse.ParseNow(time.RFC3339, DEFAULT_PRO_LOOKAHEAD)
cfg.EolMatchDate, err = tparse.ParseNow(time.RFC3339, DefaultProLookahead)
if err != nil {
return fmt.Errorf("bad --lookahead value: '%s'", cfg.Lookahead)
}
Expand Down
10 changes: 5 additions & 5 deletions internal/xeolio/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ type PolicyType string
type CycleOperator string

const (
XeolAPIUrl = "https://api.xeol.io"
XeolEngineUrl = "https://engine.xeol.io"
XeolAPIURL = "https://api.xeol.io"
XeolEngineURL = "https://engine.xeol.io"

PolicyTypeEol PolicyType = "EOL"

Expand All @@ -28,7 +28,7 @@ const (
)

type Policy struct {
Id string `json:"id"`
ID string `json:"id"`
PolicyType PolicyType `json:"policy_type"`
WarnDate string `json:"warn_date"`
DenyDate string `json:"deny_date"`
Expand Down Expand Up @@ -102,7 +102,7 @@ func (x *XeolClient) makeRequest(method, url, path string, body io.Reader, out i

func (x *XeolClient) FetchPolicies() ([]Policy, error) {
var policies []Policy
err := x.makeRequest("GET", XeolAPIUrl, "v1/policy", nil, &policies)
err := x.makeRequest("GET", XeolAPIURL, "v1/policy", nil, &policies)
if err != nil {
return nil, err
}
Expand All @@ -116,5 +116,5 @@ func (x *XeolClient) SendEvent(payload report.XeolEventPayload) error {
return fmt.Errorf("error marshalling xeol.io API request: %v", err)
}

return x.makeRequest("PUT", XeolEngineUrl, "v1/scan", bytes.NewBuffer(p), nil)
return x.makeRequest("PUT", XeolEngineURL, "v1/scan", bytes.NewBuffer(p), nil)
}
4 changes: 2 additions & 2 deletions xeol/event/parsers/parsers.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ func checkEventType(actual, expected partybus.EventType) error {
return nil
}

func ParsePolicyEvaluationMessage(e partybus.Event) (*policy.PolicyEvaluationResult, error) {
func ParsePolicyEvaluationMessage(e partybus.Event) (*policy.EvaluationResult, error) {
if err := checkEventType(e.Type, event.PolicyEvaluationMessage); err != nil {
return nil, err
}

pt, ok := e.Value.(policy.PolicyEvaluationResult)
pt, ok := e.Value.(policy.EvaluationResult)
if !ok {
return nil, newPayloadErr(e.Type, "Value", e.Value)
}
Expand Down
24 changes: 12 additions & 12 deletions xeol/policy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@ package policy
import (
"time"

"github.com/Masterminds/semver"
"github.com/wagoodman/go-partybus"

"github.com/xeol-io/xeol/internal/bus"
"github.com/xeol-io/xeol/internal/log"

"github.com/Masterminds/semver"
"github.com/xeol-io/xeol/internal/xeolio"
"github.com/xeol-io/xeol/xeol/event"
"github.com/xeol-io/xeol/xeol/match"
)

const (
DateLayout = "2006-01-02"
PolicyTypeWarn PolicyEvaluationType = "WARN"
PolicyTypeDeny PolicyEvaluationType = "DENY"
DateLayout = "2006-01-02"
PolicyTypeWarn EvaluationType = "WARN"
PolicyTypeDeny EvaluationType = "DENY"
)

var timeNow = time.Now

type PolicyEvaluationType string
type EvaluationType string

type PolicyEvaluationResult struct {
Type PolicyEvaluationType
type EvaluationResult struct {
Type EvaluationType
ProductName string
Cycle string
FailDate string
Expand Down Expand Up @@ -84,13 +84,13 @@ func denyMatch(policy xeolio.Policy) bool {
return false
}

func evaluateMatches(policies []xeolio.Policy, matches match.Matches) []PolicyEvaluationResult {
var results []PolicyEvaluationResult
func evaluateMatches(policies []xeolio.Policy, matches match.Matches) []EvaluationResult {
var results []EvaluationResult
for _, policy := range policies {
for _, match := range matches.Sorted() {
if cycleOperatorMatch(match, policy) {
if denyMatch(policy) {
results = append(results, PolicyEvaluationResult{
results = append(results, EvaluationResult{
Type: PolicyTypeDeny,
ProductName: match.Cycle.ProductName,
Cycle: match.Cycle.ReleaseCycle,
Expand All @@ -99,7 +99,7 @@ func evaluateMatches(policies []xeolio.Policy, matches match.Matches) []PolicyEv
continue
}
if warnMatch(policy) {
results = append(results, PolicyEvaluationResult{
results = append(results, EvaluationResult{
Type: PolicyTypeWarn,
ProductName: match.Cycle.ProductName,
Cycle: match.Cycle.ReleaseCycle,
Expand Down
13 changes: 7 additions & 6 deletions xeol/policy/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

syftPkg "github.com/anchore/syft/syft/pkg"
"github.com/google/uuid"

"github.com/xeol-io/xeol/internal/xeolio"
"github.com/xeol-io/xeol/xeol/eol"
"github.com/xeol-io/xeol/xeol/match"
Expand All @@ -18,7 +19,7 @@ func TestEvaluate(t *testing.T) {
name string
policy []xeolio.Policy
matches []match.Match
want []PolicyEvaluationResult
want []EvaluationResult
}{
{
name: "policy with no matches",
Expand Down Expand Up @@ -72,7 +73,7 @@ func TestEvaluate(t *testing.T) {
},
},
},
want: []PolicyEvaluationResult{
want: []EvaluationResult{
{
Type: PolicyTypeDeny,
ProductName: "foo",
Expand Down Expand Up @@ -105,7 +106,7 @@ func TestEvaluate(t *testing.T) {
},
},
},
want: []PolicyEvaluationResult{
want: []EvaluationResult{
{
Type: PolicyTypeWarn,
ProductName: "foo",
Expand Down Expand Up @@ -139,7 +140,7 @@ func TestEvaluate(t *testing.T) {
},
},
},
want: []PolicyEvaluationResult{
want: []EvaluationResult{
{
Type: PolicyTypeWarn,
ProductName: "foo",
Expand Down Expand Up @@ -173,7 +174,7 @@ func TestEvaluate(t *testing.T) {
},
},
},
want: []PolicyEvaluationResult{
want: []EvaluationResult{
{
Type: PolicyTypeWarn,
ProductName: "foo",
Expand Down Expand Up @@ -226,7 +227,7 @@ func TestEvaluate(t *testing.T) {
},
},
},
want: []PolicyEvaluationResult{
want: []EvaluationResult{
{
Type: PolicyTypeWarn,
ProductName: "foo",
Expand Down

0 comments on commit 231a871

Please sign in to comment.