Class: VagrantDockerCertificatesManager::Actions::Install
- Inherits:
-
Object
- Object
- VagrantDockerCertificatesManager::Actions::Install
- Defined in:
- lib/vagrant-docker-certificates-manager/actions/install.rb
Class Method Summary collapse
-
.perform_install(cfg, env) ⇒ Hash
Installs a configured certificate into the current host trust store.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ Install
constructor
A new instance of Install.
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) ⇒ Hash
Installs a configured certificate into the current host trust store.
The operation is idempotent: when the fingerprint is already tracked, the current machine adopts the existing registry entry instead of reinstalling the certificate.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/vagrant-docker-certificates-manager/actions/install.rb', line 36 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) mid = env && env[:machine]&.id if Registry.all.key?(fp) Registry.adopt(fp, mid) if mid return { code: 0, status: "success", data: { os: OS.detect, cert: name, already: true } } 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.(cfg.cert_path), "name" => name, "nickname" => Cert.nickname_for(name), "os" => os.to_s, "owners" => [mid].compact }) { 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 |