@@ -21,14 +21,15 @@ import (
21
21
22
22
// UpStream creates upstream handler struct
23
23
type UpStream struct {
24
- Name string
25
- proxy http.Handler
24
+ Name string
25
+ proxy http.Handler
26
26
// TODO: Kick out separat config options and use more generic one
27
- allowed []* regexp.Regexp
28
- bindMounts []string
29
- devMappings []string
30
- gpu bool
31
- pinUser string
27
+ allowed []* regexp.Regexp
28
+ bindMounts []string
29
+ devMappings []string
30
+ gpu bool
31
+ pinUser string
32
+ pinUserEnabled bool
32
33
}
33
34
34
35
// UnixSocket just provides the path, so that I can test it
@@ -64,8 +65,27 @@ func newReverseProxy(dial func(network, addr string) (net.Conn, error)) *httputi
64
65
}
65
66
}
66
67
68
+ func NewUpstreamPO (po ProxyOptions ) * UpStream {
69
+ us := NewUnixSocket (po .ProxySocket )
70
+ a := []* regexp.Regexp {}
71
+ for _ , r := range po .Patterns {
72
+ p , _ := regexp .Compile (r )
73
+ a = append (a , p )
74
+ }
75
+ upstream := & UpStream {
76
+ Name : po .ProxySocket ,
77
+ proxy : newReverseProxy (us .connectSocket ),
78
+ allowed : a ,
79
+ bindMounts : po .BindMounts ,
80
+ devMappings : po .DevMappings ,
81
+ gpu : po .Gpu ,
82
+ pinUser : po .PinUser ,
83
+ pinUserEnabled : po .PinUserEnabled ,
84
+ }
85
+ return upstream
86
+ }
67
87
// NewUpstream returns a new socket (magic)
68
- func NewUpstream (socket string , regs []string , binds []string , devs []string , gpu bool , pinUser string ) * UpStream {
88
+ func NewUpstream (socket string , regs []string , binds []string , devs []string , gpu bool , pinUser string , pinUserB bool ) * UpStream {
69
89
us := NewUnixSocket (socket )
70
90
a := []* regexp.Regexp {}
71
91
for _ , r := range regs {
@@ -80,6 +100,7 @@ func NewUpstream(socket string, regs []string, binds []string, devs []string, gp
80
100
devMappings : devs ,
81
101
gpu : gpu ,
82
102
pinUser : pinUser ,
103
+ pinUserEnabled : pinUserB ,
83
104
}
84
105
return upstream
85
106
}
@@ -141,14 +162,20 @@ func (u *UpStream) ServeHTTP(w http.ResponseWriter, req *http.Request) {
141
162
config .Env = append (config .Env , "PATH=/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" )
142
163
config .Env = append (config .Env , "LD_LIBRARY_PATH=/usr/local/nvidia/" )
143
164
}
144
- if u .pinUser != "" {
165
+ if u .pinUserEnabled {
166
+ fmt .Print ("Alter User setting " )
145
167
// TODO: Should depend on calling user from syscall.GetsockoptUcred()
146
- if config .User != "" {
147
- fmt .Printf ("Overwrite User with '%s', was '%s'\n " , u .pinUser , config .User )
148
- } else {
149
- fmt .Printf ("Overwrite User with '%s'\n " , u .pinUser )
168
+ switch {
169
+ case config .User != "" && u .pinUser == "" :
170
+ fmt .Printf (" - Remove setting User, was '%s'\n " , config .User )
171
+ config .User = ""
172
+ case config .User != "" && u .pinUser != "" :
173
+ fmt .Printf (" - Overwrite User with '%s', was '%s'\n " , u .pinUser , config .User )
174
+ config .User = u .pinUser
175
+ default :
176
+ fmt .Printf (" - Set User to '%s'\n " , u .pinUser )
177
+ config .User = u .pinUser
150
178
}
151
- config .User = u .pinUser
152
179
}
153
180
for _ , bMount := range u .bindMounts {
154
181
if bMount == "" {
0 commit comments