Newer
Older
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
package handlers
import (
"encoding/json"
"log"
"net/http"
"github.com/openfaas/faas/gateway/types"
"github.com/openfaas/faas/gateway/version"
)
// MakeInfoHandler is responsible for display component version information
func MakeInfoHandler(h http.Handler) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
sw := types.NewStringResponseWriter()
h.ServeHTTP(sw, r)
log.Printf("Body: %s", sw.Body())
provider := make(map[string]interface{})
providerVersion := &types.VersionInfo{}
err := json.Unmarshal(sw.Body(), &provider)
if err != nil {
log.Printf("Error unmarshalling provider json. Got %s. Error %s\n", string(sw.Body()), err.Error())
}
versionMap := provider["version"].(map[string]interface{})
providerVersion.SHA = versionMap["sha"].(string)
providerVersion.Release = versionMap["release"].(string)
gatewayInfo := &types.GatewayInfo{
Version: &types.VersionInfo{
CommitMessage: version.GitCommitMessage,
Release: version.BuildVersion(),
SHA: version.GitCommitSHA,
},
Provider: &types.ProviderInfo{
Version: providerVersion,
Name: provider["provider"].(string),
Orchestration: provider["orchestration"].(string),
},
}
jsonOut, marshalErr := json.Marshal(gatewayInfo)
if marshalErr != nil {
log.Printf("Error during unmarshal of gateway info request %s\n", marshalErr.Error())
w.WriteHeader(http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write(jsonOut)
}
}