Skip to content

Commit

Permalink
Changing localhost out for certnames
Browse files Browse the repository at this point in the history
  • Loading branch information
ragingra committed Sep 20, 2024
1 parent 8aa3e99 commit f1c5d38
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 38 deletions.
8 changes: 0 additions & 8 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1075,14 +1075,6 @@ Run on a PE primary node to check if Code Manager is enabled.

**Supports noop?** false

#### Parameters

##### `host`

Data type: `String[1]`

Hostname of the PE primary node

### <a name="code_sync_status"></a>`code_sync_status`

A task to confirm code is in sync accross the cluster for clusters with code manager configured
Expand Down
4 changes: 1 addition & 3 deletions plans/add_replica.pp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
$replica_target = peadm::get_targets($replica_host, 1)
$replica_postgresql_target = peadm::get_targets($replica_postgresql_host, 1)

$code_manager_enabled = run_task(
'peadm::code_manager_enabled', $primary_target, host => $primary_target.peadm::certname()
).first.value['code_manager_enabled']
$code_manager_enabled = run_task('peadm::code_manager_enabled', $primary_target).first.value['code_manager_enabled']

if $code_manager_enabled == false {
fail('Code Manager must be enabled to add a replica. Please refer to the docs for more information on enabling Code Manager.')
Expand Down
2 changes: 1 addition & 1 deletion tasks/backup_classification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def execute!
private

def https_client
client = Net::HTTP.new('localhost', '4433')
client = Net::HTTP.new(Puppet.settings[:certname], 4433)
client.use_ssl = true
client.cert = @cert ||= OpenSSL::X509::Certificate.new(File.read(Puppet.settings[:hostcert]))
client.key = @key ||= OpenSSL::PKey::RSA.new(File.read(Puppet.settings[:hostprivkey]))
Expand Down
7 changes: 1 addition & 6 deletions tasks/code_manager_enabled.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
{
"description": "Run on a PE primary node to check if Code Manager is enabled.",
"parameters": {
"host": {
"type": "String[1]",
"description": "Hostname of the PE primary node"
}
},
"parameters": {},
"input_method": "stdin"
}
18 changes: 6 additions & 12 deletions tasks/code_manager_enabled.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@
require 'net/http'
require 'puppet'

# GetPEAdmConfig task class
class GetPEAdmConfig
def initialize(params)
@host = params['host']
end

# CodeManagerEnabled task class
class CodeManagerEnabled
def execute!
code_manager_enabled = groups.dig('PE Master', 'classes', 'puppet_enterprise::profile::master', 'code_manager_auto_configure')

Expand All @@ -20,18 +16,16 @@ def execute!
puts({ 'code_manager_enabled' => code_manager_enabled_value }.to_json)
end

# Returns a GetPEAdmConfig::NodeGroups object created from the /groups object
# returned by the classifier
def groups
@groups ||= begin
net = https(@host, 4433)
net = https
res = net.get('/classifier-api/v1/groups')
NodeGroup.new(JSON.parse(res.body))
end
end

def https(host, port)
https = Net::HTTP.new(host, port)
def https
https = Net::HTTP.new(Puppet.settings[:certname], 4433)
https.use_ssl = true
https.cert = @cert ||= OpenSSL::X509::Certificate.new(File.read(Puppet.settings[:hostcert]))
https.key = @key ||= OpenSSL::PKey::RSA.new(File.read(Puppet.settings[:hostprivkey]))
Expand Down Expand Up @@ -68,6 +62,6 @@ def dig(name, *args)
# testing of this task.
unless ENV['RSPEC_UNIT_TEST_MODE']
Puppet.initialize_settings
task = GetPEAdmConfig.new(JSON.parse(STDIN.read))
task = GetPEAdmConfig.new()

Check failure on line 65 in tasks/code_manager_enabled.rb

View workflow job for this annotation

GitHub Actions / Setup Test Matrix

Style/MethodCallWithoutArgsParentheses: Do not use parentheses for method calls with no arguments. (https://rubystyle.guide#method-invocation-parens)

Check failure on line 65 in tasks/code_manager_enabled.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 7.24, Ruby Ver: 2.7)

Style/MethodCallWithoutArgsParentheses: Do not use parentheses for method calls with no arguments. (https://rubystyle.guide#method-invocation-parens)

Check failure on line 65 in tasks/code_manager_enabled.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

Style/MethodCallWithoutArgsParentheses: Do not use parentheses for method calls with no arguments. (https://rubystyle.guide#method-invocation-parens)
task.execute!
end
2 changes: 1 addition & 1 deletion tasks/code_sync_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def execute!
private

def https_client
client = Net::HTTP.new('localhost', '8140')
client = Net::HTTP.new(Puppet.settings[:certname], 8140)
client.use_ssl = true
client.cert = @cert ||= OpenSSL::X509::Certificate.new(File.read(Puppet.settings[:hostcert]))
client.key = @key ||= OpenSSL::PKey::RSA.new(File.read(Puppet.settings[:hostprivkey]))
Expand Down
8 changes: 2 additions & 6 deletions tasks/puppet_infra_upgrade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,13 @@ def execute!
end
end

def inventory_uri
@inventory_uri ||= URI.parse('https://localhost:8143/orchestrator/v1/inventory')
end

def request_object(nodes:, token_file:)
token = File.read(token_file)
body = {
'nodes' => nodes,
}.to_json

request = Net::HTTP::Post.new(inventory_uri.request_uri)
request = Net::HTTP::Post.new('/orchestrator/v1/inventory')
request['Content-Type'] = 'application/json'
request['X-Authentication'] = token.chomp
request.body = body
Expand All @@ -59,7 +55,7 @@ def request_object(nodes:, token_file:)
end

def https_object
https = Net::HTTP.new(inventory_uri.host, inventory_uri.port)
https = Net::HTTP.new(Puppet.settings[:certname], 8143)
https.use_ssl = true
https.cert = OpenSSL::X509::Certificate.new(File.read(Puppet.settings[:hostcert]))
https.key = OpenSSL::PKey::RSA.new(File.read(Puppet.settings[:hostprivkey]))
Expand Down
2 changes: 1 addition & 1 deletion tasks/restore_classification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def execute!
private

def https_client
client = Net::HTTP.new('localhost', '4433')
client = Net::HTTP.new(Puppet.settings[:certname], 4433)
client.use_ssl = true
client.cert = @cert ||= OpenSSL::X509::Certificate.new(File.read(Puppet.settings[:hostcert]))
client.key = @key ||= OpenSSL::PKey::RSA.new(File.read(Puppet.settings[:hostprivkey]))
Expand Down

0 comments on commit f1c5d38

Please sign in to comment.