mirror of
https://github.com/alvierahman90/gohookr.git
synced 2024-12-22 14:31:58 +00:00
don't remember what this does lol
This commit is contained in:
parent
8f0cf776b1
commit
749a3bc9b3
13
config.yml
Normal file
13
config.yml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
listenaddress: 127.0.0.1:8654
|
||||||
|
services:
|
||||||
|
test:
|
||||||
|
script:
|
||||||
|
program: "echo"
|
||||||
|
arguments:
|
||||||
|
- test
|
||||||
|
tests:
|
||||||
|
- program: ./example.sh
|
||||||
|
appendpayload: true
|
||||||
|
disablesignatureverification: false
|
||||||
|
signatureheader: test
|
||||||
|
secret: thisisasecret
|
@ -1,5 +1,12 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"io/ioutil"
|
||||||
|
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
|
)
|
||||||
|
|
||||||
// The struct that represents the config.json file
|
// The struct that represents the config.json file
|
||||||
type Config struct {
|
type Config struct {
|
||||||
ListenAddress string
|
ListenAddress string
|
||||||
@ -33,3 +40,23 @@ func (c Config) Validate() error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Config) Load(config_filename string) error {
|
||||||
|
|
||||||
|
raw_config, err := ioutil.ReadFile(config_filename)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(raw_config, &c)
|
||||||
|
if err == nil {
|
||||||
|
return c.Validate()
|
||||||
|
}
|
||||||
|
|
||||||
|
err = yaml.Unmarshal(raw_config, &c)
|
||||||
|
if err == nil {
|
||||||
|
return c.Validate()
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
0
example.sh
Executable file → Normal file
0
example.sh
Executable file → Normal file
5
go.mod
5
go.mod
@ -2,4 +2,7 @@ module git.alv.cx/alvierahman90/gohookr
|
|||||||
|
|
||||||
go 1.16
|
go 1.16
|
||||||
|
|
||||||
require github.com/gorilla/mux v1.8.0
|
require (
|
||||||
|
github.com/gorilla/mux v1.8.0
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
|
||||||
|
)
|
||||||
|
4
go.sum
4
go.sum
@ -1,2 +1,6 @@
|
|||||||
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
|
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
|
||||||
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
|
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
26
main.go
26
main.go
@ -4,7 +4,6 @@ import (
|
|||||||
"crypto/hmac"
|
"crypto/hmac"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@ -33,7 +32,7 @@ func main() {
|
|||||||
checkSignature = p != "true"
|
checkSignature = p != "true"
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err := loadConfig(config_filename)
|
var err = c.Load(config_filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err.Error())
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
@ -49,28 +48,9 @@ func main() {
|
|||||||
log.Fatal(http.ListenAndServe(c.ListenAddress, r))
|
log.Fatal(http.ListenAndServe(c.ListenAddress, r))
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadConfig(config_filename string) (config.Config, error) {
|
|
||||||
var c config.Config
|
|
||||||
|
|
||||||
raw_config, err := ioutil.ReadFile(config_filename)
|
|
||||||
if err != nil {
|
|
||||||
return config.Config{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := json.Unmarshal(raw_config, &c); err != nil {
|
|
||||||
return config.Config{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := c.Validate(); err != nil {
|
|
||||||
return config.Config{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return c, nil
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func webhookHandler(w http.ResponseWriter, r *http.Request) {
|
func webhookHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
c, err := loadConfig(config_filename)
|
var c config.Config
|
||||||
|
var err = c.Load(config_filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeResponse(w, 500, "Unable to read config file")
|
writeResponse(w, 500, "Unable to read config file")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user