Skip to content

Commit

Permalink
config, api: updates config format, adds CRUD endpoints for Integrati…
Browse files Browse the repository at this point in the history
…on management (#39)

* updates configurations and validation

* adds CRUD endpoints for Integration management

* updates structure to support backward compatibility for v0

* fix lints

* updates endpoint to adhere REST conventions

* fix golints

* adds openapi spec
  • Loading branch information
ashwiniag authored Dec 19, 2024
1 parent ba966ba commit 8d4a880
Show file tree
Hide file tree
Showing 41 changed files with 6,623 additions and 36 deletions.
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ var rootCmd = &cobra.Command{
Use: "gokakashi",
Short: "GoKakashi - The Container image vulnerability management platform",
Run: func(cmd *cobra.Command, args []string) {
// Display help if no subcommand is provided
_ = cmd.Help()
},
}

func init() {
rootCmd.AddCommand(versionCmd)

// To independently process its own configuration file path.
serverConfigFilePath = serverCmd.Flags().String("config", "", "Path to the config YAML file")
rootCmd.AddCommand(serverCmd)

Expand Down
43 changes: 35 additions & 8 deletions cmd/server.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package cmd

import (
"github.com/robfig/cron/v3"
config "github.com/shinobistack/gokakashi/internal/config/v0"
configv1 "github.com/shinobistack/gokakashi/internal/config/v1"
restapi "github.com/shinobistack/gokakashi/internal/restapi/v0"
restapiv1 "github.com/shinobistack/gokakashi/internal/restapi/v1"
"github.com/shinobistack/gokakashi/pkg/utils"
"github.com/shinobistack/gokakashi/pkg/web"
"github.com/spf13/cobra"
"log"
"os"
"os/signal"
"strings"
"syscall"
"time"

"github.com/robfig/cron/v3"
"github.com/shinobistack/gokakashi/internal/config/v0"
restapi "github.com/shinobistack/gokakashi/internal/restapi/server"
"github.com/shinobistack/gokakashi/pkg/utils"
"github.com/shinobistack/gokakashi/pkg/web"
"github.com/spf13/cobra"
)

var serverCmd = &cobra.Command{
Expand All @@ -26,11 +27,37 @@ var serverConfigFilePath *string

func runServer(cmd *cobra.Command, args []string) {
if *serverConfigFilePath != "" {
handleConfigV0()
handleConfigV1()
return
}
// ToDo: To introduce config version. A way to support old and latest config
handleConfigV0()
}

func handleConfigV1() {
log.Println("=== Starting goKakashi Tool ===")

// Load and validate the configuration file
cfg, err := configv1.LoadAndValidateConfig(*serverConfigFilePath)
if err != nil {
log.Fatalf("Error: %v", err)
}

log.Println("Starting API server for scan functionality...")
s := &restapiv1.Server{
AuthToken: cfg.Site.APIToken,
Websites: cfg.Site.Host,
Port: cfg.Site.Port,
}
go s.Serve()

// Graceful shutdown handling
shutdown := make(chan os.Signal, 1)
signal.Notify(shutdown, syscall.SIGINT, syscall.SIGTERM)
<-shutdown

log.Println("Shutting down goKakashi gracefully...")
}
func handleConfigV0() {
log.Println("=== Starting goKakashi Tool ===")

Expand Down
Loading

0 comments on commit 8d4a880

Please sign in to comment.