ability to replace the private key
This commit is contained in:
parent
5294e277d1
commit
b5d9b81e96
2 changed files with 26 additions and 1 deletions
|
@ -160,12 +160,36 @@ func GetRepoKey(c *gin.Context) {
|
|||
repo := session.Repo(c)
|
||||
keys, err := store.GetKey(c, repo)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusNotFound, err)
|
||||
c.String(404, "Error fetching repository key")
|
||||
} else {
|
||||
c.String(http.StatusOK, keys.Public)
|
||||
}
|
||||
}
|
||||
|
||||
func PostRepoKey(c *gin.Context) {
|
||||
repo := session.Repo(c)
|
||||
keys, err := store.GetKey(c, repo)
|
||||
if err != nil {
|
||||
c.String(404, "Error fetching repository key")
|
||||
return
|
||||
}
|
||||
body, _ := ioutil.ReadAll(c.Request.Body)
|
||||
pkey := crypto.UnmarshalPrivateKey(body)
|
||||
if pkey == nil {
|
||||
c.String(500, "Cannot unmarshal private key. Invalid format.")
|
||||
return
|
||||
}
|
||||
|
||||
keys.Public = string(crypto.MarshalPublicKey(&pkey.PublicKey))
|
||||
keys.Private = string(crypto.MarshalPrivateKey(pkey))
|
||||
|
||||
err = store.UpdateKey(c, keys)
|
||||
if err != nil {
|
||||
c.String(500, "Error updating repository key")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func DeleteRepo(c *gin.Context) {
|
||||
remote := remote.FromContext(c)
|
||||
repo := session.Repo(c)
|
||||
|
|
|
@ -99,6 +99,7 @@ func Load(middleware ...gin.HandlerFunc) http.Handler {
|
|||
|
||||
repo.GET("", controller.GetRepo)
|
||||
repo.GET("/key", controller.GetRepoKey)
|
||||
repo.POST("/key", controller.PostRepoKey)
|
||||
repo.GET("/builds", controller.GetBuilds)
|
||||
repo.GET("/builds/:number", controller.GetBuild)
|
||||
repo.GET("/logs/:number/:job", controller.GetBuildLogs)
|
||||
|
|
Loading…
Reference in a new issue