From a442d96a622418f90a021e260d0ed2447bf86cf8 Mon Sep 17 00:00:00 2001 From: Alex Dreyer Date: Fri, 2 Nov 2018 12:23:44 +0000 Subject: [PATCH] (demo) Update apikey task to be a puppet remote task --- .../util/network_device/panos/device.rb | 4 ++++ tasks/apikey.json | 16 +++----------- tasks/apikey.rb | 21 +++++++++++++++++-- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/lib/puppet/util/network_device/panos/device.rb b/lib/puppet/util/network_device/panos/device.rb index a69c17c7..ec63ccbe 100644 --- a/lib/puppet/util/network_device/panos/device.rb +++ b/lib/puppet/util/network_device/panos/device.rb @@ -101,6 +101,10 @@ def commit api.job_request('commit', cmd: '') end + def apikey + api.apikey + end + private def api diff --git a/tasks/apikey.json b/tasks/apikey.json index dc0dc702..5af40627 100644 --- a/tasks/apikey.json +++ b/tasks/apikey.json @@ -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" ] } diff --git a/tasks/apikey.rb b/tasks/apikey.rb index ccbe2d98..12c54af4 100755 --- a/tasks/apikey.rb +++ b/tasks/apikey.rb @@ -17,8 +17,25 @@ #### the real task ### require 'json' -require 'puppet/util/network_device/panos/device' + +def add_plugin_paths(install_dir) + 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)