mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-29 20:00:30 +00:00
41af9c0720
Since we are not able to list the already set secrets I have added the required API andpoint and the required sub command to list them.
68 lines
1.3 KiB
Go
68 lines
1.3 KiB
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/drone/drone/model"
|
|
"github.com/drone/drone/router/middleware/session"
|
|
"github.com/drone/drone/store"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func GetSecrets(c *gin.Context) {
|
|
repo := session.Repo(c)
|
|
secrets, err := store.GetSecretList(c, repo)
|
|
|
|
if err != nil {
|
|
c.AbortWithStatus(http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
var list []*model.Secret
|
|
|
|
for _, s := range secrets {
|
|
list = append(list, s.Clone())
|
|
}
|
|
|
|
c.JSON(http.StatusOK, list)
|
|
}
|
|
|
|
func PostSecret(c *gin.Context) {
|
|
repo := session.Repo(c)
|
|
|
|
in := &model.Secret{}
|
|
err := c.Bind(in)
|
|
if err != nil {
|
|
c.String(http.StatusBadRequest, "Invalid JSON input. %s", err.Error())
|
|
return
|
|
}
|
|
in.ID = 0
|
|
in.RepoID = repo.ID
|
|
|
|
err = store.SetSecret(c, in)
|
|
if err != nil {
|
|
c.String(http.StatusInternalServerError, "Unable to persist secret. %s", err.Error())
|
|
return
|
|
}
|
|
|
|
c.String(http.StatusOK, "")
|
|
}
|
|
|
|
func DeleteSecret(c *gin.Context) {
|
|
repo := session.Repo(c)
|
|
name := c.Param("secret")
|
|
|
|
secret, err := store.GetSecret(c, repo, name)
|
|
if err != nil {
|
|
c.String(http.StatusNotFound, "Cannot find secret %s.", name)
|
|
return
|
|
}
|
|
err = store.DeleteSecret(c, secret)
|
|
if err != nil {
|
|
c.String(http.StatusInternalServerError, "Unable to delete secret. %s", err.Error())
|
|
return
|
|
}
|
|
|
|
c.String(http.StatusOK, "")
|
|
}
|