Skip to content

Commit

Permalink
feat: Added new 'reconcile' command (skeleton only)
Browse files Browse the repository at this point in the history
  • Loading branch information
copernico committed Oct 2, 2020
1 parent 5634e46 commit 91fc03c
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
37 changes: 37 additions & 0 deletions kaybee/cmd/reconcile.go
Original file line number Diff line number Diff line change
@@ -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()
}
45 changes: 45 additions & 0 deletions kaybee/internal/tasks/reconcile.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 91fc03c

Please sign in to comment.