# typed: false # frozen_string_literal: true def set_env_var(production:, staging:, local:) case Rails.env when "production" %x(op read "#{production}").chomp when "staging" %x(op read "#{staging}").chomp else local end end def productionish? Rails.env.production? || Rails.env.staging? end def print_user_api_errors? (Rails.env.development? || Rails.env.staging?) || ENV.fetch("DEBUG", false) end def plug_shortname plug_name.downcase end def plug_name plug_module[4..] # 4= "Plug".length end def plug_module Rails.application.class.module_parent.name end def plug_url if Rails.env.production? "#{plug_shortname}.plugs.yetto.app" elsif Rails.env.staging? "#{plug_shortname}.plugs.yetto.dev" elsif Rails.env.development? "#{%x(hostname).chomp.downcase}-plug-#{plug_shortname}.ngrok.io" elsif Rails.env.test? "#{plug_shortname}.plugs.yetto.test" end end module Hephaestus YETTO_EMAIL_DOMAIN = if Rails.env.production? "yetto.email" elsif Rails.env.staging? "yetto.dev" elsif Rails.env.development? "yetto-dev.email" elsif Rails.env.test? "yetto.test" end PROTOCOL = Rails.env.development? ? "http://" : "https://" YETTO_URL = if Rails.env.production? "web.yetto.app" elsif Rails.env.staging? "web.yetto.dev" elsif Rails.env.development? "localhost:3000" elsif Rails.env.test? "web.yetto.test" end SLACK_LOG_URL = set_env_var( production: "op://Infra/Secrets/SLACK_LOG_URL", staging: "op://Infra/Secrets/SLACK_LOG_URL", local: ENV.fetch("SLACK_LOG_URL", "https://slack.com/the_log_room"), ) YETTO_API_URL = "#{YETTO_URL}/api" YETTO_REDIRECT_URL = productionish? ? "#{PROTOCOL}#{YETTO_URL}" : "#{PROTOCOL}127.0.0.1:3000" # Every plug has these secrets YETTO_PLUG_PEM = set_env_var( production: "op://Plug-#{plug_name}/Production/YETTO_PLUG_PEM", staging: "op://Plug-#{plug_name}/Staging/YETTO_PLUG_PEM", local: ENV.fetch("YETTO_PLUG_PEM", Rails.root.join("test/fixtures/files/fake_pem_file/fake.pem").read), ) YETTO_SIGNING_SECRET = set_env_var( production: "op://Plug-#{plug_name}/Production/YETTO_SIGNING_SECRET", staging: "op://Plug-#{plug_name}/Staging/YETTO_SIGNING_SECRET", local: ENV.fetch("YETTO_SIGNING_SECRET", "super-secret"), ) YETTO_PLUG_ID = set_env_var( production: "op://Plug-#{plug_name}/Production/YETTO_PLUG_ID", staging: "op://Plug-#{plug_name}/Staging/YETTO_PLUG_ID", local: ENV.fetch("YETTO_PLUG_ID", "plug-id"), ) end