Skip to content

Commit

Permalink
Add params_for_create and verify_credentials
Browse files Browse the repository at this point in the history
Add a method to return the needed parameters to add a foreman provider
and a method to verify credentials with these parametes.
  • Loading branch information
agrare committed Oct 1, 2019
1 parent 9bb740a commit 6faaec1
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ class ManageIQ::Providers::Foreman::ConfigurationManager < ManageIQ::Providers::
:with_provider_connection,
:to => :provider

class << self
delegate :params_for_create,
:verify_credentials,
:to => ManageIQ::Providers::Foreman::Provider
end

def self.ems_type
@ems_type ||= "foreman_configuration".freeze
end
Expand Down
50 changes: 50 additions & 0 deletions app/models/manageiq/providers/foreman/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,56 @@ class ManageIQ::Providers::Foreman::Provider < ::Provider
validates :name, :presence => true, :uniqueness => true
validates :url, :presence => true

def self.params_for_create
@params_for_create ||= {
:title => "Configure AWS",
:fields => [
{
:component => "text-field",
:name => "endpoints.default.base_url",
:label => "URL",
:isRequired => true,
:validate => [{:type => "required-validator"}]
},
{
:component => "text-field",
:name => "endpoints.default.username",
:label => "User",
:isRequired => true,
:validate => [{:type => "required-validator"}]
},
{
:component => "text-field",
:name => "endpoints.default.password",
:label => "Password",
:type => "password",
:isRequired => true,
:validate => [{:type => "required-validator"}]
},
{
:component => "checkbox",
:name => "endpoints.default.verify_ssl",
:label => "Verify SSL"
}
]
}.freeze
end

# Verify Credentials
# args: {
# "endpoints" => {
# "default" => {
# "base_url" => nil,
# "username" => nil,
# "password" => nil,
# "verify_ssl" => nil
# }
# }
# }
def self.verify_credentials(args)
raw_connect(*args.dig("endpoints", "default")&.values_at("base_url", "username", "password", "verify_ssl"))
end

def self.raw_connect(base_url, username, password, verify_ssl)
require 'foreman_api_client'
ForemanApiClient.logger ||= $log
Expand Down
6 changes: 6 additions & 0 deletions app/models/manageiq/providers/foreman/provisioning_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ class ManageIQ::Providers::Foreman::ProvisioningManager < ManageIQ::Providers::P
:with_provider_connection,
:to => :provider

class << self
delegate :params_for_create,
:verify_credentials,
:to => ManageIQ::Providers::Foreman::Provider
end

has_many :configuration_locations, :foreign_key => :provisioning_manager_id
has_many :configuration_organizations, :foreign_key => :provisioning_manager_id

Expand Down

0 comments on commit 6faaec1

Please sign in to comment.