Implement optional signature
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
a48bc1f1bc
commit
b4b531409f
3 changed files with 33 additions and 16 deletions
|
|
@ -39,6 +39,11 @@ func initializeDroneOauth() {
|
|||
}
|
||||
}
|
||||
|
||||
type RepositoryAdminPull struct {
|
||||
Tag *string `json:"tag"`
|
||||
OptionalSignature bool `json:"sig_optional"`
|
||||
}
|
||||
|
||||
func declareAPIAuthRepositoriesRoutes(router *gin.RouterGroup) {
|
||||
router.GET("/repositories", func(c *gin.Context) {
|
||||
var u *User
|
||||
|
|
@ -203,12 +208,12 @@ func declareAPIAuthRepositoriesRoutes(router *gin.RouterGroup) {
|
|||
return
|
||||
}
|
||||
|
||||
var tag *string
|
||||
var rap RepositoryAdminPull
|
||||
if loggeduser.IsAdmin {
|
||||
c.ShouldBindJSON(&tag)
|
||||
c.ShouldBindJSON(&rap)
|
||||
}
|
||||
|
||||
TriggerTagUpdate(c, work, repo, u, tag)
|
||||
TriggerTagUpdate(c, work, repo, u, rap.Tag, rap.OptionalSignature)
|
||||
})
|
||||
|
||||
repositoriesRoutes.GET("/state", func(c *gin.Context) {
|
||||
|
|
@ -327,7 +332,7 @@ func declareCallbacksRoutes(router *gin.RouterGroup) {
|
|||
|
||||
tmp := strings.SplitN(hook.Ref, "/", 3)
|
||||
if len(tmp) != 3 {
|
||||
TriggerTagUpdate(c, work, repo, user, nil)
|
||||
TriggerTagUpdate(c, work, repo, user, nil, false)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -355,7 +360,7 @@ func declareCallbacksRoutes(router *gin.RouterGroup) {
|
|||
}
|
||||
}
|
||||
|
||||
TriggerTagUpdate(c, work, repo, user, &tmp[2])
|
||||
TriggerTagUpdate(c, work, repo, user, &tmp[2], false)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -387,7 +392,7 @@ func repositoryHandler(c *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
func TriggerTagUpdate(c *gin.Context, work *Work, repo *Repository, u *User, tag *string) {
|
||||
func TriggerTagUpdate(c *gin.Context, work *Work, repo *Repository, u *User, tag *string, sig_optional bool) {
|
||||
loggeduser := c.MustGet("LoggedUser").(*User)
|
||||
now := time.Now()
|
||||
|
||||
|
|
@ -411,14 +416,20 @@ func TriggerTagUpdate(c *gin.Context, work *Work, repo *Repository, u *User, tag
|
|||
}
|
||||
}
|
||||
|
||||
client := drone.NewClient(droneEndpoint, droneConfig)
|
||||
result, err := client.BuildCreate("srs", "atsebay.t-worker", "", "master", map[string]string{
|
||||
env := map[string]string{
|
||||
"REPO_URL": repo.URI,
|
||||
"REPO_TAG": repo_tag,
|
||||
"LOGIN": login,
|
||||
"GROUPS": groups,
|
||||
"DEST": fmt.Sprintf("%d", work.Id),
|
||||
})
|
||||
}
|
||||
|
||||
if sig_optional {
|
||||
env["TAG_SIG_OPTIONAL"] = "1"
|
||||
}
|
||||
|
||||
client := drone.NewClient(droneEndpoint, droneConfig)
|
||||
result, err := client.BuildCreate("srs", "atsebay.t-worker", "", "master", env)
|
||||
if err != nil {
|
||||
log.Println("Unable to communicate with Drone:", err.Error())
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Unable to communication with the extraction service."})
|
||||
|
|
|
|||
Reference in a new issue