diff --git a/controller/repo.go b/controller/repo.go index 3e9f86948..ce72889d7 100644 --- a/controller/repo.go +++ b/controller/repo.go @@ -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) diff --git a/docs/build/cache.md b/docs/build/cache.md index d05a35de0..9773fe02b 100644 --- a/docs/build/cache.md +++ b/docs/build/cache.md @@ -2,7 +2,7 @@ > This feature is still considered experimental -Drone allows you to cache directories within the build workspace. When a build successfully completes, the named directories are gzipped and stored on the host machine. When a new build starts, the named directories are restored from the gzipped files. This can be used to improve the performance of your builds. +Drone allows you to cache directories within the build workspace (`/drone`). When a build successfully completes, the named directories are gzipped and stored on the host machine. When a new build starts, the named directories are restored from the gzipped files. This can be used to improve the performance of your builds. Below is an example `.drone.yml` configured to cache the `.git` and the `node_modules` directory: diff --git a/docs/build/env.md b/docs/build/env.md index 7556146f9..9f08556f7 100644 --- a/docs/build/env.md +++ b/docs/build/env.md @@ -31,6 +31,7 @@ Drone also injects `CI_` prefixed variables for compatibility with other systems A subset of variables may be substituted directly into the Yaml at runtime using the `$$` notation: +* `$$BUILD_NUMBER` build number for the current build * `$$COMMIT` git sha for the current build, long format * `$$BRANCH` git branch for the current build * `$$BUILD_NUMBER` build number for the current build diff --git a/router/router.go b/router/router.go index 5e1c54d8c..464a40694 100644 --- a/router/router.go +++ b/router/router.go @@ -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)