Skip to content

Commit

Permalink
system reports
Browse files Browse the repository at this point in the history
Signed-off-by: Amir Malka <amirm@armosec.io>
  • Loading branch information
amirmalka committed Aug 24, 2023
1 parent ca176fe commit 753df32
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
14 changes: 7 additions & 7 deletions adapters/v1/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ import (
cs "github.com/armosec/armoapi-go/containerscan"
v1 "github.com/armosec/armoapi-go/containerscan/v1"
"github.com/armosec/armoapi-go/identifiers"
sysreport "github.com/armosec/logger-go/system-reports/datastructures"
"github.com/armosec/utils-go/httputils"
pkgcautils "github.com/armosec/utils-k8s-go/armometadata"
wlidpkg "github.com/armosec/utils-k8s-go/wlid"
"github.com/hashicorp/go-multierror"
backendClientV1 "github.com/kubescape/backend/pkg/client/v1"
sysreportClient "github.com/kubescape/backend/pkg/client/v1"
sysreport "github.com/kubescape/backend/pkg/server/v1/systemreports"
"github.com/kubescape/kubevuln/core/domain"
"github.com/kubescape/kubevuln/core/ports"
"go.opentelemetry.io/otel"
Expand All @@ -27,7 +28,7 @@ type BackendAdapter struct {
clusterConfig pkgcautils.ClusterConfig
getCVEExceptionsFunc func(string, string, *identifiers.PortalDesignator) ([]armotypes.VulnerabilityExceptionPolicy, error)
httpPostFunc func(httputils.IHttpClient, string, map[string]string, []byte) (*http.Response, error)
sendStatusFunc func(*sysreport.BaseReport, string, bool, chan<- error)
sendStatusFunc func(*sysreportClient.BaseReportSender, string, bool, chan<- error)
}

var _ ports.Platform = (*BackendAdapter)(nil)
Expand All @@ -41,8 +42,8 @@ func NewBackendAdapter(accountID, apiServerRestURL, eventReceiverRestURL string)
},
getCVEExceptionsFunc: backendClientV1.GetCVEExceptionByDesignator,
httpPostFunc: httputils.HttpPost,
sendStatusFunc: func(report *sysreport.BaseReport, status string, sendReport bool, errChan chan<- error) {
report.SendStatus(status, sendReport, errChan) // TODO - update this function to use from kubescape/backend
sendStatusFunc: func(sender *sysreportClient.BaseReportSender, status string, sendReport bool, errChan chan<- error) {
sender.SendStatus(status, sendReport, errChan) // TODO - update this function to use from kubescape/backend
},
}
}
Expand Down Expand Up @@ -107,8 +108,6 @@ func (a *BackendAdapter) SendStatus(ctx context.Context, step int) error {
report := sysreport.NewBaseReport(
a.clusterConfig.AccountID,
ReporterName,
a.clusterConfig.EventReceiverRestURL,
&http.Client{},
)
report.Status = statuses[step]
report.Target = fmt.Sprintf("vuln scan:: scanning wlid: %v , container: %v imageTag: %v imageHash: %s",
Expand All @@ -121,7 +120,8 @@ func (a *BackendAdapter) SendStatus(ctx context.Context, step int) error {
report.Details = details[step]

ReportErrorsChan := make(chan error)
a.sendStatusFunc(report, sysreport.JobSuccess, true, ReportErrorsChan)
sender := sysreportClient.NewBaseReportSender(a.clusterConfig.EventReceiverRestURL, &http.Client{}, report)
a.sendStatusFunc(sender, sysreport.JobSuccess, true, ReportErrorsChan)
err := <-ReportErrorsChan
return err
}
Expand Down
7 changes: 4 additions & 3 deletions adapters/v1/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import (
"github.com/armosec/armoapi-go/armotypes"
v1 "github.com/armosec/armoapi-go/containerscan/v1"
"github.com/armosec/armoapi-go/identifiers"
sysreport "github.com/armosec/logger-go/system-reports/datastructures"
"github.com/armosec/utils-go/httputils"
"github.com/armosec/utils-k8s-go/armometadata"
"github.com/google/uuid"
"github.com/kinbiko/jsonassert"
sysreportClient "github.com/kubescape/backend/pkg/client/v1"
sysreport "github.com/kubescape/backend/pkg/server/v1/systemreports"
"github.com/kubescape/kubevuln/core/domain"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -247,8 +248,8 @@ func TestBackendAdapter_SendStatus(t *testing.T) {
for _, tt := range tests { //nolint:govet
t.Run(tt.name, func(t *testing.T) {
a := &BackendAdapter{
sendStatusFunc: func(report *sysreport.BaseReport, s string, b bool, c chan<- error) {
assert.NotEqual(t, *report, tt.report) //nolint:govet
sendStatusFunc: func(sender *sysreportClient.BaseReportSender, s string, b bool, c chan<- error) {
assert.NotEqual(t, *sender.GetReport(), tt.report) //nolint:govet
close(c)
},
}
Expand Down
8 changes: 7 additions & 1 deletion adapters/v1/backend_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ func (a *BackendAdapter) postResults(ctx context.Context, report *v1.ScanResultR
return
}

urlBase := beClient.GetVulnerabilitiesReportURL(eventReceiverURL, report.Designators.Attributes[identifiers.AttributeCustomerGUID])
urlBase, err := beClient.GetVulnerabilitiesReportURL(eventReceiverURL, report.Designators.Attributes[identifiers.AttributeCustomerGUID])
if err != nil {
logger.L().Ctx(ctx).Error("failed to get vulnerabilities report url", helpers.Error(err),
helpers.String("wlid", wlid))
errorChan <- err
return
}
resp, err := a.httpPostFunc(http.DefaultClient, urlBase.String(), map[string]string{"Content-Type": "application/json"}, payload)
if err != nil {
logger.L().Ctx(ctx).Error("failed posting to event", helpers.Error(err),
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
github.com/anchore/syft v0.76.0
github.com/aquilax/truncate v1.0.0
github.com/armosec/armoapi-go v0.0.220
github.com/armosec/logger-go v0.0.14
github.com/armosec/utils-go v0.0.20
github.com/armosec/utils-k8s-go v0.0.17
github.com/distribution/distribution v2.8.2+incompatible
Expand All @@ -22,7 +21,7 @@ require (
github.com/google/uuid v1.3.0
github.com/hashicorp/go-multierror v1.1.1
github.com/kinbiko/jsonassert v1.1.1
github.com/kubescape/backend v0.0.0-20230823064127-e914c64f4aba
github.com/kubescape/backend v0.0.0-20230824164030-dba6312a2632
github.com/kubescape/go-logger v0.0.14-0.20230730134225-e59751254525
github.com/kubescape/k8s-interface v0.0.135-0.20230730135750-e6e709507847
github.com/kubescape/storage v0.0.16
Expand Down Expand Up @@ -130,7 +129,6 @@ require (
github.com/goccy/go-json v0.10.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/glog v1.1.1 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
Expand Down
7 changes: 2 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,6 @@ github.com/armosec/armoapi-go v0.0.220 h1:gfg2UmcFgcyStjp5ZXfwE8yb0H43eaRX9H/Kkq
github.com/armosec/armoapi-go v0.0.220/go.mod h1:Y1ZcqPUTQ+F8JiQzErrToK5ULrPvClxZoshHmV9PIlU=
github.com/armosec/gojay v1.2.15 h1:sSB2vnAvacUNkw9nzUYZKcPzhJOyk6/5LK2JCNdmoZY=
github.com/armosec/gojay v1.2.15/go.mod h1:vzVAaay2TWJAngOpxu8aqLbye9jMgoKleuAOK+xsOts=
github.com/armosec/logger-go v0.0.14 h1:5YpXMlYt/7zIAcmJP4q1BmWNH/7bpkSndfZTyysrtUE=
github.com/armosec/logger-go v0.0.14/go.mod h1:OKV/cBcEjNv/T62vd1cnD2lf07POPSpy3PQkURfoCeI=
github.com/armosec/utils-go v0.0.20 h1:bvr+TMumEYdMsGFGSsaQysST7K02nNROFvuajNuKPlw=
github.com/armosec/utils-go v0.0.20/go.mod h1:ZEFiSv8KpTFNT19jHis1IengiF/BGDvg7tHmXo+cwxs=
github.com/armosec/utils-k8s-go v0.0.17 h1:HUntJGR0/PHt7bp8S0zLhVcJ6sDz061Hc9mAM9ha1lA=
Expand Down Expand Up @@ -524,7 +522,6 @@ github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4=
github.com/golang/glog v1.1.1 h1:jxpi2eWoU84wbX9iIEyAeeoac3FLuifZpY9tcNUD9kw=
github.com/golang/glog v1.1.1/go.mod h1:zR+okUeTbrL6EL3xHUDxZuEtGv04p5shwip1+mL/rLQ=
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
Expand Down Expand Up @@ -764,8 +761,8 @@ github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kubescape/backend v0.0.0-20230823064127-e914c64f4aba h1:SMrex81D7x42fMYVdRNqXK4SzJggdozHv/GC1fMOO+E=
github.com/kubescape/backend v0.0.0-20230823064127-e914c64f4aba/go.mod h1:V3ohHdCYWZmaPLNACQv+j7uVDm2jRDCjLsUk7FBfXbU=
github.com/kubescape/backend v0.0.0-20230824164030-dba6312a2632 h1:46anzK6eoZbmQe7WkSO3CHWRiNic0ya2lzgSdOw3cmI=
github.com/kubescape/backend v0.0.0-20230824164030-dba6312a2632/go.mod h1:rEkxLNQdOGQNKAZekZBn0z/r8FIymBRSmwLFqkUenAQ=
github.com/kubescape/go-logger v0.0.14-0.20230730134225-e59751254525 h1:9wzR38LebiA58cGxRBnsF78k4eJGnk7UetoTPKkyz2A=
github.com/kubescape/go-logger v0.0.14-0.20230730134225-e59751254525/go.mod h1:Al+yTE+vemECb/Myn2G9+2o2uFmMtphbkQmxf4OEHxE=
github.com/kubescape/k8s-interface v0.0.135-0.20230730135750-e6e709507847 h1:GGuS6pE6KGa5q7j9fkRN3p1eQw16/jLUMnPR8FT3O6M=
Expand Down

0 comments on commit 753df32

Please sign in to comment.