diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4effa451..02f25e0d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,7 +14,7 @@ jobs: - name: Setup Golang uses: actions/setup-go@v3 with: - go-version: ~1.21.5 + go-version: ~1.21.6 - uses: actions/cache@v3 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9e12797f..f79ca457 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,7 +13,7 @@ jobs: - name: Setup Golang uses: actions/setup-go@v3 with: - go-version: ~1.21.5 + go-version: ~1.21.6 - uses: actions/cache@v3 with: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 61f37fed..ed14f0be 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,7 @@ jobs: - name: Setup Golang uses: actions/setup-go@v3 with: - go-version: ~1.21.5 + go-version: ~1.21.6 - uses: actions/cache@v3 with: diff --git a/ci/build.sh b/ci/build.sh index 3514c1f7..89e4ddf5 100755 --- a/ci/build.sh +++ b/ci/build.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -e + export GO111MODULE="on" go install github.com/mitchellh/gox@latest # cross compile CGO_ENABLED=0 gox -os "linux darwin windows" -arch "amd64" -osarch="darwin/arm64" -osarch="darwin/arm64" -osarch="linux/arm64" -osarch="windows/386" -output "dist/{{.Dir}}_{{.OS}}_{{.Arch}}" -ldflags "-X main.buildStamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X main.gitRevision=`git describe --tags || git rev-parse HEAD` -s -w" diff --git a/ci/test.sh b/ci/test.sh index 54dbccd7..796a126b 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -1,7 +1,9 @@ #!/bin/bash +set -e + export GO111MODULE="on" -go test -tags 's3 metadata' -v -race -coverprofile=coverage.txt -covermode=atomic -coverpkg github.com/aerokube/selenoid,github.com/aerokube/selenoid/session,github.com/aerokube/selenoid/config,github.com/aerokube/selenoid/protect,github.com/aerokube/selenoid/service,github.com/aerokube/selenoid/upload +go test -tags 's3 metadata' -v -race -coverprofile=coverage.txt -covermode=atomic -coverpkg github.com/aerokube/selenoid,github.com/aerokube/selenoid/session,github.com/aerokube/selenoid/config,github.com/aerokube/selenoid/protect,github.com/aerokube/selenoid/service,github.com/aerokube/selenoid/upload,github.com/aerokube/selenoid/info,github.com/aerokube/selenoid/jsonerror go install golang.org/x/vuln/cmd/govulncheck@latest "$(go env GOPATH)"/bin/govulncheck -tags production ./... diff --git a/go.mod b/go.mod index 1fb44132..7b9ffd5c 100644 --- a/go.mod +++ b/go.mod @@ -3,32 +3,46 @@ module github.com/aerokube/selenoid go 1.21 require ( - github.com/aerokube/ggr v0.0.0-20221124163939-c041f40a7e45 - github.com/aerokube/util v1.0.1 - github.com/aws/aws-sdk-go v1.44.197 - github.com/docker/docker v24.0.7+incompatible - github.com/docker/go-connections v0.4.0 + github.com/aerokube/ggr v0.0.0-20240109084922-a37629b63e72 + github.com/aws/aws-sdk-go v1.50.3 + github.com/docker/docker v25.0.1+incompatible + github.com/docker/go-connections v0.5.0 github.com/docker/go-units v0.5.0 - github.com/google/uuid v1.5.0 - github.com/gorilla/websocket v1.5.0 + github.com/google/uuid v1.6.0 + github.com/gorilla/websocket v1.5.1 github.com/imdario/mergo v0.3.13 - github.com/mafredri/cdp v0.33.0 + github.com/mafredri/cdp v0.34.1 github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.8.4 - golang.org/x/net v0.17.0 + golang.org/x/net v0.20.0 ) require ( + github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect github.com/Microsoft/go-winio v0.6.1 // indirect + github.com/containerd/log v0.1.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/docker/distribution v2.8.2+incompatible // indirect + github.com/distribution/reference v0.5.0 // indirect + github.com/felixge/httpsnoop v1.0.4 // indirect + github.com/go-logr/logr v1.4.1 // indirect + github.com/go-logr/stdr v1.2.2 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect + github.com/moby/term v0.5.0 // indirect + github.com/morikuni/aec v1.0.0 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect github.com/opencontainers/image-spec v1.0.2 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/mod v0.10.0 // indirect - golang.org/x/sys v0.13.0 // indirect - golang.org/x/tools v0.9.1 // indirect + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.47.0 // indirect + go.opentelemetry.io/otel v1.22.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.22.0 // indirect + go.opentelemetry.io/otel/metric v1.22.0 // indirect + go.opentelemetry.io/otel/sdk v1.22.0 // indirect + go.opentelemetry.io/otel/trace v1.22.0 // indirect + golang.org/x/mod v0.14.0 // indirect + golang.org/x/sys v0.16.0 // indirect + golang.org/x/time v0.5.0 // indirect + golang.org/x/tools v0.17.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect + gotest.tools/v3 v3.5.1 // indirect ) diff --git a/go.sum b/go.sum index 708c8e4b..fa9563b3 100644 --- a/go.sum +++ b/go.sum @@ -2,28 +2,35 @@ github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25 github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= -github.com/aandryashin/matchers v0.0.0-20161126170413-435295ea180e h1:ogUKYFNcdYUIBSLibE4+EjbTJazoHr5JsWWx21Lpn8c= -github.com/aandryashin/matchers v0.0.0-20161126170413-435295ea180e/go.mod h1:cbmYNkm9xeQlNoWEPtOUcvNok2gSD7ErMnYkRW+eHi8= -github.com/aerokube/ggr v0.0.0-20221124163939-c041f40a7e45 h1:c5tRxpN9LcoV/6rv69SXrNzT0EiXYNtufsqM8M7Gauc= -github.com/aerokube/ggr v0.0.0-20221124163939-c041f40a7e45/go.mod h1:ihsnG0Nf22lmjMKqK43xP2Iom8jnnD0oz9PkeWcRhNY= -github.com/aerokube/util v1.0.1 h1:AgZ4KyFIRHB6B7k4ypMXPYAv7TcjlhOHg7JDsqERc04= -github.com/aerokube/util v1.0.1/go.mod h1:rCvfLQKS1FYa4Jj1S7XTZF63jdPkld82FrcR0V2MRc0= -github.com/aws/aws-sdk-go v1.44.197 h1:pkg/NZsov9v/CawQWy+qWVzJMIZRQypCtYjUBXFomF8= -github.com/aws/aws-sdk-go v1.44.197/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= +github.com/aerokube/ggr v0.0.0-20240109084922-a37629b63e72 h1:qEvnGebmcJLlz3fi12Lkm7/Zs/bGRvTZAM2la4jDIJo= +github.com/aerokube/ggr v0.0.0-20240109084922-a37629b63e72/go.mod h1:sUiJLMjwnDBLwD6zVKz1LSgNaDkoc7hx55sMJiTt2bk= +github.com/aws/aws-sdk-go v1.50.3 h1:NnXC/ukOakZbBwQcwAzkAXYEB4SbWboP9TFx9vvhIrE= +github.com/aws/aws-sdk-go v1.50.3/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= +github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= +github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I= +github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/docker/distribution v2.8.2+incompatible h1:T3de5rq0dB1j30rp0sA2rER+m322EBzniBPB6ZIzuh8= -github.com/docker/distribution v2.8.2+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= -github.com/docker/docker v24.0.7+incompatible h1:Wo6l37AuwP3JaMnZa226lzVXGA3F9Ig1seQen0cKYlM= -github.com/docker/docker v24.0.7+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= -github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= -github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= +github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0= +github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= +github.com/docker/docker v25.0.1+incompatible h1:k5TYd5rIVQRSqcTwCID+cyVA0yRg86+Pcrz1ls0/frA= +github.com/docker/docker v25.0.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c= +github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc= github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= +github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= +github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= +github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= @@ -35,16 +42,21 @@ github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU= -github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= -github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= +github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 h1:YBftPWNWd4WwGqtY2yeZL2ef8rHAxPBD8KFhJpmcqms= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0/go.mod h1:YN5jB8ie0yfIUg6VvR9Kz84aCaG7AsGZnLjhHbUqwPg= github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk= github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg= github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= @@ -57,8 +69,8 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o github.com/klauspost/compress v1.10.3 h1:OP96hzwJVBIHYU52pVTI6CczrxPvrGfgqF9N5eTO0Q8= github.com/klauspost/compress v1.10.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= -github.com/mafredri/cdp v0.33.0 h1:McuQjNe0DyctTUxt8zY6jGTlpPoy2gciqxtvKhz0XPM= -github.com/mafredri/cdp v0.33.0/go.mod h1:Dbsh7eY/zhQlsddEDWzZGOztv9Jf2gzKq47M7a2P3C4= +github.com/mafredri/cdp v0.34.1 h1:EeLNc+6pkDx2hrAm1arIjiofoH0fM5On1uAFzcuUn+o= +github.com/mafredri/cdp v0.34.1/go.mod h1:Dbsh7eY/zhQlsddEDWzZGOztv9Jf2gzKq47M7a2P3C4= github.com/mafredri/go-lint v0.0.0-20180911205320-920981dfc79e/go.mod h1:k/zdyxI3q6dup24o8xpYjJKTCf2F7rfxLp6w/efTiWs= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0= @@ -75,6 +87,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= +github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= @@ -84,71 +98,78 @@ github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVM github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.47.0 h1:sv9kVfal0MK0wBMCOGr+HeJm9v803BkJxGrk2au7j08= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.47.0/go.mod h1:SK2UL73Zy1quvRPonmOmRDiWk1KBV3LyIeeIxcEApWw= +go.opentelemetry.io/otel v1.22.0 h1:xS7Ku+7yTFvDfDraDIJVpw7XPyuHlB9MCiqqX5mcJ6Y= +go.opentelemetry.io/otel v1.22.0/go.mod h1:eoV4iAi3Ea8LkAEI9+GFT44O6T/D0GWAVFyZVCC6pMI= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.22.0 h1:9M3+rhx7kZCIQQhQRYaZCdNu1V73tm4TvXs2ntl98C4= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.22.0/go.mod h1:noq80iT8rrHP1SfybmPiRGc9dc5M8RPmGvtwo7Oo7tc= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.22.0 h1:FyjCyI9jVEfqhUh2MoSkmolPjfh5fp2hnV0b0irxH4Q= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.22.0/go.mod h1:hYwym2nDEeZfG/motx0p7L7J1N1vyzIThemQsb4g2qY= +go.opentelemetry.io/otel/metric v1.22.0 h1:lypMQnGyJYeuYPhOM/bgjbFM6WE44W1/T45er4d8Hhg= +go.opentelemetry.io/otel/metric v1.22.0/go.mod h1:evJGjVpZv0mQ5QBRJoBF64yMuOf4xCWdXjK8pzFvliY= +go.opentelemetry.io/otel/sdk v1.22.0 h1:6coWHw9xw7EfClIC/+O31R8IY3/+EiRFHevmHafB2Gw= +go.opentelemetry.io/otel/sdk v1.22.0/go.mod h1:iu7luyVGYovrRpe2fmj3CVKouQNdTOkxtLzPvPz1DOc= +go.opentelemetry.io/otel/trace v1.22.0 h1:Hg6pPujv0XG9QaVbGOBVHunyuLcCC3jN7WEhPx83XD0= +go.opentelemetry.io/otel/trace v1.22.0/go.mod h1:RbbHXVqKES9QhzZq/fE5UnOSILqRt40a21sPw2He1xo= +go.opentelemetry.io/proto/otlp v1.0.0 h1:T0TX0tmXU8a3CbNXzEKGeU5mIVOdf0oykP+u2lIVU/I= +go.opentelemetry.io/proto/otlp v1.0.0/go.mod h1:Sy6pihPLfYHkr3NkUbEhGHFhINUSI/v80hjKIs5JXpM= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk= -golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0= +golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= -golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= -golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= +golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI= -golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= +golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210319071255-635bc2c9138d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= +golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= -golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= +golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.9.1 h1:8WMNJAz3zrtPmnYC7ISf5dEn3MT0gY7jBJfw27yrrLo= -golang.org/x/tools v0.9.1/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc= +golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc= +golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/genproto/googleapis/api v0.0.0-20231002182017-d307bd883b97 h1:W18sezcAYs+3tDZX4F80yctqa12jcP1PUS2gQu1zTPU= +google.golang.org/genproto/googleapis/api v0.0.0-20231002182017-d307bd883b97/go.mod h1:iargEX0SFPm3xcfMI0d1domjg0ZF4Aa0p2awqyxhvF0= +google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97 h1:6GQBEOdGkX6MMTLT9V+TjtIRZCw9VPD5Z+yHY9wMgS0= +google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97/go.mod h1:v7nGkzlmW8P3n/bKmWBn2WpBjpOEx8Q6gMueudAmKfY= +google.golang.org/grpc v1.60.1 h1:26+wFr+cNqSGFcOXcabYC0lUVJVRa2Sb2ortSK7VrEU= +google.golang.org/grpc v1.60.1/go.mod h1:OlCHIeLYqSSsLi6i49B5QGdzaMZK9+M7LXN2FKz4eGM= +google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= +google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= @@ -157,7 +178,7 @@ gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o= -gotest.tools/v3 v3.4.0/go.mod h1:CtbdzLSsqVhDgMtKsx03ird5YTGB3ar27v0u/yKBW5g= +gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU= +gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU= nhooyr.io/websocket v1.8.7 h1:usjR2uOr/zjjkVMy0lW+PPohFok7PCow5sDjLgX4P4g= nhooyr.io/websocket v1.8.7/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0= diff --git a/info/info.go b/info/info.go new file mode 100644 index 00000000..868471ea --- /dev/null +++ b/info/info.go @@ -0,0 +1,27 @@ +package info + +import ( + "net" + "net/http" + "time" +) + +func RequestInfo(r *http.Request) (string, string) { + const unknownUser = "unknown" + user := "" + if u, _, ok := r.BasicAuth(); ok { + user = u + } else { + user = unknownUser + } + remote := r.Header.Get("X-Forwarded-For") + if remote != "" { + return user, remote + } + remote, _, _ = net.SplitHostPort(r.RemoteAddr) + return user, remote +} + +func SecondsSince(start time.Time) float64 { + return time.Now().Sub(start).Seconds() +} diff --git a/main.go b/main.go index 9759211b..a4c0e9dc 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,8 @@ import ( "encoding/json" "flag" "fmt" + "github.com/aerokube/selenoid/info" + "github.com/docker/docker/api" "log" "net" "net/http" @@ -24,8 +26,6 @@ import ( "github.com/aerokube/selenoid/service" "github.com/aerokube/selenoid/session" "github.com/aerokube/selenoid/upload" - "github.com/aerokube/util" - "github.com/aerokube/util/docker" "github.com/docker/docker/client" "github.com/pkg/errors" "golang.org/x/net/websocket" @@ -187,7 +187,7 @@ func init() { } ip, _, _ := net.SplitHostPort(u.Host) environment.IP = ip - cli, err = docker.CreateCompatibleDockerClient( + cli, err = createCompatibleDockerClient( func(specifiedApiVersion string) { log.Printf("[-] [INIT] [Using Docker API version: %s]", specifiedApiVersion) }, @@ -204,6 +204,57 @@ func init() { manager = &service.DefaultManager{Environment: &environment, Client: cli, Config: conf} } +func createCompatibleDockerClient(onVersionSpecified, onVersionDetermined, onUsingDefaultVersion func(string)) (*client.Client, error) { + const dockerApiVersion = "DOCKER_API_VERSION" + dockerApiVersionEnv := os.Getenv(dockerApiVersion) + if dockerApiVersionEnv != "" { + onVersionSpecified(dockerApiVersionEnv) + } else { + maxMajorVersion, maxMinorVersion := parseVersion(api.DefaultVersion) + minMajorVersion, minMinorVersion := parseVersion("1.24") + for majorVersion := maxMajorVersion; majorVersion >= minMajorVersion; majorVersion-- { + for minorVersion := maxMinorVersion; minorVersion >= minMinorVersion; minorVersion-- { + apiVersion := fmt.Sprintf("%d.%d", majorVersion, minorVersion) + _ = os.Setenv(dockerApiVersion, apiVersion) + docker, err := client.NewClientWithOpts(client.FromEnv) + if err != nil { + return nil, err + } + if isDockerAPIVersionCorrect(docker) { + onVersionDetermined(apiVersion) + return docker, nil + } + _ = docker.Close() + } + } + onUsingDefaultVersion(api.DefaultVersion) + } + return client.NewClientWithOpts(client.FromEnv) +} + +func parseVersion(ver string) (int, int) { + const point = "." + pieces := strings.Split(ver, point) + major, err := strconv.Atoi(pieces[0]) + if err != nil { + return 0, 0 + } + minor, err := strconv.Atoi(pieces[1]) + if err != nil { + return 0, 0 + } + return major, minor +} + +func isDockerAPIVersionCorrect(docker *client.Client) bool { + ctx := context.Background() + apiInfo, err := docker.ServerVersion(ctx) + if err != nil { + return false + } + return apiInfo.APIVersion == docker.ClientVersion() +} + func parseGgrHost(s string) *ggr.Host { h, p, err := net.SplitHostPort(s) if err != nil { @@ -260,7 +311,7 @@ func post(next http.HandlerFunc) http.HandlerFunc { func ping(w http.ResponseWriter, _ *http.Request) { w.Header().Add("Content-Type", "application/json") - json.NewEncoder(w).Encode(struct { + _ = json.NewEncoder(w).Encode(struct { Uptime string `json:"uptime"` LastReloadTime string `json:"lastReloadTime"` NumRequests uint64 `json:"numRequests"` @@ -274,7 +325,7 @@ func video(w http.ResponseWriter, r *http.Request) { deleteFileIfExists(requestId, w, r, videoOutputDir, paths.Video, "DELETED_VIDEO_FILE") return } - user, remote := util.RequestInfo(r) + user, remote := info.RequestInfo(r) if _, ok := r.URL.Query()[jsonParam]; ok { listFilesAsJson(requestId, w, videoOutputDir, "VIDEO_ERROR") return @@ -285,7 +336,7 @@ func video(w http.ResponseWriter, r *http.Request) { } func deleteFileIfExists(requestId uint64, w http.ResponseWriter, r *http.Request, dir string, prefix string, status string) { - user, remote := util.RequestInfo(r) + user, remote := info.RequestInfo(r) fileName := strings.TrimPrefix(r.URL.Path, prefix) filePath := filepath.Join(dir, fileName) _, err := os.Stat(filePath) @@ -332,7 +383,7 @@ func handler() http.Handler { }) root.HandleFunc(paths.Status, func(w http.ResponseWriter, r *http.Request) { w.Header().Add("Content-Type", "application/json") - json.NewEncoder(w).Encode(conf.State(sessions, limit, queue.Queued(), queue.Pending())) + _ = json.NewEncoder(w).Encode(conf.State(sessions, limit, queue.Queued(), queue.Pending())) }) root.HandleFunc(paths.Ping, ping) root.Handle(paths.VNC, websocket.Handler(vnc)) @@ -383,7 +434,7 @@ func main() { sessions.Each(func(k string, s *session.Session) { if enableFileUpload { - os.RemoveAll(path.Join(os.TempDir(), k)) + _ = os.RemoveAll(path.Join(os.TempDir(), k)) } s.Cancel() }) diff --git a/protect/queue.go b/protect/queue.go index d6c3f28c..53c75893 100644 --- a/protect/queue.go +++ b/protect/queue.go @@ -2,13 +2,13 @@ package protect import ( "errors" + "github.com/aerokube/selenoid/info" "log" "math" "net/http" "time" "github.com/aerokube/selenoid/jsonerror" - "github.com/aerokube/util" ) // Queue - struct to hold a number of sessions @@ -47,9 +47,9 @@ func (q *Queue) Check(next http.HandlerFunc) http.HandlerFunc { <-q.limit default: if q.disabled { - user, remote := util.RequestInfo(r) + user, remote := info.RequestInfo(r) log.Printf("[-] [QUEUE_IS_FULL] [%s] [%s]", user, remote) - err := errors.New("Queue Is Full") + err := errors.New("queue is full") jsonerror.UnknownError(err).Encode(w) return } @@ -61,7 +61,7 @@ func (q *Queue) Check(next http.HandlerFunc) http.HandlerFunc { // Protect - handler to control limit of sessions func (q *Queue) Protect(next http.HandlerFunc) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - user, remote := util.RequestInfo(r) + user, remote := info.RequestInfo(r) log.Printf("[-] [NEW_REQUEST] [%s] [%s]", user, remote) s := time.Now() go func() { diff --git a/selenoid.go b/selenoid.go index 1987d387..96e50843 100644 --- a/selenoid.go +++ b/selenoid.go @@ -9,6 +9,7 @@ import ( "encoding/json" "errors" "fmt" + "github.com/aerokube/selenoid/info" "io" "log" "net" @@ -27,7 +28,6 @@ import ( "github.com/aerokube/selenoid/jsonerror" "github.com/aerokube/selenoid/service" "github.com/aerokube/selenoid/session" - "github.com/aerokube/util" "github.com/docker/docker/api/types" "github.com/docker/docker/pkg/stdcopy" "github.com/imdario/mergo" @@ -110,9 +110,9 @@ func getSerial() uint64 { func create(w http.ResponseWriter, r *http.Request) { sessionStartTime := time.Now() requestId := serial() - user, remote := util.RequestInfo(r) + user, remote := info.RequestInfo(r) body, err := io.ReadAll(r.Body) - r.Body.Close() + _ = r.Body.Close() if err != nil { log.Printf("[%d] [ERROR_READING_REQUEST] [%v]", requestId, err) jsonerror.InvalidArgument(err).Encode(w) @@ -147,7 +147,7 @@ func create(w http.ResponseWriter, r *http.Request) { var finalVideoName, finalLogName string for _, fmc := range firstMatchCaps { caps = browser.Caps - mergo.Merge(&caps, *fmc) + _ = mergo.Merge(&caps, *fmc) caps.ProcessExtensionCapabilities() sessionTimeout, err = getSessionTimeout(caps.SessionTimeout, maxTimeout, timeout) if err != nil { @@ -223,7 +223,7 @@ func create(w http.ResponseWriter, r *http.Request) { select { case <-ctx.Done(): if rsp != nil { - rsp.Body.Close() + _ = rsp.Body.Close() } switch ctx.Err() { case context.DeadlineExceeded: @@ -235,7 +235,7 @@ func create(w http.ResponseWriter, r *http.Request) { log.Printf("[%d] [SESSION_FAILED] [%s] [%s]", requestId, u.String(), err) jsonerror.UnknownError(err).Encode(w) case context.Canceled: - log.Printf("[%d] [CLIENT_DISCONNECTED] [%s] [%s] [%.2fs]", requestId, user, remote, util.SecondsSince(sessionStartTime)) + log.Printf("[%d] [CLIENT_DISCONNECTED] [%s] [%s] [%.2fs]", requestId, user, remote, info.SecondsSince(sessionStartTime)) } queue.Drop() cancel() @@ -244,7 +244,7 @@ func create(w http.ResponseWriter, r *http.Request) { } if err != nil { if rsp != nil { - rsp.Body.Close() + _ = rsp.Body.Close() } log.Printf("[%d] [SESSION_FAILED] [%s] [%s]", requestId, u.String(), err) jsonerror.SessionNotCreated(err).Encode(w) @@ -286,6 +286,7 @@ func create(w http.ResponseWriter, r *http.Request) { log.Printf("[%d] [ERROR_READING_RESPONSE] [%v]", requestId, err) queue.Drop() cancel() + w.WriteHeader(resp.StatusCode) return } newBody, sessionId, err := processBody(body, r.Host) @@ -293,12 +294,13 @@ func create(w http.ResponseWriter, r *http.Request) { log.Printf("[%d] [ERROR_PROCESSING_RESPONSE] [%v]", requestId, err) queue.Drop() cancel() + w.WriteHeader(resp.StatusCode) return } resp.Body = io.NopCloser(bytes.NewReader(newBody)) resp.ContentLength = int64(len(newBody)) w.WriteHeader(resp.StatusCode) - w.Write(newBody) + _, _ = w.Write(newBody) s.ID = sessionId } if s.ID == "" { @@ -372,7 +374,7 @@ func create(w http.ResponseWriter, r *http.Request) { sess.Cancel = cancelAndRenameFiles sessions.Put(s.ID, sess) queue.Create() - log.Printf("[%d] [SESSION_CREATED] [%s] [%d] [%.2fs]", requestId, s.ID, i, util.SecondsSince(sessionStartTime)) + log.Printf("[%d] [SESSION_CREATED] [%s] [%d] [%.2fs]", requestId, s.ID, i, info.SecondsSince(sessionStartTime)) } func removeSelenoidOptions(input []byte) []byte { @@ -515,7 +517,7 @@ func getTemporaryFileName(dir string, extension string) string { func generateRandomFileName(extension string) string { randBytes := make([]byte, 16) - rand.Read(randBytes) + _, _ = rand.Read(randBytes) return "selenoid" + hex.EncodeToString(randBytes) + extension } @@ -555,7 +557,7 @@ func proxy(w http.ResponseWriter, r *http.Request) { } if r.Method == http.MethodDelete && len(fragments) == 3 { if enableFileUpload { - os.RemoveAll(filepath.Join(os.TempDir(), id)) + _ = os.RemoveAll(filepath.Join(os.TempDir(), id)) } cancel = sess.Cancel sessions.Remove(id) @@ -590,7 +592,7 @@ func proxy(w http.ResponseWriter, r *http.Request) { func defaultErrorHandler(requestId uint64) func(http.ResponseWriter, *http.Request, error) { return func(w http.ResponseWriter, r *http.Request, err error) { - user, remote := util.RequestInfo(r) + user, remote := info.RequestInfo(r) log.Printf("[%d] [CLIENT_DISCONNECTED] [%s] [%s] [Error: %v]", requestId, user, remote, err) w.WriteHeader(http.StatusBadGateway) } @@ -681,7 +683,7 @@ func fileUpload(w http.ResponseWriter, r *http.Request) { }{ V: fileName, } - json.NewEncoder(w).Encode(reply) + _ = json.NewEncoder(w).Encode(reply) } func vnc(wsconn *websocket.Conn) { @@ -702,11 +704,11 @@ func vnc(wsconn *websocket.Conn) { defer conn.Close() wsconn.PayloadType = websocket.BinaryFrame go func() { - io.Copy(wsconn, conn) - wsconn.Close() + _, _ = io.Copy(wsconn, conn) + _ = wsconn.Close() log.Printf("[%d] [VNC_SESSION_CLOSED] [%s]", requestId, sid) }() - io.Copy(conn, wsconn) + _, _ = io.Copy(conn, wsconn) log.Printf("[%d] [VNC_CLIENT_DISCONNECTED] [%s]", requestId, sid) } else { log.Printf("[%d] [VNC_NOT_ENABLED] [%s]", requestId, sid) @@ -728,7 +730,7 @@ func logs(w http.ResponseWriter, r *http.Request) { deleteFileIfExists(requestId, w, r, logOutputDir, paths.Logs, "DELETED_LOG_FILE") return } - user, remote := util.RequestInfo(r) + user, remote := info.RequestInfo(r) if _, ok := r.URL.Query()[jsonParam]; ok { listFilesAsJson(requestId, w, logOutputDir, "LOG_ERROR") return @@ -753,7 +755,7 @@ func listFilesAsJson(requestId uint64, w http.ResponseWriter, dir string, errSta ret = append(ret, f.Name()) } w.Header().Add("Content-Type", "application/json") - json.NewEncoder(w).Encode(ret) + _ = json.NewEncoder(w).Encode(ret) } func streamLogs(wsconn *websocket.Conn) { @@ -774,7 +776,7 @@ func streamLogs(wsconn *websocket.Conn) { } defer r.Close() wsconn.PayloadType = websocket.BinaryFrame - stdcopy.StdCopy(wsconn, wsconn, r) + _, _ = stdcopy.StdCopy(wsconn, wsconn, r) log.Printf("[%d] [CONTAINER_LOGS_DISCONNECTED] [%s]", requestId, sid) } else { log.Printf("[%d] [SESSION_NOT_FOUND] [%s]", requestId, sid) @@ -784,7 +786,7 @@ func streamLogs(wsconn *websocket.Conn) { func status(w http.ResponseWriter, _ *http.Request) { w.Header().Set("Content-Type", "application/json") ready := limit > sessions.Len() - json.NewEncoder(w).Encode( + _ = json.NewEncoder(w).Encode( map[string]interface{}{ "value": map[string]interface{}{ "message": fmt.Sprintf("Selenoid %s built at %s", gitRevision, buildStamp), @@ -795,7 +797,7 @@ func status(w http.ResponseWriter, _ *http.Request) { func welcome(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusOK) - w.Write([]byte(fmt.Sprintf("You are using Selenoid %s!", gitRevision))) + _, _ = w.Write([]byte(fmt.Sprintf("You are using Selenoid %s!", gitRevision))) } func onTimeout(t time.Duration, f func()) chan struct{} { diff --git a/selenoid_test.go b/selenoid_test.go index 357345a1..ee09ece2 100644 --- a/selenoid_test.go +++ b/selenoid_test.go @@ -480,7 +480,7 @@ func TestProxySessionPanicOnAbortHandler(t *testing.T) { req, _ := http.NewRequest(http.MethodGet, With(srv.URL).Path(fmt.Sprintf("/wd/hub/session/%s/url?abort-handler=true", sess["sessionId"])), nil) resp, err = http.DefaultClient.Do(req) - assert.NoError(t, err) + assert.Error(t, err) sessions.Remove(sess["sessionId"]) queue.Release() @@ -502,7 +502,8 @@ func TestSessionDeleted(t *testing.T) { req, _ := http.NewRequest(http.MethodDelete, With(srv.URL).Path(fmt.Sprintf("/wd/hub/session/%s", sess["sessionId"])), nil) - http.DefaultClient.Do(req) + _, err = http.DefaultClient.Do(req) + assert.NoError(t, err) resp, err = http.Get(With(srv.URL).Path("/status")) assert.NoError(t, err) @@ -927,18 +928,42 @@ func TestDevtools(t *testing.T) { } func TestAddedSeCdpCapability(t *testing.T) { - manager = &HTTPTest{Handler: Selenium()} + fn := func(input map[string]interface{}) { + input["value"] = map[string]interface{}{ + "sessionId": input["sessionId"], + "capabilities": make(map[string]interface{}), + } + delete(input, "sessionId") + } + manager = &HTTPTest{Handler: Selenium(fn)} resp, err := http.Post(With(srv.URL).Path("/wd/hub/session"), "", bytes.NewReader([]byte("{}"))) assert.NoError(t, err) assert.Equal(t, resp.StatusCode, http.StatusOK) - var sess map[string]string + var sess map[string]interface{} assert.NoError(t, json.NewDecoder(resp.Body).Decode(&sess)) ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond) defer cancel() - conn, err := rpcc.DialContext(ctx, sess["se:cdp"]) + rv, ok := sess["value"] + assert.True(t, ok) + value, ok := rv.(map[string]interface{}) + assert.True(t, ok) + rc, ok := value["capabilities"] + assert.True(t, ok) + rs, ok := value["sessionId"] + assert.True(t, ok) + sessionId, ok := rs.(string) + assert.True(t, ok) + capabilities, ok := rc.(map[string]interface{}) + assert.True(t, ok) + rws, ok := capabilities["se:cdp"] + assert.True(t, ok) + ws, ok := rws.(string) + assert.True(t, ok) + assert.NotEmpty(t, ws) + conn, err := rpcc.DialContext(ctx, ws) assert.NoError(t, err) defer conn.Close() @@ -946,7 +971,7 @@ func TestAddedSeCdpCapability(t *testing.T) { err = c.Page.Enable(ctx) assert.NoError(t, err) - sessions.Remove(sess["sessionId"]) + sessions.Remove(sessionId) queue.Release() } diff --git a/service/docker.go b/service/docker.go index 6b407aa6..805e46bc 100644 --- a/service/docker.go +++ b/service/docker.go @@ -3,6 +3,8 @@ package service import ( "context" "fmt" + "github.com/aerokube/selenoid/info" + "github.com/docker/docker/api/types" "log" "net" "net/url" @@ -14,8 +16,6 @@ import ( "github.com/aerokube/selenoid/config" "github.com/aerokube/selenoid/session" - "github.com/aerokube/util" - "github.com/docker/docker/api/types" ctr "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/network" "github.com/docker/docker/api/types/strslice" @@ -164,12 +164,12 @@ func (d *Docker) StartWithCancel() (*StartedService, error) { browserContainerId := container.ID videoContainerId := "" log.Printf("[%d] [STARTING_CONTAINER] [%s] [%s]", requestId, image, browserContainerId) - err = cl.ContainerStart(ctx, browserContainerId, types.ContainerStartOptions{}) + err = cl.ContainerStart(ctx, browserContainerId, ctr.StartOptions{}) if err != nil { removeContainer(ctx, cl, requestId, browserContainerId) return nil, fmt.Errorf("start container: %v", err) } - log.Printf("[%d] [CONTAINER_STARTED] [%s] [%s] [%.2fs]", requestId, image, browserContainerId, util.SecondsSince(browserContainerStartTime)) + log.Printf("[%d] [CONTAINER_STARTED] [%s] [%s] [%.2fs]", requestId, image, browserContainerId, info.SecondsSince(browserContainerStartTime)) if len(d.AdditionalNetworks) > 0 { for _, networkName := range d.AdditionalNetworks { @@ -217,7 +217,7 @@ func (d *Docker) StartWithCancel() (*StartedService, error) { removeContainer(ctx, cl, requestId, browserContainerId) return nil, fmt.Errorf("wait: %v", err) } - log.Printf("[%d] [SERVICE_STARTED] [%s] [%s] [%.2fs]", requestId, image, browserContainerId, util.SecondsSince(serviceStartTime)) + log.Printf("[%d] [SERVICE_STARTED] [%s] [%s] [%.2fs]", requestId, image, browserContainerId, info.SecondsSince(serviceStartTime)) log.Printf("[%d] [PROXY_TO] [%s] [%s]", requestId, browserContainerId, u.String()) var publishedPortsInfo map[string]string @@ -245,7 +245,7 @@ func (d *Docker) StartWithCancel() (*StartedService, error) { } defer removeContainer(ctx, cl, requestId, browserContainerId) if d.LogOutputDir != "" && (d.SaveAllLogs || d.Log) { - r, err := d.Client.ContainerLogs(ctx, browserContainerId, types.ContainerLogsOptions{ + r, err := d.Client.ContainerLogs(ctx, browserContainerId, ctr.LogsOptions{ Timestamps: true, ShowStdout: true, ShowStderr: true, @@ -545,13 +545,13 @@ func startVideoContainer(ctx context.Context, cl *client.Client, requestId uint6 videoContainerId := videoContainer.ID log.Printf("[%d] [STARTING_VIDEO_CONTAINER] [%s] [%s]", requestId, videoContainerImage, videoContainerId) - err = cl.ContainerStart(ctx, videoContainerId, types.ContainerStartOptions{}) + err = cl.ContainerStart(ctx, videoContainerId, ctr.StartOptions{}) if err != nil { removeContainer(ctx, cl, requestId, browserContainer.ID) removeContainer(ctx, cl, requestId, videoContainerId) return "", fmt.Errorf("start video container: %v", err) } - log.Printf("[%d] [VIDEO_CONTAINER_STARTED] [%s] [%s] [%.2fs]", requestId, videoContainerImage, videoContainerId, util.SecondsSince(videoContainerStartTime)) + log.Printf("[%d] [VIDEO_CONTAINER_STARTED] [%s] [%s] [%.2fs]", requestId, videoContainerImage, videoContainerId, info.SecondsSince(videoContainerStartTime)) return videoContainerId, nil } @@ -585,7 +585,7 @@ func stopVideoContainer(ctx context.Context, cli *client.Client, requestId uint6 func removeContainer(ctx context.Context, cli *client.Client, requestId uint64, id string) { log.Printf("[%d] [REMOVING_CONTAINER] [%s]", requestId, id) - err := cli.ContainerRemove(ctx, id, types.ContainerRemoveOptions{Force: true, RemoveVolumes: true}) + err := cli.ContainerRemove(ctx, id, ctr.RemoveOptions{Force: true, RemoveVolumes: true}) if err != nil { log.Printf("[%d] [FAILED_TO_REMOVE_CONTAINER] [%s] [%v]", requestId, id, err) return diff --git a/service/driver.go b/service/driver.go index 25348eb0..72b8a39e 100644 --- a/service/driver.go +++ b/service/driver.go @@ -3,6 +3,7 @@ package service import ( "errors" "fmt" + "github.com/aerokube/selenoid/info" "log" "net" "net/url" @@ -12,7 +13,6 @@ import ( "time" "github.com/aerokube/selenoid/session" - "github.com/aerokube/util" ) // Driver - driver processes manager @@ -63,7 +63,7 @@ func (d *Driver) StartWithCancel() (*StartedService, error) { cmd.Stdout = f cmd.Stderr = f } - l.Close() + _ = l.Close() log.Printf("[%d] [STARTING_PROCESS] [%s]", requestId, cmdLine) s := time.Now() err = cmd.Start() @@ -75,7 +75,7 @@ func (d *Driver) StartWithCancel() (*StartedService, error) { d.stopProcess(cmd) return nil, err } - log.Printf("[%d] [PROCESS_STARTED] [%d] [%.2fs]", requestId, cmd.Process.Pid, util.SecondsSince(s)) + log.Printf("[%d] [PROCESS_STARTED] [%d] [%.2fs]", requestId, cmd.Process.Pid, info.SecondsSince(s)) log.Printf("[%d] [PROXY_TO] [%s]", requestId, u.String()) hp := session.HostPort{} if d.Caps.VNC { @@ -93,7 +93,7 @@ func (d *Driver) stopProcess(cmd *exec.Cmd) { return } if stdout, ok := cmd.Stdout.(*os.File); ok && !d.CaptureDriverLogs && d.LogOutputDir != "" { - stdout.Close() + _ = stdout.Close() } - log.Printf("[%d] [TERMINATED_PROCESS] [%d] [%.2fs]", d.RequestId, cmd.Process.Pid, util.SecondsSince(s)) + log.Printf("[%d] [TERMINATED_PROCESS] [%d] [%.2fs]", d.RequestId, cmd.Process.Pid, info.SecondsSince(s)) } diff --git a/service/driver_unix.go b/service/driver_unix.go index 8f95e3d0..edcf0fcd 100644 --- a/service/driver_unix.go +++ b/service/driver_unix.go @@ -10,6 +10,6 @@ import ( func stopProc(cmd *exec.Cmd) error { exitCode := cmd.Process.Signal(syscall.SIGINT) - cmd.Wait() + _ = cmd.Wait() return exitCode } diff --git a/service/driver_windows.go b/service/driver_windows.go index 782bb1ab..3166722b 100644 --- a/service/driver_windows.go +++ b/service/driver_windows.go @@ -9,6 +9,6 @@ import ( func stopProc(cmd *exec.Cmd) error { error := cmd.Process.Kill() - cmd.Wait() + _ = cmd.Wait() return error } diff --git a/service/service.go b/service/service.go index bcb17f3d..79571db7 100644 --- a/service/service.go +++ b/service/service.go @@ -109,7 +109,7 @@ func wait(u string, t time.Duration) error { req.Close = true resp, err := http.DefaultClient.Do(req) if resp != nil { - resp.Body.Close() + _ = resp.Body.Close() } if err != nil { <-time.After(50 * time.Millisecond) diff --git a/service_test.go b/service_test.go index 86012f16..0503d391 100644 --- a/service_test.go +++ b/service_test.go @@ -16,7 +16,6 @@ import ( "github.com/aerokube/selenoid/config" "github.com/aerokube/selenoid/service" "github.com/aerokube/selenoid/session" - "github.com/aerokube/util" "github.com/docker/docker/api/types/container" "github.com/docker/docker/client" assert "github.com/stretchr/testify/require" @@ -60,7 +59,7 @@ func testMux() http.Handler { func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusCreated) output := `{"id": "e90e34656806", "warnings": []}` - w.Write([]byte(output)) + _, _ = w.Write([]byte(output)) }, )) mux.HandleFunc("/v1.29/containers/e90e34656806/start", http.HandlerFunc( @@ -80,9 +79,9 @@ func testMux() http.Handler { w.WriteHeader(http.StatusOK) const streamTypeStderr = 2 header := []byte{streamTypeStderr, 0, 0, 0, 0, 0, 0, 9} - w.Write(header) + _, _ = w.Write(header) data := []byte("test-data") - w.Write(data) + _, _ = w.Write(data) }, )) mux.HandleFunc("/v%s/containers/e90e34656806", http.HandlerFunc( @@ -160,7 +159,7 @@ func testMux() http.Handler { "Mounts": [] } `, p, p, p, p, p, p) - w.Write([]byte(output)) + _, _ = w.Write([]byte(output)) }, )) mux.HandleFunc("/v1.29/networks/net-1/connect", http.HandlerFunc( @@ -310,7 +309,7 @@ func failingMux(numDeleteRequests *int) http.Handler { func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusCreated) output := `{"id": "e90e34656806", "warnings": []}` - w.Write([]byte(output)) + _, _ = w.Write([]byte(output)) }, )) mux.HandleFunc("/v1.29/containers/e90e34656806/start", http.HandlerFunc( @@ -334,7 +333,7 @@ func TestDeleteContainerOnStartupError(t *testing.T) { env := testEnvironment() starter := createDockerStarter(t, env, testConfig(env)) _, err := starter.StartWithCancel() - assert.NoError(t, err) + assert.Error(t, err) assert.Equal(t, numDeleteRequests, 1) } @@ -364,7 +363,7 @@ func TestGetVNC(t *testing.T) { }) defer sessions.Remove("test-session") - u := fmt.Sprintf("ws://%s/vnc/test-session", util.HostPort(srv.URL)) + u := fmt.Sprintf("ws://%s/vnc/test-session", hostPort(srv.URL)) assert.Equal(t, readDataFromWebSocket(t, u), "test-data") } @@ -408,6 +407,6 @@ func TestGetLogs(t *testing.T) { }) defer sessions.Remove("test-session") - u := fmt.Sprintf("ws://%s/logs/test-session", util.HostPort(srv.URL)) + u := fmt.Sprintf("ws://%s/logs/test-session", hostPort(srv.URL)) assert.Equal(t, readDataFromWebSocket(t, u), "test-data") } diff --git a/upload/uploader.go b/upload/uploader.go index 3bbb70b1..4a48ded8 100644 --- a/upload/uploader.go +++ b/upload/uploader.go @@ -1,11 +1,11 @@ package upload import ( + "github.com/aerokube/selenoid/info" "log" "time" "github.com/aerokube/selenoid/event" - "github.com/aerokube/util" ) var ( @@ -39,7 +39,7 @@ func AddUploader(u Uploader) { func (ul *Upload) OnFileCreated(createdFile event.CreatedFile) { if len(ul.uploaders) > 0 { for _, uploader := range ul.uploaders { - go func() { + go func(uploader Uploader) { s := time.Now() uploaded, err := uploader.Upload(createdFile) if err != nil { @@ -47,9 +47,9 @@ func (ul *Upload) OnFileCreated(createdFile event.CreatedFile) { return } if uploaded { - log.Printf("[%d] [UPLOADED_FILE] [%s] [%.2fs]", createdFile.RequestId, createdFile.Name, util.SecondsSince(s)) + log.Printf("[%d] [UPLOADED_FILE] [%s] [%.2fs]", createdFile.RequestId, createdFile.Name, info.SecondsSince(s)) } - }() + }(uploader) } } } diff --git a/utils_test.go b/utils_test.go index 2bafa970..eb0f44ff 100644 --- a/utils_test.go +++ b/utils_test.go @@ -78,7 +78,7 @@ type StartupError struct{} func (m *StartupError) StartWithCancel() (*service.StartedService, error) { log.Println("Starting StartupError Service...") log.Println("Failed to start StartupError Service...") - return nil, errors.New("Failed to start Service") + return nil, errors.New("failed to start Service") } func (m *StartupError) Find(caps session.Caps, requestId uint64) (service.Starter, bool) { @@ -97,7 +97,7 @@ func (r With) Path(p string) string { return fmt.Sprintf("%s%s", r, p) } -func Selenium() http.Handler { +func Selenium(nsp ...func(map[string]interface{})) http.Handler { var lock sync.RWMutex sessions := make(map[string]struct{}) mux := http.NewServeMux() @@ -110,9 +110,13 @@ func Selenium() http.Handler { lock.Lock() sessions[u] = struct{}{} lock.Unlock() - json.NewEncoder(w).Encode(struct { - S string `json:"sessionId"` - }{u}) + ret := map[string]interface{}{ + "sessionId": u, + } + for _, n := range nsp { + n(ret) + } + _ = json.NewEncoder(w).Encode(&ret) }) mux.HandleFunc("/session/", func(w http.ResponseWriter, r *http.Request) { u := strings.Split(r.URL.Path, "/")[2] @@ -127,7 +131,7 @@ func Selenium() http.Handler { out := "this call was relayed by the reverse proxy" // Setting wrong Content-Length leads to abort handler error w.Header().Add("Content-Length", strconv.Itoa(2*len(out))) - fmt.Fprintln(w, out) + _, _ = fmt.Fprintln(w, out) return } d, _ := time.ParseDuration(r.FormValue("timeout")) @@ -141,7 +145,7 @@ func Selenium() http.Handler { }) mux.HandleFunc("/testfile", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) - w.Write([]byte("test-data")) + _, _ = w.Write([]byte("test-data")) }) upgrader := websocket.Upgrader{ CheckOrigin: func(_ *http.Request) bool { @@ -179,7 +183,7 @@ func Selenium() http.Handler { } } w.WriteHeader(http.StatusOK) - w.Write([]byte("test-clipboard-value")) + _, _ = w.Write([]byte("test-clipboard-value")) }) return mux } @@ -249,7 +253,7 @@ func TestSumUsedTotalGreaterThanPending(t *testing.T) { req = req.WithContext(ctx) _, err = http.DefaultClient.Do(req) - assert.NoError(t, err) + assert.Error(t, err) assert.Equal(t, queue.Pending(), 0) assert.Equal(t, queue.Used(), 2) }