tag checking and validation complete.

lint-refactor
KatolaZ 8 years ago
parent 40c8aae584
commit 95955f17a3
  1. 63
      commits.go
  2. 86
      examples/worker1/allowed_users.asc
  3. BIN
      examples/worker1/allowed_users.pgp
  4. 10
      examples/worker1/worker1.cfg
  5. 1
      types.go
  6. 14
      workers.go

@ -71,9 +71,38 @@ func get_valid_keys(commit *git.Commit, keys *map[string]openpgp.KeyRing) []stri
return ret return ret
} }
func exec_tag(tag SCORSHtag, valid_keys []string) error { func intersect_keys(ref map[string]bool, keys []string) []string {
return nil var ret []string
for _, k := range keys {
if _, ok := ref[k]; ok {
ret = append(ret, k)
}
}
return ret
}
func find_tag_config(tag_name string, w *SCORSHworker) (*SCORSHtag_cfg, bool) {
for _, c := range w.Tags {
if c.Name == tag_name {
return &c, true
}
}
return nil, false
}
func exec_tag(tag *SCORSHtag_cfg) []error {
var ret []error
for _, c := range tag.Commands {
debug.log("[tag: %s] attempting command: %s\n", tag.Name, c.URL)
ret = append(ret, nil)
}
return ret
} }
// traverse all the commits between two references, looking for scorsh // traverse all the commits between two references, looking for scorsh
@ -143,18 +172,32 @@ func walk_commits(msg SCORSHmsg, w *SCORSHworker) error {
// 1) get the list of all the keys which verify the message // 1) get the list of all the keys which verify the message
valid_keys := get_valid_keys(commit, &(w.Keys)) valid_keys := get_valid_keys(commit, &(w.Keys))
debug.log("validated keyrings on commit: %s\n", valid_keys) debug.log("[worker: %s] validated keyrings on commit: %s\n", w.Name, valid_keys)
// 2) Try to execute each of the tag included in the message
// 2) then for each tag in the message
for _, t := range tags.Tags { for _, t := range tags.Tags {
err = exec_tag(t, valid_keys) // a) check that the tag is among those accepted by the worker
if err != nil { tag_cfg, good_tag := find_tag_config(t.Tag, w)
log.Printf("[worker: %s] unable to execute tag: %s : %s", w.Name, t.Tag, err) debug.log("[worker: %s] good_tag: %s\n", w.Name, good_tag)
} else {
log.Printf("[worker: %s] tag %s executed\n", w.Name, t.Tag) if !good_tag {
continue
}
// b) check that at least one of the accepted tag keys is in valid_keys
good_keys := intersect_keys(w.TagKeys[t.Tag], valid_keys) != nil
debug.log("[worker: %s] good_keys: %s\n", w.Name, good_keys)
if !good_keys {
continue
} }
}
// c) If everything is OK, execute the tag
if good_tag && good_keys {
errs := exec_tag(tag_cfg)
debug.log("[worker: %s] errors in tag %s: %s\n", w.Name, t.Tag, errs)
}
}
} }
//signature, signed, err := check_signature(commit, &w.Keys) //signature, signed, err := check_signature(commit, &w.Keys)

