Class: PagesDomains::CreateAcmeOrderService

Inherits:
Object
  • Object
show all
Defined in:
app/services/pages_domains/create_acme_order_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pages_domain) ⇒ CreateAcmeOrderService

Returns a new instance of CreateAcmeOrderService.


7
8
9
# File 'app/services/pages_domains/create_acme_order_service.rb', line 7

def initialize(pages_domain)
  @pages_domain = pages_domain
end

Instance Attribute Details

#pages_domainObject (readonly)

Returns the value of attribute pages_domain.


5
6
7
# File 'app/services/pages_domains/create_acme_order_service.rb', line 5

def pages_domain
  @pages_domain
end

Instance Method Details

#executeObject


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/services/pages_domains/create_acme_order_service.rb', line 11

def execute
  lets_encrypt_client = Gitlab::LetsEncrypt::Client.new
  order = lets_encrypt_client.new_order(pages_domain.domain)

  challenge = order.new_challenge

  private_key = OpenSSL::PKey::RSA.new(4096)
  saved_order = pages_domain.acme_orders.create!(
    url: order.url,
    expires_at: order.expires,
    private_key: private_key.to_pem,

    challenge_token: challenge.token,
    challenge_file_content: challenge.file_content
  )

  challenge.request_validation
  saved_order
end