@@ -21,14 +21,15 @@ import (
2121
2222// UpStream creates upstream handler struct
2323type UpStream struct {
24- Name string
25- proxy http.Handler
24+ Name string
25+ proxy http.Handler
2626 // 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
3233}
3334
3435// 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
6465 }
6566}
6667
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+ }
6787// 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 {
6989 us := NewUnixSocket (socket )
7090 a := []* regexp.Regexp {}
7191 for _ , r := range regs {
@@ -80,6 +100,7 @@ func NewUpstream(socket string, regs []string, binds []string, devs []string, gp
80100 devMappings : devs ,
81101 gpu : gpu ,
82102 pinUser : pinUser ,
103+ pinUserEnabled : pinUserB ,
83104 }
84105 return upstream
85106}
@@ -141,14 +162,20 @@ func (u *UpStream) ServeHTTP(w http.ResponseWriter, req *http.Request) {
141162 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" )
142163 config .Env = append (config .Env , "LD_LIBRARY_PATH=/usr/local/nvidia/" )
143164 }
144- if u .pinUser != "" {
165+ if u .pinUserEnabled {
166+ fmt .Print ("Alter User setting " )
145167 // 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
150178 }
151- config .User = u .pinUser
152179 }
153180 for _ , bMount := range u .bindMounts {
154181 if bMount == "" {
0 commit comments