forked from harness/harness
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sign.go
40 lines (31 loc) · 774 Bytes
/
sign.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package api
import (
"io/ioutil"
"github.com/drone/drone/router/middleware/session"
"github.com/gin-gonic/gin"
"github.com/square/go-jose"
)
func Sign(c *gin.Context) {
repo := session.Repo(c)
in, err := ioutil.ReadAll(c.Request.Body)
if err != nil {
c.String(400, "Unable to read request body. %s.", err.Error())
return
}
signer, err := jose.NewSigner(jose.HS256, []byte(repo.Hash))
if err != nil {
c.String(500, "Unable to create the signer. %s.", err.Error())
return
}
signed, err := signer.Sign(in)
if err != nil {
c.String(500, "Unable to sign input. %s", err.Error())
return
}
out, err := signed.CompactSerialize()
if err != nil {
c.String(500, "Unable to serialize signature. %s", err.Error())
return
}
c.String(200, out)
}