-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime_host_info.go
More file actions
68 lines (60 loc) · 1.51 KB
/
runtime_host_info.go
File metadata and controls
68 lines (60 loc) · 1.51 KB
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
package websession
import (
"log"
"os"
"strings"
"sync"
"github.com/borghives/kosmos-go"
)
type RutimeHostInfo struct {
kosmos.BaseModel `bson:",inline" kosmos:"hostinfo"`
BuildId string `bson:"build_id"`
ImageId string `bson:"image_id"`
AppName string `bson:"app_name"`
AppCommand string `bson:"app_command"`
EnvVars []string `bson:"env_vars"`
}
func getNonSecretEnvVars() []string {
envVars := []string{}
for _, env := range os.Environ() {
//exclude secrets
if !strings.HasPrefix(env, "CSRF_LATEST") &&
!strings.HasPrefix(env, "SESSION_LATEST") &&
!strings.HasPrefix(env, "SECRET_") &&
!strings.Contains(env, "SECRET") {
envVars = append(envVars, env)
}
}
return envVars
}
var (
hostinfo RutimeHostInfo
once sync.Once
)
func GetHostInfo() RutimeHostInfo {
once.Do(func() {
hostinfo = getHostInfo()
})
return hostinfo
}
func getHostInfo() RutimeHostInfo {
retval := RutimeHostInfo{
BuildId: os.Getenv("BUILD_ID"),
ImageId: os.Getenv("IMAGE_DIGEST"),
AppName: os.Getenv("APP_NAME"),
AppCommand: strings.Join(os.Args, " "),
EnvVars: getNonSecretEnvVars(),
}
retval.CollapseID()
return retval
}
func GetAllowedHosts() map[string]bool {
// Determine allowed hosts for HTTP service.
var allowedHosts = map[string]bool{}
envAllowHosts := CollapseConstants().AllowHosts
for host := range strings.SplitSeq(envAllowHosts, " ") {
allowedHosts[host] = true
log.Printf("Has allow host: %s", host)
}
return allowedHosts
}