Class: Dev::Template::Certificate

Inherits:
BaseInterface show all
Defined in:
lib/firespring_dev_commands/templates/certificate.rb

Overview

Class contains rake templates for managing configured certificates

Instance Attribute Summary collapse

Attributes inherited from BaseInterface

#exclude

Instance Method Summary collapse

Methods inherited from BaseInterface

#create_tasks!

Constructor Details

#initialize(domains, email:, paths:, exclude: []) ⇒ Certificate

Returns a new instance of Certificate.



9
10
11
12
13
14
15
# File 'lib/firespring_dev_commands/templates/certificate.rb', line 9

def initialize(domains, email:, paths:, exclude: [])
  @domains = domains
  @email = email
  @paths = Array(paths)

  super(exclude:)
end

Instance Attribute Details

#domainsObject (readonly)

Returns the value of attribute domains.



7
8
9
# File 'lib/firespring_dev_commands/templates/certificate.rb', line 7

def domains
  @domains
end

#emailObject (readonly)

Returns the value of attribute email.



7
8
9
# File 'lib/firespring_dev_commands/templates/certificate.rb', line 7

def email
  @email
end

#pathsObject (readonly)

Returns the value of attribute paths.



7
8
9
# File 'lib/firespring_dev_commands/templates/certificate.rb', line 7

def paths
  @paths
end

Instance Method Details

#create_generate_task!Object

Create the rake task for the generate method



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/firespring_dev_commands/templates/certificate.rb', line 18

def create_generate_task!
  # Have to set a local variable to be accessible inside of the instance_eval block
  domains = @domains
  email = @email
  paths = @paths
  exclude = @exclude

  DEV_COMMANDS_TOP_LEVEL.instance_eval do
    return if exclude.include?(:generate)

    namespace :certificate do
      desc 'Requests a new certificate for the configured domain using the route53 validation and deposits it in the configured paths'
      task generate: %w(init_docker ensure_aws_credentials) do
        Dev::Docker.new.pull_image('certbot/dns-route53', 'latest')
        c = Dev::Certificate.new(domains, email)
        c.request
        paths.each { |path| c.save(path) }
      end
    end
  end
end