This commit is contained in:
@@ -31,8 +31,6 @@ type ListSecret struct {
|
|||||||
|
|
||||||
func RetrieveSecret(c *gin.Context) {
|
func RetrieveSecret(c *gin.Context) {
|
||||||
var input RetrieveInput
|
var input RetrieveInput
|
||||||
//var results []models.Secret
|
|
||||||
//var userIsAdmin bool = false
|
|
||||||
|
|
||||||
// Validate the input matches our struct
|
// Validate the input matches our struct
|
||||||
if err := c.ShouldBindJSON(&input); err != nil {
|
if err := c.ShouldBindJSON(&input); err != nil {
|
||||||
@@ -41,15 +39,6 @@ func RetrieveSecret(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
log.Printf("RetrieveSecret received JSON input '%v'\n", input)
|
log.Printf("RetrieveSecret received JSON input '%v'\n", input)
|
||||||
|
|
||||||
/*
|
|
||||||
// Get the user and role id of the requestor
|
|
||||||
u, err := models.UserGetRoleFromToken(c)
|
|
||||||
if err != nil {
|
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Populate fields
|
// Populate fields
|
||||||
s := models.Secret{}
|
s := models.Secret{}
|
||||||
s.DeviceName = input.DeviceName
|
s.DeviceName = input.DeviceName
|
||||||
@@ -161,36 +150,13 @@ func retrieveSpecifiedSecret(s *models.Secret, c *gin.Context) {
|
|||||||
UserId: UserId,
|
UserId: UserId,
|
||||||
SecretId: results[i].SecretId,
|
SecretId: results[i].SecretId,
|
||||||
IpAddress: c.ClientIP(),
|
IpAddress: c.ClientIP(),
|
||||||
EventText: fmt.Sprintf("User %s retrieved SecretId %d", safeList[0].User.UserName, results[i].SecretId),
|
EventText: fmt.Sprintf("User '%s' retrieved SecretId %d", safeList[0].User.UserName, results[i].SecretId),
|
||||||
}
|
}
|
||||||
a.AuditLogAdd()
|
a.AuditLogAdd()
|
||||||
}
|
}
|
||||||
|
|
||||||
// output results as json
|
// output results as json
|
||||||
c.JSON(http.StatusOK, gin.H{"message": "success", "data": results, "count": len(results)})
|
c.JSON(http.StatusOK, gin.H{"message": "success", "data": results, "count": len(results)})
|
||||||
|
|
||||||
/*
|
|
||||||
if len(results) == 1 {
|
|
||||||
|
|
||||||
// Create audit record
|
|
||||||
a := models.Audit{
|
|
||||||
UserId: UserId,
|
|
||||||
SecretId: results[0].SecretId,
|
|
||||||
IpAddress: c.ClientIP(),
|
|
||||||
EventText: fmt.Sprintf("Retrieved Secret Id %d", results[0].SecretId),
|
|
||||||
}
|
|
||||||
a.AuditLogAdd()
|
|
||||||
|
|
||||||
// output results as json
|
|
||||||
c.JSON(http.StatusOK, gin.H{"message": "success", "data": results})
|
|
||||||
} else if len(results) > 1 {
|
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": "found multiple matching secrets"})
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": "found no matching secrets"})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ListSecrets(c *gin.Context) {
|
func ListSecrets(c *gin.Context) {
|
||||||
@@ -233,47 +199,3 @@ func ListSecrets(c *gin.Context) {
|
|||||||
c.JSON(http.StatusOK, gin.H{"message": "success", "data": output})
|
c.JSON(http.StatusOK, gin.H{"message": "success", "data": output})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func RetrieveMultpleSecrets(c *gin.Context) {
|
|
||||||
// TODO implement with new schema
|
|
||||||
/*
|
|
||||||
var input RetrieveInput
|
|
||||||
|
|
||||||
// Validate the input matches our struct
|
|
||||||
if err := c.ShouldBindJSON(&input); err != nil {
|
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
log.Printf("StoreSecret received JSON input '%v'\n", input)
|
|
||||||
|
|
||||||
// Get the user and role id of the requestor
|
|
||||||
user_id, err := token.ExtractTokenID(c)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
u, err := models.GetUserRoleByID(user_id)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Populate fields
|
|
||||||
s := models.Secret{}
|
|
||||||
s.RoleId = u.RoleId
|
|
||||||
s.DeviceName = input.DeviceName
|
|
||||||
s.DeviceCategory = input.DeviceCategory
|
|
||||||
|
|
||||||
results, err := models.GetSecrets(&s, false)
|
|
||||||
if err != nil {
|
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// output results as json
|
|
||||||
c.JSON(http.StatusOK, gin.H{"message": "success", "data": results})
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
1
main.go
1
main.go
@@ -282,7 +282,6 @@ func main() {
|
|||||||
secretRoutes.POST("/retrieve", controllers.RetrieveSecret) // TODO deprecate, replace retrieve with get
|
secretRoutes.POST("/retrieve", controllers.RetrieveSecret) // TODO deprecate, replace retrieve with get
|
||||||
secretRoutes.POST("/get", controllers.RetrieveSecret)
|
secretRoutes.POST("/get", controllers.RetrieveSecret)
|
||||||
secretRoutes.GET("/list", controllers.ListSecrets)
|
secretRoutes.GET("/list", controllers.ListSecrets)
|
||||||
//secretRoutes.POST("/retrieveMultiple", controllers.RetrieveMultpleSecrets) // TODO is this still required?
|
|
||||||
secretRoutes.POST("/store", controllers.StoreSecret) // TODO deprecate, replace store with add
|
secretRoutes.POST("/store", controllers.StoreSecret) // TODO deprecate, replace store with add
|
||||||
secretRoutes.POST("/add", controllers.StoreSecret)
|
secretRoutes.POST("/add", controllers.StoreSecret)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user