Skip to content

Commit

Permalink
properly use github secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
MiaAltieri committed Feb 16, 2024
1 parent 3a9b9ab commit fc2c80c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
7 changes: 3 additions & 4 deletions tests/integration/backup_tests/helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.
import os
import subprocess

import ops
Expand Down Expand Up @@ -95,11 +94,11 @@ async def count_failed_backups(db_unit: ops.model.Unit) -> int:
return failed_backups


async def set_credentials(ops_test: OpsTest, cloud: str) -> None:
async def set_credentials(ops_test: OpsTest, github_secrets, cloud: str) -> None:
"""Sets the s3 crednetials for the provided cloud, valid options are AWS or GCP."""
# set access key and secret keys
access_key = os.environ.get(f"{cloud}_ACCESS_KEY", False)
secret_key = os.environ.get(f"{cloud}_SECRET_KEY", False)
access_key = github_secrets[f"{cloud}_ACCESS_KEY_ID"]
secret_key = github_secrets[f"{cloud}_SECRET_ACCESS_KEY"]
assert access_key and secret_key, f"{cloud} access key and secret key not provided."

s3_integrator_unit = ops_test.model.applications[S3_APP_NAME].units[0]
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/backup_tests/test_backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ async def test_blocked_incorrect_conf(ops_test: OpsTest, github_secrets) -> None
db_app_name = await get_app_name(ops_test)

# set correct AWS credentials for s3 storage but incorrect configs
await helpers.set_credentials(ops_test, cloud="AWS")
await helpers.set_credentials(ops_test, github_secrets, cloud="AWS")

# wait for both applications to be idle with the correct statuses
async with ops_test.fast_forward():
Expand Down Expand Up @@ -138,7 +138,7 @@ async def test_ready_correct_conf(ops_test: OpsTest) -> None:
async def test_create_and_list_backups(ops_test: OpsTest, github_secrets) -> None:
db_app_name = await get_app_name(ops_test)
leader_unit = await helpers.get_leader_unit(ops_test, db_app_name=db_app_name)
await helpers.set_credentials(ops_test, cloud="AWS")
await helpers.set_credentials(ops_test, github_secrets, cloud="AWS")
# verify backup list works
logger.error("!!!!! test_create_and_list_backups >>> %s", leader_unit)
action = await leader_unit.run_action(action_name="list-backups")
Expand Down Expand Up @@ -188,7 +188,7 @@ async def test_multi_backup(ops_test: OpsTest, continuous_writes_to_db, github_s

# while first backup is running change access key, secret keys, and bucket name
# for GCP
await helpers.set_credentials(ops_test, cloud="GCP")
await helpers.set_credentials(ops_test, github_secrets, cloud="GCP")

# change to GCP configs and wait for PBM to resync
configuration_parameters = {
Expand Down Expand Up @@ -231,7 +231,7 @@ async def test_multi_backup(ops_test: OpsTest, continuous_writes_to_db, github_s
assert backups == 1, "Backup not created in first bucket on GCP."

# set AWS credentials, set configs for s3 storage, and wait to resync
await helpers.set_credentials(ops_test, cloud="AWS")
await helpers.set_credentials(ops_test, github_secrets, cloud="AWS")
configuration_parameters = {
"bucket": "data-charms-testing",
"region": "us-east-1",
Expand Down Expand Up @@ -314,7 +314,7 @@ async def test_restore_new_cluster(
):
# configure test for the cloud provider
db_app_name = await get_app_name(ops_test)
await helpers.set_credentials(ops_test, cloud=cloud_provider)
await helpers.set_credentials(ops_test, github_secrets, cloud=cloud_provider)
if cloud_provider == "AWS":
configuration_parameters = {
"bucket": "data-charms-testing",
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ set_env =
pass_env =
CI
GITHUB_OUTPUT
SECRETS_FROM_GITHUB
allowlist_externals =
{[testenv:build-wrapper]allowlist_externals}
deps =
Expand Down

0 comments on commit fc2c80c

Please sign in to comment.