Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/puppet/util/network_device/panos/device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ def commit
api.job_request('commit', cmd: '<commit></commit>')
end

def apikey
api.apikey
end

private

def api
Expand Down
16 changes: 3 additions & 13 deletions tasks/apikey.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
{
"puppet_task_version": 1,
"supports_noop": false,
"input_method": "stdin",
"description": "Retrieve a PAN-OS apikey using PAN-OS host, username and password.",
"parameters": {
"host": {
"description": "The host to connect to",
"type": "String"
},
"user": {
"description": "The user name",
"type": "String"
},
"password": {
"description": "The password",
"type": "String"
}
}
},
"files": [ "panos/lib/puppet/util/network_device/panos/device.rb" ]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ensures the device is copied to the target so the module does not need to be installed in /etc/puppetlabs/code. The puppet-resource_api gem is still required though.

}
21 changes: 19 additions & 2 deletions tasks/apikey.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,25 @@
#### the real task ###

require 'json'
require 'puppet/util/network_device/panos/device'

def add_plugin_paths(install_dir)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the type of logic I think we can pull out into a helper. The generic ruby task helper probably should add "lib" from any modules to the loadpath anyway.

Dir.glob(File.join([install_dir, '*'])).each do |mod|
$LOAD_PATH << File.join([mod, "lib"])
end
end

params = JSON.parse(ENV['PARAMS'] || STDIN.read)
device = Puppet::Util::NetworkDevice::Panos::Device.new(params)
#params = {key: "foo"}
target = params['_target']
unless target
puts "Panos task must be run on a proxy"
exit 1
end

add_plugin_paths(params['_installdir'])


require 'puppet/util/network_device/panos/device'

device = Puppet::Util::NetworkDevice::Panos::Device.new(target)
puts JSON.generate(apikey: device.apikey)