vagrant-docker-certificates-manager 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +8 -0
- data/LICENSE.md +22 -0
- data/README.md +197 -0
- data/lib/vagrant-docker-certificates-manager/VERSION +1 -0
- data/lib/vagrant-docker-certificates-manager/actions/install.rb +60 -0
- data/lib/vagrant-docker-certificates-manager/actions/uninstall.rb +47 -0
- data/lib/vagrant-docker-certificates-manager/command.rb +190 -0
- data/lib/vagrant-docker-certificates-manager/config.rb +38 -0
- data/lib/vagrant-docker-certificates-manager/helpers.rb +179 -0
- data/lib/vagrant-docker-certificates-manager/plugin.rb +32 -0
- data/lib/vagrant-docker-certificates-manager/util/cert.rb +35 -0
- data/lib/vagrant-docker-certificates-manager/util/os.rb +132 -0
- data/lib/vagrant-docker-certificates-manager/util/registry.rb +53 -0
- data/lib/vagrant-docker-certificates-manager/util/ui.rb +31 -0
- data/lib/vagrant-docker-certificates-manager/version.rb +10 -0
- data/lib/vagrant-docker-certificates-manager.rb +3 -0
- data/locales/en.yml +93 -0
- data/locales/fr.yml +93 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 023a4ac2fc48aacbf0de2d60bfa2b91a8890318b623c2169538ea748db884367
|
4
|
+
data.tar.gz: 8b709c9e9c8a637e80df487b3ca0381e9ff1cd0c2334941024819a842050e4b6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2cdba816ec1797ad404199e153bdb3e25b9b105bc62ea872d1068efbdaf0649e9e80ea8b1044c46f966b19e19cda29c85fb09c80af5632cf1acbe794e3152fc0
|
7
|
+
data.tar.gz: 8697e75304b157574141dc5b7ebeef2d81ffcc4c6bb27d23277f45f25418a40bb8c1e3de045f8b7bb418adfff601d3eb7058b2af15df97d4ecf16e92f324274e
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## [0.2.0](https://github.com/julienpoirou/vagrant-docker-certificates-manager/compare/v0.1.0...v0.2.0) (2025-08-20)
|
4
|
+
|
5
|
+
|
6
|
+
### Fonctionnalités ✨
|
7
|
+
|
8
|
+
* **init:** V0.1.0 ([e3a22bf](https://github.com/julienpoirou/vagrant-docker-certificates-manager/commit/e3a22bf18484e23106d2cca9d0ef9c67618956f8))
|
data/LICENSE.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
MIT License
|
2
|
+
===========
|
3
|
+
|
4
|
+
Copyright (c) 2025 Julien Poirou <julienpoirou@protonmail.com>
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
of this software and associated documentation files (the “Software”), to deal
|
8
|
+
in the Software without restriction, including without limitation the rights
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
11
|
+
furnished to do so, subject to the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be included in
|
14
|
+
all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,197 @@
|
|
1
|
+
# vagrant-docker-certificates-manager
|
2
|
+
|
3
|
+
[](https://github.com/julienpoirou/vagrant-docker-certificates-manager/actions/workflows/ci.yml)
|
4
|
+
[](https://github.com/julienpoirou/vagrant-docker-certificates-manager/actions/workflows/codeql.yml)
|
5
|
+
[](https://github.com/julienpoirou/vagrant-docker-certificates-manager/releases)
|
6
|
+
[](https://rubygems.org/gems/vagrant-docker-certificates-manager)
|
7
|
+
[](LICENSE.md)
|
8
|
+
[](https://www.conventionalcommits.org)
|
9
|
+
[](https://renovatebot.com)
|
10
|
+
[](https://rubygems.org/gems/vagrant-docker-certificates-manager)
|
11
|
+
|
12
|
+
Vagrant plugin to **install/uninstall a local Root CA certificate** into the host system trust stores and (optionally) browser NSS stores. Works on **macOS, Linux and Windows**.
|
13
|
+
|
14
|
+
- Can install the certificate on `vagrant up` (opt‑in)
|
15
|
+
- CLI: `vagrant certs add | remove | list | version | help`
|
16
|
+
- Optional support for Firefox and Chromium-based browsers (NSS)
|
17
|
+
- Multilingual output (**en**, **fr**) and `--no-emoji` option
|
18
|
+
|
19
|
+
> Requirements: **Vagrant ≥ 2.2**, **Ruby ≥ 3.1**.
|
20
|
+
> For Linux: `update-ca-certificates` (Debian/Ubuntu) and optional `libnss3-tools` for browser stores.
|
21
|
+
> ⚠️ **Only install certificates you trust**.
|
22
|
+
|
23
|
+
---
|
24
|
+
|
25
|
+
## Table of contents
|
26
|
+
|
27
|
+
- [Why this plugin?](#why-this-plugin)
|
28
|
+
- [Installation](#installation)
|
29
|
+
- [Quick start](#quick-start)
|
30
|
+
- [Vagrantfile configuration](#vagrantfile-configuration)
|
31
|
+
- [CLI usage](#cli-usage)
|
32
|
+
- [How it works](#how-it-works)
|
33
|
+
- [OS-specific notes](#os-specific-notes)
|
34
|
+
- [Environment variables](#environment-variables)
|
35
|
+
- [Troubleshooting](#troubleshooting)
|
36
|
+
- [Contributing & Development](#contributing--development)
|
37
|
+
- [License](#license)
|
38
|
+
|
39
|
+
> 🇫🇷 **Français :** voir [README.fr.md](README.fr.md)
|
40
|
+
|
41
|
+
---
|
42
|
+
|
43
|
+
## Why this plugin?
|
44
|
+
|
45
|
+
Local development with HTTPS often relies on a **local CA** (e.g. `rootca.cert.pem`) to sign project certificates (`*.local`). Manually adding that CA to each teammate’s **system trust store** and **browser** is tedious and error‑prone. This plugin makes it **repeatable**, **scriptable** and **cross‑platform**.
|
46
|
+
|
47
|
+
---
|
48
|
+
|
49
|
+
## Installation
|
50
|
+
|
51
|
+
From RubyGems (once published):
|
52
|
+
|
53
|
+
```bash
|
54
|
+
vagrant plugin install vagrant-docker-certificates-manager
|
55
|
+
```
|
56
|
+
|
57
|
+
From source:
|
58
|
+
|
59
|
+
```bash
|
60
|
+
git clone https://github.com/julienpoirou/vagrant-docker-certificates-manager
|
61
|
+
cd vagrant-docker-certificates-manager
|
62
|
+
bundle install
|
63
|
+
rake
|
64
|
+
vagrant plugin install .
|
65
|
+
```
|
66
|
+
|
67
|
+
---
|
68
|
+
|
69
|
+
## Quick start
|
70
|
+
|
71
|
+
### Minimal Vagrantfile
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
Vagrant.configure("2") do |config|
|
75
|
+
config.vm.box = "hashicorp/ubuntu-22.04"
|
76
|
+
|
77
|
+
# Required
|
78
|
+
config.docker_certificates.cert_path = "./certs/rootca.cert.pem" # your Root CA
|
79
|
+
config.docker_certificates.cert_name = "noesi.local"
|
80
|
+
|
81
|
+
# Optional
|
82
|
+
config.docker_certificates.install_on_up = true # auto-install on `vagrant up`
|
83
|
+
# config.docker_certificates.manage_firefox = true
|
84
|
+
# config.docker_certificates.manage_nss_browsers = true
|
85
|
+
# config.docker_certificates.locale = "fr" # or "en"
|
86
|
+
end
|
87
|
+
```
|
88
|
+
|
89
|
+
Bring the VM up:
|
90
|
+
|
91
|
+
```bash
|
92
|
+
vagrant up
|
93
|
+
```
|
94
|
+
|
95
|
+
This will attempt to install the CA into the host trust store (and optional browsers) using OS-specific commands.
|
96
|
+
|
97
|
+
---
|
98
|
+
|
99
|
+
## Vagrantfile configuration
|
100
|
+
|
101
|
+
| Key | Type | Default | Description |
|
102
|
+
|---------------------------|---------|----------|-------------|
|
103
|
+
| `cert_path` | String | `nil` | **Required.** Path to your Root CA PEM file on the **host**. |
|
104
|
+
| `cert_name` | String | `local.dev` | Display/friendly name for OS/browser stores. |
|
105
|
+
| `install_on_up` | Bool | `false` | Install automatically during `vagrant up`. |
|
106
|
+
| `manage_firefox` | Bool | `false` | Attempt to add CA to Firefox profiles (if found). |
|
107
|
+
| `manage_nss_browsers` | Bool | `true` | Attempt to add CA to user NSS DB (Chromium/Brave/etc.). |
|
108
|
+
| `locale` | String | `"en"` | Language for messages (`"en"` or `"fr"`). |
|
109
|
+
| `verbose` | Bool | `false` | Print extra diagnostics (when supported). |
|
110
|
+
|
111
|
+
**Validation**
|
112
|
+
- `cert_path` must exist and be a file.
|
113
|
+
- On Linux, you may need `sudo` and `libnss3-tools` for browser stores.
|
114
|
+
|
115
|
+
---
|
116
|
+
|
117
|
+
## CLI usage
|
118
|
+
|
119
|
+
```
|
120
|
+
vagrant certs <command> [--lang en|fr] [--no-emoji]
|
121
|
+
|
122
|
+
Commands:
|
123
|
+
add <PATH> Install the CA from PATH into system/browser stores
|
124
|
+
remove <PATH> Remove the CA that was installed from PATH
|
125
|
+
list Show tracked certificates installed via this plugin
|
126
|
+
version Print plugin version
|
127
|
+
help [TOPIC] Show help (topics: add, remove, list, version, help)
|
128
|
+
```
|
129
|
+
|
130
|
+
Examples:
|
131
|
+
|
132
|
+
```bash
|
133
|
+
vagrant certs add ./certs/rootca.cert.pem
|
134
|
+
vagrant certs remove ./certs/rootca.cert.pem --lang fr
|
135
|
+
vagrant certs list --no-emoji
|
136
|
+
vagrant certs version
|
137
|
+
vagrant certs help add
|
138
|
+
```
|
139
|
+
|
140
|
+
---
|
141
|
+
|
142
|
+
## How it works
|
143
|
+
|
144
|
+
- **macOS**: uses `security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain` to add a CA; removal via `security delete-certificate -Z <sha1>`.
|
145
|
+
- **Linux (Debian/Ubuntu)**: copies the CA into `/usr/local/share/ca-certificates/<name>.crt` and runs `update-ca-certificates`. For browser stores, uses `certutil` (NSS) if present and profiles are found.
|
146
|
+
- **Windows**: uses `certutil -addstore -f ROOT <path>` to add the CA to the “Trusted Root Certification Authorities”; removal via `certutil -delstore ROOT <thumbprint>`.
|
147
|
+
|
148
|
+
The plugin can also auto‑install on `vagrant up` when `install_on_up` is `true`.
|
149
|
+
|
150
|
+
---
|
151
|
+
|
152
|
+
## OS-specific notes
|
153
|
+
|
154
|
+
- **Privileges**: writing to system trust stores often needs **Admin/root**. You may be prompted for your password or need to run an elevated shell.
|
155
|
+
- **Firefox**: when enabled, the plugin scans for profiles (native, Flatpak, Snap on Linux). If `certutil` is not installed, Firefox integration is skipped.
|
156
|
+
- **NSS browsers**: for Chromium/Brave/Opera/etc., we try `~/.pki/nssdb` or browser-specific profile DBs. Behavior varies by distro and packaging.
|
157
|
+
- **PEM format**: the Root CA should be in PEM. If needed, convert with `openssl x509 -in rootca.crt -out rootca.pem -outform pem`.
|
158
|
+
|
159
|
+
---
|
160
|
+
|
161
|
+
## Environment variables
|
162
|
+
|
163
|
+
| Variable | Purpose |
|
164
|
+
|-----------------|---------|
|
165
|
+
| `VDCM_LANG` | Force language (`en`/`fr`) regardless of config. |
|
166
|
+
| `VDCM_NO_EMOJI` | When `1`, disables emoji in output. |
|
167
|
+
| `VDCM_DEBUG` | When `1`, prints extra debug logs from the plugin. |
|
168
|
+
|
169
|
+
---
|
170
|
+
|
171
|
+
## Troubleshooting
|
172
|
+
|
173
|
+
- **Permission denied**: run an elevated shell (Admin on Windows, `sudo` on Linux/macOS) or allow the password prompt.
|
174
|
+
- **Linux: `certutil` missing**: install NSS tools, e.g. `sudo apt-get update && sudo apt-get install -y libnss3-tools`.
|
175
|
+
- **Firefox not updated**: ensure Firefox is closed; confirm the profile directories exist; Flatpak/Snap paths differ.
|
176
|
+
- **Wrong certificate**: verify the file path and format (`*.pem`). Check with `openssl x509 -in rootca.pem -text -noout`.
|
177
|
+
|
178
|
+
---
|
179
|
+
|
180
|
+
## Contributing & Development
|
181
|
+
|
182
|
+
```bash
|
183
|
+
git clone https://github.com/julienpoirou/vagrant-docker-certificates-manager
|
184
|
+
cd vagrant-docker-certificates-manager
|
185
|
+
bundle install
|
186
|
+
rake # runs RSpec
|
187
|
+
```
|
188
|
+
|
189
|
+
- Conventional Commits are welcome.
|
190
|
+
- CI runs tests and linting.
|
191
|
+
- Issues and PRs are appreciated!
|
192
|
+
|
193
|
+
---
|
194
|
+
|
195
|
+
## License
|
196
|
+
|
197
|
+
MIT © 2025 Julien Poirou
|
@@ -0,0 +1 @@
|
|
1
|
+
0.2.0
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../util/os"
|
4
|
+
require_relative "../util/ui"
|
5
|
+
require_relative "../util/cert"
|
6
|
+
require_relative "../util/registry"
|
7
|
+
require_relative "../helpers"
|
8
|
+
|
9
|
+
module VagrantDockerCertificatesManager
|
10
|
+
module Actions
|
11
|
+
class Install
|
12
|
+
def initialize(app, env); @app = app; @env = env; end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
cfg = env[:machine].config.docker_certificates
|
16
|
+
UiHelpers.set_locale!(cfg.locale || ENV["LANG"] || "en")
|
17
|
+
if cfg.install_on_up
|
18
|
+
Ui.say(env, :info, "install.start", name: cfg.cert_name, path: cfg.cert_path)
|
19
|
+
result = self.class.perform_install(cfg, env)
|
20
|
+
Ui.say(env, result[:status] == "success" ? :info : :error,
|
21
|
+
result[:status] == "success" ? "install.success" : "install.fail",
|
22
|
+
name: cfg.cert_name)
|
23
|
+
end
|
24
|
+
@app.call(env)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.perform_install(cfg, env)
|
28
|
+
unless File.file?(cfg.cert_path)
|
29
|
+
return { code: 1, status: "error",
|
30
|
+
error: UiHelpers.t("errors.invalid_path", path: cfg.cert_path) }
|
31
|
+
end
|
32
|
+
|
33
|
+
name = cfg.cert_name.to_s.strip.empty? ? Cert.default_name_from(cfg.cert_path) : cfg.cert_name
|
34
|
+
fp = Cert.sha1(cfg.cert_path)
|
35
|
+
if Registry.all.key?(fp)
|
36
|
+
return { code: 1, status: "error",
|
37
|
+
error: UiHelpers.t("errors.already_present", name: name) }
|
38
|
+
end
|
39
|
+
|
40
|
+
os = OS.detect
|
41
|
+
ok = case os
|
42
|
+
when :mac then OS.mac_add_trusted_cert(cfg.cert_path, name)
|
43
|
+
when :linux then OS.linux_install_cert(cfg.cert_path, name, nss: cfg.manage_nss_browsers,
|
44
|
+
firefox: cfg.manage_firefox)
|
45
|
+
when :windows then OS.win_install_cert(cfg.cert_path, name)
|
46
|
+
else return { code: 2, status: "error", error: UiHelpers.t("errors.os_unsupported") }
|
47
|
+
end
|
48
|
+
return({ code: 3, status: "error", error: UiHelpers.t("errors.install_failed") }) unless ok
|
49
|
+
|
50
|
+
Registry.track(fp, {
|
51
|
+
"path" => File.expand_path(cfg.cert_path),
|
52
|
+
"name" => name,
|
53
|
+
"nickname" => Cert.nickname_for(name),
|
54
|
+
"os" => os.to_s
|
55
|
+
})
|
56
|
+
{ code: 0, status: "success", data: { os: os, cert: name } }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../util/os"
|
4
|
+
require_relative "../util/ui"
|
5
|
+
require_relative "../util/cert"
|
6
|
+
require_relative "../util/registry"
|
7
|
+
require_relative "../helpers"
|
8
|
+
|
9
|
+
module VagrantDockerCertificatesManager
|
10
|
+
module Actions
|
11
|
+
class Uninstall
|
12
|
+
def initialize(app, env); @app = app; @env = env; end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
cfg = env[:machine].config.docker_certs
|
16
|
+
UiHelpers.set_locale!(cfg.locale || "en")
|
17
|
+
if cfg.remove_on_destroy
|
18
|
+
Ui.say(env, :info, "uninstall.start", name: cfg.cert_name)
|
19
|
+
result = self.class.perform_uninstall(cfg, env)
|
20
|
+
Ui.say(env, result[:status] == "success" ? :info : :warn,
|
21
|
+
result[:status] == "success" ? "uninstall.success" : "uninstall.fail",
|
22
|
+
name: cfg.cert_name)
|
23
|
+
end
|
24
|
+
@app.call(env)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.perform_uninstall(cfg, _env)
|
28
|
+
fp_entry = Registry.find_by_path(cfg.cert_path)
|
29
|
+
unless fp_entry
|
30
|
+
return({ code: 1, status: "error",
|
31
|
+
error: UiHelpers.t("errors.not_found_for_remove", path: cfg.cert_path) })
|
32
|
+
end
|
33
|
+
fp, rec = fp_entry
|
34
|
+
os = OS.detect
|
35
|
+
ok = case os
|
36
|
+
when :mac then OS.mac_remove_by_fp(fp)
|
37
|
+
when :linux then OS.linux_uninstall_cert(rec["name"], nss: cfg.manage_nss_browsers,
|
38
|
+
firefox: cfg.manage_firefox)
|
39
|
+
when :windows then OS.win_remove_by_fp(fp)
|
40
|
+
else return({ code: 2, status: "error", error: UiHelpers.t("errors.os_unsupported") })
|
41
|
+
end
|
42
|
+
Registry.untrack(fp) if ok
|
43
|
+
ok ? { code: 0, status: "success" } : { code: 4, status: "error", error: UiHelpers.t("errors.remove_failed") }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,190 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "optparse"
|
4
|
+
|
5
|
+
require_relative "util/ui"
|
6
|
+
require_relative "util/cert"
|
7
|
+
require_relative "util/registry"
|
8
|
+
require_relative "util/os"
|
9
|
+
require_relative "version"
|
10
|
+
require_relative "helpers"
|
11
|
+
|
12
|
+
module VagrantDockerCertificatesManager
|
13
|
+
BASE_CMD = if defined?(Vagrant) && Vagrant.respond_to?(:plugin)
|
14
|
+
Vagrant.plugin("2", :command)
|
15
|
+
else
|
16
|
+
Class.new do
|
17
|
+
def initialize(argv = [], env = {})
|
18
|
+
@argv = argv || []
|
19
|
+
@env = env || {}
|
20
|
+
end
|
21
|
+
|
22
|
+
def parse_options(parser)
|
23
|
+
parser.order!(@argv)
|
24
|
+
@argv
|
25
|
+
rescue OptionParser::InvalidOption
|
26
|
+
nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class Command < BASE_CMD
|
32
|
+
def initialize(*args)
|
33
|
+
argv, env =
|
34
|
+
if args.size == 2 && args.first.is_a?(Array)
|
35
|
+
[args.first, args.last]
|
36
|
+
elsif args.size == 2 && args.last.is_a?(Array)
|
37
|
+
[args.last, args.first]
|
38
|
+
else
|
39
|
+
[args[0].is_a?(Array) ? args[0] : [], args[1] || {}]
|
40
|
+
end
|
41
|
+
|
42
|
+
super(argv, env) if defined?(super)
|
43
|
+
@argv = argv
|
44
|
+
@env = env
|
45
|
+
end
|
46
|
+
|
47
|
+
def execute
|
48
|
+
UiHelpers.setup_i18n!
|
49
|
+
|
50
|
+
opts = { lang: nil, no_emoji: false }
|
51
|
+
|
52
|
+
parser = OptionParser.new do |o|
|
53
|
+
o.banner = UiHelpers.t("cli.usage", default: "Usage: vagrant certs <add|remove|list|version|help> [options]")
|
54
|
+
o.on("--lang LANG", UiHelpers.t("cli.opt_lang", default: "Force language (en|fr)")) { |v| opts[:lang] = v }
|
55
|
+
o.on("--no-emoji", UiHelpers.t("cli.opt_no_emoji", default: "Disable emoji in CLI output")) do
|
56
|
+
opts[:no_emoji] = true
|
57
|
+
end
|
58
|
+
o.on("-h", "--help", UiHelpers.t("cli.opt_help", default: "Show help and exit")) do
|
59
|
+
UiHelpers.print_general_help(no_emoji: opts[:no_emoji], ui: @env.ui)
|
60
|
+
return 0
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
argv = parse_options(parser)
|
65
|
+
return 0 unless argv
|
66
|
+
|
67
|
+
UiHelpers.set_locale!(opts[:lang] || "en")
|
68
|
+
ENV["VDCM_NO_EMOJI"] = "1" if opts[:no_emoji]
|
69
|
+
|
70
|
+
env = { ui: @env.ui, no_emoji: opts[:no_emoji] }
|
71
|
+
|
72
|
+
sub = argv.shift
|
73
|
+
case sub
|
74
|
+
when "add", "install"
|
75
|
+
path = argv.shift
|
76
|
+
unless path && File.file?(path)
|
77
|
+
Ui.say(env, :error, "errors.invalid_path", path: (path || "").to_s)
|
78
|
+
return 1
|
79
|
+
end
|
80
|
+
|
81
|
+
name = Cert.default_name_from(path)
|
82
|
+
fp = Cert.sha1(path)
|
83
|
+
nick = Cert.nickname_for(name)
|
84
|
+
|
85
|
+
if Registry.all.key?(fp)
|
86
|
+
Ui.say(env, :error, "errors.already_present", name: name)
|
87
|
+
return 1
|
88
|
+
end
|
89
|
+
|
90
|
+
os = OS.detect
|
91
|
+
ok = case os
|
92
|
+
when :mac
|
93
|
+
OS.mac_has_cert_fingerprint?(fp) ? false : OS.mac_add_trusted_cert(path, name)
|
94
|
+
when :linux
|
95
|
+
OS.linux_has_cert_file?(name) ? false : OS.linux_install_cert(path, name, nss: true, firefox: false)
|
96
|
+
when :windows
|
97
|
+
OS.win_has_cert_fingerprint?(fp) ? false : OS.win_install_cert(path, name)
|
98
|
+
else
|
99
|
+
Ui.say(env, :error, "errors.os_unsupported")
|
100
|
+
return 2
|
101
|
+
end
|
102
|
+
|
103
|
+
unless ok
|
104
|
+
Ui.say(env, :error, "errors.install_failed")
|
105
|
+
return 3
|
106
|
+
end
|
107
|
+
|
108
|
+
Registry.track(fp, {
|
109
|
+
"path" => File.expand_path(path),
|
110
|
+
"name" => name,
|
111
|
+
"nickname" => nick,
|
112
|
+
"os" => os.to_s
|
113
|
+
})
|
114
|
+
Ui.say(env, :info, "add.success", name: name)
|
115
|
+
0
|
116
|
+
|
117
|
+
when "remove", "uninstall"
|
118
|
+
path = argv.shift
|
119
|
+
unless path && !path.strip.empty?
|
120
|
+
Ui.say(env, :error, "errors.missing_path_remove")
|
121
|
+
return 1
|
122
|
+
end
|
123
|
+
|
124
|
+
fp = if File.file?(path)
|
125
|
+
Cert.sha1(path)
|
126
|
+
else
|
127
|
+
(Registry.find_by_path(path) || [nil]).first
|
128
|
+
end
|
129
|
+
|
130
|
+
unless fp
|
131
|
+
Ui.say(env, :error, "errors.not_found_for_remove", path: path)
|
132
|
+
return 1
|
133
|
+
end
|
134
|
+
|
135
|
+
name_for_remove = (Registry.all[fp] || {})["name"] || Cert.default_name_from(path)
|
136
|
+
|
137
|
+
os = OS.detect
|
138
|
+
ok = case os
|
139
|
+
when :mac then OS.mac_remove_by_fp(fp)
|
140
|
+
when :linux then OS.linux_uninstall_cert(name_for_remove)
|
141
|
+
when :windows then OS.win_remove_by_fp(fp)
|
142
|
+
else
|
143
|
+
Ui.say(env, :error, "errors.os_unsupported")
|
144
|
+
return 2
|
145
|
+
end
|
146
|
+
|
147
|
+
if ok
|
148
|
+
Registry.untrack(fp)
|
149
|
+
Ui.say(env, :info, "remove.success")
|
150
|
+
0
|
151
|
+
else
|
152
|
+
Ui.say(env, :warn, "errors.remove_failed")
|
153
|
+
4
|
154
|
+
end
|
155
|
+
|
156
|
+
when "list", "status"
|
157
|
+
entries = Registry.all
|
158
|
+
if entries.empty?
|
159
|
+
Ui.say(env, :info, "list.empty")
|
160
|
+
return 0
|
161
|
+
end
|
162
|
+
Ui.say(env, :info, "list.header")
|
163
|
+
entries.each do |fp, v|
|
164
|
+
@env.ui.info(" • #{v['name']} (#{fp}) [#{v['os']}] #{v['path']}")
|
165
|
+
end
|
166
|
+
0
|
167
|
+
|
168
|
+
when "version"
|
169
|
+
emoji = UiHelpers.e(:version, no_emoji: opts[:no_emoji])
|
170
|
+
line = UiHelpers.t("messages.version_line", default: "v%{v}.", v: VagrantDockerCertificatesManager::VERSION)
|
171
|
+
@env.ui.info("#{emoji} #{line}".strip)
|
172
|
+
0
|
173
|
+
|
174
|
+
when "help", "helps", nil, ""
|
175
|
+
topic = argv.shift
|
176
|
+
if topic && !topic.strip.empty?
|
177
|
+
UiHelpers.print_topic_help(topic, no_emoji: opts[:no_emoji], ui: @env.ui)
|
178
|
+
else
|
179
|
+
UiHelpers.print_general_help(no_emoji: opts[:no_emoji], ui: @env.ui)
|
180
|
+
end
|
181
|
+
0
|
182
|
+
|
183
|
+
else
|
184
|
+
Ui.say(env, :error, "errors.unknown_command", cmd: sub)
|
185
|
+
UiHelpers.print_general_help(no_emoji: opts[:no_emoji], ui: @env.ui)
|
186
|
+
1
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module VagrantDockerCertificatesManager
|
4
|
+
class Config < Vagrant.plugin("2", :config)
|
5
|
+
attr_accessor :cert_path, :cert_name, :install_on_up, :remove_on_destroy,
|
6
|
+
:manage_firefox, :manage_nss_browsers, :locale, :verbose,
|
7
|
+
:container_name
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@cert_path = "certs/rootca.cert.pem"
|
11
|
+
@cert_name = "local.dev"
|
12
|
+
@install_on_up = false
|
13
|
+
@remove_on_destroy = false
|
14
|
+
@manage_firefox = false
|
15
|
+
@manage_nss_browsers = true
|
16
|
+
@locale = "en"
|
17
|
+
@verbose = false
|
18
|
+
@container_name = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def finalize!
|
22
|
+
@cert_path = @container_name unless @container_name.to_s.strip.empty?
|
23
|
+
@install_on_up = !!@install_on_up
|
24
|
+
@remove_on_destroy = !!@remove_on_destroy
|
25
|
+
@manage_firefox = !!@manage_firefox
|
26
|
+
@manage_nss_browsers = !!@manage_nss_browsers
|
27
|
+
@verbose = !!@verbose
|
28
|
+
@locale = (@locale || "en").to_s
|
29
|
+
end
|
30
|
+
|
31
|
+
def validate(_machine)
|
32
|
+
errors = []
|
33
|
+
errors << "cert_path must be provided" if @cert_path.to_s.strip.empty?
|
34
|
+
errors << "cert_name must be provided" if @cert_name.to_s.strip.empty?
|
35
|
+
{ "vagrant-docker-certificates-manager" => errors }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|