Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify AWS_REGION variables #10158

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ DISCOURSE_URL=https://forum.worldcubeassociation.org
SURVEY_SECRET=wacdoesnotknowthis
S3_AVATARS_BUCKET=wca-avatar
S3_AVATARS_ASSET_HOST=https://avatars.worldcubeassociation.org
STORAGE_AWS_REGION=us-west-2
S3_AVATARS_REGION=us-west-2
AWS_REGION=us-west-2
ACTIVERECORD_PRIMARY_KEY=abcdefghijklmnopqrstuvwxyz1234567890
ACTIVERECORD_DETERMINISTIC_KEY=abcdefghijklmnopqrstuvwxyz1234567890
ACTIVERECORD_KEY_DERIVATION_SALT=abcdefghijklmnopqrstuvwxyz1234567890
Expand Down
3 changes: 1 addition & 2 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ DISCOURSE_URL=https://forum.worldcubeassociation.org
SURVEY_SECRET=wacdoesnotknowthis
S3_AVATARS_BUCKET=wca-avatar
S3_AVATARS_ASSET_HOST=https://avatars.worldcubeassociation.org
S3_AVATARS_REGION=us-west-2
STORAGE_AWS_REGION=us-west-2
AWS_REGION=us-west-2
ACTIVERECORD_PRIMARY_KEY=abcdefghijklmnopqrstuvwxyz1234567890
ACTIVERECORD_DETERMINISTIC_KEY=abcdefghijklmnopqrstuvwxyz1234567890
ACTIVERECORD_KEY_DERIVATION_SALT=abcdefghijklmnopqrstuvwxyz1234567890
Expand Down
1 change: 0 additions & 1 deletion app/controllers/database_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def current_results_export(file_type)
file_name = "#{DbDumpHelper::RESULTS_EXPORT_FOLDER}/#{base_name}"

bucket = Aws::S3::Resource.new(
region: EnvConfig.STORAGE_AWS_REGION,
credentials: Aws::ECSCredentials.new,
).bucket(DbDumpHelper::BUCKET_NAME)

Expand Down
1 change: 0 additions & 1 deletion app/controllers/panel_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def generate_db_token

@db_tokens = @db_endpoints.transform_values do |url|
token_generator.auth_token({
region: EnvConfig.DATABASE_AWS_REGION,
endpoint: "#{url}:3306",
user_name: EnvConfig.DATABASE_WRT_USER,
})
Expand Down
1 change: 0 additions & 1 deletion app/helpers/documents_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module DocumentsHelper

private def archive_metadata
bucket = Aws::S3::Resource.new(
region: EnvConfig.STORAGE_AWS_REGION,
credentials: Aws::ECSCredentials.new,
).bucket(BUCKET_NAME)

Expand Down
1 change: 0 additions & 1 deletion app/helpers/regulation_translations_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ module RegulationTranslationsHelper

private def regulations_bucket
Aws::S3::Resource.new(
region: EnvConfig.STORAGE_AWS_REGION,
credentials: Aws::ECSCredentials.new,
).bucket(BUCKET_NAME)
end
Expand Down
1 change: 0 additions & 1 deletion app/models/regulation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def self.reset_regulations

if Rails.env.production? && !EnvConfig.ASSETS_COMPILATION?
reload_regulations(Aws::S3::Resource.new(
region: EnvConfig.STORAGE_AWS_REGION,
credentials: Aws::ECSCredentials.new,
))
end
Expand Down
1 change: 0 additions & 1 deletion app/models/user_avatar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ def invalidate_thumbnail_if_approved
return unless thumbnail_changed

cloudfront_sdk = ::Aws::CloudFront::Client.new(
region: EnvConfig.S3_AVATARS_REGION,
access_key_id: AppSecrets.AWS_ACCESS_KEY_ID,
secret_access_key: AppSecrets.AWS_SECRET_ACCESS_KEY,
)
Expand Down
3 changes: 0 additions & 3 deletions config/storage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@ s3_default: &s3_default
amazon:
<<: *s3_default
bucket: <%= EnvConfig.STORAGE_AWS_BUCKET %>
region: <%= EnvConfig.STORAGE_AWS_REGION %>

s3_avatars_public:
<<: *s3_default
bucket: <%= EnvConfig.S3_AVATARS_BUCKET %>
region: <%= EnvConfig.S3_AVATARS_REGION %>
public: true

s3_avatars_private:
<<: *s3_default
bucket: <%= EnvConfig.S3_AVATARS_PRIVATE_BUCKET %>
region: <%= EnvConfig.S3_AVATARS_REGION %>
9 changes: 2 additions & 7 deletions env_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,20 @@
mandatory :SIDEKIQ_REDIS_URL, :string
mandatory :DISCOURSE_URL, :string
mandatory :STORAGE_AWS_BUCKET, :string
mandatory :STORAGE_AWS_REGION, :string
mandatory :S3_AVATARS_BUCKET, :string
mandatory :S3_AVATARS_PRIVATE_BUCKET, :string
mandatory :S3_AVATARS_ASSET_HOST, :string
mandatory :S3_AVATARS_REGION, :string
mandatory :AVATARS_PUBLIC_STORAGE, :string
mandatory :AVATARS_PRIVATE_STORAGE, :string
mandatory :CDN_AVATARS_DISTRIBUTION_ID, :string
mandatory :DATABASE_AWS_REGION, :string
mandatory :AWS_REGION, :string
mandatory :DATABASE_WRT_USER, :string
optional :PAYPAL_BASE_URL, :string ## TODO: Change to mandatory when launching paypal
mandatory :WRC_WEBHOOK_URL, :string

