Skip to content

Commit 5520986

Browse files
committed
polish
1 parent d8c79e0 commit 5520986

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

cmd/docker-socket-firewall/main.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import (
66
"context"
77
"flag"
88
"github.com/docker/go-connections/sockets"
9+
"github.com/linead/docker-socket-firewall/pkg/opa"
10+
"github.com/pkg/errors"
11+
log "github.com/sirupsen/logrus"
912
"golang.org/x/net/context/ctxhttp"
1013
"io"
1114
"io/ioutil"
@@ -15,9 +18,6 @@ import (
1518
"os"
1619
"regexp"
1720
"time"
18-
"github.com/linead/docker-socket-firewall/pkg/opa"
19-
"github.com/pkg/errors"
20-
log "github.com/sirupsen/logrus"
2121
)
2222

2323
var opaHandler opa.DockerHandler
@@ -41,9 +41,9 @@ func serveReverseProxy(w http.ResponseWriter, req *http.Request) {
4141
req.RequestURI = ""
4242
req.Close = true
4343

44-
if ( req.Header.Get("Connection") == "Upgrade") {
45-
if ( req.Header.Get("Upgrade") != "tcp" && req.Header.Get("Upgrade") != "h2c" ) {
46-
http.Error(w, "Unsupported upgrade protocol: " + req.Header.Get("Protocol"), http.StatusInternalServerError)
44+
if req.Header.Get("Connection") == "Upgrade" {
45+
if req.Header.Get("Upgrade") != "tcp" && req.Header.Get("Upgrade") != "h2c" {
46+
http.Error(w, "Unsupported upgrade protocol: "+req.Header.Get("Protocol"), http.StatusInternalServerError)
4747
return
4848
}
4949
log.Debug("Connection upgrading")
@@ -112,7 +112,7 @@ func hijack(req *http.Request, w http.ResponseWriter) {
112112
return
113113
}
114114

115-
if(br.Buffered() > 0) {
115+
if br.Buffered() > 0 {
116116
log.Debugf("Found buffered bytes")
117117
var bs = make([]byte, br.Buffered())
118118
br.Read(bs)
@@ -126,7 +126,7 @@ func hijack(req *http.Request, w http.ResponseWriter) {
126126
log.Debugf("%s Streaming connections", desc)
127127
written, err := copyBuffer(dst, src)
128128
log.Debugf("%s wrote %v, err: %v", desc, written, err)
129-
errc<-err
129+
errc <- err
130130
}
131131

132132
go streamFn(outConn, c, errClient, "docker -> client")

pkg/opa/opa.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
log "github.com/sirupsen/logrus"
1818
)
1919

20+
//DockerHandler validates either a regular request or a build request (with supplied dockerfile)
2021
type DockerHandler interface {
2122
ValidateRequest(r *http.Request) (bool, error)
2223
ValidateDockerFile(r *http.Request, dockerFile string) (bool, error)
@@ -31,13 +32,6 @@ type DockerOpaHandler struct {
3132
const authAllowPath string = "data.docker.authz.allow"
3233
const buildAllowPath string = "data.docker.build.allow"
3334

34-
//// NewDockerOpaHandler constructs the
35-
//func NewDockerOpaHandler(pPolicy string, dPolicy string) *DockerOpaHandler {
36-
// return &DockerOpaHandler{
37-
// ProxyPolicyFile: pPolicy,
38-
// DockerfilePolicyFile: dPolicy,
39-
// }
40-
//}
4135

4236
// ValidateRequest validates a standard docker request (not build)
4337
// verifies against the ProxyPolicyFile using the path data.docker.authz.allow

0 commit comments

Comments
 (0)