@ -1,62 +1,30 @@
-----BEGIN PGP PUBLIC KEY BLOCK----- -----BEGIN PGP PUBLIC KEY BLOCK-----
mQGiBEFi1/MRBADTOYQBLugy99OG588zPBaOhDPaCfeeB/XiMbMLdO6RzCCZtuU7 mQENBFltDTcBCAC+ngq5DpxpDMJEnQUsB9m1CNE8Em8Fox24FzFLvcUiC3Gf9w2c
e1G3I+8yIOLNUhfkmIT5Q7aU7FQA6OEexMvA3hijma7uLWs0GPGBC6U2XWEGVCcM Pmh6EJSwrEuwzqGIJ+VRPxB+uVBZ2IJvwgCuQ6N4itBVsuCjduhkDZafRvsX1Tuh
NNCVgZXv8JAEGdyWZmYBO+StYzp7tPhoujUMbY3ChPFes2IB1tlpJeYkuwCglKi6 6/DJiWcA/WYMtBJ8EacdxYMM8dwo4rt+8nffq1tZiDNzAfR5ezYnqi/ICmbdjVoA
ENT7n1pp0ZL02HyW7sUeFIED/3X1G6hKpcO12KXhdl70bI1ELBEoXW8S6E5+zN9v oR0BW/gmXbaxSDc/CIotU2Z7omBS+44qVI6W4fi9RnbwRSl8C0dp+FJQcfkYBnP7
bj/3SDVMMc99k7vmxd8MVhQviCuwHdX9115fiuUcb6atSdtbXMvCR729rlH+QfCA GDNKdIZKARCUFJUz++HLvKneRXi0y+fZeQ/w7uQ8BO1lNoxRep3TpfztqnpMHUmC
aEdJ5O784zcpaTaplRlSVhqbkqU0O0qs2Uwpzyq2YOmqOWaUoxWjaAEZ3MTinJ05 S02InQFdebJRmywR88q32WB747sQ9OXQYM/PABEBAAG0EFND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y27Wrf7UQGZexGBjLb
ppJcsm27hswBZwDdkubiHiA5VcxJIhk2SyBgvjSiwLa9nVsPpp8P1PlGH7e8ijTk
ynF2rI4+P9tGkskagHPbs7gLSbpfHDiex/U3p1V9ry6OsoIKcrZAx5do5PQi7iaz
JGXmPPu/XM9XR1+Gj9vCoxg56AHgAE9RAX6SH99ECtRLiCVbwGpVj98A0LRy7Nf9
SMX7gYhJBBgRAgAJBQJBYtf/AhsMAAoJEF8gs64LXwYvwWkAnAnoHai6n3a3WnM1
zIolhmQMfsj3AJ4i/olraFAACc1BCJESK6dVFiSvoQ==
=aSn2
-----END PGP PUBLIC KEY BLOCK----- -----END PGP PUBLIC KEY BLOCK-----

@ -19,6 +19,16 @@ w_tags:
## c_hash: "12da324fb76s924acbce" ## c_hash: "12da324fb76s924acbce"
} }
] ]
},
{
t_name: "build",
t_keyrings: ["allowed_users.asc"],
t_commands: [
{
c_url: "file:///home/katolaz/bin/scorsh_build.sh"
}
]
} }
] ]
... ...

@ -45,6 +45,7 @@ type SCORSHworker_cfg struct {
Tagfile string `yaml:"w_tagfile"` Tagfile string `yaml:"w_tagfile"`
Keyrings []string `yaml:"w_keyrings"` Keyrings []string `yaml:"w_keyrings"`
Tags []SCORSHtag_cfg `yaml:"w_tags"` Tags []SCORSHtag_cfg `yaml:"w_tags"`
TagKeys map[string]map[string]bool
} }
// State of a worker // State of a worker

@ -9,7 +9,6 @@ import (
"os" "os"
"regexp" "regexp"
"strings" "strings"
"time"
) )
func (worker *SCORSHworker) Matches(repo, branch string) bool { func (worker *SCORSHworker) Matches(repo, branch string) bool {
@ -96,9 +95,6 @@ func Worker(w *SCORSHworker) {
if err != nil { if err != nil {
log.Printf("[worker: %s] error in walk_commits: %s", err) log.Printf("[worker: %s] error in walk_commits: %s", err)
} }
debug.log("[worker: %s] Received message: %s", w.Name, msg)
debug.log("[worker: %s] StatusChan: %s\n", w.Name, w.StatusChan)
time.Sleep(1000 * time.Millisecond)
w.StatusChan <- msg w.StatusChan <- msg
debug.log("[worker: %s] Sent message back: %s", w.Name, msg) debug.log("[worker: %s] Sent message back: %s", w.Name, msg)
} }
@ -133,6 +129,16 @@ func StartWorkers(master *SCORSHmaster) error {
close(worker.MsgChan) close(worker.MsgChan)
return fmt.Errorf("[Starting worker: %s] Unable to load tags: %s\n", worker.Name, err) return fmt.Errorf("[Starting worker: %s] Unable to load tags: %s\n", worker.Name, err)
} }
// Create the map of keyring for each tag
worker.TagKeys = make(map[string]map[string]bool)
for _, t := range worker.Tags {
worker.TagKeys[t.Name] = make(map[string]bool)
for _, k := range t.Keyrings {
worker.TagKeys[t.Name][k] = true
}
}
// Add the repos definitions to the map master.Repos // Add the repos definitions to the map master.Repos
for _, repo_name := range worker.Repos { for _, repo_name := range worker.Repos {
master.Repos[repo_name] = append(master.Repos[repo_name], worker) master.Repos[repo_name] = append(master.Repos[repo_name], worker)

Loading…
Cancel
Save