MCPcopy
hub / github.com/yusing/godoxy / NewHandler

Function NewHandler

socket-proxy/pkg/handler.go:48–186  ·  view source on GitHub ↗

ref: https://github.com/Tecnativa/docker-socket-proxy/blob/master/haproxy.cfg

()

Source from the content-addressed store, hash-verified

46
47// ref: https://github.com/Tecnativa/docker-socket-proxy/blob/master/haproxy.cfg
48func NewHandler() http.Handler {
49 r := mux.NewRouter()
50 socketHandler := DockerSocketHandler(DockerSocket)
51
52 const apiVersionPrefix = `/{version:(?:v[\d\.]+)?}`
53 const containerPath = "/containers/{id:[a-zA-Z0-9_.-]+}"
54
55 allowedPaths := []string{}
56 deniedPaths := []string{}
57
58 if DockerContainers {
59 allowedPaths = append(allowedPaths, "/containers")
60 if !DockerRestarts {
61 deniedPaths = append(deniedPaths, containerPath+"/stop")
62 deniedPaths = append(deniedPaths, containerPath+"/restart")
63 deniedPaths = append(deniedPaths, containerPath+"/kill")
64 }
65 if !DockerStart {
66 deniedPaths = append(deniedPaths, containerPath+"/start")
67 }
68 if !DockerStop && DockerRestarts {
69 deniedPaths = append(deniedPaths, containerPath+"/stop")
70 }
71 }
72 if DockerAuth {
73 allowedPaths = append(allowedPaths, "/auth")
74 }
75 if DockerBuild {
76 allowedPaths = append(allowedPaths, "/build")
77 }
78 if DockerCommit {
79 allowedPaths = append(allowedPaths, "/commit")
80 }
81 if DockerConfigs {
82 allowedPaths = append(allowedPaths, "/configs")
83 }
84 if DockerDistribution {
85 allowedPaths = append(allowedPaths, "/distribution")
86 }
87 if DockerEvents {
88 allowedPaths = append(allowedPaths, "/events")
89 }
90 if DockerExec {
91 allowedPaths = append(allowedPaths, "/exec")
92 }
93 if DockerGrpc {
94 allowedPaths = append(allowedPaths, "/grpc")
95 }
96 if DockerImages {
97 allowedPaths = append(allowedPaths, "/images")
98 }
99 if DockerInfo {
100 allowedPaths = append(allowedPaths, "/info")
101 }
102 if DockerNetworks {
103 allowedPaths = append(allowedPaths, "/networks")
104 }
105 if DockerNodes {

Calls 3

ServeHTTPMethod · 0.65
HandleFuncMethod · 0.45
ErrorMethod · 0.45

Tested by 3

TestNewDockerHandlerFunction · 0.56