Skip to content

Commit

Permalink
Add key handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
zachhuff386 committed Aug 15, 2019
1 parent 3198bf8 commit 7a87ac7
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions handlers/key.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package handlers

import (
"github.com/gin-gonic/gin"
"github.com/pritunl/pritunl-vault/utils"
"github.com/pritunl/pritunl-vault/vault"
)

func keyGet(c *gin.Context) {
payload, err := vault.Primary.GetServerKey()
if err != nil {
utils.AbortWithError(c, 500, err)
return
}

c.JSON(200, payload)
}

func keyPost(c *gin.Context) {
payload := &vault.Payload{}

err := c.Bind(payload)
if err != nil {
utils.AbortWithError(c, 500, err)
return
}

err = vault.Primary.LoadHostKey(payload)
if err != nil {
utils.AbortWithError(c, 500, err)
return
}

c.Status(200)
}

func masterPost(c *gin.Context) {
payload := &vault.Payload{}

err := c.Bind(payload)
if err != nil {
utils.AbortWithError(c, 500, err)
return
}

err = vault.Primary.LoadMasterKey(payload)
if err != nil {
utils.AbortWithError(c, 500, err)
return
}

c.Status(200)
}

func initGet(c *gin.Context) {
initKeyData, err := vault.Primary.GetInitKey()
if err != nil {
utils.AbortWithError(c, 500, err)
return
}

c.String(200, initKeyData)
}

0 comments on commit 7a87ac7

Please sign in to comment.