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

Add EPSS Ingestor command to ingest-worker #1070

Merged
merged 9 commits into from
Jan 18, 2023
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion lunatrace/bsl/ingest-worker/cmd/analysiscli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
//
// See the License for the specific language governing permissions and
// limitations under the License.
//
package main

import (
Expand Down
51 changes: 51 additions & 0 deletions lunatrace/bsl/ingest-worker/cmd/ingestworker/epss/epss.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright by LunaSec (owned by Refinery Labs, Inc)
//
// Licensed under the Business Source License v1.1
// (the "License"); you may not use this file except in compliance with the
// License. You may obtain a copy of the License at
//
// https://github.com/lunasec-io/lunasec/blob/master/licenses/BSL-LunaTrace.txt
//
// See the License for the specific language governing permissions and
// limitations under the License.
package epss

import (
"github.com/ajvpot/clifx"
"github.com/lunasec-io/lunasec/lunatrace/bsl/ingest-worker/pkg/epss"
"github.com/rs/zerolog/log"
"github.com/urfave/cli/v2"
"go.uber.org/fx"
)

type Params struct {
fx.In

Ingester epss.EPSSIngester
}

func NewCommand(p Params) clifx.CommandResult {
return clifx.CommandResult{
Command: &cli.Command{
Name: "epss",
Subcommands: []*cli.Command{
{
Name: "ingest",
Usage: "[file or directory]",
Flags: []cli.Flag{},
Subcommands: []*cli.Command{},
Action: func(ctx *cli.Context) error {
log.Info().
Msg("Updating EPSS Scores")
err := p.Ingester.Ingest(ctx.Context)
if err == nil {
log.Info().
Msg("Updated EPSS Scores")
}
return err
},
},
},
},
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
//
// See the License for the specific language governing permissions and
// limitations under the License.
//
package license

import (
Expand Down
4 changes: 4 additions & 0 deletions lunatrace/bsl/ingest-worker/cmd/ingestworker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ package main

import (
"github.com/lunasec-io/lunasec/lunatrace/bsl/ingest-worker/cmd/ingestworker/cwe"
"github.com/lunasec-io/lunasec/lunatrace/bsl/ingest-worker/cmd/ingestworker/epss"
packageCommand "github.com/lunasec-io/lunasec/lunatrace/bsl/ingest-worker/cmd/ingestworker/package"
"github.com/lunasec-io/lunasec/lunatrace/bsl/ingest-worker/cmd/ingestworker/vulnerability"
"github.com/lunasec-io/lunasec/lunatrace/bsl/ingest-worker/pkg/config/ingestworker"
cwe2 "github.com/lunasec-io/lunasec/lunatrace/bsl/ingest-worker/pkg/cwe"
"github.com/lunasec-io/lunasec/lunatrace/bsl/ingest-worker/pkg/dbfx"
epss2 "github.com/lunasec-io/lunasec/lunatrace/bsl/ingest-worker/pkg/epss"
"github.com/lunasec-io/lunasec/lunatrace/bsl/ingest-worker/pkg/graphqlfx"
"github.com/lunasec-io/lunasec/lunatrace/bsl/ingest-worker/pkg/metadata/registry"
"github.com/lunasec-io/lunasec/lunatrace/bsl/ingest-worker/pkg/metadata/replicator"
Expand Down Expand Up @@ -49,6 +51,7 @@ func main() {

fx.Provide(
cwe2.NewCWEIngester,
epss2.NewEPSSIngester,
),

// todo make a module
Expand All @@ -74,6 +77,7 @@ func main() {
fx.Provide(
vulnerability.NewCommand,
cwe.NewCommand,
epss.NewCommand,
),
fx.Provide(
packageCommand.NewCommand,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
//
// See the License for the specific language governing permissions and
// limitations under the License.
//
package ingest

import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
//
// See the License for the specific language governing permissions and
// limitations under the License.
//
package vulnerability

import (
"context"
"github.com/go-co-op/gocron"
"github.com/lunasec-io/lunasec/lunatrace/bsl/ingest-worker/pkg/cwe"
"github.com/lunasec-io/lunasec/lunatrace/bsl/ingest-worker/pkg/epss"
"github.com/rs/zerolog/log"
"github.com/urfave/cli/v2"
"go.uber.org/fx"
Expand All @@ -27,8 +28,9 @@ import (
type Params struct {
fx.In

Ingester vulnerability.FileAdvisoryIngester
CWEIngester cwe.CWEIngester
Ingester vulnerability.FileAdvisoryIngester
CWEIngester cwe.CWEIngester
EPSSIngester epss.EPSSIngester
}

func NewCommand(p Params) clifx.CommandResult {
Expand Down Expand Up @@ -62,22 +64,55 @@ func NewCommand(p Params) clifx.CommandResult {
sourceRelativePath := ctx.String("source-relative-path")
cron := ctx.String("cron")

log.Info().
Msg("Updating CWEs")
err := p.CWEIngester.Ingest(ctx.Context)
if err == nil {
runIngestion := func() error {
log.Info().
Msg("Updating CWEs")

err := p.CWEIngester.Ingest(ctx.Context)

if err != nil {
freeqaz marked this conversation as resolved.
Show resolved Hide resolved
log.Error().
Err(err).
Msg("failed to update CWEs")
return err
}

log.Info().
Msg("Updated CWEs")
} else {
return err
}

runIngestion := func() error {
log.Info().
Str("source", source).
Str("cron", cron).
Msg("starting vulnerability ingestion")
return p.Ingester.IngestVulnerabilitiesFromSource(advisoryLocation, source, sourceRelativePath)
err = p.Ingester.IngestVulnerabilitiesFromSource(advisoryLocation, source, sourceRelativePath)

if err != nil {
log.Error().
Err(err).
Str("source", source).
Str("cron", cron).
Msg("failed to ingest vulnerabilities")
return err
}

log.Info().
Str("source", source).
Str("cron", cron).
Msg("starting epss ingestion")

epssContext := context.Background()
err = p.EPSSIngester.Ingest(epssContext)

if err != nil {
log.Error().
Err(err).
Str("source", source).
Str("cron", cron).
Msg("failed to ingest epss")
return err
}

return nil
}

if cron != "" {
Expand Down
1 change: 0 additions & 1 deletion lunatrace/bsl/ingest-worker/cmd/queuehandler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
//
// See the License for the specific language governing permissions and
// limitations under the License.
//
package main

import (
Expand Down
3 changes: 1 addition & 2 deletions lunatrace/bsl/ingest-worker/cmd/registryproxy/main.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// Copyright by LunaSec (owned by Refinery Labs, Inc)
//
// Licensed under the Business Source License v1.1
// Licensed under the Business Source License v1.1
// (the "License"); you may not use this file except in compliance with the
// License. You may obtain a copy of the License at
//
// https://github.com/lunasec-io/lunasec/blob/master/licenses/BSL-LunaTrace.txt
//
// See the License for the specific language governing permissions and
// limitations under the License.
//
package main

import (
Expand Down
3 changes: 1 addition & 2 deletions lunatrace/bsl/ingest-worker/pkg/awsfx/config.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// Copyright by LunaSec (owned by Refinery Labs, Inc)
//
// Licensed under the Business Source License v1.1
// Licensed under the Business Source License v1.1
// (the "License"); you may not use this file except in compliance with the
// License. You may obtain a copy of the License at
//
// https://github.com/lunasec-io/lunasec/blob/master/licenses/BSL-LunaTrace.txt
//
// See the License for the specific language governing permissions and
// limitations under the License.
//
package awsfx

import (
Expand Down
3 changes: 1 addition & 2 deletions lunatrace/bsl/ingest-worker/pkg/awsfx/module.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// Copyright by LunaSec (owned by Refinery Labs, Inc)
//
// Licensed under the Business Source License v1.1
// Licensed under the Business Source License v1.1
// (the "License"); you may not use this file except in compliance with the
// License. You may obtain a copy of the License at
//
// https://github.com/lunasec-io/lunasec/blob/master/licenses/BSL-LunaTrace.txt
//
// See the License for the specific language governing permissions and
// limitations under the License.
//
package awsfx

import "go.uber.org/fx"
Expand Down
1 change: 0 additions & 1 deletion lunatrace/bsl/ingest-worker/pkg/awsfx/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
//
// See the License for the specific language governing permissions and
// limitations under the License.
//
package awsfx

import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
//
// See the License for the specific language governing permissions and
// limitations under the License.
//
package ingestworker

import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
//
// See the License for the specific language governing permissions and
// limitations under the License.
//
package queuehandler

import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// Copyright by LunaSec (owned by Refinery Labs, Inc)
//
// Licensed under the Business Source License v1.1
// Licensed under the Business Source License v1.1
// (the "License"); you may not use this file except in compliance with the
// License. You may obtain a copy of the License at
//
// https://github.com/lunasec-io/lunasec/blob/master/licenses/BSL-LunaTrace.txt
//
// See the License for the specific language governing permissions and
// limitations under the License.
//
package registryproxy

import (
Expand Down
3 changes: 1 addition & 2 deletions lunatrace/bsl/ingest-worker/pkg/cwe/fetch.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// Copyright by LunaSec (owned by Refinery Labs, Inc)
//
// Licensed under the Business Source License v1.1
// Licensed under the Business Source License v1.1
// (the "License"); you may not use this file except in compliance with the
// License. You may obtain a copy of the License at
//
// https://github.com/lunasec-io/lunasec/blob/master/licenses/BSL-LunaTrace.txt
//
// See the License for the specific language governing permissions and
// limitations under the License.
//
package cwe

import (
Expand Down
3 changes: 1 addition & 2 deletions lunatrace/bsl/ingest-worker/pkg/cwe/fetch_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// Copyright by LunaSec (owned by Refinery Labs, Inc)
//
// Licensed under the Business Source License v1.1
// Licensed under the Business Source License v1.1
// (the "License"); you may not use this file except in compliance with the
// License. You may obtain a copy of the License at
//
// https://github.com/lunasec-io/lunasec/blob/master/licenses/BSL-LunaTrace.txt
//
// See the License for the specific language governing permissions and
// limitations under the License.
//
package cwe

import (
Expand Down