ability to replace the private key

This commit is contained in:
Brad Rydzewski 2015-11-20 10:31:10 -08:00
parent 5294e277d1
commit b5d9b81e96
2 changed files with 26 additions and 1 deletions

View file

@ -160,12 +160,36 @@ func GetRepoKey(c *gin.Context) {
repo := session.Repo(c) repo := session.Repo(c)
keys, err := store.GetKey(c, repo) keys, err := store.GetKey(c, repo)
if err != nil { if err != nil {
c.AbortWithError(http.StatusNotFound, err) c.String(404, "Error fetching repository key")
} else { } else {
c.String(http.StatusOK, keys.Public) 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) { func DeleteRepo(c *gin.Context) {
remote := remote.FromContext(c) remote := remote.FromContext(c)
repo := session.Repo(c) repo := session.Repo(c)

View file

@ -99,6 +99,7 @@ func Load(middleware ...gin.HandlerFunc) http.Handler {
repo.GET("", controller.GetRepo) repo.GET("", controller.GetRepo)
repo.GET("/key", controller.GetRepoKey) repo.GET("/key", controller.GetRepoKey)
repo.POST("/key", controller.PostRepoKey)
repo.GET("/builds", controller.GetBuilds) repo.GET("/builds", controller.GetBuilds)
repo.GET("/builds/:number", controller.GetBuild) repo.GET("/builds/:number", controller.GetBuild)
repo.GET("/logs/:number/:job", controller.GetBuildLogs) repo.GET("/logs/:number/:job", controller.GetBuildLogs)