77require 'open3'
88require 'timeout'
99require 'etc'
10+ require 'puppet'
1011
1112# Class to run and execute the `puppet infra upgrade` command as a task.
1213class PuppetInfraUpgrade
@@ -39,39 +40,38 @@ def execute!
3940 end
4041 end
4142
42- def inventory_uri
43- @inventory_uri ||= URI . parse ( 'https://localhost:8143/orchestrator/v1/inventory' )
44- end
45-
4643 def request_object ( nodes :, token_file :)
4744 token = File . read ( token_file )
4845 body = {
4946 'nodes' => nodes ,
5047 } . to_json
5148
52- request = Net ::HTTP ::Post . new ( inventory_uri . request_uri )
49+ request = Net ::HTTP ::Post . new ( '/orchestrator/v1/inventory' )
5350 request [ 'Content-Type' ] = 'application/json'
5451 request [ 'X-Authentication' ] = token . chomp
5552 request . body = body
5653
5754 request
5855 end
5956
60- def http_object
61- http = Net ::HTTP . new ( inventory_uri . host , inventory_uri . port )
62- http . use_ssl = true
63- http . verify_mode = OpenSSL ::SSL ::VERIFY_NONE
57+ def https_object
58+ https = Net ::HTTP . new ( Puppet . settings [ :certname ] , 8143 )
59+ https . use_ssl = true
60+ https . cert = OpenSSL ::X509 ::Certificate . new ( File . read ( Puppet . settings [ :hostcert ] ) )
61+ https . key = OpenSSL ::PKey ::RSA . new ( File . read ( Puppet . settings [ :hostprivkey ] ) )
62+ https . verify_mode = OpenSSL ::SSL ::VERIFY_PEER
63+ https . ca_file = Puppet . settings [ :localcacert ]
6464
65- http
65+ https
6666 end
6767
6868 def wait_until_connected ( nodes :, token_file :, timeout : 120 )
69- http = http_object
69+ https = https_object
7070 request = request_object ( nodes : nodes , token_file : token_file )
7171 inventory = { }
7272 Timeout . timeout ( timeout ) do
7373 loop do
74- response = http . request ( request )
74+ response = https . request ( request )
7575 unless response . is_a? Net ::HTTPSuccess
7676 raise "Unexpected result from orchestrator: #{ response . class } \n #{ response } "
7777 end
@@ -92,6 +92,7 @@ def wait_until_connected(nodes:, token_file:, timeout: 120)
9292# environment flag is used to disable auto-execution and enable Ruby unit
9393# testing of this task.
9494unless ENV [ 'RSPEC_UNIT_TEST_MODE' ]
95+ Puppet . initialize_settings
9596 upgrade = PuppetInfraUpgrade . new ( JSON . parse ( STDIN . read ) )
9697 upgrade . execute!
9798end
0 commit comments