File tree Expand file tree Collapse file tree 3 files changed +43
-12
lines changed Expand file tree Collapse file tree 3 files changed +43
-12
lines changed Original file line number Diff line number Diff line change 1+ require 'spec_helper_acceptance'
2+ require 'json'
3+
4+ describe 'API Key task' do
5+ before ( :each ) do
6+ params = {
7+ 'credentials_file' => credentials ,
8+ }
9+ ENV [ 'PARAMS' ] = JSON . generate ( params )
10+ end
11+
12+ let ( :result ) do
13+ puts "Executing apikey.rb task with `#{ ENV [ 'PARAMS' ] } `" if debug_output?
14+ Open3 . capture2e ( 'bundle exec ruby -Ilib tasks/apikey.rb' )
15+ end
16+ let ( :stdout_str ) { result [ 0 ] }
17+ let ( :status ) { result [ 1 ] }
18+
19+ context 'when apikey task is called with valid credentials' do
20+ let ( :credentials ) { "file://#{ Dir . getwd } /spec/fixtures/acceptance-credentials.conf" }
21+
22+ it 'will return an API key' do
23+ expect ( stdout_str ) . to match %r{"apikey":}
24+ puts stdout_str if debug_output?
25+ expect ( status . exitstatus ) . to eq 0
26+ end
27+ end
28+ context 'when apikey task is called with invalid credential_file parameter specified' do
29+ let ( :credentials ) { 'foo' }
30+
31+ it 'will throw an error and not return an API key' do
32+ expect ( stdout_str ) . not_to match %r{"apikey":}
33+ expect ( stdout_str ) . to match %r{Unexpected url 'foo' found. Only file:/// URLs for configuration supported at the moment}
34+ puts stdout_str if debug_output?
35+ expect ( status . exitstatus ) . not_to eq 0
36+ end
37+ end
38+ end
Original file line number Diff line number Diff line change 33 "supports_noop" : false ,
44 "description" : " Retrieve a PAN-OS apikey using PAN-OS host, username and password." ,
55 "parameters" : {
6- "host" : {
7- "description" : " The host to connect to" ,
8- "type" : " String"
9- },
10- "user" : {
11- "description" : " The user name" ,
12- "type" : " String"
13- },
14- "password" : {
15- "description" : " The password" ,
6+ "credentials_file" : {
7+ "description" : " The filename of the credentials file (as referenced in device.conf)" ,
168 "type" : " String"
179 }
1810 }
Original file line number Diff line number Diff line change 2020require 'puppet/resource_api/transport/wrapper'
2121
2222params = JSON . parse ( ENV [ 'PARAMS' ] || STDIN . read )
23+
2324wrapper = Puppet ::ResourceApi ::Transport ::Wrapper . new ( 'panos' , params [ 'credentials_file' ] )
24- transport = wrapper . transport
25+ api = Puppet :: Transport :: Panos :: API . new ( wrapper . transport . instance_variable_get ( :@connection_info ) )
2526
26- puts JSON . generate ( apikey : transport . apikey )
27+ puts JSON . generate ( apikey : api . apikey )
You can’t perform that action at this time.
0 commit comments