mirror of
https://gitee.com/gokins/gokins.git
synced 2024-12-01 18:58:35 +08:00
commit
17a41ea31c
@ -219,5 +219,14 @@ Gokins目前还处于需要不断进步的阶段,如果你有兴趣假如我
|
||||
1. 日志入库改为日志文件,减少数据库大小
|
||||
2. 环境变量PATH优化,加入变量获取
|
||||
|
||||
### Gokins V0.2.0 (更新日期2020-10-24)
|
||||
- 新增功能 :
|
||||
1. 新增gitlab、gitee的webhook触发流水线的方式
|
||||
2. 新增流水行执行完毕后的后续再执行工作功能
|
||||
|
||||
- bug fix :
|
||||
1. 修复一些已知问题
|
||||
|
||||
|
||||
***
|
||||
|
||||
|
@ -2,6 +2,9 @@ package mgr
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/hmac"
|
||||
"crypto/sha1"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@ -9,6 +12,8 @@ import (
|
||||
"gokins/model"
|
||||
"gokins/service/dbService"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/dop251/goja"
|
||||
@ -45,7 +50,7 @@ func (c *trigHookTask) stop() {
|
||||
}
|
||||
}
|
||||
func (c *trigHookTask) isRun() bool {
|
||||
return c.cncl == nil
|
||||
return c.cncl != nil
|
||||
}
|
||||
func (c *trigHookTask) start(pars ...interface{}) error {
|
||||
if c.tg == nil || c.cncl != nil {
|
||||
@ -145,6 +150,7 @@ func (c *trigHookTask) run() (rterr error) {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *trigHookTask) initVm() {
|
||||
csl := c.vm.NewObject()
|
||||
c.vm.Set("console", csl)
|
||||
@ -160,6 +166,10 @@ func (c *trigHookTask) initVm() {
|
||||
})
|
||||
c.vm.Set("getBody", func() interface{} {
|
||||
if c.body == nil {
|
||||
if c.conf.Plug == "github" {
|
||||
unescape, _ := url.QueryUnescape(string(c.bodys)[8:])
|
||||
c.bodys = []byte(unescape)
|
||||
}
|
||||
c.body = ruisUtil.NewMapo(c.bodys)
|
||||
}
|
||||
return c.body
|
||||
@ -171,4 +181,29 @@ func (c *trigHookTask) initVm() {
|
||||
c.vm.Set("encodeSha1", func(body string) string {
|
||||
return ruisUtil.Sha1String(body)
|
||||
})
|
||||
|
||||
c.vm.Set("verifySignature", func(secret string, signature string, body []byte) bool {
|
||||
return verifySignature([]byte(secret), signature, body)
|
||||
})
|
||||
|
||||
}
|
||||
func signBody(secret, body []byte) []byte {
|
||||
computed := hmac.New(sha1.New, secret)
|
||||
computed.Write(body)
|
||||
return []byte(computed.Sum(nil))
|
||||
}
|
||||
|
||||
func verifySignature(secret []byte, signature string, body []byte) bool {
|
||||
|
||||
const signaturePrefix = "sha1="
|
||||
const signatureLength = 45 // len(SignaturePrefix) + len(hex(sha1))
|
||||
|
||||
if len(signature) != signatureLength || !strings.HasPrefix(signature, signaturePrefix) {
|
||||
return false
|
||||
}
|
||||
|
||||
actual := make([]byte, 20)
|
||||
hex.Decode(actual, []byte(signature[5:]))
|
||||
|
||||
return hmac.Equal(signBody(secret, body), actual)
|
||||
}
|
||||
|
@ -58,21 +58,21 @@ function main(){
|
||||
}
|
||||
`,
|
||||
}
|
||||
/*HookjsMap["github"] = &Hookjs{
|
||||
Uis: map[string]string{"secretkey": "string", "branch": "string"},
|
||||
HookjsMap["github"] = &Hookjs{
|
||||
Uis: map[string]string{"secretkey": "string", "branch": "string"},
|
||||
Desc: "secretkey:签名秘钥,branch:push对象分支",
|
||||
Defs: `{"secretkey":"pwd","branch":"master"}`,
|
||||
js: `
|
||||
js: `
|
||||
|
||||
function main(){
|
||||
console.log('start run main function!!!!');
|
||||
var ret={check:false};
|
||||
var conf=getConf();
|
||||
var body=getBody();
|
||||
var bodys=getBodys();
|
||||
var nm=getHeader('X-GitHub-Event');
|
||||
var tk=getHeader('X-Hub-Signature');
|
||||
console.log('sha1',tk,encodeSha1(getBodys()+conf.secretkey));
|
||||
if(tk!=encodeSha1(conf.secretkey+getBodys())){
|
||||
if(verifySignature(tk,conf.password,bodys)){
|
||||
ret.errs='触发请求秘钥错误';
|
||||
return ret;
|
||||
}
|
||||
@ -87,7 +87,7 @@ function main(){
|
||||
return ret
|
||||
}
|
||||
`,
|
||||
}*/
|
||||
}
|
||||
HookjsMap["gitlab"] = &Hookjs{
|
||||
Uis: map[string]string{"token": "string", "branch": "string"},
|
||||
Desc: "token:秘钥,branch:push对象分支",
|
||||
|
@ -70,7 +70,7 @@ func (c *trigTimeTask) stop() {
|
||||
}
|
||||
}
|
||||
func (c *trigTimeTask) isRun() bool {
|
||||
return c.cncl == nil
|
||||
return c.cncl != nil
|
||||
}
|
||||
func (c *trigTimeTask) run() {
|
||||
defer ruisUtil.Recovers("RunTask start", func(errs string) {
|
||||
|
@ -64,7 +64,7 @@ func (c *trigWorkedTask) stop() {
|
||||
}
|
||||
}
|
||||
func (c *trigWorkedTask) isRun() bool {
|
||||
return c.cncl == nil
|
||||
return c.cncl != nil
|
||||
}
|
||||
func (c *trigWorkedTask) run() error {
|
||||
defer ruisUtil.Recovers("RunTask start", func(errs string) {
|
||||
|
Loading…
Reference in New Issue
Block a user