forked from weaveworks/weave
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_exec_interceptor.go
44 lines (34 loc) · 1016 Bytes
/
create_exec_interceptor.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 proxy
import (
"net/http"
"strings"
)
type createExecInterceptor struct{ proxy *Proxy }
func (i *createExecInterceptor) InterceptRequest(r *http.Request) error {
options := jsonObject{}
if err := unmarshalRequestBody(r, &options); err != nil {
return err
}
container, err := inspectContainerInPath(i.proxy.client, r.URL.Path)
if err != nil {
return err
}
if _, hasWeaveWait := container.Volumes["/w"]; !hasWeaveWait {
return nil
}
cidrs, err := i.proxy.weaveCIDRs(container.HostConfig.NetworkMode, container.Config.Env)
if err != nil {
Log.Infof("Leaving container %s alone because %s", container.ID, err)
return nil
}
cmd, err := options.StringArray("Cmd")
if err != nil {
return err
}
Log.Infof("Exec in container %s with WEAVE_CIDR \"%s\"", container.ID, strings.Join(cidrs, " "))
options["Cmd"] = append(weaveWaitEntrypoint, cmd...)
return marshalRequestBody(r, options)
}
func (i *createExecInterceptor) InterceptResponse(r *http.Response) error {
return nil
}