-
Notifications
You must be signed in to change notification settings - Fork 48
/
explore.go
49 lines (40 loc) · 1.45 KB
/
explore.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
// +build !lambdabinary
package sparta
import (
"fmt"
"github.com/Sirupsen/logrus"
)
// Explore supports interactive command line invocation of the previously
// provisioned Sparta service
func Explore(lambdaAWSInfos []*LambdaAWSInfo, port int, logger *logrus.Logger) error {
validationErr := validateSpartaPreconditions(lambdaAWSInfos, logger)
if validationErr != nil {
return validationErr
}
if 0 == port {
port = 9999
}
urlHost := fmt.Sprintf("http://localhost:%d", port)
logger.Info("The following URLs are available for testing.")
msgText := ""
// Get unique paths
lambdaPaths := make(map[string]*LambdaAWSInfo, 0)
for _, eachLambdaInfo := range lambdaAWSInfos {
lambdaPaths[eachLambdaInfo.lambdaFnName] = eachLambdaInfo
}
for _, eachLambdaInfo := range lambdaPaths {
functionURL := fmt.Sprintf("%s/%s", urlHost, eachLambdaInfo.lambdaFnName)
logger.WithFields(logrus.Fields{
"URL": functionURL,
}).Info(eachLambdaInfo.lambdaFnName)
if msgText == "" {
msgText = fmt.Sprintf("\tcurl -vs -X POST -H \"Content-Type: application/json\" --data @testEvent.json %s", functionURL)
}
}
logger.Info("Functions can be invoked via application/json over POST")
logger.Info(msgText)
logger.Info("Where @testEvent.json is a local file with top level `context` and `event` properties:")
logger.Info("\t{\"context\": {}, \"event\": {}}")
// Start up the localhost server and publish the info
return Execute(lambdaAWSInfos, port, 0, logger)
}