admin: New route to import teams from CyberRange format
This commit is contained in:
parent
cb4ceecbf5
commit
b62369f89f
1 changed files with 49 additions and 0 deletions
|
@ -186,6 +186,9 @@ func declareTeamsRoutes(router *gin.RouterGroup) {
|
||||||
declareTeamsPasswordRoutes(apiTeamsRoutes)
|
declareTeamsPasswordRoutes(apiTeamsRoutes)
|
||||||
declareTeamClaimsRoutes(apiTeamsRoutes)
|
declareTeamClaimsRoutes(apiTeamsRoutes)
|
||||||
declareTeamCertificateRoutes(apiTeamsRoutes)
|
declareTeamCertificateRoutes(apiTeamsRoutes)
|
||||||
|
|
||||||
|
// Import teams from cyberrange
|
||||||
|
router.POST("/cyberrange-teams.json", importTeamsFromCyberrange)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TeamHandler(c *gin.Context) {
|
func TeamHandler(c *gin.Context) {
|
||||||
|
@ -317,6 +320,52 @@ func allAssociations(c *gin.Context) {
|
||||||
c.JSON(http.StatusOK, ret)
|
c.JSON(http.StatusOK, ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func importTeamsFromCyberrange(c *gin.Context) {
|
||||||
|
var ut []fic.CyberrangeTeam
|
||||||
|
err := c.ShouldBindJSON(&fic.CyberrangeAPIResponse{Data: &ut})
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
teams, err := fic.GetTeams()
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("Impossible de récupérer la liste des équipes actuelles: %s", err.Error())})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, crteam := range ut {
|
||||||
|
var exist_team *fic.Team
|
||||||
|
for _, team := range teams {
|
||||||
|
if team.Name == crteam.Name && team.ExternalId == crteam.UUID {
|
||||||
|
exist_team = team
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if exist_team != nil {
|
||||||
|
exist_team.Name = crteam.Name
|
||||||
|
exist_team.ExternalId = crteam.UUID
|
||||||
|
_, err = exist_team.Update()
|
||||||
|
} else {
|
||||||
|
_, err = fic.CreateTeam(crteam.Name, 0, crteam.UUID)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("Impossible d'ajouter/de modifier l'équipe %v: %s", crteam, err.Error())})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
teams, err = fic.GetTeams()
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("Impossible de récupérer la liste des équipes après import: %s", err.Error())})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, teams)
|
||||||
|
}
|
||||||
|
|
||||||
func createTeam(c *gin.Context) {
|
func createTeam(c *gin.Context) {
|
||||||
var ut fic.Team
|
var ut fic.Team
|
||||||
err := c.ShouldBindJSON(&ut)
|
err := c.ShouldBindJSON(&ut)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue