-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
72 lines (59 loc) · 1.48 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"fmt"
"os"
"strconv"
"github.com/MichaelPalmer1/scoutr-go/pkg/config"
"github.com/MichaelPalmer1/scoutr-go/pkg/helpers"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
)
func list(event events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
// Convert log retention to int
logRetention, err := strconv.Atoi(os.Getenv("LogRetentionDays"))
if err != nil {
panic(err)
}
// Build config
config := config.Config{
DataTable: os.Getenv("DataTable"),
AuthTable: os.Getenv("AuthTable"),
AuditTable: os.Getenv("AuditTable"),
GroupTable: os.Getenv("GroupTable"),
LogRetentionDays: logRetention,
}
// Initialize api gateway
api, request := helpers.InitAPIGateway(event, config)
// List the data
data, err := api.List(request)
// Handle any errors
if errorResponse := helpers.APIGatewayErrorHandler(err); errorResponse != nil {
return *errorResponse, nil
}
// Send response
return helpers.ProcessAPIGatewayResponse(data)
}
func local() {
identity := events.APIGatewayRequestIdentity{
APIKeyID: "qtz1hy6j23",
SourceIP: "1.2.3.4",
UserAgent: "Fake",
}
context := events.APIGatewayProxyRequestContext{
Identity: identity,
}
event := events.APIGatewayProxyRequest{
Path: "/items",
HTTPMethod: "GET",
RequestContext: context,
}
resp, err := list(event)
if err != nil {
panic(err)
}
fmt.Println(resp)
}
func main() {
// local()
lambda.Start(list)
}