Class: LetsencryptStandalone::Domain

Inherits:
Base
  • Object
show all
Defined in:
lib/letsencrypt_standalone/domain.rb

Constant Summary collapse

@@default_private_key_name =
'private_key.pem'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#endpoint_url, #logger, logger, #output_dir, #path, #ssl_subdir

Constructor Details

#initialize(params:, path: './') ⇒ Domain

Returns a new instance of Domain.



12
13
14
15
16
17
18
19
20
21
# File 'lib/letsencrypt_standalone/domain.rb', line 12

def initialize(params:, path: './')
  @host = params.fetch(:host)
  @private_key_name = params.fetch(:private_key, @@default_private_key_name)
  @private_key_path = File.join(output_dir,@host, @private_key_name)
	  @files = params[:certificates]
  if params.has_key? :certificates
    load_certs
  end
  load_private_key
end

Instance Attribute Details

#certificatesObject

Returns the value of attribute certificates.



7
8
9
# File 'lib/letsencrypt_standalone/domain.rb', line 7

def certificates
  @certificates
end

#filesObject

Returns the value of attribute files.



7
8
9
# File 'lib/letsencrypt_standalone/domain.rb', line 7

def files
  @files
end

#hostObject

Returns the value of attribute host.



7
8
9
# File 'lib/letsencrypt_standalone/domain.rb', line 7

def host
  @host
end

#private_keyObject

Returns the value of attribute private_key.



7
8
9
# File 'lib/letsencrypt_standalone/domain.rb', line 7

def private_key
  @private_key
end

#private_key_nameObject (readonly)

Returns the value of attribute private_key_name.



8
9
10
# File 'lib/letsencrypt_standalone/domain.rb', line 8

def private_key_name
  @private_key_name
end

#private_key_pathObject (readonly)

Returns the value of attribute private_key_path.



8
9
10
# File 'lib/letsencrypt_standalone/domain.rb', line 8

def private_key_path
  @private_key_path
end

Instance Method Details

#host_dirObject



23
24
25
# File 'lib/letsencrypt_standalone/domain.rb', line 23

def host_dir
  @host_dir ||= File.join(output_dir, host)
end

#validate(client:) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/letsencrypt_standalone/domain.rb', line 27

def validate(client:)
  authorization = client.authorize(domain: self.host)
  #The http-01 method will require you to respond to a HTTP request.
  @challenge = authorization.http01

  # Save the file. We'll create a public directory to serve it from, and inside it we'll create the challenge file.
  FileUtils.mkdir_p(File.join(config.www_root, File.dirname(@challenge.filename)))

  # We'll write the content of the file
  File.write(File.join(config.www_root, @challenge.filename), @challenge.file_content)

  # try to verify
  @challenge.request_verification
end

#verify_statusObject



42
43
44
# File 'lib/letsencrypt_standalone/domain.rb', line 42

def verify_status
  @challenge.verify_status
end