summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKatolaZ <katolaz@freaknet.org>2017-07-15 01:35:36 +0100
committerKatolaZ <katolaz@freaknet.org>2017-07-15 01:35:36 +0100
commit74f8a74ecf8284fd4182cabab797f17bb18e7032 (patch)
treefccf6ded5d4a894b5863039b99ce977023bd0f79
parent726b399e4747032a3d052339cd62c57ae5b6767c (diff)
Added Makefile -- gofmt
-rw-r--r--Makefile18
-rw-r--r--commits.go17
-rw-r--r--config.go5
-rw-r--r--scorsh.go40
-rw-r--r--spooler.go18
-rw-r--r--types.go8
-rw-r--r--workers.go25
7 files changed, 66 insertions, 65 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..942de72
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,18 @@
+BUILD=go build
+
+
+SOURCES=scorsh.go \
+types.go \
+config.go \
+spooler.go \
+commits.go \
+workers.go
+
+all: scorsh
+
+
+scorsh: $(SOURCES)
+ $(BUILD) scorsh.go types.go config.go spooler.go commits.go workers.go
+
+clean:
+ rm scorsh
diff --git a/commits.go b/commits.go
index 7703273..46672cf 100644
--- a/commits.go
+++ b/commits.go
@@ -6,7 +6,7 @@ import (
"golang.org/x/crypto/openpgp"
"os"
"strings"
-// "log"
+ // "log"
)
func CommitToString(commit *git.Commit) string {
@@ -24,16 +24,16 @@ func CommitToString(commit *git.Commit) string {
// FIXME: RETURN THE ENTITY PROVIDED BY THE CHECK, OR nil
func check_signature(commit *git.Commit, keys []*openpgp.KeyRing) (signature, signed string, err error) {
-
+
signature, signed, err = commit.ExtractSignature()
if err == nil {
for _, keyring := range keys {
-
+
_, err_sig :=
openpgp.CheckArmoredDetachedSignature(*keyring, strings.NewReader(signed),
- strings.NewReader(signature))
-
+ strings.NewReader(signature))
+
if err_sig == nil {
fmt.Printf("Good signature \n")
return signature, signed, nil
@@ -41,11 +41,10 @@ func check_signature(commit *git.Commit, keys []*openpgp.KeyRing) (signature, si
err = err_sig
}
}
-
+
return "", "", err
}
-
// traverse all the commits between two references, looking for scorsh
// commands
// fixme: we don't have just one keyring here....
@@ -91,12 +90,12 @@ func walk_commits(msg SCORSHmsg, w *SCORSHworker) error {
// We should look for scorsh-tags, and if the commit has any,
// check if it can be verified by any of the keyrings associated
// with the scorsh-tag
-
+
//signature, signed, err := check_signature(commit, &keyring)
//_, _, err := check_signature(commit, w.keys)
//if err != nil {
// log.Printf("%s\n", SCORSHerr(SCORSH_ERR_SIGNATURE))
- //
+ //
//}
cur_commit = commit.Parent(0)
} else {
diff --git a/config.go b/config.go
index 38ce531..970c49c 100644
--- a/config.go
+++ b/config.go
@@ -29,7 +29,7 @@ func ReadGlobalConfig(fname string) *SCORSHmaster {
}
fmt.Printf("%s", cfg)
-
+
if cfg.Logfile != "" {
f, err := os.OpenFile(cfg.Logfile, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0600)
if err != nil {
@@ -40,7 +40,7 @@ func ReadGlobalConfig(fname string) *SCORSHmaster {
}
if cfg.LogPrefix != "" {
- log.SetPrefix(cfg.LogPrefix+ " ")
+ log.SetPrefix(cfg.LogPrefix + " ")
}
// If the user has not set a spooldir, crash loudly
@@ -59,4 +59,3 @@ func ReadGlobalConfig(fname string) *SCORSHmaster {
return cfg
}
-
diff --git a/scorsh.go b/scorsh.go
index 0fb91a8..aca3121 100644
--- a/scorsh.go
+++ b/scorsh.go
@@ -6,14 +6,13 @@ import (
"log"
)
-// manage debugging messages
+// manage debugging messages
const debug debugging = true
type debugging bool
-
-func (d debugging) log(format string, args ...interface{}){
+func (d debugging) log(format string, args ...interface{}) {
if d {
log.Printf(format, args...)
}
@@ -45,12 +44,11 @@ func SCORSHerr(err int) error {
}
-
func FindMatchingWorkers(master *SCORSHmaster, msg *SCORSHmsg) []*SCORSHworker {
-
+
var ret []*SCORSHworker
-
- for idx,w := range master.Workers {
+
+ for idx, w := range master.Workers {
if w.Matches(msg.Repo, msg.Branch) {
debug.log("--- Worker: %s matches %s:%s\n", w.Name, msg.Repo, msg.Branch)
ret = append(ret, &(master.Workers[idx]))
@@ -59,34 +57,33 @@ func FindMatchingWorkers(master *SCORSHmaster, msg *SCORSHmsg) []*SCORSHworker {
return ret
}
-
func Master(master *SCORSHmaster) {
// master main loop:
var matching_workers []*SCORSHworker
var push_msg SCORSHmsg
-
+
matching_workers = make([]*SCORSHworker, len(master.Workers))
log.Println("[master] Master started ")
-
+
for {
select {
// - receive stuff from the spooler
- case push_msg = <- master.Spooler:
+ case push_msg = <-master.Spooler:
debug.log("[master] received message: %s\n", push_msg)
-
+
// - lookup the repos map for matching workers
matching_workers = FindMatchingWorkers(master, &push_msg)
debug.log("[master] matching workers: %s\n", matching_workers)
-
+
// add the message to PendingMsg
//...
// - dispatch the message to all the matching workers
for _, w := range matching_workers {
- // increase the counter associated to the message
+ // increase the counter associated to the message
w.MsgChan <- push_msg
}
}
@@ -97,14 +94,12 @@ func InitMaster() *SCORSHmaster {
master := ReadGlobalConfig(*conf_file)
-
master.Repos = make(map[string][]*SCORSHworker)
master.WorkingMsg = make(map[string]int)
// This is the mutex-channel on which we receive acks from workers
master.StatusChan = make(chan SCORSHmsg, 1)
master.Spooler = make(chan SCORSHmsg, 1)
-
err_workers := StartWorkers(master)
if err_workers != nil {
log.Fatal("Error starting workers: ", err_workers)
@@ -114,20 +109,19 @@ func InitMaster() *SCORSHmaster {
err_spooler := StartSpooler(master)
if err_spooler != nil {
log.Fatal("Error starting spooler: ", err_spooler)
- }
+ }
return master
-
-}
+}
func main() {
flag.Parse()
-
+
master := InitMaster()
-
+
go Master(master)
- <- master.StatusChan
-
+ <-master.StatusChan
+
}
diff --git a/spooler.go b/spooler.go
index 9b4fc1c..8febf31 100644
--- a/spooler.go
+++ b/spooler.go
@@ -6,15 +6,14 @@ import (
"github.com/go-yaml/yaml"
"io/ioutil"
"log"
-// "time"
+ // "time"
)
// parse a request file and return a SCORSHmessage
func parse_request(fname string, msg *SCORSHmsg) error {
-
debug.log("[parse_request] message at start: %s\n", msg)
-
+
data, err := ioutil.ReadFile(fname)
if err != nil {
log.Printf("Unable to open file: %s\n", fname)
@@ -22,10 +21,9 @@ func parse_request(fname string, msg *SCORSHmsg) error {
}
debug.log("[parse_request] file contains: \n%s\n", data)
-
+
debug.log("[parse_request] reading message from file: %s\n", fname)
-
-
+
err = yaml.Unmarshal([]byte(data), msg)
if err != nil {
return fmt.Errorf("Error parsing message: %s", err)
@@ -34,14 +32,13 @@ func parse_request(fname string, msg *SCORSHmsg) error {
return nil
}
-
func spooler(watcher *fsnotify.Watcher, worker chan SCORSHmsg) {
log.Println("Spooler started correctly")
var msg *SCORSHmsg
msg = new(SCORSHmsg)
-
+
for {
select {
case event := <-watcher.Events:
@@ -61,7 +58,6 @@ func spooler(watcher *fsnotify.Watcher, worker chan SCORSHmsg) {
}
}
-
func StartSpooler(master *SCORSHmaster) error {
watcher, err := fsnotify.NewWatcher()
@@ -74,8 +70,8 @@ func StartSpooler(master *SCORSHmaster) error {
if err != nil {
return fmt.Errorf("Error adding folder: %s\n", err)
}
-
+
go spooler(watcher, master.Spooler)
-
+
return nil
}
diff --git a/types.go b/types.go
index 6b5a384..50b278f 100644
--- a/types.go
+++ b/types.go
@@ -55,8 +55,8 @@ type SCORSHworker_state struct {
// The type SCORSHworker represents the configuration and state of a
// worker
type SCORSHworker struct {
- SCORSHworker_cfg `yaml:",inline"`
- SCORSHworker_state
+ SCORSHworker_cfg `yaml:",inline"`
+ SCORSHworker_state
}
// Configuration of the master
@@ -82,8 +82,6 @@ type SCORSHmaster struct {
SCORSHmaster_state
}
-
-
func (cfg *SCORSHmaster) String() string {
var buff bytes.Buffer
@@ -122,7 +120,6 @@ func (cfg *SCORSHmaster) String() string {
return buff.String()
}
-
func (msg *SCORSHmsg) String() string {
var buff bytes.Buffer
@@ -139,4 +136,3 @@ func (msg *SCORSHmsg) String() string {
return buff.String()
}
-
diff --git a/workers.go b/workers.go
index 694a0e9..33c6166 100644
--- a/workers.go
+++ b/workers.go
@@ -12,7 +12,7 @@ import (
)
func (worker *SCORSHworker) Matches(repo, branch string) bool {
-
+
for _, r := range worker.Repos {
parts := strings.SplitN(r, ":", 2)
repo_pattern := parts[0]
@@ -58,20 +58,19 @@ func (w *SCORSHworker) LoadKeyrings() error {
// Still to be implemented
func (w *SCORSHworker) LoadTags() error {
-
+
w_tags, err := ioutil.ReadFile(w.Tagfile)
- if err != nil{
+ if err != nil {
return fmt.Errorf("Cannot read worker config: %s", err)
}
-
err = yaml.Unmarshal(w_tags, w)
//err = yaml.Unmarshal(w_tags, tags)
if err != nil {
return fmt.Errorf("Error while reading tags: %s", err)
}
-
+
return nil
}
@@ -79,11 +78,11 @@ func (w *SCORSHworker) LoadTags() error {
func Worker(w *SCORSHworker) {
var msg SCORSHmsg
-
+
log.Printf("[worker: %s] Started\n", w.Name)
w.StatusChan <- msg
-
+
// This is the main worker loop
for {
select {
@@ -104,14 +103,14 @@ func Worker(w *SCORSHworker) {
func StartWorkers(master *SCORSHmaster) error {
num_workers := len(master.Workers)
-
+
// We should now start each worker
log.Printf("num_workers: %d\n", num_workers)
-
- for w:=0; w<num_workers; w++ {
-
- worker := & (master.Workers[w])
+
+ for w := 0; w < num_workers; w++ {
+
+ worker := &(master.Workers[w])
// Set the Status and Msg channels
worker.StatusChan = master.StatusChan
worker.MsgChan = make(chan SCORSHmsg)
@@ -132,7 +131,7 @@ func StartWorkers(master *SCORSHmaster) error {
master.Repos[repo_name] = append(master.Repos[repo_name], worker)
}
go Worker(worker)
- <- master.StatusChan
+ <-master.StatusChan
}
return nil
}