Class: Hephaestus::Engine

Inherits:
Rails::Engine
  • Object
show all
Defined in:
lib/hephaestus/engine.rb

Constant Summary collapse

GIT_SHA =
case Rails.env
when "production", "staging"
  ENV["GIT_SHA"] || ""
when "development"
  %x(git rev-parse HEAD)
when "test"
  "deadbeef"
end.chomp

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.fetch_infra_secret(label:, default:) ⇒ Object

we need to check if the 1Password CLI is installed and load it ASAP, because it contains all the secrets



67
68
69
70
71
72
73
# File 'lib/hephaestus/engine.rb', line 67

def fetch_infra_secret(label:, default:)
  if productionish?
    op_read("op://Infra/Global Secrets/#{label}")
  else
    ENV.fetch(label, default.is_a?(Pathname) ? default.read : default)
  end
end

.insert_routesObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/hephaestus/engine.rb', line 45

def insert_routes
  Rails.application.routes.draw do
    # Staff pages
    get("staff", to: "staff#index")

    constraints(->(request) { StaffController.staff_request?(request) }) do
      mount(MissionControl::Jobs::Engine, at: "staff/jobs", as: :staff_jobs)
    end

    #############################################
    # error pages -- these MUST be at the end! ##
    #############################################

    get("/500", to: "application#render500") if Rails.env.production? || Rails.env.staging?

    match("/", to: "application#not_found", via: :all)
    match("/*unmatched_route", to: "application#not_found", via: :all)
  end
end

Instance Method Details

#check_dependencies!Object



82
83
84
# File 'lib/hephaestus/engine.rb', line 82

def check_dependencies!
  raise "1Password CLI is not installed" unless cli_installed?
end

#cli_installed?Boolean

Returns:

  • (Boolean)


86
87
88
89
# File 'lib/hephaestus/engine.rb', line 86

def cli_installed?
  %x(#{include_sudo?}op --version 2> /dev/null)
  $CHILD_STATUS.success?
end

#include_sudo?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/hephaestus/engine.rb', line 91

def include_sudo?
  !Rails.env.local? ? "sudo -E " : ""
end

#op_read(label) ⇒ Object



76
77
78
79
80
# File 'lib/hephaestus/engine.rb', line 76

def op_read(label)
  %x(#{include_sudo?}op read "#{label}").chomp.tap do
    raise "Failed to fetch `#{label}` from 1Password" unless $CHILD_STATUS.success?
  end
end