├── .gitignore ├── CODE_OF_CONDUCT.md ├── Gemfile ├── LICENSE ├── README.md ├── Rakefile ├── lib ├── vagrant-trellis-cert.rb └── vagrant_plugins │ └── trellis_cert │ ├── certificate.rb │ ├── command │ ├── distrust.rb │ ├── root.rb │ └── trust.rb │ ├── config.rb │ ├── identity.rb │ ├── plugin.rb │ ├── result.rb │ └── ssl_config.rb └── vagrant-trellis-cert.gemspec /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /Gemfile.lock 4 | /_yardoc/ 5 | /coverage/ 6 | /doc/ 7 | /pkg/ 8 | /spec/reports/ 9 | /tmp/ 10 | 11 | .rbenv-gemsets 12 | .ruby-version 13 | /.gems/ 14 | /vagrant-trellis-cert-*.gem 15 | .rubocop-http* 16 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at vagrant-trellis-cert@typist.tech. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source 'https://rubygems.org' 4 | git_source(:github) { |repo_name| "https://github.com/#{repo_name}" } 5 | 6 | # To make `$ bundle exec vagrant` works 7 | embedded_directories = %w[/Applications/Vagrant/embedded /opt/vagrant/embedded] 8 | embedded_directories.each do |path| 9 | ENV['VAGRANT_INSTALLER_EMBEDDED_DIR'] = path if File.directory?(path) 10 | end 11 | 12 | unless ENV.key?('VAGRANT_INSTALLER_EMBEDDED_DIR') 13 | $stderr.puts "Couldn't find a packaged install of vagrant, and we need this" 14 | $stderr.puts 'in order to make use of the RubyEncoder libraries.' 15 | $stderr.puts 'I looked in:' 16 | embedded_directories.each do |path| 17 | $stderr.puts " #{path}" 18 | end 19 | end 20 | 21 | group :development do 22 | # We depend on Vagrant for development, but we don't add it as a 23 | # gem dependency because we expect to be installed within the 24 | # Vagrant environment itself using `vagrant plugin`. 25 | gem 'vagrant', github: 'hashicorp/vagrant' 26 | end 27 | 28 | group :plugins do 29 | gemspec 30 | end 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017-2020 Typist Tech 4 | Copyright (c) 2017-2020 Tang Rufus 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. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | # Vagrant Trellis Cert 4 | 5 |
6 | 7 |
8 | 9 | [![Gem](https://img.shields.io/gem/v/vagrant-trellis-cert.svg?style=flat-square)](https://rubygems.org/gems/vagrant-trellis-cert) 10 | [![Gem](https://img.shields.io/gem/dt/vagrant-trellis-cert.svg?style=flat-square)](https://rubygems.org/gems/vagrant-trellis-cert) 11 | [![license](https://img.shields.io/github/license/TypistTech/vagrant-trellis-cert.svg?style=flat-square)](https://github.com/TypistTech/vagrant-trellis-cert/blob/master/LICENSE) 12 | [![Twitter Follow @TangRufus](https://img.shields.io/twitter/follow/TangRufus?style=flat-square&color=1da1f2&logo=twitter)](https://twitter.com/tangrufus) 13 | [![Hire Typist Tech](https://img.shields.io/badge/Hire-Typist%20Tech-ff69b4.svg?style=flat-square)](https://www.typist.tech/contact/) 14 | 15 |
16 | 17 |

18 | Trust Trellis self-signed certificates with a single command 19 |
20 |
21 | Built with ♥ by Typist Tech 22 |

23 | 24 | --- 25 | 26 | **Vagrant Trellis Cert** is an open source project and completely free to use. 27 | 28 | However, the amount of effort needed to maintain and develop new features is not sustainable without proper financial backing. If you have the capability, please consider donating using the links below: 29 | 30 |
31 | 32 | [![GitHub via Sponsor](https://img.shields.io/badge/Sponsor-GitHub-ea4aaa?style=flat-square&logo=github)](https://github.com/sponsors/TangRufus) 33 | [![Sponsor via PayPal](https://img.shields.io/badge/Sponsor-PayPal-blue.svg?style=flat-square&logo=paypal)](https://typist.tech/go/paypal-donate/) 34 | [![More Sponsorship Information](https://img.shields.io/badge/Sponsor-More%20Details-ff69b4?style=flat-square)](https://typist.tech/donate/vagrant-trellis-cert/) 35 | 36 |
37 | 38 | --- 39 | 40 | ## Usage 41 | 42 | ```sh-session 43 | Usage: vagrant trellis-cert trust [options] [vm-id] 44 | Usage: vagrant trellis-cert distrust [options] [vm-id] 45 | 46 | -h, --help Print this help 47 | 48 | # Example: Running within Trellis directory 49 | $ vagrant trellis-cert trust 50 | $ vagrant trellis-cert distrust 51 | 52 | # Example: Specify VM id 53 | $ vagrant global-status 54 | id name provider state directory 55 | ----------------------------------------------------------------------------------- 56 | fb90ab5 default virtualbox running /Users/me/Code/trellis 57 | 58 | $ vagrant trellis-cert trust fb90ab5 59 | $ vagrant trellis-cert distrust fb90ab5 60 | ``` 61 | 62 | --- 63 | 64 |

65 | Typist Tech is ready to build your next awesome WordPress site. Hire us! 66 |

67 | 68 | --- 69 | 70 | ## Minimum Requirements 71 | 72 | - macOS 10.13.3 73 | - Vagrant 2.0.3 74 | 75 | ## Installation 76 | 77 | ```sh-session 78 | $ vagrant plugin install vagrant-trellis-cert 79 | ``` 80 | 81 | ## FAQs 82 | 83 | ### What to do when `getaddrinfo: nodename nor servname provided, or not known` 84 | 85 | Make sure your hosts file (`/etc/hosts`) contains all the domains you're self-signing. 86 | 87 | Usually it can be rectified by `$ vagrant reload --provision` or `$ vagrant hostmanager`. 88 | 89 | Ask on [Root Discourse](https://discourse.roots.io/) if the problem persists. 90 | 91 | ### It looks awesome. Where can I find some more goodies like this 92 | 93 | - Articles on [Typist Tech's blog](https://typist.tech) 94 | - [Tang Rufus' WordPress plugins](https://profiles.wordpress.org/tangrufus#content-plugins) on wp.org 95 | - More projects on [Typist Tech's GitHub profile](https://github.com/TypistTech) 96 | - Stay tuned on [Typist Tech's newsletter](https://typist.tech/go/newsletter) 97 | - Follow [Tang Rufus' Twitter account](https://twitter.com/TangRufus) 98 | - **Hire [Tang Rufus](https://typist.tech/contact) to build your next awesome site** 99 | 100 | ### Where can I give 5-star reviews? 101 | 102 | Thanks! Glad you like it. It's important to let me knows somebody is using this project. Please consider: 103 | 104 | - [tweet](https://twitter.com/intent/tweet?text=Vagrant%20Trellis%20Cert%20-%20Trust%20Trellis%20self-signed%20certificates%20with%20a%20single%20command&url=https://github.com/TypistTech/vagrant-trellis-cert&hashtags=webdev,wordpress&via=TangRufus&url=https://github.com/TypistTech/vagrant-trellis-cert&hashtags=webdev,wordpress&via=TangRufus) something good with mentioning [@TangRufus](https://twitter.com/tangrufus) 105 | - ★ star [the Github repo](https://github.com/TypistTech/vagrant-trellis-cert) 106 | - [👀 watch](https://github.com/TypistTech/vagrant-trellis-cert/subscription) the Github repo 107 | - write tutorials and blog posts 108 | - **[hire](https://www.typist.tech/contact/) Typist Tech** 109 | 110 | ## Feedback 111 | 112 | **Please provide feedback!** We want to make this project as useful as possible. 113 | Please [submit an issue](https://github.com/TypistTech/vagrant-trellis-cert/issues/new) and point out what you do and don't like, or fork the project and [send pull requests](https://github.com/TypistTech/vagrant-trellis-cert/pulls/). 114 | **No issue is too small.** 115 | 116 | ## Security Vulnerabilities 117 | 118 | If you discover a security vulnerability within this project, please email us at [vagrant-trellis-cert@typist.tech](mailto:vagrant-trellis-cert@typist.tech). 119 | All security vulnerabilities will be promptly addressed. 120 | 121 | ## Credits 122 | 123 | [Vagrant Trellis Cert](https://github.com/TypistTech/vagrant-trellis-cert) is a [Typist Tech](https://www.typist.tech) project and maintained by [Tang Rufus](https://twitter.com/Tangrufus), freelance developer for [hire](https://www.typist.tech/contact/). 124 | 125 | Special thanks to [the Roots team](https://roots.io/about/) whose [Trellis](https://github.com/roots/trellis) make this project possible. 126 | 127 | Full list of contributors can be found [here](https://github.com/TypistTech/vagrant-trellis-cert/graphs/contributors). 128 | 129 | ## License 130 | 131 | [Vagrant Trellis Cert](https://github.com/TypistTech/vagrant-trellis-cert) is released under the [MIT License](https://opensource.org/licenses/MIT). 132 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'bundler/gem_tasks' 4 | -------------------------------------------------------------------------------- /lib/vagrant-trellis-cert.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | begin 4 | require 'vagrant' 5 | rescue LoadError 6 | raise 'The Vagrant Trellis Cert plugin must be run within Vagrant.' 7 | end 8 | 9 | # This is a sanity check to make sure no one is attempting to install 10 | # this into an early Vagrant version. 11 | # Requiring 2.0.3 or later because of Ruby 2.4.2 12 | if Vagrant::VERSION < '2.0.3' 13 | raise 'The Vagrant Trellis Cert plugin is only compatible with Vagrant 2.0.3 or later' 14 | end 15 | 16 | require 'vagrant_plugins/trellis_cert/identity' 17 | require 'vagrant_plugins/trellis_cert/plugin' 18 | -------------------------------------------------------------------------------- /lib/vagrant_plugins/trellis_cert/certificate.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'socket' 4 | require 'openssl' 5 | 6 | module VagrantPlugins 7 | module TrellisCert 8 | class Certificate 9 | def initialize(host:, tmp_dir:) 10 | @host = host 11 | @tmp_dir = tmp_dir 12 | end 13 | 14 | def download 15 | fetch 16 | 17 | File.open(path, 'w') do |file| 18 | file.write(@cert.to_der) 19 | end 20 | end 21 | 22 | def path 23 | "#{@tmp_dir}/#{@host}.der" 24 | end 25 | 26 | private 27 | 28 | def fetch 29 | tcp_client = TCPSocket.new(@host, 443) 30 | ssl_client = OpenSSL::SSL::SSLSocket.new(tcp_client) 31 | ssl_client.hostname = @host 32 | ssl_client.connect 33 | @cert = OpenSSL::X509::Certificate.new(ssl_client.peer_cert) 34 | ensure 35 | ssl_client&.sysclose 36 | tcp_client&.close 37 | end 38 | end 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /lib/vagrant_plugins/trellis_cert/command/distrust.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'vagrant_plugins/trellis_cert/ssl_config' 4 | require 'vagrant_plugins/trellis_cert/result' 5 | 6 | module VagrantPlugins 7 | module TrellisCert 8 | module Command 9 | class Distrust < Vagrant.plugin('2', :command) 10 | KEYCHAIN = '~/Library/Keychains/login.keychain' 11 | 12 | def execute 13 | _options, argv = parse_options! 14 | 15 | @env.ui.info('Removing certificates...') 16 | 17 | ssl_config = SSLConfig.new(root_path: machine_root_path(argv)) 18 | 19 | result = distrust(ssl_config.canonicals) 20 | 21 | result.print(ui: @env.ui) 22 | 23 | result.exit_code 24 | end 25 | 26 | private 27 | 28 | def parse_options! 29 | options = {} 30 | opts = OptionParser.new do |o| 31 | o.banner = 'Usage: vagrant trellis-cert distrust [options] [vm-id]' 32 | o.separator '' 33 | 34 | o.on('-h', '--help', 'Print this help') do 35 | @env.ui.info(opts) 36 | exit 37 | end 38 | end 39 | [options, parse_options(opts)] 40 | end 41 | 42 | def machine_root_path(argv) 43 | with_target_vms(argv) do |machine| 44 | return machine.env.root_path 45 | end 46 | end 47 | 48 | def distrust(hosts) 49 | Result.new.tap do |result| 50 | hosts.map do |host| 51 | is_success = system("security delete-certificate -c #{host} #{KEYCHAIN} >/dev/null 2>/dev/null") 52 | 53 | result.add(host: host, is_success: is_success) 54 | end 55 | end 56 | end 57 | end 58 | end 59 | end 60 | end 61 | -------------------------------------------------------------------------------- /lib/vagrant_plugins/trellis_cert/command/root.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'optparse' 4 | 5 | module VagrantPlugins 6 | module TrellisCert 7 | module Command 8 | class Root < Vagrant.plugin('2', :command) 9 | def self.synopsis 10 | 'trust Trellis self-signed certificates' 11 | end 12 | 13 | def initialize(argv, env) 14 | super 15 | 16 | @main_args, @sub_command, @sub_args = split_main_and_subcommand(argv) 17 | 18 | @subcommands = Vagrant::Registry.new 19 | 20 | @subcommands.register(:trust) do 21 | require_relative 'trust' 22 | Trust 23 | end 24 | 25 | @subcommands.register(:distrust) do 26 | require_relative 'distrust' 27 | Distrust 28 | end 29 | end 30 | 31 | def execute 32 | return help if help? || !sub_command? 33 | 34 | # Initialize and execute the command class 35 | @subcommands.get(@sub_command&.to_sym) 36 | .new(@sub_args, @env) 37 | .execute 38 | rescue Vagrant::Errors::VagrantError => e 39 | raise e 40 | rescue StandardError => e 41 | raise Vagrant::Errors::CLIInvalidUsage, help: "#{e.message}\r\n\r\nBacktrace:\r\n#{e.backtrace&.join("\r\n")}" 42 | end 43 | 44 | private 45 | 46 | def help? 47 | (@main_args & %w[-h --help]).any? 48 | end 49 | 50 | def sub_command? 51 | @subcommands.key?(@sub_command&.to_sym) 52 | end 53 | 54 | def help 55 | option_parser = OptionParser.new do |opts| 56 | opts.banner = 'Usage: vagrant trellis-cert []' 57 | opts.separator '' 58 | opts.separator 'Available subcommands:' 59 | 60 | @subcommands.keys.sort.each do |key| 61 | opts.separator " #{key}" 62 | end 63 | 64 | opts.separator '' 65 | opts.separator "For help on any individual command run 'vagrant trellis-cert COMMAND -h'" 66 | end 67 | 68 | @env.ui.info(option_parser.help, prefix: false) 69 | end 70 | end 71 | end 72 | end 73 | end 74 | -------------------------------------------------------------------------------- /lib/vagrant_plugins/trellis_cert/command/trust.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'vagrant_plugins/trellis_cert/certificate' 4 | require 'vagrant_plugins/trellis_cert/ssl_config' 5 | require 'vagrant_plugins/trellis_cert/result' 6 | 7 | module VagrantPlugins 8 | module TrellisCert 9 | module Command 10 | class Trust < Vagrant.plugin('2', :command) 11 | KEYCHAIN = '~/Library/Keychains/login.keychain' 12 | 13 | def execute 14 | _options, argv = parse_options! 15 | 16 | @env.ui.info('Importing certificates...') 17 | 18 | ssl_config = SSLConfig.new(root_path: machine_root_path(argv)) 19 | 20 | result = trust(ssl_config.canonicals) 21 | 22 | result.print(ui: @env.ui) 23 | 24 | result.exit_code 25 | end 26 | 27 | private 28 | 29 | def parse_options! 30 | options = {} 31 | opts = OptionParser.new do |o| 32 | o.banner = 'Usage: vagrant trellis-cert trust [options] [vm-id]' 33 | o.separator '' 34 | 35 | o.on('-h', '--help', 'Print this help') do 36 | @env.ui.info(opts) 37 | exit 38 | end 39 | end 40 | [options, parse_options(opts)] 41 | end 42 | 43 | def machine_root_path(argv) 44 | with_target_vms(argv) do |machine| 45 | # Machine must be up so that we can download SSL certificates. 46 | raise Vagrant::Errors::SSHNotReady unless machine.communicate.ready? 47 | 48 | return machine.env.root_path 49 | end 50 | end 51 | 52 | def trust(hosts) 53 | result = Result.new 54 | 55 | Dir.mktmpdir do |tmp_dir| 56 | hosts.map do |host| 57 | certificate = Certificate.new(host: host, tmp_dir: tmp_dir) 58 | certificate.download 59 | 60 | is_success = system("security add-trusted-cert -k #{KEYCHAIN} #{certificate.path} >/dev/null 2>/dev/null") 61 | 62 | result.add(host: host, is_success: is_success) 63 | end 64 | end 65 | 66 | result 67 | end 68 | end 69 | end 70 | end 71 | end 72 | -------------------------------------------------------------------------------- /lib/vagrant_plugins/trellis_cert/config.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'yaml' 4 | 5 | # This class is fork form TangRufus/trellis@b4a2d87 6 | # See: https://github.com/TangRufus/trellis/commit/b4a2d87d911d85ef863ce6fe25c 7 | # 8 | # TODO: Remove after roots/trellis#890 is merged. 9 | # 10 | module VagrantPlugins 11 | module TrellisCert 12 | class Config 13 | def initialize(root_path:) 14 | @root_path = root_path 15 | end 16 | 17 | def multisite_subdomains? 18 | @using_multisite_subdomains ||= begin 19 | wordpress_sites.any? do |(_name, site)| 20 | site.dig('multisite', 'enabled') && site.dig('multisite', 'subdomains') 21 | end 22 | end 23 | end 24 | 25 | def canonicals 26 | @canonicals ||= site_hosts.map { |host| host['canonical'] } 27 | end 28 | 29 | def redirects 30 | @redirects ||= site_hosts.flat_map { |host| host['redirects'] }.compact 31 | end 32 | 33 | def site_hosts 34 | @site_hosts ||= begin 35 | wordpress_sites.flat_map { |(_name, site)| site['site_hosts'] }.tap do |hosts| 36 | fail_with message: template_content if malformed?(site_hosts: hosts) 37 | end 38 | end 39 | end 40 | 41 | def wordpress_sites 42 | @wordpress_sites ||= begin 43 | content['wordpress_sites'].tap do |sites| 44 | fail_with message: "No sites found in #{path}." if sites.to_h.empty? 45 | end 46 | end 47 | end 48 | 49 | def content 50 | @content ||= begin 51 | fail_with message: "#{path} was not found. Please check `root_path`." unless exist? 52 | YAML.load_file(path) 53 | end 54 | end 55 | 56 | private 57 | 58 | def malformed?(site_hosts:) 59 | site_hosts.any? do |host| 60 | !host.is_a?(Hash) || !host.key?('canonical') 61 | end 62 | end 63 | 64 | def exist? 65 | File.exist?(path) 66 | end 67 | 68 | def path 69 | File.join(@root_path, 'group_vars', 'development', 'wordpress_sites.yml') 70 | end 71 | 72 | def template_content 73 | File.read(File.join(@root_path, 'roles', 'common', 'templates', 'site_hosts.j2')).sub!('{{ env }}', 'development').gsub!(/com$/, 'test') 74 | end 75 | 76 | def fail_with(message:) 77 | raise Vagrant::Errors::VagrantError.new, message 78 | end 79 | end 80 | end 81 | end 82 | -------------------------------------------------------------------------------- /lib/vagrant_plugins/trellis_cert/identity.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module VagrantPlugins 4 | module TrellisCert 5 | module Identity 6 | def self.name 7 | 'vagrant-trellis-cert' 8 | end 9 | 10 | def self.version 11 | '0.5.2' 12 | end 13 | 14 | def self.description 15 | 'Trust all Trellis self-signed certificates with single command' 16 | end 17 | 18 | def self.summary 19 | description 20 | end 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /lib/vagrant_plugins/trellis_cert/plugin.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module VagrantPlugins 4 | module TrellisCert 5 | class Plugin < Vagrant.plugin('2') 6 | name Identity.name 7 | 8 | description Identity.description 9 | 10 | command 'trellis-cert' do 11 | require_relative 'command/root' 12 | Command::Root 13 | end 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /lib/vagrant_plugins/trellis_cert/result.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module VagrantPlugins 4 | module TrellisCert 5 | class Result 6 | def initialize 7 | @store = { 8 | true => [], 9 | false => [] 10 | } 11 | end 12 | 13 | def add(host:, is_success:) 14 | @store[is_success] << host 15 | end 16 | 17 | def print(ui:) 18 | successes.each do |host| 19 | ui.success("SUCCESS: #{host}") 20 | end 21 | 22 | failures.each do |host| 23 | ui.error("FAIL: #{host}") 24 | end 25 | end 26 | 27 | def exit_code 28 | !successes.empty? && failures.empty? ? 1 : 0 29 | end 30 | 31 | private 32 | 33 | def successes 34 | @store[true] 35 | end 36 | 37 | def failures 38 | @store[false] 39 | end 40 | end 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /lib/vagrant_plugins/trellis_cert/ssl_config.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # TODO: Require actual Trellis::Config dynamically after roots/trellis#890 is merged. 4 | require 'vagrant_plugins/trellis_cert/config' 5 | 6 | module VagrantPlugins 7 | module TrellisCert 8 | class SSLConfig < Config 9 | def wordpress_sites 10 | @wordpress_sites ||= begin 11 | super.select do |_name, site| 12 | site&.dig('ssl', 'enabled') 13 | end 14 | end 15 | end 16 | end 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /vagrant-trellis-cert.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | lib = File.expand_path('../lib', __FILE__) 4 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 5 | require 'vagrant_plugins/trellis_cert/identity.rb' 6 | 7 | Gem::Specification.new do |spec| 8 | spec.name = VagrantPlugins::TrellisCert::Identity.name 9 | spec.version = VagrantPlugins::TrellisCert::Identity.version 10 | spec.authors = ['Tang Rufus', 'Typist Tech'] 11 | spec.email = ['tangrufus@gmail.com', 'vagrant-trellis-cert@typist.tech'] 12 | spec.metadata = { 13 | 'homepage_uri' => 'https://typist.tech/projects/vagrant-trellis-cert/', 14 | 'source_code_uri' => 'https://github.com/TypistTech/vagrant-trellis-cert', 15 | 'bug_tracker_uri' => 'https://github.com/TypistTech/vagrant-trellis-cert/issues', 16 | 'mailing_list_uri' => 'https://typist.tech/go/newsletter/', 17 | } 18 | spec.summary = VagrantPlugins::TrellisCert::Identity.summary 19 | spec.homepage = 'https://typist.tech/projects/vagrant-trellis-cert' 20 | spec.license = 'MIT' 21 | 22 | spec.required_ruby_version = ['~> 2.4', '>= 2.4.2'] 23 | 24 | spec.files = `git ls-files -z`.split("\x0").reject do |f| 25 | f.match(%r{^(test|spec|features)/}) 26 | end 27 | spec.bindir = 'exe' 28 | spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } 29 | spec.require_paths = ['lib'] 30 | 31 | spec.add_development_dependency 'bundler', '~> 2.1', '>= 2.1.4' 32 | spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.1' 33 | end 34 | --------------------------------------------------------------------------------