forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 1
/
azure_credential.rb
96 lines (85 loc) · 2.85 KB
/
azure_credential.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
class ManageIQ::Providers::EmbeddedAnsible::AutomationManager::AzureCredential < ManageIQ::Providers::EmbeddedAnsible::AutomationManager::CloudCredential
COMMON_ATTRIBUTES = [
{
:component => 'text-field',
:label => N_('Username'),
:helperText => N_('The username to use to connect to the Microsoft Azure account'),
:name => 'userid',
:id => 'userid',
},
{
:component => 'password-field',
:label => N_('Password'),
:helperText => N_('The password to use to connect to the Microsoft Azure account'),
:name => 'password',
:id => 'password',
:type => 'password',
},
].freeze
EXTRA_ATTRIBUTES = [
{
:component => 'text-field',
:label => N_('Subscription ID'),
:helperText => N_('The Subscription ID for the Microsoft Azure account'),
:name => 'subscription',
:id => 'subscription',
:isRequired => true,
:validate => [{:type => 'required'}],
},
{
:component => 'text-field',
:label => N_('Tenant ID'),
:helperText => N_('The Tenant ID for the Microsoft Azure account'),
:name => 'tenant',
:id => 'tenant',
:maxLength => 1024,
},
{
:component => 'password-field',
:label => N_('Client Secret'),
:helperText => N_('The Client Secret for the Microsoft Azure account'),
:name => 'secret',
:id => 'secret',
:type => 'password',
:maxLength => 1024,
},
{
:component => 'text-field',
:label => N_('Client ID'),
:helperText => N_('The Client ID for the Microsoft Azure account'),
:name => 'client',
:id => 'client',
:maxLength => 128,
},
].freeze
API_ATTRIBUTES = (COMMON_ATTRIBUTES + EXTRA_ATTRIBUTES).freeze
API_OPTIONS = {
:type => 'cloud',
:label => N_('Azure'),
:attributes => API_ATTRIBUTES
}.freeze
alias secret auth_key
def self.display_name(number = 1)
n_('Credential (Microsoft Azure)', 'Credentials (Microsoft Azure)', number)
end
def self.params_to_attributes(params)
attrs = super.dup
attrs[:auth_key] = attrs.delete(:secret) if attrs.key?(:secret)
if %i[client tenant subscription].any? { |opt| attrs.has_key?(opt) }
attrs[:options] ||= {}
attrs[:options][:client] = attrs.delete(:client) if attrs.key?(:client)
attrs[:options][:tenant] = attrs.delete(:tenant) if attrs.key?(:tenant)
attrs[:options][:subscription] = attrs.delete(:subscription) if attrs.key?(:subscription)
end
attrs
end
def client
options && options[:client]
end
def tenant
options && options[:tenant]
end
def subscription
options && options[:subscription]
end
end