Class: VagrantDockerCertificatesManager::Actions::Install

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-docker-certificates-manager/actions/install.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ Install

Returns a new instance of Install.



12
# File 'lib/vagrant-docker-certificates-manager/actions/install.rb', line 12

def initialize(app, env); @app = app; @env = env; end

Class Method Details

.perform_install(cfg, env) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/vagrant-docker-certificates-manager/actions/install.rb', line 27

def self.perform_install(cfg, env)
  unless File.file?(cfg.cert_path)
    return { code: 1, status: "error",
error: UiHelpers.t("errors.invalid_path", path: cfg.cert_path) }
  end

  name = cfg.cert_name.to_s.strip.empty? ? Cert.default_name_from(cfg.cert_path) : cfg.cert_name
  fp   = Cert.sha1(cfg.cert_path)
  if Registry.all.key?(fp)
    return { code: 1, status: "error",
error: UiHelpers.t("errors.already_present", name: name) }
  end

  os = OS.detect
  ok = case os
       when :mac     then OS.mac_add_trusted_cert(cfg.cert_path, name)
       when :linux   then OS.linux_install_cert(cfg.cert_path, name, nss: cfg.manage_nss_browsers,
firefox: cfg.manage_firefox)
       when :windows then OS.win_install_cert(cfg.cert_path, name)
       else return { code: 2, status: "error", error: UiHelpers.t("errors.os_unsupported") }
       end
  return({ code: 3, status: "error", error: UiHelpers.t("errors.install_failed") }) unless ok

  Registry.track(fp, {
    "path"      => File.expand_path(cfg.cert_path),
    "name"      => name,
    "nickname"  => Cert.nickname_for(name),
    "os"        => os.to_s
  })
  { code: 0, status: "success", data: { os: os, cert: name } }
end

Instance Method Details

#call(env) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/vagrant-docker-certificates-manager/actions/install.rb', line 14

def call(env)
  cfg = env[:machine].config.docker_certificates
  UiHelpers.set_locale!(cfg.locale || ENV["LANG"] || "en")
  if cfg.install_on_up
    Ui.say(env, :info, "install.start", name: cfg.cert_name, path: cfg.cert_path)
    result = self.class.perform_install(cfg, env)
    Ui.say(env, result[:status] == "success" ? :info : :error,
           result[:status] == "success" ? "install.success" : "install.fail",
           name: cfg.cert_name)
  end
  @app.call(env)
end