-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
52 lines (44 loc) · 1.54 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
package main
import (
"errors"
"fmt"
"log"
"time"
"github.com/aws/aws-lambda-go/lambda"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/srkgupta/mattermost-vulnerability-metrics/lib"
)
func LambdaHandler() (string, error) {
// Validate Environment variables
err := lib.ValidateAndGetEnvVars()
if err != nil {
fmt.Printf("There was an error validating environment variables: %s", err.Error())
return "Unable to save response", errors.New("missing environment variables")
}
// Trigger Playbook Export
exportedData, err := lib.ExportPlaybookRuns(lib.GetPlaybookId())
if err != nil {
fmt.Printf("There was an error exporting playbook runs: %s", err.Error())
return "Unable to save response", errors.New("cant export playbooks")
}
// Upload to S3
sess := session.Must(session.NewSession(&aws.Config{}))
destination1 := fmt.Sprintf("audit/%s.csv", time.Now().UTC().Format("20060102150405"))
uploadedFile, sErr := lib.UploadS3File(sess, exportedData, destination1)
if sErr != nil {
log.Printf("There was an issue uploading to s3: %s\n", sErr.Error())
return "Unable to save response", errors.New("cant save response")
}
destination2 := "results/metrics.csv"
_, sErr = lib.UploadS3File(sess, exportedData, destination2)
if sErr != nil {
log.Printf("There was an issue uploading to s3: %s\n", sErr.Error())
return "Unable to save response", errors.New("cant save response")
}
log.Printf("Uploaded File: %s", uploadedFile)
return uploadedFile, nil
}
func main() {
lambda.Start(LambdaHandler)
}