admin: Able to import Cyberrange teams from interface
This commit is contained in:
parent
f1ada8ce99
commit
485e6b0173
4 changed files with 64 additions and 8 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
|
|
@ -320,8 +321,21 @@ func allAssociations(c *gin.Context) {
|
|||
}
|
||||
|
||||
func importTeamsFromCyberrange(c *gin.Context) {
|
||||
file, err := c.FormFile("file")
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errmsg": "Failed to get file: " + err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
src, err := file.Open()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errmsg": "Failed to open file: " + err.Error()})
|
||||
return
|
||||
}
|
||||
defer src.Close()
|
||||
|
||||
var ut []fic.CyberrangeTeam
|
||||
err := c.ShouldBindJSON(&fic.CyberrangeAPIResponse{Data: &ut})
|
||||
err = json.NewDecoder(src).Decode(&fic.CyberrangeAPIResponse{Data: &ut})
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": err.Error()})
|
||||
return
|
||||
|
|
|
|||
Reference in a new issue