-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
54 lines (44 loc) · 1.05 KB
/
main.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
51
52
53
54
package main
import (
"fmt"
"time"
"github.com/aws/aws-lambda-go/lambda"
"github.com/ninthsun91/SyncGithubToFibery/request"
"github.com/ninthsun91/SyncGithubToFibery/utils"
)
type LambdaEvent struct {
Body string `json:"body"`
Headers map[string]string `json:"headers"`
}
func HandleRequest(event *LambdaEvent) (*string, error) {
signature := event.Headers["x-hub-signature-256"]
if !utils.VerifySignature(signature, event.Body) {
fmt.Println("invalid signature")
return nil, fmt.Errorf("invalid signature")
}
err := request.Sync()
if err != nil {
return nil, err
}
fmt.Println("sync started")
check := true
for check {
resp, err := request.Status()
if err != nil {
fmt.Println("error getting status", err)
check = false
return nil, err
}
if resp.State != request.IN_PROGRESS {
check = false
fmt.Println("sync completed")
return &resp.Message, nil
}
fmt.Println("sync in progress")
time.Sleep(time.Second * 5)
}
return nil, fmt.Errorf("unknown error")
}
func main() {
lambda.Start(HandleRequest)
}