Skip to content

Commit

Permalink
func deployChallenge fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rizul2108 committed Dec 22, 2023
1 parent 1b66b95 commit 15bc421
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 8 deletions.
8 changes: 7 additions & 1 deletion cliHelpers/chalDeployerService/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@ func DeployChallenge() error {
challengeType := "web"
log.Println("Starting")

katanaDir, err := utils.GetKatanaRootPath()
if err != nil {
return err
}
challengesDir:=katanaDir+"/challenges"

//Read folder challenge by os
dir, err := os.Open("./challenges")
dir, err := os.Open(challengesDir)

//Loop over all subfolders in the challenge folder
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ func init() {
rootCmd.AddCommand(infraService.GitCmd)
rootCmd.AddCommand(infraService.CreateTeamCmd)
rootCmd.AddCommand(chalDeployerService.DelChalCmd)
rootCmd.AddCommand(chalDeployerService.DeployChalCmd)
}
2 changes: 1 addition & 1 deletion lib/wireguard/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func ApplyFirewall() error {
if err != nil {
log.Println(err)
}
filepath = filepath + "/katana-services/Wireguard/root/defaults/firewall.conf"
filepath = filepath + "/katana-services/wireguard/root/defaults/firewall.conf"
err = os.WriteFile(filepath, []byte(finalIprules), 0644)
if err != nil {
fmt.Println("Error writing to file:", err)
Expand Down
23 changes: 19 additions & 4 deletions services/challengedeployerservice/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@ func Deploy(c *fiber.Ctx) error {
challengeType := "web"
log.Println("Starting")

katanaDir, err := utils.GetKatanaRootPath()
if err != nil {
return err
}
challengesDir:=katanaDir+"/challenges"

//Read folder challenge by os
dir, err := os.Open("./challenges")
dir, err := os.Open(challengesDir)

//Loop over all subfolders in the challenge folder
if err != nil {
Expand Down Expand Up @@ -80,9 +86,18 @@ func Deploy(c *fiber.Ctx) error {
}
}
}
CopyChallengeIntoTsuka(challengePath, folderName, challengeType)
CopyFlagDataIntoKashira(challengePath, folderName)
CopyChallengeCheckerIntoKissaki(challengePath, folderName)
err = CopyChallengeIntoTsuka(challengePath, folderName, challengeType)
if err != nil {
return err
}
err = CopyChallengeIntoTsuka(challengePath, folderName, challengeType)
if err != nil {
return err
}
err = CopyChallengeIntoTsuka(challengePath, folderName, challengeType)
if err != nil {
return err
}
}
}
return c.JSON(res)
Expand Down
17 changes: 16 additions & 1 deletion services/challengedeployerservice/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"os"
"strconv"
"strings"

git "github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/config"
Expand All @@ -28,6 +29,18 @@ func CopyChallengeIntoTsuka(dirPath string, challengeName string, challengeType
err := os.Mkdir("teams/"+path, 0755)
if err != nil {
log.Println(err)
if (strings.Contains(err.Error(), "file exists")) {
err = os.RemoveAll("teams/" + path)
if err != nil {
log.Println(err)
}
err = os.Mkdir("teams/"+path, 0755)
if err != nil {
log.Println(err)
}
}else{
return err
}
}
git.PlainInit("teams/"+path, false)
repo, err := git.PlainOpen("teams/" + path)
Expand All @@ -45,7 +58,9 @@ func CopyChallengeIntoTsuka(dirPath string, challengeName string, challengeType

if err != nil {
log.Println(err)
return err
if (!strings.Contains(err.Error(), "remote already exists")) {
return err
}
}
podsInTeam, err := utils.GetPods(map[string]string{
"app": g.ClusterConfig.TeamLabel,
Expand Down
3 changes: 2 additions & 1 deletion services/master/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"

cfg "github.com/sdslabs/katana/configs"
challengeDeployerService "github.com/sdslabs/katana/services/challengedeployerservice"
infraSetService "github.com/sdslabs/katana/services/infrasetservice"
Expand Down Expand Up @@ -47,7 +48,7 @@ func Server() error {
admin.Get("/createTeams", infraSetService.CreateTeams)
admin.Post("/challengeUpdate", challengeDeployerService.ChallengeUpdate)
admin.Get("/deploy", challengeDeployerService.Deploy)
admin.Post("/deployChallenge", challengeDeployerService.DeployChallenge)
admin.Post("/deployChallenge", challengeDeployerService.Deploy)
admin.Get("/gitServer", infraSetService.GitServer)
admin.Get("/deleteChallenge/:chall_name", challengeDeployerService.DeleteChallenge)
log.Printf("Listening on %s:%d\n", cfg.APIConfig.Host, cfg.APIConfig.Port)
Expand Down

0 comments on commit 15bc421

Please sign in to comment.