Skip to content

Commit

Permalink
Add params_for_create and verify_credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Nov 12, 2019
1 parent 5a6f135 commit 06b4ee9
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions app/models/manageiq/providers/nuage/manager_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,80 @@ module ManageIQ::Providers::Nuage::ManagerMixin
extend ActiveSupport::Concern

module ClassMethods
def params_for_create
@params_for_create ||= {
:title => "Configure Nuage",
:fields => [
{
:component => "text-field",
:name => "endpoints.default.server",
:label => "Server Hostname/IP Address",
: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 => "number",
:isRequired => true,
:validate => [{:type => "required-validator"}]
},
{
:component => "text-field",
:name => "endpoints.default.protocol",
:label => "Security Protocol",
:initialValue => "ssl-no-validation", # TODO This should be a dropdown
:isRequired => true,
:validate => [{:type => "required-validator"}]
}
]
}.freeze
end

# Verify Credentials
#
# args: {
# "endpoints" => {
# "default" => {
# "username" => String,
# "password" => String,
# "server" => String,
# "port" => Integer,
# "protocol" => String
# }
# }
def verify_credentials(args)
default_endpoint = args.dig("endpoints", "default")

username, password, host, port, protocol = default_endpoint&.values_at(
"username", "password", "server", "port", "protocol"
)

endpoint_opts = {
:protocol => protocol,
:hostname => server,
:api_port => port
}

!!raw_connect(username, password, endpoint_opts)
end

def raw_connect(username, password, endpoint_opts)
protocol = endpoint_opts[:protocol].strip if endpoint_opts[:protocol]
hostname = endpoint_opts[:hostname].strip
Expand Down

0 comments on commit 06b4ee9

Please sign in to comment.