Merge pull request #34 from rahonavis/2078-bindjson
#2078 - fix BindJSON calls
This commit is contained in:
commit
00a026c2a5
|
@ -46,7 +46,10 @@ func postServerPower(c *gin.Context) {
|
||||||
s := GetServer(c.Param("server"))
|
s := GetServer(c.Param("server"))
|
||||||
|
|
||||||
var data server.PowerAction
|
var data server.PowerAction
|
||||||
c.BindJSON(&data)
|
// BindJSON sends 400 if the request fails, all we need to do is return
|
||||||
|
if err := c.BindJSON(&data); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if !data.IsValid() {
|
if !data.IsValid() {
|
||||||
c.AbortWithStatusJSON(http.StatusUnprocessableEntity, gin.H{
|
c.AbortWithStatusJSON(http.StatusUnprocessableEntity, gin.H{
|
||||||
|
@ -98,8 +101,13 @@ func postServerCommands(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var data struct{ Commands []string `json:"commands"` }
|
var data struct {
|
||||||
c.BindJSON(&data)
|
Commands []string `json:"commands"`
|
||||||
|
}
|
||||||
|
// BindJSON sends 400 if the request fails, all we need to do is return
|
||||||
|
if err := c.BindJSON(&data); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
for _, command := range data.Commands {
|
for _, command := range data.Commands {
|
||||||
if err := s.Environment.SendCommand(command); err != nil {
|
if err := s.Environment.SendCommand(command); err != nil {
|
||||||
|
|
|
@ -15,7 +15,10 @@ func postServerBackup(c *gin.Context) {
|
||||||
s := GetServer(c.Param("server"))
|
s := GetServer(c.Param("server"))
|
||||||
|
|
||||||
data := &backup.Request{}
|
data := &backup.Request{}
|
||||||
c.BindJSON(&data)
|
// BindJSON sends 400 if the request fails, all we need to do is return
|
||||||
|
if err := c.BindJSON(&data); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var adapter backup.BackupInterface
|
var adapter backup.BackupInterface
|
||||||
var err error
|
var err error
|
||||||
|
@ -41,7 +44,6 @@ func postServerBackup(c *gin.Context) {
|
||||||
}
|
}
|
||||||
}(adapter, s)
|
}(adapter, s)
|
||||||
|
|
||||||
|
|
||||||
c.Status(http.StatusAccepted)
|
c.Status(http.StatusAccepted)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,10 @@ func putServerRenameFile(c *gin.Context) {
|
||||||
RenameFrom string `json:"rename_from"`
|
RenameFrom string `json:"rename_from"`
|
||||||
RenameTo string `json:"rename_to"`
|
RenameTo string `json:"rename_to"`
|
||||||
}
|
}
|
||||||
c.BindJSON(&data)
|
// BindJSON sends 400 if the request fails, all we need to do is return
|
||||||
|
if err := c.BindJSON(&data); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if data.RenameFrom == "" || data.RenameTo == "" {
|
if data.RenameFrom == "" || data.RenameTo == "" {
|
||||||
c.AbortWithStatusJSON(http.StatusUnprocessableEntity, gin.H{
|
c.AbortWithStatusJSON(http.StatusUnprocessableEntity, gin.H{
|
||||||
|
@ -113,7 +116,10 @@ func postServerCopyFile(c *gin.Context) {
|
||||||
var data struct {
|
var data struct {
|
||||||
Location string `json:"location"`
|
Location string `json:"location"`
|
||||||
}
|
}
|
||||||
c.BindJSON(&data)
|
// BindJSON sends 400 if the request fails, all we need to do is return
|
||||||
|
if err := c.BindJSON(&data); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if err := s.Filesystem.Copy(data.Location); err != nil {
|
if err := s.Filesystem.Copy(data.Location); err != nil {
|
||||||
TrackedServerError(err, s).AbortWithServerError(c)
|
TrackedServerError(err, s).AbortWithServerError(c)
|
||||||
|
@ -130,7 +136,10 @@ func postServerDeleteFile(c *gin.Context) {
|
||||||
var data struct {
|
var data struct {
|
||||||
Location string `json:"location"`
|
Location string `json:"location"`
|
||||||
}
|
}
|
||||||
c.BindJSON(&data)
|
// BindJSON sends 400 if the request fails, all we need to do is return
|
||||||
|
if err := c.BindJSON(&data); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if err := s.Filesystem.Delete(data.Location); err != nil {
|
if err := s.Filesystem.Delete(data.Location); err != nil {
|
||||||
TrackedServerError(err, s).AbortWithServerError(c)
|
TrackedServerError(err, s).AbortWithServerError(c)
|
||||||
|
@ -167,7 +176,10 @@ func postServerCreateDirectory(c *gin.Context) {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Path string `json:"path"`
|
Path string `json:"path"`
|
||||||
}
|
}
|
||||||
c.BindJSON(&data)
|
// BindJSON sends 400 if the request fails, all we need to do is return
|
||||||
|
if err := c.BindJSON(&data); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if err := s.Filesystem.CreateDirectory(data.Name, data.Path); err != nil {
|
if err := s.Filesystem.CreateDirectory(data.Name, data.Path); err != nil {
|
||||||
TrackedServerError(err, s).AbortWithServerError(c)
|
TrackedServerError(err, s).AbortWithServerError(c)
|
||||||
|
|
|
@ -77,7 +77,10 @@ func postUpdateConfiguration(c *gin.Context) {
|
||||||
// A copy of the configuration we're using to bind the data recevied into.
|
// A copy of the configuration we're using to bind the data recevied into.
|
||||||
cfg := *config.Get()
|
cfg := *config.Get()
|
||||||
|
|
||||||
c.BindJSON(&cfg)
|
// BindJSON sends 400 if the request fails, all we need to do is return
|
||||||
|
if err := c.BindJSON(&cfg); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
config.Set(&cfg)
|
config.Set(&cfg)
|
||||||
if err := config.Get().WriteToDisk(); err != nil {
|
if err := config.Get().WriteToDisk(); err != nil {
|
||||||
|
@ -90,4 +93,4 @@ func postUpdateConfiguration(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Status(http.StatusNoContent)
|
c.Status(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user