diff --git a/.github/workflows/images-test.yaml b/.github/workflows/images-test.yaml index 100012b..9c2595b 100644 --- a/.github/workflows/images-test.yaml +++ b/.github/workflows/images-test.yaml @@ -19,7 +19,7 @@ jobs: fetch-depth: "0" - name: Pull all images run: | - docker-compose pull --ignore-pull-failures + docker compose pull --ignore-pull-failures - name: Install test harness run: | yarn add leia-parser mocha chai command-line-test diff --git a/Dockerfile b/Dockerfile index a8a26cd..6fd1386 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,12 @@ -FROM golang:alpine +FROM golang:1.21-alpine -WORKDIR /go-dbaas +WORKDIR /internal-services-test ADD . . RUN go get github.com/joho/godotenv -RUN go build && chmod +x ./go-dbaas +RUN go build && chmod +x ./internal-services-test ENV SOLR_HOST=solr \ REDIS_HOST=redis \ @@ -14,4 +14,4 @@ ENV SOLR_HOST=solr \ EXPOSE 3000 -CMD sleep 10 && ./go-dbaas +CMD sleep 10 && ./internal-services-test diff --git a/TESTING_dockercompose.md b/TESTING_dockercompose.md index a298468..9862af9 100644 --- a/TESTING_dockercompose.md +++ b/TESTING_dockercompose.md @@ -10,10 +10,10 @@ Run the following commands to get up and running with this example. ```bash # should remove any previous runs and poweroff -docker-compose down --volumes --remove-orphans +docker compose down --volumes --remove-orphans # should start up our services successfully -docker-compose build && docker-compose up -d +docker compose build && docker compose up -d ``` Verification commands @@ -23,59 +23,59 @@ Run the following commands to validate things are rolling as they should. ```bash # Ensure services are ready to connect -docker run --rm --net internal-services-test_default jwilder/dockerize dockerize -wait tcp://mariadb-10-4:3306 -timeout 1m -docker run --rm --net internal-services-test_default jwilder/dockerize dockerize -wait tcp://mariadb-10-6:3306 -timeout 1m +docker run --rm --net internal-services-test_default jwilder/dockerize dockerize -wait tcp://mariadb-10-5:3306 -timeout 1m +docker run --rm --net internal-services-test_default jwilder/dockerize dockerize -wait tcp://mariadb-10-11:3306 -timeout 1m docker run --rm --net internal-services-test_default jwilder/dockerize dockerize -wait tcp://postgres-11:5432 -timeout 1m docker run --rm --net internal-services-test_default jwilder/dockerize dockerize -wait tcp://postgres-15:5432 -timeout 1m docker run --rm --net internal-services-test_default jwilder/dockerize dockerize -wait tcp://opensearch-2:9200 -timeout 1m docker run --rm --net internal-services-test_default jwilder/dockerize dockerize -wait tcp://mongo-4:27017 -timeout 1m -docker run --rm --net internal-services-test_default jwilder/dockerize dockerize -wait tcp://redis-5:6379 -timeout 1m docker run --rm --net internal-services-test_default jwilder/dockerize dockerize -wait tcp://redis-6:6379 -timeout 1m +docker run --rm --net internal-services-test_default jwilder/dockerize dockerize -wait tcp://redis-7:6379 -timeout 1m docker run --rm --net internal-services-test_default jwilder/dockerize dockerize -wait tcp://solr-7:8983 -timeout 1m docker run --rm --net internal-services-test_default jwilder/dockerize dockerize -wait tcp://solr-8:8983 -timeout 1m # commons should be running Alpine Linux -docker-compose exec -T commons sh -c "cat /etc/os-release" | grep "Alpine Linux" +docker compose exec -T commons sh -c "cat /etc/os-release" | grep "Alpine Linux" -# mariadb-10-4 should be able to read/write data -docker-compose exec -T commons sh -c "curl -kL http://go-web:3000/mariadb-10-4" | grep "SERVICE_HOST=10.4" -docker-compose exec -T commons sh -c "curl -kL http://go-web:3000/mariadb-10-4" | grep "LAGOON_TEST_VAR=internal-services-test" +# mariadb-10-5 should be able to read/write data +docker compose exec -T commons sh -c "curl -kL http://go-web:3000/mariadb?service=mariadb-10-5" | grep "SERVICE_HOST=10.5" +docker compose exec -T commons sh -c "curl -kL http://go-web:3000/mariadb?service=mariadb-10-5" | grep "LAGOON_TEST_VAR=internal-services-test" -# mariadb-10-6 should be able to read/write data -docker-compose exec -T commons sh -c "curl -kL http://go-web:3000/mariadb-10-6" | grep "SERVICE_HOST=10.6" -docker-compose exec -T commons sh -c "curl -kL http://go-web:3000/mariadb-10-6" | grep "LAGOON_TEST_VAR=internal-services-test" +# mariadb-10-11 should be able to read/write data +docker compose exec -T commons sh -c "curl -kL http://go-web:3000/mariadb?service=mariadb-10-11" | grep "SERVICE_HOST=10.11" +docker compose exec -T commons sh -c "curl -kL http://go-web:3000/mariadb?service=mariadb-10-11" | grep "LAGOON_TEST_VAR=internal-services-test" # postgres-11 should be able to read/write data -docker-compose exec -T commons sh -c "curl -kL http://go-web:3000/postgres-11" | grep "SERVICE_HOST=PostgreSQL 11" -docker-compose exec -T commons sh -c "curl -kL http://go-web:3000/postgres-11" | grep "LAGOON_TEST_VAR=internal-services-test" +docker compose exec -T commons sh -c "curl -kL http://go-web:3000/postgres?service=postgres-11" | grep "SERVICE_HOST=PostgreSQL 11" +docker compose exec -T commons sh -c "curl -kL http://go-web:3000/postgres?service=postgres-11" | grep "LAGOON_TEST_VAR=internal-services-test" # postgres-15 should be able to read/write data -docker-compose exec -T commons sh -c "curl -kL http://go-web:3000/postgres-15" | grep "SERVICE_HOST=PostgreSQL 15" -docker-compose exec -T commons sh -c "curl -kL http://go-web:3000/postgres-15" | grep "LAGOON_TEST_VAR=internal-services-test" +docker compose exec -T commons sh -c "curl -kL http://go-web:3000/postgres?service=postgres-15" | grep "SERVICE_HOST=PostgreSQL 15" +docker compose exec -T commons sh -c "curl -kL http://go-web:3000/postgres?service=postgres-15" | grep "LAGOON_TEST_VAR=internal-services-test" # opensearch-2 should be able to read/write data -docker-compose exec -T commons sh -c "curl -kL http://go-web:3000/opensearch-2" | grep "SERVICE_HOST=opensearch-2" -docker-compose exec -T commons sh -c "curl -kL http://go-web:3000/opensearch-2" | grep "LAGOON_TEST_VAR=internal-services-test" +docker compose exec -T commons sh -c "curl -kL http://go-web:3000/opensearch?service=opensearch-2" | grep "SERVICE_HOST=opensearch-2" +docker compose exec -T commons sh -c "curl -kL http://go-web:3000/opensearch?service=opensearch-2" | grep "LAGOON_TEST_VAR=internal-services-test" # mongo-4 should be able to read/write data -docker-compose exec -T commons sh -c "curl -kL http://go-web:3000/mongo-4" | grep "SERVICE_HOST=" -docker-compose exec -T commons sh -c "curl -kL http://go-web:3000/mongo-4" | grep "LAGOON_TEST_VAR=internal-services-test" - -# redis-5 should be able to read/write data -docker-compose exec -T commons sh -c "curl -kL http://go-web:3000/redis-5" | grep "SERVICE_HOST=redis-5" -docker-compose exec -T commons sh -c "curl -kL http://go-web:3000/redis-5" | grep "LAGOON_TEST_VAR=internal-services-test" +docker compose exec -T commons sh -c "curl -kL http://go-web:3000/mongo?service=mongo-4" | grep "SERVICE_HOST=" +docker compose exec -T commons sh -c "curl -kL http://go-web:3000/mongo?service=mongo-4" | grep "LAGOON_TEST_VAR=internal-services-test" # redis-6 should be able to read/write data -docker-compose exec -T commons sh -c "curl -kL http://go-web:3000/redis-6" | grep "SERVICE_HOST=redis-6" -docker-compose exec -T commons sh -c "curl -kL http://go-web:3000/redis-6" | grep "LAGOON_TEST_VAR=internal-services-test" +docker compose exec -T commons sh -c "curl -kL http://go-web:3000/redis?service=redis-6" | grep "SERVICE_HOST=redis-6" +docker compose exec -T commons sh -c "curl -kL http://go-web:3000/redis?service=redis-6" | grep "LAGOON_TEST_VAR=internal-services-test" + +# redis-7 should be able to read/write data +docker compose exec -T commons sh -c "curl -kL http://go-web:3000/redis?service=redis-7" | grep "SERVICE_HOST=redis-7" +docker compose exec -T commons sh -c "curl -kL http://go-web:3000/redis?service=redis-7" | grep "LAGOON_TEST_VAR=internal-services-test" # solr-7 should be able to read/write data -docker-compose exec -T commons sh -c "curl -kL http://go-web:3000/solr-7" | grep "SERVICE_HOST=solr-7" -docker-compose exec -T commons sh -c "curl -kL http://go-web:3000/solr-7" | grep "LAGOON_TEST_VAR=internal-services-test" +docker compose exec -T commons sh -c "curl -kL http://go-web:3000/solr?service=solr-7" | grep "SERVICE_HOST=solr-7" +docker compose exec -T commons sh -c "curl -kL http://go-web:3000/solr?service=solr-7" | grep "LAGOON_TEST_VAR=internal-services-test" # solr-8 should be able to read/write data -docker-compose exec -T commons sh -c "curl -kL http://go-web:3000/solr-8" | grep "SERVICE_HOST=solr-8" -docker-compose exec -T commons sh -c "curl -kL http://go-web:3000/solr-8" | grep "LAGOON_TEST_VAR=internal-services-test" +docker compose exec -T commons sh -c "curl -kL http://go-web:3000/solr?service=solr-8" | grep "SERVICE_HOST=solr-8" +docker compose exec -T commons sh -c "curl -kL http://go-web:3000/solr?service=solr-8" | grep "LAGOON_TEST_VAR=internal-services-test" ``` Destroy tests @@ -85,5 +85,5 @@ Run the following commands to trash this app like nothing ever happened. ```bash # should be able to destroy our services with success -docker-compose down --volumes --remove-orphans +docker compose down --volumes --remove-orphans ``` diff --git a/docker-compose.yml b/docker-compose.yml index 587dc9f..3a7403c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,15 +20,15 @@ services: - LAGOON_GIT_SHA=SHA256 - LAGOON_ENVIRONMENT_TYPE=development - mariadb-10-4: - image: uselagoon/mariadb-10.4:latest + mariadb-10-5: + image: uselagoon/mariadb-10.5:latest labels: lagoon.type: mariadb-single ports: - '3306' - mariadb-10-6: - image: uselagoon/mariadb-10.6:latest + mariadb-10-11: + image: uselagoon/mariadb-10.11:latest labels: lagoon.type: mariadb ports: @@ -78,14 +78,14 @@ services: ports: - '27017' - redis-5: + redis-6: image: uselagoon/redis-5:latest labels: lagoon.type: redis ports: - '6379' - redis-6: + redis-7: image: uselagoon/redis-6:latest labels: lagoon.type: redis diff --git a/go.mod b/go.mod index 9ad67cc..b6078ff 100644 --- a/go.mod +++ b/go.mod @@ -1,29 +1,31 @@ -module go-dbaas +module internal-services-test -go 1.19 +go 1.21 require ( - github.com/cespare/xxhash/v2 v2.1.2 // indirect + github.com/go-redis/redis/v8 v8.11.5 + github.com/go-sql-driver/mysql v1.7.1 + github.com/gorilla/mux v1.8.1 + github.com/lib/pq v1.10.9 + github.com/opensearch-project/opensearch-go v1.1.0 + github.com/vanng822/go-solr v0.10.0 + go.mongodb.org/mongo-driver v1.12.1 +) + +require ( + github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect - github.com/go-redis/redis/v8 v8.11.5 // indirect - github.com/go-redis/redis/v9 v9.0.0-rc.1 // indirect - github.com/go-sql-driver/mysql v1.6.0 // indirect - github.com/golang/snappy v0.0.1 // indirect - github.com/gorilla/mux v1.8.0 // indirect - github.com/joho/godotenv v1.4.0 // indirect - github.com/klauspost/compress v1.13.6 // indirect - github.com/lib/pq v1.10.7 // indirect - github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect - github.com/opensearch-project/opensearch-go v1.1.0 // indirect - github.com/pkg/errors v0.9.1 // indirect - github.com/stevenferrer/solr-go v0.3.2 // indirect - github.com/vanng822/go-solr v0.10.0 // indirect + github.com/golang/snappy v0.0.4 // indirect + github.com/google/go-cmp v0.5.8 // indirect + github.com/klauspost/compress v1.17.2 // indirect + github.com/montanaflynn/stats v0.7.1 // indirect + github.com/onsi/gomega v1.21.1 // indirect + github.com/stretchr/testify v1.8.0 // indirect github.com/xdg-go/pbkdf2 v1.0.0 // indirect - github.com/xdg-go/scram v1.1.1 // indirect - github.com/xdg-go/stringprep v1.0.3 // indirect - github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect - go.mongodb.org/mongo-driver v1.11.0 // indirect - golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect - golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect - golang.org/x/text v0.3.7 // indirect + github.com/xdg-go/scram v1.1.2 // indirect + github.com/xdg-go/stringprep v1.0.4 // indirect + github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect + golang.org/x/crypto v0.14.0 // indirect + golang.org/x/sync v0.5.0 // indirect + golang.org/x/text v0.14.0 // indirect ) diff --git a/go.sum b/go.sum index 2659572..d504eda 100644 --- a/go.sum +++ b/go.sum @@ -1,77 +1,113 @@ github.com/aws/aws-sdk-go v1.42.27/go.mod h1:OGr6lGMAKGlG9CVrYnWYDKIyb829c6EVBRjxqjmPepc= -github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= -github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= +github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= 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/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= +github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= +github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI= github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo= -github.com/go-redis/redis/v9 v9.0.0-rc.1 h1:/+bS+yeUnanqAbuD3QwlejzQZ+4eqgfUtFTG4b+QnXs= -github.com/go-redis/redis/v9 v9.0.0-rc.1/go.mod h1:8et+z03j0l8N+DvsVnclzjf3Dl/pFHgRk+2Ct1qw66A= -github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= -github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= -github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= +github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI= +github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= +github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= -github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= -github.com/jarcoal/httpmock v1.2.0/go.mod h1:oCoTsnAz4+UoOUIf5lJOWV2QQIW5UoeUI6aM2YnWAZk= +github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= +github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= +github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= -github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg= -github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= -github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc= github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw= -github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= -github.com/maxatome/go-testdeep v1.11.0/go.mod h1:011SgQ6efzZYAen6fDn4BqQ+lUR72ysdyKe7Dyogw70= -github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0= +github.com/klauspost/compress v1.17.2 h1:RlWWUY/Dr4fL8qk9YG7DTZ7PDgME2V4csBXA8L/ixi4= +github.com/klauspost/compress v1.17.2/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= +github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= +github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE= +github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= +github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= +github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= +github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= +github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= +github.com/onsi/gomega v1.21.1 h1:OB/euWYIExnPBohllTicTHmGTrMaqJ67nIu80j0/uEM= +github.com/onsi/gomega v1.21.1/go.mod h1:iYAIXgPSaDHak0LCMA+AWBpIKBr8WZicMxnE8luStNc= github.com/opensearch-project/opensearch-go v1.1.0 h1:eG5sh3843bbU1itPRjA9QXbxcg8LaZ+DjEzQH9aLN3M= github.com/opensearch-project/opensearch-go v1.1.0/go.mod h1:+6/XHCuTH+fwsMJikZEWsucZ4eZMma3zNSeLrTtVGbo= -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/stevenferrer/solr-go v0.3.2 h1:7aR6qTGh4EoET5vIrcOv8h9+bbPZ8lz33nSmKOO/zO4= -github.com/stevenferrer/solr-go v0.3.2/go.mod h1:XFyPLn7yqpUhh8WQx2/XuBi5W6cDPthsv+KnEkQNSyo= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= +github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/vanng822/go-solr v0.10.0 h1:oygAxyFL2apSN8vddxDXoyho40z66Guu9nwH7ANr6wM= github.com/vanng822/go-solr v0.10.0/go.mod h1:FSglzTPzoNVKTXP+SqEQiiz284cKzcKpeRXmwPa81wc= github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= -github.com/xdg-go/scram v1.1.1 h1:VOMT+81stJgXW3CpHyqHN3AXDYIMsx56mEFrB37Mb/E= -github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g= -github.com/xdg-go/stringprep v1.0.3 h1:kdwGpVNwPFtjs98xCGkHjQtGKh86rDcRZN17QEMCOIs= -github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8= -github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA= +github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY= +github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4= +github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8= +github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM= github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= -go.mongodb.org/mongo-driver v1.11.0 h1:FZKhBSTydeuffHj9CBjXlR8vQLee1cQyTWYPA6/tqiE= -go.mongodb.org/mongo-driver v1.11.0/go.mod h1:s7p5vEtfbeR1gYi6pnj3c3/urpbLv2T5Sfd6Rp2HBB8= -golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d h1:sK3txAijHtOK88l68nt020reeT1ZdKLIYetKl95FzVY= +github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a h1:fZHgsYlfvtyqToslyjUt3VOPF4J7aK/3MPcK7xp3PDk= +github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a/go.mod h1:ul22v+Nro/R083muKhosV54bj5niojjWZvU8xrevuH4= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +go.mongodb.org/mongo-driver v1.12.1 h1:nLkghSU8fQNaK7oUmDhQFsnrtcoNy7Z6LVFKsEecqgE= +go.mongodb.org/mongo-driver v1.12.1/go.mod h1:/rGBTebI3XYboVmgz+Wv3Bcbl3aD0QF9zl6kDDw18rQ= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +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-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211216030914-fe4d6282115f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/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.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE= +golang.org/x/sync v0.5.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-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/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.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/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +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/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.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/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= diff --git a/main.go b/main.go index b77aa78..a7f2998 100644 --- a/main.go +++ b/main.go @@ -3,12 +3,12 @@ package main import ( "bytes" "fmt" + "github.com/gorilla/mux" "log" "net/http" "os" "strings" - - "github.com/gorilla/mux" + "time" ) var ( @@ -19,15 +19,26 @@ type funcType func() map[string]string func main() { r := mux.NewRouter() - r.HandleFunc("/{mariadb:mariadb-.*}", mariadbHandler) - r.HandleFunc("/{postgres:postgres-.*}", postgresHandler) - r.HandleFunc("/{redis:redis-.*}", redisHandler) - r.HandleFunc("/{solr:solr-.*}", solrHandler) - r.HandleFunc("/{mongo:mongo-.*}", mongoHandler) - r.HandleFunc("/{opensearch:opensearch-.*}", opensearchHandler) + r.HandleFunc("/mariadb", mariadbHandler) + r.HandleFunc("/postgres", postgresHandler) + r.HandleFunc("/redis", redisHandler) + r.HandleFunc("/solr", solrHandler) + r.HandleFunc("/mongo", mongoHandler) + r.HandleFunc("/opensearch", opensearchHandler) r.HandleFunc("/", handleReq) http.Handle("/", r) - log.Fatal(http.ListenAndServe(":3000", nil)) + + log.Fatal(http.ListenAndServe(":3000", timeoutHandler(r))) +} + +func timeoutHandler(m *mux.Router) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + driver := strings.ReplaceAll(r.URL.Path, "/", "") + service := r.URL.Query().Get("service") + incompatibleError := fmt.Sprintf("%s is not a compatible driver with service: %s", driver, service) + timeoutHandler := http.TimeoutHandler(m, 3*time.Second, incompatibleError) + timeoutHandler.ServeHTTP(w, r) + } } func handleReq(w http.ResponseWriter, r *http.Request) { @@ -68,9 +79,9 @@ func cleanRoute(basePath string) (string, string) { // getEnv get key environment variable if exist otherwise return defalutValue func getEnv(key, defaultValue string) string { - value := os.Getenv(key) - if len(value) == 0 { - return defaultValue - } - return value + value := os.Getenv(key) + if len(value) == 0 { + return defaultValue + } + return value } diff --git a/mariadb.go b/mariadb.go index 29c531d..15111ad 100644 --- a/mariadb.go +++ b/mariadb.go @@ -3,12 +3,11 @@ package main import ( "database/sql" "fmt" + _ "github.com/go-sql-driver/mysql" "log" "net/http" "os" "strings" - - _ "github.com/go-sql-driver/mysql" ) var ( @@ -17,8 +16,8 @@ var ( ) func mariadbHandler(w http.ResponseWriter, r *http.Request) { - mariadbPath := r.URL.Path - localService, lagoonService := cleanRoute(mariadbPath) + service := r.URL.Query().Get("service") + localService, lagoonService := cleanRoute(service) mariadbUser := getEnv(fmt.Sprintf("%s_USERNAME", lagoonService), "lagoon") mariadbPassword := getEnv(fmt.Sprintf("%s_PASSWORD", lagoonService), "lagoon") mariadbHost := getEnv(fmt.Sprintf("%s_HOST", lagoonService), localService) diff --git a/mongo.go b/mongo.go index ddde9ae..d755dff 100644 --- a/mongo.go +++ b/mongo.go @@ -23,8 +23,8 @@ var ( ) func mongoHandler(w http.ResponseWriter, r *http.Request) { - mongoPath := r.URL.Path - localService, lagoonService := cleanRoute(mongoPath) + service := r.URL.Query().Get("service") + localService, lagoonService := cleanRoute(service) mongoUser := getEnv(fmt.Sprintf("%s_USERNAME", lagoonService), "lagoon") mongoPassword := getEnv(fmt.Sprintf("%s_PASSWORD", lagoonService), "lagoon") mongoHost := getEnv(fmt.Sprintf("%s_HOST", lagoonService), localService) diff --git a/opensearch.go b/opensearch.go index 8aae8d3..424a4c7 100644 --- a/opensearch.go +++ b/opensearch.go @@ -17,12 +17,15 @@ import ( ) var ( - opensearchHost = os.Getenv("OPENSEARCH_HOST") - opensearchConnectionStr = fmt.Sprintf("http://%s:9200", opensearchHost) + opensearchHost string ) func opensearchHandler(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, opensearchConnector()) + service := r.URL.Query().Get("service") + opensearchHost = service + opensearchConnectionStr := fmt.Sprintf("http://%s:9200", opensearchHost) + + fmt.Fprintf(w, opensearchConnector(opensearchConnectionStr)) } func cleanOpensearchOutput(sr *opensearchapi.Response) string { @@ -90,12 +93,12 @@ func createOpensearchIndexDocument(client *opensearch.Client) { time.Sleep(1 * time.Second) } -func opensearchConnector() string { +func opensearchConnector(connectionString string) string { client, _ := opensearch.NewClient(opensearch.Config{ Transport: &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, }, - Addresses: []string{opensearchConnectionStr}, + Addresses: []string{connectionString}, }) createOpensearchIndexDocument(client) diff --git a/postgres.go b/postgres.go index ba24ab0..9bc2a0a 100644 --- a/postgres.go +++ b/postgres.go @@ -18,8 +18,8 @@ var ( ) func postgresHandler(w http.ResponseWriter, r *http.Request) { - postgresPath := r.URL.Path - localService, lagoonService := cleanRoute(postgresPath) + service := r.URL.Query().Get("service") + localService, lagoonService := cleanRoute(service) postgresUser := getEnv(fmt.Sprintf("%s_USERNAME", lagoonService), "lagoon") postgresPassword := getEnv(fmt.Sprintf("%s_PASSWORD", lagoonService), "lagoon") postgresHost := getEnv(fmt.Sprintf("%s_HOST", lagoonService), localService) diff --git a/redis.go b/redis.go index ef66668..91c4ffe 100644 --- a/redis.go +++ b/redis.go @@ -16,8 +16,8 @@ var ( ) func redisHandler(w http.ResponseWriter, r *http.Request) { - redisPath := r.URL.Path - redisRoute := strings.ReplaceAll(redisPath, "/", "") + service := r.URL.Query().Get("service") + redisRoute := strings.ReplaceAll(service, "/", "") redisConnectionStr := fmt.Sprintf("%s:6379", redisRoute) fmt.Fprintf(w, redisConnector(redisConnectionStr, redisRoute)) } diff --git a/renovate.json b/renovate.json index 6be5b57..62883f1 100644 --- a/renovate.json +++ b/renovate.json @@ -3,5 +3,11 @@ "extends": [ "config:base" ], - "dependencyDashboard": true + "dependencyDashboard": true, + "packageRules": [ + { + "matchManagers": ["github-actions"], + "groupName": "GitHub actions" + } + ] } diff --git a/solr.go b/solr.go index 7536941..49ddb8e 100644 --- a/solr.go +++ b/solr.go @@ -12,8 +12,8 @@ import ( ) func solrHandler(w http.ResponseWriter, r *http.Request) { - solrPath := r.URL.Path - solrRoute := strings.ReplaceAll(solrPath, "/", "") + service := r.URL.Query().Get("service") + solrRoute := strings.ReplaceAll(service, "/", "") solrConnectionStr := fmt.Sprintf("http://%s:8983/solr", solrRoute) fmt.Fprintf(w, convertSolrDoc(solrConnector(solrConnectionStr), solrRoute)) }