# Production-specific stuff
mandatory :VAULT_ADDR, :string
mandatory :VAULT_APPLICATION, :string
mandatory :VAULT_AWS_REGION, :string
mandatory :TASK_ROLE, :string
mandatory :WCA_REGISTRATIONS_URL, :string
mandatory :WCA_REGISTRATIONS_POLL_URL, :string
Expand All @@ -39,15 +36,13 @@
optional :SIDEKIQ_REDIS_URL, :string, ''
optional :DISCOURSE_URL, :string, ''
optional :STORAGE_AWS_BUCKET, :string, ''
optional :STORAGE_AWS_REGION, :string, ''
optional :AWS_REGION, :string, ''
optional :S3_AVATARS_BUCKET, :string, ''
optional :S3_AVATARS_PRIVATE_BUCKET, :string, ''
optional :S3_AVATARS_ASSET_HOST, :string, ''
optional :S3_AVATARS_REGION, :string, ''
optional :AVATARS_PUBLIC_STORAGE, :string, ''
optional :AVATARS_PRIVATE_STORAGE, :string, ''
optional :CDN_AVATARS_DISTRIBUTION_ID, :string, ''
optional :DATABASE_AWS_REGION, :string, ''
optional :DATABASE_WRT_USER, :string, ''
optional :WCA_REGISTRATIONS_URL, :string, ''
optional :WCA_REGISTRATIONS_POLL_URL, :string, ''
Expand Down
14 changes: 1 addition & 13 deletions infra/wca_on_rails/production/rails.tf
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,7 @@ locals {
value = aws_s3_bucket.storage-bucket.id
},
{
name = "STORAGE_AWS_REGION"
value = var.region
},
{
name = "VAULT_AWS_REGION"
value = var.region
},
{
name = "S3_AVATARS_REGION"
value = var.region
},
{
name = "DATABASE_AWS_REGION"
name = "AWS_REGION"
value = var.region
},
{
Expand Down
14 changes: 1 addition & 13 deletions infra/wca_on_rails/staging/rails.tf
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,7 @@ locals {
value = aws_s3_bucket.storage-bucket.id
},
{
name = "STORAGE_AWS_REGION"
value = var.region
},
{
name = "VAULT_AWS_REGION"
value = var.region
},
{
name = "S3_AVATARS_REGION"
value = var.region
},
{
name = "DATABASE_AWS_REGION"
name = "AWS_REGION"
value = var.region
},
{
Expand Down
4 changes: 1 addition & 3 deletions lib/db_dump_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ def self.zip_and_upload_to_s3(zip_filename, s3_path, *zip_contents)

LogTask.log_task "Moving zipped file to 's3://#{s3_path}'" do
bucket = Aws::S3::Resource.new(
region: EnvConfig.STORAGE_AWS_REGION,
credentials: Aws::ECSCredentials.new,
).bucket(BUCKET_NAME)
bucket.object(s3_path).upload_file(zip_filename)
Expand All @@ -106,8 +105,7 @@ def self.zip_and_upload_to_s3(zip_filename, s3_path, *zip_contents)

# Invalidate Export Route in Prod
if EnvConfig.WCA_LIVE_SITE?
Aws::CloudFront::Client.new(region: EnvConfig.STORAGE_AWS_REGION,
credentials: Aws::ECSCredentials.new)
Aws::CloudFront::Client.new(credentials: Aws::ECSCredentials.new)
.create_invalidation({
distribution_id: EnvConfig.CDN_ASSETS_DISTRIBUTION_ID,
invalidation_batch: {
Expand Down
1 change: 0 additions & 1 deletion lib/regulations_s3_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module RegulationsS3Helper
WCA_REGULATIONS_BUCKET = "wca-regulations"
def self.fetch_regulations_from_s3(key, version_file)
bucket = Aws::S3::Resource.new(
region: EnvConfig.STORAGE_AWS_REGION,
credentials: Aws::ECSCredentials.new,
).bucket(WCA_REGULATIONS_BUCKET)

Expand Down
2 changes: 1 addition & 1 deletion vault_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# Assume the correct role from the underlying task
role_credentials = Aws::ECSCredentials.new

Vault.auth.aws_iam(EnvConfig.TASK_ROLE, role_credentials, nil, "https://sts.#{EnvConfig.VAULT_AWS_REGION}.amazonaws.com")
Vault.auth.aws_iam(EnvConfig.TASK_ROLE, role_credentials, nil, "https://sts.#{EnvConfig.AWS_REGION}.amazonaws.com")

# Use SSL verification, also read as ENV["VAULT_SSL_VERIFY"]
# We are using Vault in internal AWS Traffic only
Expand Down