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

Add verify_credentials and params_for_create #136

Merged
merged 1 commit into from
Oct 1, 2019
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
55 changes: 55 additions & 0 deletions app/models/manageiq/providers/microsoft/infra_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,61 @@ def self.description
@description ||= "Microsoft System Center VMM".freeze
end

def self.params_for_create
@params_for_create ||= {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No constant like the other providers?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought a constant plus a class method could be confusing, didn't want people to use the constant instead. Plus the rest of this class uses the @ ||= style to prevent allocating these on every method call

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok...I'd almost rather we change the other ones with constants to be consistent, then.

:title => "Configure #{description}",
: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 => "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
end

def self.raw_connect(connect_params, validate = false)
require 'winrm'

Expand Down