Skip to content
This repository has been archived by the owner on Jul 25, 2023. It is now read-only.

Adjusted DDF schema for provider creation + validation #160

Merged
merged 1 commit into from
Jul 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 76 additions & 42 deletions app/models/manageiq/providers/microsoft/infra_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,54 +30,88 @@ def self.params_for_create
:title => "Configure #{description}",
:fields => [
{
:component => "text-field",
:name => "endpoints.default.server",
:label => "Server Hostname/IP Address",
:isRequired => true,
:validate => [{:type => "required-validator"}]
:component => 'sub-form',
:name => 'endpoints-subform',
:title => _("Endpoints"),
:fields => [{
:component => 'validate-provider-credentials',
:name => 'endpoints.default.valid',
:skipSubmit => true,
:validationDependencies => %w[type zone_id],
:fields => [
{
:component => "text-field",
:name => "endpoints.default.hostname",
:label => _("Hostname (or IPv4 or IPv6 address)"),
:isRequired => true,
:validate => [{:type => "required-validator"}]
},
{
:component => "select-field",
:name => "endpoints.default.security_protocol",
:label => _("Security Protocol"),
:isRequired => true,
:validate => [{:type => "required-validator"}],
:options => [
{
:label => _("SSL"),
:value => "ssl",
},
{
:label => _("Kerberos"),
:value => "kerberos",
}
]
},
{
:component => "text-field",
:name => "realm",
:label => _("Realm"),
:isRequired => true,
:validate => [{:type => "required-validator"}],
:helperText => _('Username must be in the format: name@realm'),
:condition => {
:when => 'endpoints.default.security_protocol',
:is => 'kerberos',
},
},
{
:component => "text-field",
:name => "authentications.default.userid",
:label => _("Username"),
:isRequired => true,
:helperText => _('Should have privileged access, such as root or administrator.'),
:validate => [{:type => "required-validator"}]
},
{
:component => "password-field",
:name => "authentications.default.password",
:label => _("Password"),
:type => "password",
:isRequired => true,
:validate => [{:type => "required-validator"}]
},
],
}],
},
{
:component => "text-field",
:name => "endpoints.default.username",
:label => "Username",
:isRequired => true,
:validate => [{:type => "required-validator"}]
},
{
:component => "text-field",
:name => "endpoints.default.password",
:label => "Password",
:type => "password",
:isRequired => true,
:validate => [{:type => "required-validator"}]
},
{
:component => "text-field",
:name => "endpoints.default.port",
:label => "Port",
:type => "numberic",
}
]
}.freeze
end

# Verify Credentials
# args: {
# "endpoints" => {
# "default" => {
# "server" => nil,
# "username" => nil,
# "password" => nil,
# "port" => nil
# }
# }
# }
def self.verify_credentials(args)
default_endpoint = args.dig("endpoints", "default")
username, password, server, port = default_endpoint&.values_at("username", "password", "server", "port")

raw_connect(build_connect_params(:user => username, :password => password, :hostname => server, :port => port), true)
true
realm = args['realm']
endpoint = args.dig("endpoints", 'default')
hostname, security_protocol = endpoint&.values_at('hostname', 'security_protocol')
authentication = args.dig("authentications", "default")
userid, password = authentication&.values_at('userid', 'password')
password = MiqPassword.try_decrypt(password)
password ||= find(args["id"]).authentication_password(authtype) if args['id']

!raw_connect(build_connect_params(:user => userid,
:password => password,
:hostname => hostname,
:realm => realm,
:security_protocol => security_protocol), true)
end

def self.raw_connect(connect_params, validate = false)
Expand Down