Skip to content

Commit

Permalink
config: updates the config related changes in schemas, CRUD and logic (
Browse files Browse the repository at this point in the history
…#101)

* updates the config related changes in schemas and logic

* updates schema and adds table for scanNotify

* adds simple CRUD for scannotify

* modularize the notifier for systems like linear, jirs etc

* adds logic of notifier who would poll evaluate the conditions and create issues

* comments unwanted struct for now until thought better
  • Loading branch information
ashwiniag authored Jan 8, 2025
1 parent 5d99d5e commit 01a1028
Show file tree
Hide file tree
Showing 54 changed files with 4,244 additions and 381 deletions.
8 changes: 7 additions & 1 deletion cmd/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,13 @@ func processTask(server, token string, task agenttasks.GetAgentTaskResponse, wor
return
}

// step 6: Verify scans.Notify field exist
// Todo: if exists update the status to notify_pending else complete
err = updateScanStatus(server, token, scan.ID, "notify_pending")
if err != nil {
log.Printf("Failed to update scan status to 'scan_in_progress': %v", err)
}

if err := updateAgentTaskStatus(server, token, task.ID, agentID, "complete"); err != nil {
log.Printf("Failed to update agent_task status to 'complete': %v", err)
}
Expand Down Expand Up @@ -356,7 +363,6 @@ func uploadReport(server, token string, scanID uuid.UUID, reportPath string) err
reqBody := scans.UpdateScanRequest{
ID: scanID,
Report: json.RawMessage(report),
Status: strPtr("success"),
}
reqBodyJSON, err := json.Marshal(reqBody)
if err != nil {
Expand Down
13 changes: 7 additions & 6 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/shinobistack/gokakashi/internal/assigner"
"github.com/shinobistack/gokakashi/internal/db"
"github.com/shinobistack/gokakashi/internal/notifier"
"log"
"os"
"os/signal"
Expand Down Expand Up @@ -82,11 +83,9 @@ func handleConfigV1() {
if err != nil {
log.Fatalf("Error: %v", err)
}

// ToDo: To set a separate connection for API calls
// Initialize a separate connection for API calls
//apiDB := restapiv1.InitDB()
//defer apiDB.Close()
// Todo: To implement connection pooling. Explore and implement.
//dbClient := restapiv1.InitDB(cfg.Database)
//defer dbClient.Close()

log.Println("Starting API server for scan functionality...")
s := &restapiv1.Server{
Expand All @@ -98,16 +97,18 @@ func handleConfigV1() {
go s.Serve()

dbConfig := cfg.Database

// Initialize a separate connection for configuration tasks
configDB := restapiv1.InitDB(dbConfig)
defer configDB.Close()

db.RunMigrations(configDB)
// Populate the database
db.PopulateDatabase(configDB, cfg)

// ToDo: To be go routine who independently and routinely checks and assigns scans in agentTasks table
go assigner.StartAssigner(cfg.Site.Host, cfg.Site.Port, cfg.Site.APIToken, 1*time.Minute)
// Todo: To introduce API calls for scanNotify and remove client passing
go notifier.StartScanNotifier(cfg.Site.Host, cfg.Site.Port, cfg.Site.APIToken, 1*time.Minute)

}

Expand Down
181 changes: 177 additions & 4 deletions ent/client.go

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

2 changes: 2 additions & 0 deletions ent/ent.go

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

12 changes: 12 additions & 0 deletions ent/hook/hook.go

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

Loading

0 comments on commit 01a1028

Please sign in to comment.