summaryrefslogtreecommitdiff
path: root/scorsh.go
blob: a5adbb80bf77c4915314861b08514f44e2140a4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package main

import (
	"errors"
	"golang.org/x/crypto/openpgp"
	"log"
	"os"
	"flag"
)

const (
	SCORSH_ERR_NO_FILE = -(1 << iota)
	SCORSH_ERR_KEYRING
	SCORSH_ERR_NO_REPO
	SCORSH_ERR_NO_COMMIT
	SCORSH_ERR_SIGNATURE
)

type SCORSHconf struct {
	spool string
}



type SCORSHmsg struct {
	repo    string
	branch  string
	old_rev string
	new_rev string
}

var conf_file = flag.String("c", "./scorsh.cfg", "Configuration file for SCORSH")



func SCORSHErr(err int) error {

	var err_str string

	switch err {
	case SCORSH_ERR_NO_FILE:
		err_str = "Invalid file name"
	case SCORSH_ERR_KEYRING:
		err_str = "Invalid keyring"
	case SCORSH_ERR_NO_REPO:
		err_str = "Invalid repository"
	case SCORSH_ERR_NO_COMMIT:
		err_str = "Invalid commit ID"
	case SCORSH_ERR_SIGNATURE:
		err_str = "Invalid signature"
	default:
		err_str = "Generic Error"
	}

	return errors.New(err_str)

}


func SCORSHWorker(keyring string, c_msg chan SCORSHmsg, c_status chan int) {

	// read the worker configuration file

	// Open the keyring file
	f, err := os.Open(keyring)
	defer f.Close()

	if err != nil {
		log.Printf("[worker] cannot open file %s\n", keyring)
		c_status <- SCORSH_ERR_NO_FILE
		return
	}

	// load the keyring
	kr, err := openpgp.ReadArmoredKeyRing(f)

	if err != nil {
		log.Printf("[worker] cannot open keyring %s\n", keyring)
		log.Printf("%s\n", err)
		c_status <- SCORSH_ERR_KEYRING
		return
	}

	// wait for messages from the  c_msg channel

	msg := <-c_msg

	// process message
	ret := walk_commits(msg, kr)

	c_status <- ret

}

func main() {

	flag.Parse()

	
	
	
}