-
Notifications
You must be signed in to change notification settings - Fork 897
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ansible_runner] Add VmwareCredential
- Loading branch information
1 parent
61cde3e
commit 4ecdab9
Showing
3 changed files
with
110 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Ansible | ||
class Runner | ||
class VmwareCredential < Credential | ||
def self.auth_type | ||
"ManageIQ::Providers::EmbeddedAnsible::AutomationManager::VmwareCredential" | ||
end | ||
|
||
# Modeled off of vmware injectors for awx: | ||
# | ||
# https://github.com/ansible/awx/blob/1242ee2b/awx/main/models/credential/injectors.py#L63-L67 | ||
# | ||
# TODO: NickL: Should we add support for the VMWARE_VALIDATE_CERTS var? | ||
# | ||
def env_vars | ||
{ | ||
"VMWARE_USER" => auth.userid || "", | ||
"VMWARE_PASSWORD" => auth.password || "", | ||
"VMWARE_HOST" => auth.host || "" | ||
} | ||
end | ||
end | ||
end | ||
end |
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
83 changes: 83 additions & 0 deletions
83
spec/lib/ansible/runner/credential/vmware_credential_spec.rb
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,83 @@ | ||
require 'ansible/runner' | ||
require 'ansible/runner/credential' | ||
|
||
RSpec.describe Ansible::Runner::VmwareCredential do | ||
it ".auth_type is the correct Authentication sub-class" do | ||
expect(described_class.auth_type).to eq("ManageIQ::Providers::EmbeddedAnsible::AutomationManager::VmwareCredential") | ||
end | ||
|
||
context "with a credential object" do | ||
around do |example| | ||
Dir.mktmpdir("ansible-runner-credential-test") do |dir| | ||
@base_dir = dir | ||
example.run | ||
end | ||
end | ||
|
||
let(:auth) { FactoryBot.create(:embedded_ansible_vmware_credential, auth_attributes) } | ||
let(:auth_attributes) do | ||
{ | ||
:userid => "manageiq-vmware", | ||
:password => "vmware_secret", | ||
:options => { | ||
:host => "vmware_host" | ||
} | ||
} | ||
end | ||
|
||
let(:cred) { described_class.new(auth.id, @base_dir) } | ||
|
||
describe "#command_line" do | ||
it "returns an empty hash" do | ||
expect(cred.command_line).to eq({}) | ||
end | ||
end | ||
|
||
# Modeled off of vmware injectors for awx: | ||
# | ||
# https://github.com/ansible/awx/blob/1242ee2b/awx/main/models/credential/injectors.py#L63-L67 | ||
# | ||
describe "#env_vars" do | ||
it "sets VMWARE_USER, VMWARE_PASSWORD, and VMWARE_HOST" do | ||
expected = { | ||
"VMWARE_USER" => "manageiq-vmware", | ||
"VMWARE_PASSWORD" => "vmware_secret", | ||
"VMWARE_HOST" => "vmware_host" | ||
} | ||
expect(cred.env_vars).to eq(expected) | ||
end | ||
|
||
it "defaults VMWARE_USER, VMWARE_PASSWORD, and VMWARE_HOST to '' if missing" do | ||
auth.update!(:userid => nil, :password => nil, :options => nil) | ||
expected = { | ||
"VMWARE_USER" => "", | ||
"VMWARE_PASSWORD" => "", | ||
"VMWARE_HOST" => "" | ||
} | ||
expect(cred.env_vars).to eq(expected) | ||
end | ||
|
||
it "handles empty options hash" do | ||
auth.update!(:options => {}) | ||
expected = { | ||
"VMWARE_USER" => "manageiq-vmware", | ||
"VMWARE_PASSWORD" => "vmware_secret", | ||
"VMWARE_HOST" => "" | ||
} | ||
expect(cred.env_vars).to eq(expected) | ||
end | ||
end | ||
|
||
describe "#extra_vars" do | ||
it "returns an empty hash" do | ||
expect(cred.extra_vars).to eq({}) | ||
end | ||
end | ||
|
||
describe "#write_password_file" do | ||
it "no-ops" do | ||
expect(cred.write_password_file).to be_nil | ||
end | ||
end | ||
end | ||
end |