Skip to content

Commit

Permalink
Migrate gcp wif
Browse files Browse the repository at this point in the history
  • Loading branch information
Neill Turner committed Dec 20, 2024
1 parent e36080a commit 7078e96
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 9 deletions.
1 change: 1 addition & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,5 @@
config.log_level = :debug # Or :info
config.log_format = :color # Console colorised non-json output
config.semantic_logger.backtrace_level = :debug # Show file and line number (expensive: not for production)
config.dfe_analytics = true
end
1 change: 1 addition & 0 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,5 @@

# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
config.dfe_analytics = false
end
1 change: 1 addition & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,5 @@
Bullet.add_safelist type: :unused_eager_loading, class_name: "TslrClaim", association: :current_school
Bullet.add_safelist type: :n_plus_one_query, class_name: "School", association: :local_authority
end
config.dfe_analytics = false
end
62 changes: 53 additions & 9 deletions config/initializers/dfe_analytics.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,58 @@
require "hosting_environment"

DfE::Analytics.configure do |config|
config.queue = :analytics
config.environment = HostingEnvironment.environment_name
# Whether to log events instead of sending them to BigQuery.
#
config.log_only = false

# Whether to use ActiveJob or dispatch events immediately.
#
config.async = true
config.entity_table_checks_enabled = true

config.enable_analytics =
proc do
disabled_by_default = Rails.env.development?
ENV.fetch("BIGQUERY_DISABLE", disabled_by_default.to_s) != "true"
end
# Which ActiveJob queue to put events on
#
config.queue = :analytics

# The name of the BigQuery table we’re writing to.
#
# config.bigquery_table_name = ENV['BIGQUERY_TABLE_NAME']

# The name of the BigQuery project we’re writing to.
#
# config.bigquery_project_id = ENV['BIGQUERY_PROJECT_ID']

# The name of the BigQuery dataset we're writing to.
#
# config.bigquery_dataset = ENV['BIGQUERY_DATASET']

# Service account JSON key for the BigQuery API. See
# https://cloud.google.com/bigquery/docs/authentication/service-account-file
#
# We base64 encode the secret otherwise the raw JSON is mangled when it gets
#  written to/read from the Azure keyvault.
config.bigquery_api_json_key = ENV['BIGQUERY_API_JSON_KEY'] ? Base64.decode64(ENV['BIGQUERY_API_JSON_KEY']) : nil

# Passed directly to the retries: option on the BigQuery client
#
# config.bigquery_retries = 3

# Passed directly to the timeout: option on the BigQuery client
#
# config.bigquery_timeout = 120

# A proc which returns true or false depending on whether you want to
# enable analytics. You might want to hook this up to a feature flag or
# environment variable.
#
config.enable_analytics = proc { Rails.application.config.dfe_analytics }

config.user_identifier = proc { |user| user&.sub }

# The environment we’re running in. This value will be attached
# to all events we send to BigQuery.
#
# config.environment = ENV.fetch('RAILS_ENV', 'development')

config.bigquery_maintenance_window = "08-09-2024 18:00..08-09-2024 19:00"

config.azure_federated_auth = ENV.include? "GOOGLE_CLOUD_CREDENTIALS"
end

0 comments on commit 7078e96

Please sign in to comment.