Skip to content

Commit

Permalink
refactor: Remove env variables prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
jachym-tousek-keboola committed Nov 18, 2024
1 parent 24af764 commit 807da0e
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 66 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ on: [ push ]
concurrency: ci

env:
TEST_AZURE_TENANT_ID: 9b85ee6f-4fb0-4a46-8cb7-4dcc6b262a89
TEST_AZURE_CLIENT_ID: 018b2e1a-41f3-48cf-a3b6-dd93f74c6d2f
TEST_AZURE_CLIENT_SECRET: ${{ secrets.TEST_AZURE_CLIENT_SECRET }}
TEST_AZURE_KEY_VAULT_URL: https://ci-go-cloud-encrypt.vault.azure.net/
TEST_AZURE_KEY_NAME: ci-go-cloud-encrypt
TEST_AWS_REGION: eu-central-1
TEST_AWS_ACCESS_KEY_ID: AKIA4DHGP53NXOCD6Y6B
TEST_AWS_SECRET_ACCESS_KEY: ${{ secrets.TEST_AWS_SECRET_ACCESS_KEY }}
TEST_AWS_KMS_KEY_ID: f14ac86a-dc61-4544-b1f7-6312773765f0
TEST_AWS_ROLE_ID: arn:aws:iam::831559560923:role/ci-go-cloud-encrypt-role
TEST_GCP_KMS_KEY_ID: projects/go-team-ci/locations/global/keyRings/ci-go-cloud-encrypt/cryptoKeys/ci-go-cloud-encrypt
AZURE_TENANT_ID: 9b85ee6f-4fb0-4a46-8cb7-4dcc6b262a89
AZURE_CLIENT_ID: 018b2e1a-41f3-48cf-a3b6-dd93f74c6d2f
AZURE_CLIENT_SECRET: ${{ secrets.TEST_AZURE_CLIENT_SECRET }}
AZURE_KEY_VAULT_URL: https://ci-go-cloud-encrypt.vault.azure.net/
AZURE_KEY_NAME: ci-go-cloud-encrypt
AWS_REGION: eu-central-1
AWS_ACCESS_KEY_ID: AKIA4DHGP53NXOCD6Y6B
AWS_SECRET_ACCESS_KEY: ${{ secrets.TEST_AWS_SECRET_ACCESS_KEY }}
AWS_KMS_KEY_ID: f14ac86a-dc61-4544-b1f7-6312773765f0
AWS_ROLE_ID: arn:aws:iam::831559560923:role/ci-go-cloud-encrypt-role
GCP_KMS_KEY_ID: projects/go-team-ci/locations/global/keyRings/ci-go-cloud-encrypt/cryptoKeys/ci-go-cloud-encrypt
jobs:
tests:
runs-on: ubuntu-latest
Expand Down
24 changes: 12 additions & 12 deletions docker-compose.ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ services:
ci:
build: .
environment:
TEST_AZURE_TENANT_ID:
TEST_AZURE_CLIENT_ID:
TEST_AZURE_CLIENT_SECRET:
TEST_AZURE_KEY_VAULT_URL:
TEST_AZURE_KEY_NAME:
TEST_AWS_REGION:
TEST_AWS_ACCESS_KEY_ID:
TEST_AWS_SECRET_ACCESS_KEY:
TEST_AWS_KMS_KEY_ID:
TEST_AWS_ROLE_ID:
TEST_GCP_KMS_KEY_ID:
TEST_GOOGLE_APPLICATION_CREDENTIALS: /code/var/gcp-private-key.json
AZURE_TENANT_ID:
AZURE_CLIENT_ID:
AZURE_CLIENT_SECRET:
AZURE_KEY_VAULT_URL:
AZURE_KEY_NAME:
AWS_REGION:
AWS_ACCESS_KEY_ID:
AWS_SECRET_ACCESS_KEY:
AWS_KMS_KEY_ID:
AWS_ROLE_ID:
GCP_KMS_KEY_ID:
GOOGLE_APPLICATION_CREDENTIALS: /code/var/gcp-private-key.json
volumes:
- ./:/code:z
- $GOOGLE_APPLICATION_CREDENTIALS:/code/var/gcp-private-key.json
17 changes: 4 additions & 13 deletions pkg/cloudencrypt/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,14 @@ func TestAWSEncryptor(t *testing.T) {

ctx := context.Background()

err := os.Setenv("AWS_ACCESS_KEY_ID", os.Getenv("TEST_AWS_ACCESS_KEY_ID"))
require.NoError(t, err)

err = os.Setenv("AWS_SECRET_ACCESS_KEY", os.Getenv("TEST_AWS_SECRET_ACCESS_KEY"))
require.NoError(t, err)

err = os.Setenv("AWS_ROLE_ID", os.Getenv("TEST_AWS_ROLE_ID"))
require.NoError(t, err)

region := os.Getenv("TEST_AWS_REGION")
region := os.Getenv("AWS_REGION")
if region == "" {
require.Fail(t, "TEST_AWS_REGION is empty")
require.Fail(t, "AWS_REGION is empty")
}

keyID := os.Getenv("TEST_AWS_KMS_KEY_ID")
keyID := os.Getenv("AWS_KMS_KEY_ID")
if keyID == "" {
require.Fail(t, "TEST_AWS_KMS_KEY_ID is empty")
require.Fail(t, "AWS_KMS_KEY_ID is empty")
}

encryptor, err := NewAWSEncryptor(ctx, region, keyID)
Expand Down
17 changes: 4 additions & 13 deletions pkg/cloudencrypt/azure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,14 @@ func TestAzureEncryptor(t *testing.T) {

ctx := context.Background()

err := os.Setenv("AZURE_TENANT_ID", os.Getenv("TEST_AZURE_TENANT_ID"))
require.NoError(t, err)

err = os.Setenv("AZURE_CLIENT_ID", os.Getenv("TEST_AZURE_CLIENT_ID"))
require.NoError(t, err)

err = os.Setenv("AZURE_CLIENT_SECRET", os.Getenv("TEST_AZURE_CLIENT_SECRET"))
require.NoError(t, err)

vaultURL := os.Getenv("TEST_AZURE_KEY_VAULT_URL")
vaultURL := os.Getenv("AZURE_KEY_VAULT_URL")
if vaultURL == "" {
require.Fail(t, "TEST_AZURE_KEY_VAULT_URL is empty")
require.Fail(t, "AZURE_KEY_VAULT_URL is empty")
}

keyName := os.Getenv("TEST_AZURE_KEY_NAME")
keyName := os.Getenv("AZURE_KEY_NAME")
if keyName == "" {
require.Fail(t, "TEST_AZURE_KEY_NAME is empty")
require.Fail(t, "AZURE_KEY_NAME is empty")
}

azureEncryptor, err := NewAzureEncryptor(ctx, vaultURL, keyName)
Expand Down
7 changes: 2 additions & 5 deletions pkg/cloudencrypt/gcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@ func TestGCPEncryptor(t *testing.T) {

ctx := context.Background()

err := os.Setenv("GOOGLE_APPLICATION_CREDENTIALS", os.Getenv("TEST_GOOGLE_APPLICATION_CREDENTIALS"))
require.NoError(t, err)

keyID := os.Getenv("TEST_GCP_KMS_KEY_ID")
keyID := os.Getenv("GCP_KMS_KEY_ID")
if keyID == "" {
require.Fail(t, "TEST_GCP_KMS_KEY_ID is empty")
require.Fail(t, "GCP_KMS_KEY_ID is empty")
}

encryptor, err := NewGCPEncryptor(ctx, keyID)
Expand Down
24 changes: 12 additions & 12 deletions provisioning/local/env-scripts/extract-variables-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ cd "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source ./functions.sh

# output variables
output_var 'TEST_AZURE_TENANT_ID' "$(terraform_output 'az_tenant_id')"
output_var 'TEST_AZURE_CLIENT_ID' "$(terraform_output 'az_application_id')"
output_var 'TEST_AZURE_CLIENT_SECRET' "$(terraform_output 'az_application_secret')"
output_var 'TEST_AZURE_KEY_VAULT_URL' "$(terraform_output 'az_key_vault_url')"
output_var 'TEST_AZURE_KEY_NAME' "$(terraform_output 'az_key_name')"
output_var 'AZURE_TENANT_ID' "$(terraform_output 'az_tenant_id')"
output_var 'AZURE_CLIENT_ID' "$(terraform_output 'az_application_id')"
output_var 'AZURE_CLIENT_SECRET' "$(terraform_output 'az_application_secret')"
output_var 'AZURE_KEY_VAULT_URL' "$(terraform_output 'az_key_vault_url')"
output_var 'AZURE_KEY_NAME' "$(terraform_output 'az_key_name')"
echo ""

output_var 'TEST_AWS_ACCESS_KEY_ID' "$(terraform_output 'aws_access_key_id')"
output_var 'TEST_AWS_SECRET_ACCESS_KEY' "$(terraform_output 'aws_access_key_secret')"
output_var 'TEST_AWS_REGION' "$(terraform_output 'aws_region')"
output_var 'TEST_AWS_KMS_KEY_ID' "$(terraform_output 'aws_kms_key_id')"
output_var 'TEST_AWS_ROLE_ID' "$(terraform_output 'aws_role_arn')"
output_var 'AWS_ACCESS_KEY_ID' "$(terraform_output 'aws_access_key_id')"
output_var 'AWS_SECRET_ACCESS_KEY' "$(terraform_output 'aws_access_key_secret')"
output_var 'AWS_REGION' "$(terraform_output 'aws_region')"
output_var 'AWS_KMS_KEY_ID' "$(terraform_output 'aws_kms_key_id')"
output_var 'AWS_ROLE_ID' "$(terraform_output 'aws_role_arn')"
echo ""

output_var 'TEST_GCP_KMS_KEY_ID' "$(terraform_output 'gcp_kms_key_id')"
output_var 'GCP_KMS_KEY_ID' "$(terraform_output 'gcp_kms_key_id')"
PRIVATE_KEY_ENCODED="$(terraform_output 'gcp_private_key')"
PRIVATE_KEY=$(printf "%s" "$PRIVATE_KEY_ENCODED" | base64 --decode)

output_file 'var/gcp-private-key.json' "$PRIVATE_KEY"
output_var 'TEST_GOOGLE_APPLICATION_CREDENTIALS' '/code/var/gcp-private-key.json'
output_var 'GOOGLE_APPLICATION_CREDENTIALS' '/code/var/gcp-private-key.json'

echo ""

0 comments on commit 807da0e

Please sign in to comment.