From e9b617be9a15016f8abb724709a6a1aef321cdb9 Mon Sep 17 00:00:00 2001 From: MaxJa4 <74194322+MaxJa4@users.noreply.github.com> Date: Wed, 23 Aug 2023 20:31:45 +0200 Subject: [PATCH] Squash for revert --- .github/workflows/test.yml | 4 + internal/storage/dropbox/dropbox.go | 2 +- test/adropbox/docker-compose.yml | 102 ++++++++++++++++++ test/{dropbox => adropbox}/oauth2_config.yaml | 0 test/{dropbox => adropbox}/run.sh | 7 +- test/{dropbox => adropbox}/user_v2.yaml | 0 test/dropbox/docker-compose.yml | 56 ---------- 7 files changed, 111 insertions(+), 60 deletions(-) create mode 100644 test/adropbox/docker-compose.yml rename test/{dropbox => adropbox}/oauth2_config.yaml (100%) rename test/{dropbox => adropbox}/run.sh (90%) rename test/{dropbox => adropbox}/user_v2.yaml (100%) delete mode 100644 test/dropbox/docker-compose.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3a539a2..b6d7755 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,6 +12,10 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Add hosts to /etc/hosts + run: | + sudo echo "127.0.0.1 host.docker.internal" | sudo tee -a /etc/hosts + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 diff --git a/internal/storage/dropbox/dropbox.go b/internal/storage/dropbox/dropbox.go index 954c638..c97524a 100644 --- a/internal/storage/dropbox/dropbox.go +++ b/internal/storage/dropbox/dropbox.go @@ -47,7 +47,7 @@ func NewStorageBackend(opts Config, logFunc storage.Log) (storage.Backend, error }, } - logFunc(storage.LogLevelInfo, "Dropbox", "Fetching fresh access token for Dropbox storage backend.") + logFunc(storage.LogLevelInfo, "Dropbox", "Fetching fresh access token from Dropbox OAuth2 endpoint '%s'...", tokenUrl) tkSource := conf.TokenSource(context.Background(), &oauth2.Token{RefreshToken: opts.RefreshToken}) token, err := tkSource.Token() if err != nil { diff --git a/test/adropbox/docker-compose.yml b/test/adropbox/docker-compose.yml new file mode 100644 index 0000000..151f2d2 --- /dev/null +++ b/test/adropbox/docker-compose.yml @@ -0,0 +1,102 @@ +version: '3' + +services: + openapi_mock: + image: muonsoft/openapi-mock + environment: + OPENAPI_MOCK_USE_EXAMPLES: if_present + OPENAPI_MOCK_SPECIFICATION_URL: '/etc/openapi/user_v2.yaml' + ports: + - 8080:8080 + volumes: + - ./user_v2.yaml:/etc/openapi/user_v2.yaml + networks: + mocking: + ipv4_address: 172.16.238.11 + + oauth2_mock: + image: ghcr.io/navikt/mock-oauth2-server:1.0.0 + ports: + - 8090:8090 + environment: + PORT: '8090' + SERVER_HOSTNAME: '172.16.238.10' + JSON_CONFIG: > + '{ + "issuer":"http://localhost:8090/default", + "authorization_endpoint":"http://localhost:8090/default/authorize", + "token_endpoint":"http://localhost:8090/default/token", + "response_types_supported":[ + "query", + "fragment", + "form_post" + ], + "subject_types_supported":[ + "public" + ], + "id_token_signing_alg_values_supported":[ + "ES256", + "ES384", + "RS256", + "RS384", + "RS512", + "PS256", + "PS384", + "PS512" + ], + "code_challenge_methods_supported":[ + "plain", + "S256" + ] + }' + hostname: host.docker.internal + networks: + mocking: + ipv4_address: 172.16.238.10 + + backup: + image: offen/docker-volume-backup:${TEST_VERSION:-canary} + hostname: host.docker.internal + depends_on: + - openapi_mock + - oauth2_mock + restart: always + environment: + BACKUP_FILENAME_EXPAND: 'true' + BACKUP_FILENAME: test-$$HOSTNAME.tar.gz + BACKUP_CRON_EXPRESSION: 0 0 5 31 2 ? + BACKUP_RETENTION_DAYS: ${BACKUP_RETENTION_DAYS:-7} + BACKUP_PRUNING_LEEWAY: 5s + BACKUP_PRUNING_PREFIX: test + DROPBOX_ENDPOINT: http://openapi_mock:8080 + DROPBOX_OAUTH2_ENDPOINT: http://172.16.238.10:8090 + DROPBOX_REFRESH_TOKEN: test + DROPBOX_APP_KEY: test + DROPBOX_APP_SECRET: test + DROPBOX_REMOTE_PATH: /test + DROPBOX_CONCURRENCY_LEVEL: 6 + volumes: + - app_data:/backup/app_data:ro + - /var/run/docker.sock:/var/run/docker.sock + networks: + mocking: + ipv4_address: 172.16.238.12 + extra_hosts: + - "host.docker.internal:host-gateway" + + offen: + image: offen/offen:latest + labels: + - docker-volume-backup.stop-during-backup=true + volumes: + - app_data:/var/opt/offen + +volumes: + app_data: + +networks: + mocking: + driver: default + ipam: + config: + - subnet: 172.16.238.0/24 \ No newline at end of file diff --git a/test/dropbox/oauth2_config.yaml b/test/adropbox/oauth2_config.yaml similarity index 100% rename from test/dropbox/oauth2_config.yaml rename to test/adropbox/oauth2_config.yaml diff --git a/test/dropbox/run.sh b/test/adropbox/run.sh similarity index 90% rename from test/dropbox/run.sh rename to test/adropbox/run.sh index e581c12..8673dc5 100644 --- a/test/dropbox/run.sh +++ b/test/adropbox/run.sh @@ -7,9 +7,10 @@ cd "$(dirname "$0")" current_test=$(basename $(pwd)) docker compose up -d -sleep 5 +sleep 10 -logs=$(docker compose exec -T backup backup) +#logs=$(docker compose exec -T backup backup) +docker compose exec backup backup sleep 5 @@ -26,7 +27,7 @@ fi # is set to 0 days (which it should not as it would mean all backups get deleted) # TODO: find out if we can test actual deletion without having to wait for a day BACKUP_RETENTION_DAYS="0" docker compose up -d -sleep 5 +sleep 10 logs=$(docker compose exec -T backup backup) diff --git a/test/dropbox/user_v2.yaml b/test/adropbox/user_v2.yaml similarity index 100% rename from test/dropbox/user_v2.yaml rename to test/adropbox/user_v2.yaml diff --git a/test/dropbox/docker-compose.yml b/test/dropbox/docker-compose.yml deleted file mode 100644 index 2fbf33b..0000000 --- a/test/dropbox/docker-compose.yml +++ /dev/null @@ -1,56 +0,0 @@ -version: '3' - -services: - openapi_mock: - image: muonsoft/openapi-mock - environment: - OPENAPI_MOCK_USE_EXAMPLES: if_present - OPENAPI_MOCK_SPECIFICATION_URL: '/etc/openapi/user_v2.yaml' - ports: - - 8080:8080 - volumes: - - ./user_v2.yaml:/etc/openapi/user_v2.yaml - - oauth2_mock: - image: ghcr.io/navikt/mock-oauth2-server:1.0.0 - ports: - - 8090:8090 - environment: - PORT: 8090 - JSON_CONFIG_PATH: '/etc/oauth2/config.yaml' - volumes: - - ./oauth2_config.yaml:/etc/oauth2/config.yaml - - backup: - image: offen/docker-volume-backup:${TEST_VERSION:-canary} - hostname: hostnametoken - depends_on: - - openapi_mock - restart: always - environment: - BACKUP_FILENAME_EXPAND: 'true' - BACKUP_FILENAME: test-$$HOSTNAME.tar.gz - BACKUP_CRON_EXPRESSION: 0 0 5 31 2 ? - BACKUP_RETENTION_DAYS: ${BACKUP_RETENTION_DAYS:-7} - BACKUP_PRUNING_LEEWAY: 5s - BACKUP_PRUNING_PREFIX: test - DROPBOX_ENDPOINT: http://openapi_mock:8080 - DROPBOX_OAUTH2_ENDPOINT: http://oauth2_mock:8090 - DROPBOX_REFRESH_TOKEN: test - DROPBOX_APP_KEY: test - DROPBOX_APP_SECRET: test - DROPBOX_REMOTE_PATH: /test - DROPBOX_CONCURRENCY_LEVEL: 6 - volumes: - - app_data:/backup/app_data:ro - - /var/run/docker.sock:/var/run/docker.sock - - offen: - image: offen/offen:latest - labels: - - docker-volume-backup.stop-during-backup=true - volumes: - - app_data:/var/opt/offen - -volumes: - app_data: