/
source.go
50 lines (40 loc) · 969 Bytes
/
source.go
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
package jenkins
import (
"encoding/json"
"github.com/ImpactInsights/valuestream/eventsources"
"github.com/opentracing/opentracing-go"
"github.com/urfave/cli"
"io/ioutil"
"net/http"
)
const (
sourceName string = "jenkins"
)
type Source struct {
tracer opentracing.Tracer
}
func (s Source) Name() string {
return sourceName
}
func (s *Source) Tracer() opentracing.Tracer {
return s.tracer
}
func (s *Source) Event(r *http.Request, payload []byte) (eventsources.Event, error) {
var be BuildEvent
err := json.Unmarshal(payload, &be)
return be, err
}
func (s *Source) SecretKey() []byte {
return nil
}
func (s *Source) ValidatePayload(r *http.Request, secretKey []byte) ([]byte, error) {
return ioutil.ReadAll(r.Body)
}
func NewSource(tracer opentracing.Tracer) (*Source, error) {
return &Source{
tracer: tracer,
}, nil
}
func NewFromCLI(c *cli.Context, tracer opentracing.Tracer) (eventsources.EventSource, error) {
return NewSource(tracer)
}