forked from kyma-project/kyma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (35 loc) · 745 Bytes
/
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
package main
import (
"log"
"net/http"
"os"
)
func main() {
http.HandleFunc("/envs", envChecker)
log.Fatal(http.ListenAndServe(":8080", nil))
}
func envChecker(w http.ResponseWriter, r *http.Request) {
var (
envName = r.URL.Query().Get("name")
expEnvValue = r.URL.Query().Get("value")
)
if envName == "" {
http.Error(w, "Missing 'name' query param", http.StatusBadRequest)
return
}
if !isEnvVariableSetInOS(envName, expEnvValue) {
w.WriteHeader(http.StatusNotFound)
return
}
w.WriteHeader(http.StatusOK)
}
func isEnvVariableSetInOS(envName, expEnvValue string) bool {
osEnvValue, found := os.LookupEnv(envName)
if !found {
return false
}
if osEnvValue != expEnvValue {
return false
}
return true
}