69 lines
1.6 KiB
Go
69 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
const (
|
|
uriSecretData = "/:secret/data/:path"
|
|
uriSecretMetadata = "/:secret/metadata/:path"
|
|
)
|
|
|
|
func setupVaultApi(router fiber.Router) {
|
|
// https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v2
|
|
|
|
/* read secret */
|
|
router.Get(uriSecretData, fiberOk, func(c *fiber.Ctx) error {
|
|
/*
|
|
ver_s := c.Query("version")
|
|
if ver_s != "" {
|
|
ver, err := strconv.ParseInt(ver_s, 10, 0)
|
|
if err != nil {
|
|
c.Status(fiber.StatusBadRequest)
|
|
return nil
|
|
}
|
|
// do job with ver
|
|
}
|
|
*/
|
|
return nil
|
|
})
|
|
/* create/update/patch secret */
|
|
router.Post(uriSecretData, fiberOk)
|
|
router.Patch(uriSecretData, fiberOk)
|
|
/* delete secret */
|
|
router.Delete(uriSecretData, fiberOk)
|
|
|
|
/* delete/undelete secret */
|
|
router.Post("/:secret/delete/:path", fiberOk)
|
|
router.Post("/:secret/undelete/:path", fiberOk)
|
|
/* destroy secret */
|
|
router.Post("/:secret/destroy/:path", fiberOk)
|
|
|
|
/* read subkeys */
|
|
// router.Get("/:secret/subkeys/:path?version=:version&depth=:depth", fiberOk)
|
|
router.Get("/:secret/subkeys/:path", fiberOk, func(c *fiber.Ctx) error {
|
|
/*
|
|
ver_s := c.Query("version")
|
|
if ver_s != "" {
|
|
ver, err := strconv.ParseInt(ver_s, 10, 0)
|
|
if err != nil {
|
|
c.Status(fiber.StatusBadRequest)
|
|
return nil
|
|
}
|
|
// do job with ver
|
|
}
|
|
*/
|
|
return nil
|
|
})
|
|
|
|
/* read metadata */
|
|
router.Get(uriSecretMetadata, fiberOk)
|
|
/* create/update metadata */
|
|
router.Post(uriSecretMetadata, fiberOk)
|
|
router.Patch(uriSecretMetadata, fiberOk)
|
|
/* delete metadata */
|
|
router.Delete(uriSecretMetadata, fiberOk)
|
|
/* list secrets */
|
|
router.Add(MethodList, uriSecretMetadata, fiberOk)
|
|
}
|