diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 8701e95..bb11ac1 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -16,11 +16,11 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Docker meta id: meta - uses: docker/metadata-action@v3 + uses: docker/metadata-action@v5 with: # list of Docker images to use as base name for tags images: | @@ -28,28 +28,28 @@ jobs: ghcr.io/${{ github.repository_owner }}/internal-services-test - name: Set up QEMU - uses: docker/setup-qemu-action@v2 + uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 - name: Login to DockerHub if: github.event_name != 'pull_request' - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Login to Docker Hub if: github.event_name != 'pull_request' - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} - name: Build and push - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v5 with: context: . platforms: linux/amd64,linux/arm64 diff --git a/.github/workflows/images-test.yaml b/.github/workflows/images-test.yaml new file mode 100644 index 0000000..9c2595b --- /dev/null +++ b/.github/workflows/images-test.yaml @@ -0,0 +1,31 @@ +name: Image test routine + +on: + push: + branches: + - 'main' + - 'dev' + pull_request: + branches: + - 'main' + +jobs: + test-suite: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: "0" + - name: Pull all images + run: | + docker compose pull --ignore-pull-failures + - name: Install test harness + run: | + yarn add leia-parser mocha chai command-line-test + - name: Generate test files + run: | + yarn leia "TESTING*.md" test -r 2 -s 'Start up tests' -t 'Verification commands' -c 'Destroy tests' --split-file + - name: Run docker-compose tests + run: | + yarn mocha --timeout 900000 test/*compose*.func.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..507f215 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/node_modules +/test +package.json +yarn.lock diff --git a/Dockerfile b/Dockerfile index a8a26cd..a2f6362 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,15 @@ -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 \ - OPENSEARCH_HOST=opensearch-2 +ENV STORAGE_LOCATION='/app/files' EXPOSE 3000 -CMD sleep 10 && ./go-dbaas +CMD sleep 10 && ./internal-services-test diff --git a/TESTING_dockercompose.md b/TESTING_dockercompose.md new file mode 100644 index 0000000..a1046d0 --- /dev/null +++ b/TESTING_dockercompose.md @@ -0,0 +1,93 @@ +Docker Compose test internal services test +========================================== + +This is a docker-compose testing suite for the internal services: + +Start up tests +-------------- + +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 + +# should start up our services successfully +docker compose build && docker compose up -d +``` + +Verification commands +--------------------- + +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-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-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" + +# 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-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?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?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?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?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?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?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?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" + +# persistent storage should be able to read/write data +docker compose exec -T commons sh -c "curl -kL http://go-web:3000/storage?path=/app/files" | grep "STORAGE_PATH=/app/files/storage.txt" +docker compose exec -T commons sh -c "curl -kL http://go-web:3000/storage?path=/app/files" | grep "LAGOON_TEST_VAR=internal-services-test" +``` + +Destroy tests +------------- + +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 +``` diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 79f1dfd..1f8fba8 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -1,48 +1,52 @@ services: - web: - build: - context: . - dockerfile: Dockerfile - labels: - lagoon.type: basic - ports: - - '3000:3000' - container_name: go-web - environment: - - MARIADB_10_4_DRUPAL_USERNAME=drupal - - MARIADB_10_4_DRUPAL_PASSWORD=drupal - - MARIADB_10_4_DRUPAL_DATABASE=drupal - - POSTGRES_SECURE_USERNAME=secure - - POSTGRES_SECURE_PASSWORD=secure - - POSTGRES_SECURE_DATABASE=secure - - POSTGRES_SECURE_HOST=postgres-secure - - POSTGRES_SECURE_PORT=5432 + commons: + image: uselagoon/commons:latest - mariadb-10-4-drupal: - image: uselagoon/mariadb-10.4-drupal - labels: - lagoon.type: mariadb-single - ports: - - '3306' - environment: - - LAGOON_TEST_VAR=test - - LAGOON_GIT_SHA=SHA256 - - LAGOON_ENVIRONMENT_TYPE=development + # web: + # build: + # context: . + # dockerfile: Dockerfile + # labels: + # lagoon.type: basic + # ports: + # - '3000:3000' + # container_name: go-web + # environment: + # - LAGOON_TEST_VAR="88@oWT47^v0QN6ZuId#rbqLW5h!#P8Zzsf0w@p7I@3B%E6b1A8" + # - MARIADB_10_4_DRUPAL_USERNAME=drupal + # - MARIADB_10_4_DRUPAL_PASSWORD=drupal + # - MARIADB_10_4_DRUPAL_DATABASE=drupal + # - POSTGRES_SECURE_USERNAME=secure + # - POSTGRES_SECURE_PASSWORD=secure + # - POSTGRES_SECURE_DATABASE=secure + # - POSTGRES_SECURE_HOST=postgres-secure + # - POSTGRES_SECURE_PORT=5432 - mongo-somedb: - image: uselagoon/mongo-4:latest - labels: - lagoon.type: mongo - ports: - - '27017' + # mariadb-10-4-drupal: + # image: uselagoon/mariadb-10.4-drupal + # labels: + # lagoon.type: mariadb-single + # ports: + # - '3306' + # environment: + # - LAGOON_TEST_VAR=test + # - LAGOON_GIT_SHA=SHA256 + # - LAGOON_ENVIRONMENT_TYPE=development - postgres-secure: - image: testlagoon/postgres-15:main - labels: - lagoon.type: postgres - ports: - - '5432' - environment: - - POSTGRES_PASSWORD=secure - - POSTGRES_USER=secure - - POSTGRES_DB=secure + # mongo-somedb: + # image: uselagoon/mongo-4:latest + # labels: + # lagoon.type: mongo + # ports: + # - '27017' + + # postgres-secure: + # image: testlagoon/postgres-15:main + # labels: + # lagoon.type: postgres + # ports: + # - '5432' + # environment: + # - POSTGRES_PASSWORD=secure + # - POSTGRES_USER=secure + # - POSTGRES_DB=secure diff --git a/docker-compose.yml b/docker-compose.yml index 6539aad..3416be1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,9 +1,10 @@ version: '2' volumes: - solrData: - solrData7: - opensearch-data1: + solr-7-data: + solr-8-data: + opensearch-2-data: + scratch: services: web: @@ -11,42 +12,45 @@ services: context: . dockerfile: Dockerfile labels: - lagoon.type: basic + lagoon.type: basic-persistent ports: - '3000:3000' container_name: go-web environment: - - LAGOON_TEST_VAR=test + - LAGOON_TEST_VAR=internal-services-test - LAGOON_GIT_SHA=SHA256 - LAGOON_ENVIRONMENT_TYPE=development + - STORAGE_LOCATION=/app/files + volumes: + - scratch:/app/files - mariadb-10-4: - image: uselagoon/mariadb-10.4 - labels: - lagoon.type: mariadb-single - ports: - - '3306' - mariadb-10-5: - image: uselagoon/mariadb-10.5 + image: uselagoon/mariadb-10.5:latest labels: lagoon.type: mariadb-single ports: - '3306' - mariadb-10-6: - image: uselagoon/mariadb-10.6 + mariadb-10-11: + image: uselagoon/mariadb-10.11:latest labels: lagoon.type: mariadb ports: - '3306' - mongo-4: - image: uselagoon/mongo:latest + postgres-11: + image: uselagoon/postgres-11:latest labels: - lagoon.type: mongo + lagoon.type: postgres-single ports: - - '27017' + - '5432' + + postgres-15: + image: uselagoon/postgres-15:latest + labels: + lagoon.type: postgres + ports: + - '5432' mysql-5-7: image: testlagoon/mysql-5.7:experimental @@ -66,9 +70,9 @@ services: image: uselagoon/opensearch-2:latest environment: - cluster.name=opensearch-cluster - - node.name=opensearch - - discovery.seed_hosts=opensearch - - cluster.initial_cluster_manager_nodes=opensearch + - node.name=opensearch-2 + - discovery.seed_hosts=opensearch-2 + - cluster.initial_cluster_manager_nodes=opensearch-2 - bootstrap.memory_lock=true - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m" ulimits: @@ -79,75 +83,53 @@ services: soft: 65536 hard: 65536 volumes: - - opensearch-data1:/usr/share/opensearch/data + - opensearch-2-data:/usr/share/opensearch/data labels: lagoon.type: opensearch ports: - '9200' - postgres-11: - image: uselagoon/postgres-11 - labels: - lagoon.type: postgres-single - ports: - - '5432' - - postgres-12: - image: uselagoon/postgres-12 - labels: - lagoon.type: postgres-single - ports: - - '5432' - - postgres-13: - image: uselagoon/postgres-13 - labels: - lagoon.type: postgres-single - ports: - - '5432' - - postgres-14: - image: uselagoon/postgres-14 + mongo-4: + image: uselagoon/mongo-4:latest labels: - lagoon.type: postgres + lagoon.type: mongo ports: - - '5432' + - '27017' - redis-5: - image: uselagoon/redis-5 + redis-6: + image: uselagoon/redis-5:latest labels: lagoon.type: redis ports: - '6379' - redis-6: - image: uselagoon/redis-6 + redis-7: + image: uselagoon/redis-6:latest labels: lagoon.type: redis ports: - '6379' solr-7: - image: uselagoon/solr-7 + image: uselagoon/solr-7:latest labels: lagoon.type: solr ports: - "8983" volumes: - - solrData7:/var/solr + - solr-7-data:/var/solr command: - solr-precreate - mycore solr-8: - image: uselagoon/solr-8 + image: uselagoon/solr-8:latest labels: lagoon.type: solr ports: - "8983" volumes: - - solrData:/var/solr + - solr-8-data:/var/solr command: - solr-precreate - mycore - diff --git a/go.mod b/go.mod index 9ad67cc..ae08217 100644 --- a/go.mod +++ b/go.mod @@ -1,29 +1,29 @@ -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-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/v2 v2.3.0 + github.com/redis/go-redis/v9 v9.3.0 + github.com/uselagoon/machinery v0.0.12 + 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/klauspost/compress v1.17.2 // indirect + github.com/montanaflynn/stats v0.7.1 // 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..e597c44 100644 --- a/go.sum +++ b/go.sum @@ -1,77 +1,125 @@ -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/aws/aws-sdk-go v1.44.263/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= +github.com/aws/aws-sdk-go-v2 v1.18.0/go.mod h1:uzbQtefpm44goOPmdKyAlXSNcwlRgF3ePWVW6EtJvvw= +github.com/aws/aws-sdk-go-v2/config v1.18.25/go.mod h1:dZnYpD5wTW/dQF0rRNLVypB396zWCcPiBIvdvSWHEg4= +github.com/aws/aws-sdk-go-v2/credentials v1.13.24/go.mod h1:jYPYi99wUOPIFi0rhiOvXeSEReVOzBqFNOX5bXYoG2o= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.3/go.mod h1:4Q0UFP0YJf0NrsEuEYHpM9fTSEVnD16Z3uyEF7J9JGM= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.33/go.mod h1:7i0PF1ME/2eUPFcjkVIwq+DOygHEoK92t5cDqNgYbIw= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.27/go.mod h1:UrHnn3QV/d0pBZ6QBAEQcqFLf8FAzLmoUfPVIueOvoM= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.34/go.mod h1:Etz2dj6UHYuw+Xw830KfzCfWGMzqvUTCjUj5b76GVDc= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.27/go.mod h1:EOwBD4J4S5qYszS5/3DpkejfuK+Z5/1uzICfPaZLtqw= +github.com/aws/aws-sdk-go-v2/service/sso v1.12.10/go.mod h1:ouy2P4z6sJN70fR3ka3wD3Ro3KezSxU6eKGQI2+2fjI= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.10/go.mod h1:AFvkxc8xfBe8XA+5St5XIHHrQQtkxqrRincx4hmMHOk= +github.com/aws/aws-sdk-go-v2/service/sts v1.19.0/go.mod h1:BgQOMsg8av8jset59jelyPW7NoZcZXLVpDsXunGDrk8= +github.com/aws/smithy-go v1.13.5/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= +github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs= +github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c= +github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA= +github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0= +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/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/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/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/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/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE= +github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= +github.com/opensearch-project/opensearch-go/v2 v2.3.0 h1:nQIEMr+A92CkhHrZgUhcfsrZjibvB3APXf2a1VwCmMQ= +github.com/opensearch-project/opensearch-go/v2 v2.3.0/go.mod h1:8LDr9FCgUTVoT+5ESjc2+iaZuldqE+23Iq0r1XeNue8= 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/redis/go-redis/v9 v9.3.0 h1:RiVDjmig62jIWp7Kk4XVLs0hzV6pI3PyTnnL0cnn0u0= +github.com/redis/go-redis/v9 v9.3.0/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M= 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/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= 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/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/uselagoon/machinery v0.0.12 h1:TJnA+FrL1uEhRTjJ6dExiL4G7SOQ+hUfGuWDmbW2HBA= +github.com/uselagoon/machinery v0.0.12/go.mod h1:h/qeMWQR4Qqu33x+8AulNDeolEwvb/G+aIsn/jyUtwk= 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.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= +golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +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.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.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/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +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.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +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/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 64553a0..d248166 100644 --- a/main.go +++ b/main.go @@ -3,32 +3,39 @@ package main import ( "bytes" "fmt" + "github.com/gorilla/mux" "log" "net/http" - "os" "strings" - - "github.com/gorilla/mux" -) - -var ( - localCheck = os.Getenv("LAGOON_ENVIRONMENT") + "time" ) 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("/{mysql:mysql-.*}", mysqlHandler) + 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("/storage", persistentStorageHandler) + r.HandleFunc("/mysql", mysqlHandler) 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) { @@ -62,16 +69,8 @@ func connectorKeyValues(values []string) string { func cleanRoute(basePath string) (string, string) { cleanRoute := strings.ReplaceAll(basePath, "/", "") localService := strings.ReplaceAll(cleanRoute, ".", "-") + //localService := strings.ReplaceAll(cleanRoute, "10.", "10-") replaceHyphen := strings.ReplaceAll(localService, "-", "_") lagoonService := strings.ToUpper(replaceHyphen) return localService, lagoonService } - -// 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 -} diff --git a/mariadb.go b/mariadb.go index 29c531d..93c4f6d 100644 --- a/mariadb.go +++ b/mariadb.go @@ -3,12 +3,12 @@ package main import ( "database/sql" "fmt" + _ "github.com/go-sql-driver/mysql" + machineryEnvVars "github.com/uselagoon/machinery/utils/variables" "log" "net/http" "os" "strings" - - _ "github.com/go-sql-driver/mysql" ) var ( @@ -17,13 +17,13 @@ var ( ) func mariadbHandler(w http.ResponseWriter, r *http.Request) { - mariadbPath := r.URL.Path - localService, lagoonService := cleanRoute(mariadbPath) - mariadbUser := getEnv(fmt.Sprintf("%s_USERNAME", lagoonService), "lagoon") - mariadbPassword := getEnv(fmt.Sprintf("%s_PASSWORD", lagoonService), "lagoon") - mariadbHost := getEnv(fmt.Sprintf("%s_HOST", lagoonService), localService) - mariadbPort := getEnv(fmt.Sprintf("%s_PORT", lagoonService), "3306") - mariadbDatabase := getEnv(fmt.Sprintf("%s_DATABASE", lagoonService), "lagoon") + service := r.URL.Query().Get("service") + localService, lagoonService := cleanRoute(service) + mariadbUser := machineryEnvVars.GetEnv(fmt.Sprintf("%s_USERNAME", lagoonService), "lagoon") + mariadbPassword := machineryEnvVars.GetEnv(fmt.Sprintf("%s_PASSWORD", lagoonService), "lagoon") + mariadbHost := machineryEnvVars.GetEnv(fmt.Sprintf("%s_HOST", lagoonService), localService) + mariadbPort := machineryEnvVars.GetEnv(fmt.Sprintf("%s_PORT", lagoonService), "3306") + mariadbDatabase := machineryEnvVars.GetEnv(fmt.Sprintf("%s_DATABASE", lagoonService), "lagoon") mariadbConnectionStr = fmt.Sprintf("%s:%s@tcp(%s:%s)/%s", mariadbUser, mariadbPassword, mariadbHost, mariadbPort, mariadbDatabase) log.Print(fmt.Sprintf("Using %s as the connstring", mariadbConnectionStr)) diff --git a/mongo.go b/mongo.go index ddde9ae..b2f6776 100644 --- a/mongo.go +++ b/mongo.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "fmt" + machineryEnvVars "github.com/uselagoon/machinery/utils/variables" "log" "net/http" "os" @@ -23,13 +24,13 @@ var ( ) func mongoHandler(w http.ResponseWriter, r *http.Request) { - mongoPath := r.URL.Path - localService, lagoonService := cleanRoute(mongoPath) - mongoUser := getEnv(fmt.Sprintf("%s_USERNAME", lagoonService), "lagoon") - mongoPassword := getEnv(fmt.Sprintf("%s_PASSWORD", lagoonService), "lagoon") - mongoHost := getEnv(fmt.Sprintf("%s_HOST", lagoonService), localService) - mongoPort := getEnv(fmt.Sprintf("%s_PORT", lagoonService), "27017") - mongoDatabase := getEnv(fmt.Sprintf("%s_DATABASE", lagoonService), "lagoon") + service := r.URL.Query().Get("service") + localService, lagoonService := cleanRoute(service) + mongoUser := machineryEnvVars.GetEnv(fmt.Sprintf("%s_USERNAME", lagoonService), "lagoon") + mongoPassword := machineryEnvVars.GetEnv(fmt.Sprintf("%s_PASSWORD", lagoonService), "lagoon") + mongoHost = machineryEnvVars.GetEnv(fmt.Sprintf("%s_HOST", lagoonService), localService) + mongoPort := machineryEnvVars.GetEnv(fmt.Sprintf("%s_PORT", lagoonService), "27017") + mongoDatabase := machineryEnvVars.GetEnv(fmt.Sprintf("%s_DATABASE", lagoonService), "lagoon") if mongoHost != localService { mongoConnectionStr = fmt.Sprintf("mongodb://%s:%s@%s:%s/%s", mongoUser, mongoPassword, mongoHost, mongoPort, mongoDatabase) @@ -81,7 +82,7 @@ func mongoConnector(connectionString string, database string) string { for _, e := range os.Environ() { pair := strings.SplitN(e, "=", 2) - bsonData := bson.D{{"Key", pair[0]}, {"value", pair[1]}} + bsonData := bson.D{{Key: "Key", Value: pair[0]}, {Key: "value", Value: pair[1]}} environmentVariables = append(environmentVariables, bsonData) if err != nil { log.Print(err) @@ -92,7 +93,7 @@ func mongoConnector(connectionString string, database string) string { if err != nil { log.Print(err) } - filter := bson.D{{"Key", primitive.Regex{Pattern: "LAGOON", Options: ""}}} + filter := bson.D{{Key: "Key", Value: primitive.Regex{Pattern: "LAGOON", Options: ""}}} cursor, _ := envCollection.Find(context.TODO(), filter, options.Find().SetProjection(bson.M{"_id": 0})) var docs []bson.M if err = cursor.All(context.TODO(), &docs); err != nil { diff --git a/mysql.go b/mysql.go index 693cd02..014c497 100644 --- a/mysql.go +++ b/mysql.go @@ -3,12 +3,12 @@ package main import ( "database/sql" "fmt" + _ "github.com/go-sql-driver/mysql" + machineryEnvVars "github.com/uselagoon/machinery/utils/variables" "log" "net/http" "os" "strings" - - _ "github.com/go-sql-driver/mysql" ) var ( @@ -17,13 +17,13 @@ var ( ) func mysqlHandler(w http.ResponseWriter, r *http.Request) { - mysqlPath := r.URL.Path - localService, lagoonService := cleanRoute(mysqlPath) - mysqlUser := getEnv(fmt.Sprintf("%s_USERNAME", lagoonService), "lagoon") - mysqlPassword := getEnv(fmt.Sprintf("%s_PASSWORD", lagoonService), "lagoon") - mysqlHost := getEnv(fmt.Sprintf("%s_HOST", lagoonService), localService) - mysqlPort := getEnv(fmt.Sprintf("%s_PORT", lagoonService), "3306") - mysqlDatabase := getEnv(fmt.Sprintf("%s_DATABASE", lagoonService), "lagoon") + service := r.URL.Query().Get("service") + localService, lagoonService := cleanRoute(service) + mysqlUser := machineryEnvVars.GetEnv(fmt.Sprintf("%s_USERNAME", lagoonService), "lagoon") + mysqlPassword := machineryEnvVars.GetEnv(fmt.Sprintf("%s_PASSWORD", lagoonService), "lagoon") + mysqlHost := machineryEnvVars.GetEnv(fmt.Sprintf("%s_HOST", lagoonService), localService) + mysqlPort := machineryEnvVars.GetEnv(fmt.Sprintf("%s_PORT", lagoonService), "3306") + mysqlDatabase := machineryEnvVars.GetEnv(fmt.Sprintf("%s_DATABASE", lagoonService), "lagoon") mysqlConnectionStr = fmt.Sprintf("%s:%s@tcp(%s:%s)/%s", mysqlUser, mysqlPassword, mysqlHost, mysqlPort, mysqlDatabase) log.Print(fmt.Sprintf("Using %s as the connstring", mysqlConnectionStr)) diff --git a/opensearch.go b/opensearch.go index 8aae8d3..fd0ea29 100644 --- a/opensearch.go +++ b/opensearch.go @@ -12,17 +12,20 @@ import ( "strings" "time" - "github.com/opensearch-project/opensearch-go" - "github.com/opensearch-project/opensearch-go/opensearchapi" + "github.com/opensearch-project/opensearch-go/v2" + "github.com/opensearch-project/opensearch-go/v2/opensearchapi" ) 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/persistentstorage.go b/persistentstorage.go new file mode 100644 index 0000000..ceb4a8e --- /dev/null +++ b/persistentstorage.go @@ -0,0 +1,47 @@ +package main + +import ( + "fmt" + machineryEnvVars "github.com/uselagoon/machinery/utils/variables" + "log" + "net/http" + "os" + "strconv" + "strings" +) + +func persistentStorageHandler(w http.ResponseWriter, r *http.Request) { + path := r.URL.Query().Get("path") + log.Print(fmt.Sprintf("Writing to %s", path)) + fmt.Fprintf(w, persistentStorageConnector(path)) +} + +func persistentStorageConnector(route string) string { + if route != machineryEnvVars.GetEnv("STORAGE_LOCATION", "") { + return "Storage location is not defined - ensure format matches '/storage?path=[path]'" + } + path := route + "/storage.txt" + f, err := os.Create(path) + if err != nil { + log.Println(err) + } + + for _, e := range os.Environ() { + if strings.Contains(e, "LAGOON_") { + _, err := f.WriteString(strconv.Quote(e) + "\n") + if err != nil { + log.Print(err) + } + e := f.Sync() + if e != nil { + log.Print(e) + } + } + } + + fileBuffer, err := os.ReadFile(path) + var results = string(fileBuffer) + storagePath := fmt.Sprintf(`"STORAGE_PATH=%s"`, path) + storageResults := storagePath + "\n" + results + return storageResults +} diff --git a/postgres.go b/postgres.go index ba24ab0..cae84a2 100644 --- a/postgres.go +++ b/postgres.go @@ -3,6 +3,7 @@ package main import ( "database/sql" "fmt" + machineryEnvVars "github.com/uselagoon/machinery/utils/variables" "log" "net/http" "os" @@ -18,13 +19,13 @@ var ( ) func postgresHandler(w http.ResponseWriter, r *http.Request) { - postgresPath := r.URL.Path - localService, lagoonService := cleanRoute(postgresPath) - postgresUser := getEnv(fmt.Sprintf("%s_USERNAME", lagoonService), "lagoon") - postgresPassword := getEnv(fmt.Sprintf("%s_PASSWORD", lagoonService), "lagoon") - postgresHost := getEnv(fmt.Sprintf("%s_HOST", lagoonService), localService) - postgresPort := getEnv(fmt.Sprintf("%s_PORT", lagoonService), "5432") - postgresDatabase := getEnv(fmt.Sprintf("%s_DATABASE", lagoonService), "lagoon") + service := r.URL.Query().Get("service") + localService, lagoonService := cleanRoute(service) + postgresUser := machineryEnvVars.GetEnv(fmt.Sprintf("%s_USERNAME", lagoonService), "lagoon") + postgresPassword := machineryEnvVars.GetEnv(fmt.Sprintf("%s_PASSWORD", lagoonService), "lagoon") + postgresHost := machineryEnvVars.GetEnv(fmt.Sprintf("%s_HOST", lagoonService), localService) + postgresPort := machineryEnvVars.GetEnv(fmt.Sprintf("%s_PORT", lagoonService), "5432") + postgresDatabase := machineryEnvVars.GetEnv(fmt.Sprintf("%s_DATABASE", lagoonService), "lagoon") postgresConnectionStr = fmt.Sprintf("user=%s password=%s dbname=%s sslmode=%s host=%s port=%s", postgresUser, postgresPassword, postgresDatabase, postgresSSL, postgresHost, postgresPort) log.Print(fmt.Sprintf("Using %s as the connstring", postgresConnectionStr)) diff --git a/redis.go b/redis.go index ef66668..9f128dc 100644 --- a/redis.go +++ b/redis.go @@ -8,7 +8,7 @@ import ( "os" "strings" - "github.com/go-redis/redis/v8" + "github.com/redis/go-redis/v9" ) var ( @@ -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 new file mode 100644 index 0000000..7adb3a3 --- /dev/null +++ b/renovate.json @@ -0,0 +1,14 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": [ + "config:base" + ], + "dependencyDashboard": true, + "packageRules": [ + { + "matchManagers": ["github-actions"], + "groupName": "GitHub actions" + } + ], + "postUpdateOptions": ["gomodTidy","gomodUpdateImportPaths"] +} 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)) }