Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions get_vuln.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"github.com/google/go-github/v57/github"
"log"
// don't need cryptographically secure random here
// nosemgrep: go.lang.security.audit.crypto.math_random.math-random-used
"math/rand/v2"
"os"
"path/filepath"
Expand Down
25 changes: 16 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import (
"github.com/joho/godotenv"
"golang.org/x/oauth2"
"log"
"math/rand"
// don't need cryptographically secure random here
// nosemgrep: go.lang.security.audit.crypto.math_random.math-random-used
"math/rand/v2"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -43,7 +45,7 @@ func main() {

_, pythonPackage, pythonVersion := getPythonVuln(githubPersonalAccessToken)

bugId := strconv.Itoa(rand.Intn(3000))
bugId := strconv.Itoa(rand.IntN(3000))

if commitMsg == "<auto>" {
commitMsg = generateCommit("Generate a short, complete commit message for a Git commit fixing a specific bug with bug ID" + bugId)
Expand Down Expand Up @@ -79,7 +81,14 @@ func main() {
return
}
}

// ensure cleanup of repo folder
defer func() {
dirRemovalErr := os.RemoveAll("./terragoat")
if dirRemovalErr != nil {
log.Fatal(err)
}
fmt.Printf("Successfully removed directory.\n")
}()
// Create and checkout new branch
w, err := repo.Worktree()
if err != nil {
Expand All @@ -102,6 +111,10 @@ func main() {
exampleFile := "./terragoat/example2.tf"
fmt.Printf("Creating file: %s\n", exampleFile)
content, err := os.ReadFile("new_resource.tf")
if err != nil {
fmt.Printf("Error opening file: %s\n", err)
return
}
err = os.WriteFile(exampleFile, content, 0644)
if err != nil {
fmt.Printf("Error creating file: %s\n", err)
Expand Down Expand Up @@ -173,12 +186,6 @@ func main() {

fmt.Printf("Successfully created PR #%d\n", pr.GetNumber())
fmt.Printf("PR URL: %s\n", pr.GetHTMLURL())

dirRemovalErr := os.RemoveAll("./terragoat")
if dirRemovalErr != nil {
log.Fatal(err)
}
fmt.Printf("Successfully removed directory.\n")
}

func GetCode(branchPrefix string, repoURL string, githubPersonalAccessToken string) (string, *git.Repository, *http.BasicAuth, error) {
Expand Down
Loading