Integrated real API implementation for org secrets
This commit is contained in:
parent
889b88d38f
commit
298dcd5a50
4 changed files with 71 additions and 23 deletions
|
@ -291,7 +291,7 @@ func PostBuild(c *gin.Context) {
|
||||||
// get the previous build so that we can send
|
// get the previous build so that we can send
|
||||||
// on status change notifications
|
// on status change notifications
|
||||||
last, _ := store.GetBuildLastBefore(c, repo, build.Branch, build.ID)
|
last, _ := store.GetBuildLastBefore(c, repo, build.Branch, build.ID)
|
||||||
secs, err := store.GetSecretList(c, repo)
|
secs, err := store.GetMergedSecretList(c, repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Error getting secrets for %s#%d. %s", repo.FullName, build.Number, err)
|
log.Errorf("Error getting secrets for %s#%d. %s", repo.FullName, build.Number, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -206,7 +206,7 @@ func PostHook(c *gin.Context) {
|
||||||
// get the previous build so that we can send
|
// get the previous build so that we can send
|
||||||
// on status change notifications
|
// on status change notifications
|
||||||
last, _ := store.GetBuildLastBefore(c, repo, build.Branch, build.ID)
|
last, _ := store.GetBuildLastBefore(c, repo, build.Branch, build.ID)
|
||||||
secs, err := store.GetSecretList(c, repo)
|
secs, err := store.GetMergedSecretList(c, repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Error getting secrets for %s#%d. %s", repo.FullName, build.Number, err)
|
log.Errorf("Error getting secrets for %s#%d. %s", repo.FullName, build.Number, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ func GetSecrets(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var list []*model.Secret
|
var list []*model.RepoSecret
|
||||||
|
|
||||||
for _, s := range secrets {
|
for _, s := range secrets {
|
||||||
list = append(list, s.Clone())
|
list = append(list, s.Clone())
|
||||||
|
@ -28,19 +28,10 @@ func GetSecrets(c *gin.Context) {
|
||||||
c.JSON(http.StatusOK, list)
|
c.JSON(http.StatusOK, list)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetTeamSecrets(c *gin.Context) {
|
|
||||||
var (
|
|
||||||
list []*model.Secret
|
|
||||||
)
|
|
||||||
|
|
||||||
// TODO(must): Integrate a real implementation
|
|
||||||
c.JSON(http.StatusOK, list)
|
|
||||||
}
|
|
||||||
|
|
||||||
func PostSecret(c *gin.Context) {
|
func PostSecret(c *gin.Context) {
|
||||||
repo := session.Repo(c)
|
repo := session.Repo(c)
|
||||||
|
|
||||||
in := &model.Secret{}
|
in := &model.RepoSecret{}
|
||||||
err := c.Bind(in)
|
err := c.Bind(in)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(http.StatusBadRequest, "Invalid JSON input. %s", err.Error())
|
c.String(http.StatusBadRequest, "Invalid JSON input. %s", err.Error())
|
||||||
|
@ -58,11 +49,6 @@ func PostSecret(c *gin.Context) {
|
||||||
c.String(http.StatusOK, "")
|
c.String(http.StatusOK, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func PostTeamSecret(c *gin.Context) {
|
|
||||||
c.String(http.StatusOK, "")
|
|
||||||
// TODO(must): Integrate a real implementation
|
|
||||||
}
|
|
||||||
|
|
||||||
func DeleteSecret(c *gin.Context) {
|
func DeleteSecret(c *gin.Context) {
|
||||||
repo := session.Repo(c)
|
repo := session.Repo(c)
|
||||||
name := c.Param("secret")
|
name := c.Param("secret")
|
||||||
|
@ -80,8 +66,3 @@ func DeleteSecret(c *gin.Context) {
|
||||||
|
|
||||||
c.String(http.StatusOK, "")
|
c.String(http.StatusOK, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteTeamSecret(c *gin.Context) {
|
|
||||||
c.String(http.StatusOK, "")
|
|
||||||
// TODO(must): Integrate a real implementation
|
|
||||||
}
|
|
67
server/team_secret.go
Normal file
67
server/team_secret.go
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/drone/drone/model"
|
||||||
|
"github.com/drone/drone/store"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetTeamSecrets(c *gin.Context) {
|
||||||
|
team := c.Param("team")
|
||||||
|
secrets, err := store.GetTeamSecretList(c, team)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithStatus(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var list []*model.TeamSecret
|
||||||
|
|
||||||
|
for _, s := range secrets {
|
||||||
|
list = append(list, s.Clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, list)
|
||||||
|
}
|
||||||
|
|
||||||
|
func PostTeamSecret(c *gin.Context) {
|
||||||
|
team := c.Param("team")
|
||||||
|
|
||||||
|
in := &model.TeamSecret{}
|
||||||
|
err := c.Bind(in)
|
||||||
|
if err != nil {
|
||||||
|
c.String(http.StatusBadRequest, "Invalid JSON input. %s", err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
in.ID = 0
|
||||||
|
in.Key = team
|
||||||
|
|
||||||
|
err = store.SetTeamSecret(c, in)
|
||||||
|
if err != nil {
|
||||||
|
c.String(http.StatusInternalServerError, "Unable to persist team secret. %s", err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.String(http.StatusOK, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func DeleteTeamSecret(c *gin.Context) {
|
||||||
|
team := c.Param("team")
|
||||||
|
name := c.Param("secret")
|
||||||
|
|
||||||
|
secret, err := store.GetTeamSecret(c, team, name)
|
||||||
|
if err != nil {
|
||||||
|
c.String(http.StatusNotFound, "Cannot find secret %s.", name)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = store.DeleteTeamSecret(c, secret)
|
||||||
|
if err != nil {
|
||||||
|
c.String(http.StatusInternalServerError, "Unable to delete team secret. %s", err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.String(http.StatusOK, "")
|
||||||
|
}
|
Loading…
Reference in a new issue