From 91fc03c0a16ecfea8306fdad91a8ddac58d6c0c0 Mon Sep 17 00:00:00 2001 From: "Antonino Sabetta (i064196)" Date: Fri, 2 Oct 2020 09:23:18 +0200 Subject: [PATCH] feat: Added new 'reconcile' command (skeleton only) --- Makefile | 6 ++++ go.sum | 1 + kaybee/cmd/reconcile.go | 37 ++++++++++++++++++++++++ kaybee/internal/tasks/reconcile.go | 45 ++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+) create mode 100644 kaybee/cmd/reconcile.go create mode 100644 kaybee/internal/tasks/reconcile.go diff --git a/Makefile b/Makefile index f15e70a9c..0a62442f0 100644 --- a/Makefile +++ b/Makefile @@ -29,6 +29,12 @@ all: $(SUBDIRS) build-docs $(SUBDIRS): $(MAKE) -C $@ +build: + $(MAKE) --directory=kaybee build + +test: + $(MAKE) --directory=kaybee test + deploy-docs: mkdocs gh-deploy diff --git a/go.sum b/go.sum index c43f9d62c..4d6bd63d0 100644 --- a/go.sum +++ b/go.sum @@ -421,6 +421,7 @@ google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRn google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= +google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a h1:Ob5/580gVHBJZgXnff1cZDbG+xLtMVE5mDRTe+nIsX4= google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= diff --git a/kaybee/cmd/reconcile.go b/kaybee/cmd/reconcile.go new file mode 100644 index 000000000..0ba14d45a --- /dev/null +++ b/kaybee/cmd/reconcile.go @@ -0,0 +1,37 @@ +/* +Copyright © 2020 SAP +*/ + +package cmd + +import ( + "github.com/sap/project-kb/kaybee/internal/tasks" + "github.com/spf13/cobra" +) + +// var vulnerabilityID string + +// reconcileCmd represents the reconcile command +var reconcileCmd = &cobra.Command{ + Use: "reconcile", + Short: "Manually reconcile conflicting statements", + Long: ``, + Run: doReconcile, +} + +func init() { + rootCmd.AddCommand(reconcileCmd) + // reconcileCmd.Flags().StringVarP(&vulnerabilityID, "reconcile", "r", "", "Vulnerability to reconcile") +} + +func doReconcile(cmd *cobra.Command, args []string) { + var vulnerabilityID string = args[0] + + t := tasks.ReconcileTask{ + Sources: configuration.Sources(), + VulnerabilityID: vulnerabilityID, + } + + t.Verbose(verbose) + t.Execute() +} diff --git a/kaybee/internal/tasks/reconcile.go b/kaybee/internal/tasks/reconcile.go new file mode 100644 index 000000000..7e3da7376 --- /dev/null +++ b/kaybee/internal/tasks/reconcile.go @@ -0,0 +1,45 @@ +package tasks + +import ( + "fmt" + + "github.com/sap/project-kb/kaybee/internal/conf" +) + +// ReconcileTask is the task that performs merging of statements, reconciling any +// conflicts using a set of pre-defined policies. +type ReconcileTask struct { + BaseTask + Sources []conf.Source + VulnerabilityID string +} + +// NewReconcileTask constructs a new ReconcileTask +func NewReconcileTask() (mergeTask *ReconcileTask) { + + mt := ReconcileTask{} + return &mt +} + +func (t *ReconcileTask) validate() (ok bool) { + + return true +} + +// Execute performs the actual task and returns true on success +func (t *ReconcileTask) Execute() (success bool) { + + if t.verbose { + fmt.Println("Reconciling statements for vulnerability ID: " + t.VulnerabilityID) + fmt.Println("Using sources:") + for _, s := range t.Sources { + fmt.Println(s) + } + } + + t.validate() + + fmt.Println("WARNING: Reconcile task not implemented yet!") + + return true +}