-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b185e91
commit c3484ee
Showing
7 changed files
with
184 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package api | ||
|
||
import "time" | ||
|
||
type Uptime struct { | ||
Since time.Time `json:"since"` | ||
Milliseconds uint64 `json:"milliseconds"` | ||
} | ||
|
||
type Status struct { | ||
Version string `json:"version"` | ||
Runtime string `json:"runtime"` | ||
Mode string `json:"mode"` | ||
Time time.Time `json:"time"` | ||
Uptime Uptime `json:"uptime"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package status | ||
|
||
import ( | ||
"net/http" | ||
"runtime" | ||
"soarca/models/api" | ||
"soarca/utils" | ||
"time" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
var status = api.Status{Uptime: api.Uptime{Since: time.Now(), Milliseconds: 0}, | ||
Mode: utils.GetEnv("LOG_MODE", "production"), | ||
Runtime: runtime.GOOS} | ||
|
||
func SetVersion(version string) { | ||
status.Version = version | ||
} | ||
|
||
// /Status GET handler for handling status api calls | ||
// Returns the status model object for SOARCA | ||
// | ||
// @Summary gets the SOARCA status | ||
// @Schemes | ||
// @Description return SOARCA status | ||
// @Tags status | ||
// @Produce json | ||
// @success 200 {object} api.Status | ||
// @failure 400 {object} api.Error | ||
// @Router /status [GET] | ||
func Api(g *gin.Context) { | ||
|
||
status.Uptime.Milliseconds = uint64(time.Since(status.Uptime.Since).Milliseconds()) | ||
status.Time = time.Now() | ||
|
||
g.JSON(http.StatusOK, status) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,32 @@ | ||
package coa | ||
package status | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func Helloworld(g *gin.Context) { | ||
g.JSON(http.StatusOK, "helloworld from /status") | ||
} | ||
|
||
func id_tester(g *gin.Context) { | ||
// Get the value of the 'id' parameter from the URL | ||
id := g.Param("id") | ||
fmt.Println(id) | ||
// /Status/ping GET handler for handling status api calls | ||
// Returns the status model object for SOARCA | ||
// | ||
// @Summary ping to see if SOARCA is up returns pong | ||
// @Schemes | ||
// @Description return SOARCA status | ||
// @Tags ping pong | ||
// @Produce plain | ||
// @success 200 string pong | ||
// @Router /status/ping [GET] | ||
func Pong(g *gin.Context) { | ||
g.Data(http.StatusOK, "text/plain", []byte("pong")) | ||
} | ||
|
||
// GET /status | ||
// GET /status/playbook | ||
// GET /status/playbook/id | ||
// GET /status/coa/id | ||
// GET /status/history | ||
// GET /status/ping | ||
func Routes(route *gin.Engine) { | ||
coa := route.Group("/status") | ||
router := route.Group("/status") | ||
{ | ||
coa.GET("/", Helloworld) | ||
coa.GET("/playbook/:id", id_tester) | ||
coa.GET("/coa/:id", id_tester) | ||
coa.GET("/history", Helloworld) | ||
// workflow.POST() | ||
router.GET("/", Api) | ||
router.GET("/ping", Pong) | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters