-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PE-38801 Task added to fetch rules for PE Infrastructure Agent group …
…and warn user that they will be replaced during convert and upgrade (#510)
- Loading branch information
1 parent
866fbf4
commit 9a9703e
Showing
7 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"description": "Run on a PE primary node to return the rules currently applied to the PE Infrastructure Agent group", | ||
"parameters": { }, | ||
"input_method": "stdin" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/opt/puppetlabs/puppet/bin/ruby | ||
# frozen_string_literal: true | ||
|
||
require 'json' | ||
require 'net/http' | ||
require 'puppet' | ||
|
||
# GetInfrastructureAgentGroupRules task class | ||
class GetInfrastructureAgentGroupRules | ||
def execute! | ||
infrastructure_agent_group = groups.find { |obj| obj['name'] == 'PE Infrastructure Agent' } | ||
if infrastructure_agent_group | ||
puts JSON.pretty_generate(infrastructure_agent_group['rule']) | ||
else | ||
puts JSON.pretty_generate({ 'error' => 'PE Infrastructure Agent group does not exist' }) | ||
end | ||
end | ||
|
||
def groups | ||
net = https(4433) | ||
res = net.get('/classifier-api/v1/groups') | ||
JSON.parse(res.body) | ||
end | ||
|
||
def https(port) | ||
https = Net::HTTP.new(Puppet.settings[:certname], port) | ||
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])) | ||
https.verify_mode = OpenSSL::SSL::VERIFY_PEER | ||
https.ca_file = Puppet.settings[:localcacert] | ||
https | ||
end | ||
end | ||
|
||
# Run the task unless an environment flag has been set, signaling not to. The | ||
# environment flag is used to disable auto-execution and enable Ruby unit | ||
# testing of this task. | ||
unless ENV['RSPEC_UNIT_TEST_MODE'] | ||
Puppet.initialize_settings | ||
GetInfrastructureAgentGroupRules.new.execute! | ||
end |