Skip to content

Commit e24602e

Browse files
author
Will Meek
committed
(FM-7602) Fix APIKey task for Transport
The APIKey task schema has been updated to accept a credentials file, as per other tasks.
1 parent a18bb23 commit e24602e

File tree

3 files changed

+43
-12
lines changed

3 files changed

+43
-12
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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

tasks/apikey.json

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,8 @@
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
}

tasks/apikey.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
require 'puppet/resource_api/transport/wrapper'
2121

2222
params = JSON.parse(ENV['PARAMS'] || STDIN.read)
23+
2324
wrapper = 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)

0 commit comments

Comments
 (0)