Sha256: b25ddf46c70c1e79db130f84344eef1d9d4e4c8eceb30d125453fb9bde80502b

Contents?: true

Size: 1.84 KB

Versions: 7

Compression:

Stored size: 1.84 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'
require 'avm/jobs/base'
require 'avm/patches/object/template'
require 'avm/eac_ubuntu_base0/apache'
require 'avm/patches/object/template'

module Avm
  module EacWebappBase0
    class ApacheHost
      JOBS = %w[write_available_no_ssl_site enable_no_ssl_site remove_ssl_site reload_apache
                run_certbot enable_ssl_site reload_apache].freeze
      include ::Avm::Jobs::Base

      def no_ssl_site_content
        ::Avm::EacWebappBase0::ApacheHost
          .template.child('no_ssl.conf')
          .apply(variables_source)
      end

      def ssl?
        options[:certbot]
      end

      private

      def apache_uncached
        ::Avm::EacUbuntuBase0::Apache.new(instance.host_env)
      end

      def enable_no_ssl_site
        infom 'Enabling no SSL site...'
        no_ssl_site.enable
      end

      def enable_ssl_site
        return unless ssl?

        infom 'Enabling SSL site...'
        ssl_site.enable
      end

      def no_ssl_site_uncached
        apache.site(instance.id)
      end

      def reload_apache
        infom 'Reloading Apache...'
        apache.service('reload')
      end

      def remove_ssl_site
        infom 'Removing SSL site...'
        ssl_site.remove
      end

      def run_certbot
        return unless ssl?

        infom 'Running Certbot...'
        instance.host_env.command(
          'sudo', 'certbot', '--apache', '--domain', instance.read_entry('web.hostname'),
          '--redirect', '--non-interactive', '--agree-tos',
          '--email', instance.read_entry('admin.email')
        ).system!
      end

      def ssl_site_uncached
        apache.site(no_ssl_site.name + '-le-ssl')
      end

      def write_available_no_ssl_site
        infom 'Writing no SSL site conf...'
        no_ssl_site.write(no_ssl_site_content)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
avm-tools-0.113.2 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/apache_host.rb
avm-eac_webapp_base0-0.2.0 lib/avm/eac_webapp_base0/apache_host.rb
avm-tools-0.110.0 vendor/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/apache_host.rb
avm-tools-0.109.1 vendor/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/apache_host.rb
avm-tools-0.109.0 vendor/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/apache_host.rb
avm-tools-0.108.0 vendor/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/apache_host.rb
avm-tools-0.107.0 vendor/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/apache_host.rb