tags are correctly authenticated

lint-refactor
KatolaZ 8 years ago
parent 95955f17a3
commit 37a6d33f46
  1. 3
      commits.go
  2. 6
      examples/scorsh_example.cfg
  3. 9
      examples/worker2/worker2.cfg
  4. 63
      workers.go

@ -57,7 +57,7 @@ func find_scorsh_message(commit *git.Commit) (string, error) {
return msg[idx:], nil return msg[idx:], nil
} }
// return a list of keyring names which verify the signature of this commit // return a list of keyring names which verify the signature of a given commit
func get_valid_keys(commit *git.Commit, keys *map[string]openpgp.KeyRing) []string { func get_valid_keys(commit *git.Commit, keys *map[string]openpgp.KeyRing) []string {
var ret []string var ret []string
@ -100,6 +100,7 @@ func exec_tag(tag *SCORSHtag_cfg) []error {
for _, c := range tag.Commands { for _, c := range tag.Commands {
debug.log("[tag: %s] attempting command: %s\n", tag.Name, c.URL) debug.log("[tag: %s] attempting command: %s\n", tag.Name, c.URL)
ret = append(ret, nil) ret = append(ret, nil)
} }
return ret return ret

@ -11,9 +11,6 @@ s_workers:
w_folder: ./worker1, w_folder: ./worker1,
w_logfile: ./worker1/worker1.log, w_logfile: ./worker1/worker1.log,
w_tagfile: "./worker1/worker1.cfg", w_tagfile: "./worker1/worker1.cfg",
w_keyrings: [
"./worker1/allowed_users.asc"
]
}, },
{ {
w_name: worker2, w_name: worker2,
@ -21,9 +18,6 @@ s_workers:
w_folder: ./worker2, w_folder: ./worker2,
w_logfile: ./worker2/worker2.log, w_logfile: ./worker2/worker2.log,
w_tagfile: "./worker2/worker2.cfg", w_tagfile: "./worker2/worker2.cfg",
w_keyrings: [
"./worker2/allowed_users.asc"
]
} }
] ]
... ...

@ -9,6 +9,15 @@ w_tags:
c_url: "file:///home/katolaz/bin/deploy.sh" c_url: "file:///home/katolaz/bin/deploy.sh"
} }
] ]
},
{
t_name: "build",
t_keyrings: ["allowed_users.asc"],
t_commands: [
{
c_url: "file:///home/katolaz/bin/scorsh_build.sh"
}
]
} }
] ]
... ...

@ -31,27 +31,38 @@ func (worker *SCORSHworker) Matches(repo, branch string) bool {
func (w *SCORSHworker) LoadKeyrings() error { func (w *SCORSHworker) LoadKeyrings() error {
w.Keys = make(map[string]openpgp.KeyRing, len(w.Keyrings)) w.Keys = make(map[string]openpgp.KeyRing, len(w.Keyrings))
w.TagKeys = make(map[string]map[string]bool)
// Open the keyring files for _, t := range w.Tags {
for _, keyring := range w.Keyrings { w.TagKeys[t.Name] = make(map[string]bool)
f, err_file := os.Open(keyring)
if err_file != nil { // Open the keyring files
log.Printf("[worker] cannot open keyring:", err_file) for _, keyring := range t.Keyrings {
f.Close() if _, ok := w.Keys[keyring]; ok {
return fmt.Errorf("Unable to open keyring: ", err_file) // keyring has been loaded: just add it to the TagKeys map
} w.TagKeys[t.Name][keyring] = true
continue
}
k_file := fmt.Sprintf("%s/%s", w.Folder, keyring)
debug.log("[worker: %s] Trying to open keyring at %s\n", w.Name, k_file)
f, err_file := os.Open(k_file)
if err_file != nil {
log.Printf("[worker] cannot open keyring: %s", err_file)
f.Close()
}
// load the keyring // load the keyring
kr, err_key := openpgp.ReadArmoredKeyRing(f) kr, err_key := openpgp.ReadArmoredKeyRing(f)
if err_key != nil { if err_key != nil {
log.Printf("[worker] cannot load keyring: ", err_key) log.Printf("[worker] cannot load keyring: %s", err_key)
f.Close()
//return fmt.Errorf("Unable to load keyring: ", err_key)
}
w.Keys[keyring] = kr
w.TagKeys[t.Name][keyring] = true
f.Close() f.Close()
return fmt.Errorf("Unable to load keyring: ", err_key)
} }
w.Keys[keyring] = kr
f.Close()
} }
return nil return nil
} }
@ -80,7 +91,6 @@ func Worker(w *SCORSHworker) {
var msg SCORSHmsg var msg SCORSHmsg
log.Printf("[worker: %s] Started\n", w.Name) log.Printf("[worker: %s] Started\n", w.Name)
debug.log("[worker: %s] MsgChan: %s\n", w.Name, w.MsgChan)
// notify that we have been started! // notify that we have been started!
w.StatusChan <- msg w.StatusChan <- msg
@ -117,26 +127,19 @@ func StartWorkers(master *SCORSHmaster) error {
// Set the Status and Msg channels // Set the Status and Msg channels
worker.StatusChan = master.StatusChan worker.StatusChan = master.StatusChan
worker.MsgChan = make(chan SCORSHmsg, 10) worker.MsgChan = make(chan SCORSHmsg, 10)
// Load worker keyrings
err := worker.LoadKeyrings()
if err != nil {
close(worker.MsgChan)
return fmt.Errorf("[Starting worker: %s] Unable to load keyrings: %s\n", worker.Name, err)
}
// Load worker tags from worker.Tagfile // Load worker tags from worker.Tagfile
err = worker.LoadTags() err := worker.LoadTags()
if err != nil { if err != nil {
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 // Load worker keyrings -- this must be called *after* LoadTags!!!!
worker.TagKeys = make(map[string]map[string]bool) err = worker.LoadKeyrings()
for _, t := range worker.Tags { if err != nil {
worker.TagKeys[t.Name] = make(map[string]bool) close(worker.MsgChan)
for _, k := range t.Keyrings { return fmt.Errorf("[Starting worker: %s] Unable to load keyrings: %s\n", worker.Name, err)
worker.TagKeys[t.Name][k] = true
}
} }
// Add the repos definitions to the map master.Repos // Add the repos definitions to the map master.Repos

Loading…
Cancel
Save