Skip to content

Commit 66a319b

Browse files
committed
Add Credential selection
1 parent 64d6491 commit 66a319b

File tree

3 files changed

+117
-21
lines changed

3 files changed

+117
-21
lines changed

app/models/manageiq/providers/embedded_ansible/automation_manager/provision_workflow.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,22 @@ def allowed_configuration_scripts(*_args)
1313
build_ci_hash_struct(cs, %w[name description manager_name])
1414
end
1515
end
16+
17+
def allowed_machine_credentials(*_args)
18+
self.class.module_parent::MachineCredential.all.each_with_object({}) do |mc, h|
19+
h[mc.id] = mc.name
20+
end
21+
end
22+
23+
def allowed_vault_credentials(*_args)
24+
self.class.module_parent::VaultCredential.all.each_with_object({}) do |vc, h|
25+
h[vc.id] = vc.name
26+
end
27+
end
28+
29+
def allowed_cloud_credentials(*args)
30+
self.class.module_parent::CloudCredential.all.each_with_object({}) do |cc, h|
31+
h[cc.id] = "#{cc.name} - #{cc.type}"
32+
end
33+
end
1634
end

product/dialogs/miq_dialogs/miq_provision_configuration_script_embedded_ansible_dialogs.yaml

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -121,27 +121,9 @@
121121
:data_type: :integer
122122
:display: :show
123123
:field_order:
124-
:customize:
125-
:description: Customize
124+
:provision:
125+
:description: Provision
126126
:fields:
127-
:root_password:
128-
:description: Root Password
129-
:required: false
130-
:display: :edit
131-
:data_type: :string
132-
:notes: Minimum 8 characters or blank
133-
:hostname:
134-
:description: Host Name
135-
:required: false
136-
:display: :edit
137-
:data_type: :string
138-
:ip_addr:
139-
:description: IP Address
140-
:required: false
141-
:notes: (Enter starting IP address)
142-
:display: :edit
143-
:data_type: :string
144-
:notes_display: :hide
145127
:verbosity:
146128
:description: Verbosity
147129
:values:
@@ -173,6 +155,27 @@
173155
:required: false
174156
:display: :edit
175157
:data_type: :integer
158+
:machine_credential_id:
159+
:values_from:
160+
:method: :allowed_machine_credentials
161+
:description: Machine Credential
162+
:required: true
163+
:display: :edit
164+
:data_type: :integer
165+
:vault_credential_id:
166+
:values_from:
167+
:method: :allowed_vault_credentials
168+
:description: Vault Credential
169+
:required: false
170+
:display: :edit
171+
:data_type: :integer
172+
:cloud_credential_id:
173+
:values_from:
174+
:method: :allowed_cloud_credentials
175+
:description: Cloud Credential
176+
:required: false
177+
:display: :edit
178+
:data_type: :string
176179
:display: :show
177180
:service:
178181
:description: Catalog
@@ -213,5 +216,5 @@
213216
- :requester
214217
- :purpose
215218
- :service
216-
- :customize
219+
- :provision
217220
- :schedule
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
describe ManageIQ::Providers::EmbeddedAnsible::AutomationManager::ProvisionWorkflow do
2+
let(:admin) { FactoryBot.create(:user_with_group) }
3+
let(:manager) { FactoryBot.create(:provider_embedded_ansible, :default_organization => 1).managers.first }
4+
let(:workflow) { described_class.new({}, admin.userid) }
5+
6+
before do
7+
EvmSpecHelper.assign_embedded_ansible_role
8+
MiqDialog.seed_dialog(Rails.root.join("product/dialogs/miq_dialogs/miq_provision_configuration_script_embedded_ansible_dialogs.yaml"))
9+
end
10+
11+
describe "#allowed_configuration_scripts" do
12+
let!(:config_script1) { FactoryBot.create(:embedded_ansible_configuration_script, :manager => manager) }
13+
let!(:config_script2) { FactoryBot.create(:embedded_ansible_configuration_script, :manager => manager) }
14+
15+
it "returns all configuration scripts" do
16+
scripts = workflow.allowed_configuration_scripts
17+
expect(scripts.count).to eq(2)
18+
expect(scripts.map { |s| s[:id] }).to match_array([config_script1.id, config_script2.id])
19+
end
20+
end
21+
22+
describe "#allowed_machine_credentials" do
23+
let!(:machine_cred1) { FactoryBot.create(:embedded_ansible_machine_credential, :manager => manager) }
24+
let!(:machine_cred2) { FactoryBot.create(:embedded_ansible_machine_credential, :manager => manager) }
25+
26+
it "returns all machine credentials" do
27+
credentials = workflow.allowed_machine_credentials
28+
expect(credentials).to be_a(Hash)
29+
expect(credentials.count).to eq(2)
30+
expect(credentials.keys).to match_array([machine_cred1.id, machine_cred2.id])
31+
expect(credentials.values).to match_array([machine_cred1.name, machine_cred2.name])
32+
end
33+
end
34+
35+
describe "#allowed_vault_credentials" do
36+
let!(:vault_cred1) { FactoryBot.create(:embedded_ansible_vault_credential, :manager => manager) }
37+
let!(:vault_cred2) { FactoryBot.create(:embedded_ansible_vault_credential, :manager => manager) }
38+
39+
it "returns all vault credentials" do
40+
credentials = workflow.allowed_vault_credentials
41+
expect(credentials).to be_a(Hash)
42+
expect(credentials.count).to eq(2)
43+
expect(credentials.keys).to match_array([vault_cred1.id, vault_cred2.id])
44+
expect(credentials.values).to match_array([vault_cred1.name, vault_cred2.name])
45+
end
46+
end
47+
48+
describe "#allowed_cloud_credentials" do
49+
let!(:amazon_cred1) { FactoryBot.create(:embedded_ansible_amazon_credential, :manager => manager) }
50+
let!(:amazon_cred2) { FactoryBot.create(:embedded_ansible_amazon_credential, :manager => manager) }
51+
let!(:azure_cred) { FactoryBot.create(:embedded_ansible_azure_credential, :manager => manager) }
52+
53+
context "when cloud_credential_type is specified" do
54+
it "returns credentials of the specified type" do
55+
workflow.values[:cloud_credential_type] = "Amazon"
56+
credentials = workflow.allowed_cloud_credentials
57+
58+
expect(credentials).to be_a(Hash)
59+
expect(credentials.count).to eq(2)
60+
expect(credentials.keys).to match_array([amazon_cred1.id, amazon_cred2.id])
61+
expect(credentials.values).to match_array([amazon_cred1.name, amazon_cred2.name])
62+
end
63+
end
64+
65+
context "when cloud_credential_type is not specified" do
66+
it "returns all cloud credentials" do
67+
credentials = workflow.allowed_cloud_credentials
68+
69+
expect(credentials).to be_a(Hash)
70+
expect(credentials.count).to eq(3)
71+
expect(credentials.keys).to match_array([amazon_cred1.id, amazon_cred2.id, azure_cred.id])
72+
end
73+
end
74+
end
75+
end

0 commit comments

Comments
 (0)