forked from aws/aws-lambda-runtime-interface-emulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
restoreHandler.go
58 lines (45 loc) · 1.56 KB
/
restoreHandler.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
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package standalone
import (
"encoding/json"
"net/http"
"strconv"
"time"
log "github.com/sirupsen/logrus"
"github.com/rymurr/aws-lambda-runtime-interface-emulator/lambda/interop"
)
type RestoreBody struct {
AwsKey string `json:"awskey"`
AwsSecret string `json:"awssecret"`
AwsSession string `json:"awssession"`
CredentialsExpiry time.Time `json:"credentialsExpiry"`
RestoreHookTimeoutMs int64 `json:"restoreHookTimeoutMs"`
}
func RestoreHandler(w http.ResponseWriter, r *http.Request, s InteropServer) {
restoreRequest := RestoreBody{}
if lerr := readBodyAndUnmarshalJSON(r, &restoreRequest); lerr != nil {
lerr.Send(w, r)
return
}
restore := &interop.Restore{
AwsKey: restoreRequest.AwsKey,
AwsSecret: restoreRequest.AwsSecret,
AwsSession: restoreRequest.AwsSession,
CredentialsExpiry: restoreRequest.CredentialsExpiry,
RestoreHookTimeoutMs: restoreRequest.RestoreHookTimeoutMs,
}
restoreResult, err := s.Restore(restore)
responseMap := make(map[string]string)
responseMap["restoreMs"] = strconv.FormatInt(restoreResult.RestoreMs, 10)
if err != nil {
log.Errorf("Failed to restore: %s", err)
responseMap["restoreError"] = err.Error()
w.WriteHeader(http.StatusBadGateway)
}
responseJSON, err := json.Marshal(responseMap)
if err != nil {
log.Panicf("Cannot marshal the response map for RESTORE, %v", responseMap)
}
w.Write(responseJSON)
}