-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
102 lines (76 loc) · 2.44 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package main
import (
"fmt"
"time"
"github.com/akseltroan/openkoth/api"
"github.com/akseltroan/openkoth/dockerapi"
"github.com/gin-gonic/gin"
)
func testDocker() {
fmt.Print("Testing docker api...")
i := 0
for i < 3 {
// close the database connection
//defer db.Close()
netID := dockerapi.CreateNetwork("vulnNet2")
time.Sleep(10 * time.Second)
dockerapi.InspectNetwork("vulnNet2")
// create a new container and return the container ID
container, err := dockerapi.CreateNewContainer("nginx")
if err != nil {
panic(err)
}
time.Sleep(10 * time.Second)
dockerapi.ListAllContainers()
dockerapi.LogsSpecificContainer(container.ID)
// StopAllContainers()
// ListAllImages()
// Pull an image from DockerHub
// PullImage("hello-world")
// Get the states of all containers in the docker environment
// GetAllContainerState()
dockerapi.GetContainerState(container.ID)
dockerapi.ConnectContainerToNetwork(container.ID, netID)
time.Sleep(10 * time.Second)
dockerapi.GetContainerIPAddress(container.ID)
dockerapi.StopContainer(container.ID)
time.Sleep(10 * time.Second)
dockerapi.RemoveNetwork(netID)
i++
}
}
// main function
func main() {
// Create a router without any middleware by default
// connect to mysql
//db, err := connect_db()
//if err != nil {
// panic(err)
//}
router := gin.New()
// Global middleware
// Logger middleware will write the logs to gin.DefaultWriter even if you set with GIN_MODE=release.
// By default gin.DefaultWriter = os.Stdout
router.Use(gin.Logger())
// Recovery middleware recovers from any panics and writes a 500 if there was one.
router.Use(gin.Recovery())
// Users
router.GET("/users", api.GetUsers)
router.GET("/users/:id", api.GetUserByID)
router.POST("/users", api.PostUsers)
router.PUT("/users/:id", api.PutUser)
router.DELETE("/users/:id", api.DeleteUser)
// Rooms
router.GET("/rooms", api.GetRooms)
router.GET("/rooms/:id", api.GetRoomByID)
router.POST("/rooms", api.PostRooms)
router.PUT("/rooms/:id", api.PutRoom)
router.DELETE("/rooms/:id", api.DeleteRoom)
router.POST("/rooms/:id/vulnMachine", api.AddVulnMachine)
router.GET("/rooms/:id/king", api.GetKing)
router.PUT("/rooms/:id/king", api.PutKing)
router.Run("localhost:8080") // Initialize a goroutine
// tmp, test docker functionalities
//go router.Run("localhost:8080")
//testDocker()
}