Skip to content

Commit

Permalink
Merge pull request #149 from agrare/add_params_for_create_and_verify_…
Browse files Browse the repository at this point in the history
…credentials

Add methods for for provider creation pluggable UI
  • Loading branch information
Fryguy authored Oct 8, 2019
2 parents 05c6f00 + 8f7439d commit 2c0567b
Showing 1 changed file with 49 additions and 4 deletions.
53 changes: 49 additions & 4 deletions app/models/manageiq/providers/kubevirt/infra_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,54 @@ def self.description
@description ||= ManageIQ::Providers::Kubevirt::Constants::PRODUCT
end

def self.params_for_create
@params_for_create ||= {
:title => "Configure #{description}",
:fields => [
{
:component => "text-field",
:name => "endpoints.default.server",
:label => "Hostname",
:isRequired => true,
:validate => [{:type => "required-validator"}]
},
{
:component => "text-field",
:name => "endpoints.default.port",
:type => "number",
:isRequired => true,
:validate => [
{
:type => "required-validator"
},
{
:type => "validatorTypes.MIN_NUMBER_VALUE",
:includeThreshold => true,
:value => 1
},
{
:type => "validatorTypes.MAX_NUMBER_VALUE",
:includeThreshold => true,
:value => 65_535
}
]
},
{
:component => "text-field",
:name => "endpoints.default.token",
:label => "Token",
:type => "password",
:isRequired => true,
:validate => [{:type => "required-validator"}]
}
]
}.freeze
end

def self.verify_credentials(args)
!!raw_connect(args.dig("endpoints", "default")&.slice("server", "port", "token")&.symbolize_keys)
end

#
# This method from the dialog that adds a provider, to verify the connection details and the
# credentials.
Expand All @@ -61,16 +109,13 @@ def self.description
# @option opts [String] :server The Kubernetes API server host name or IP address.
# @option opts [Integer] :port The Kubernetes API port number.
# @option opts [String] :token The Kubernetes authentication token.
# @option opts [Integer] :verify_ssl Integer indicating if the Kubernetes API server certificate
# should be verified.
# @option opts [Integer] :ca_certs Trusted CA certificates, in PEM format.
#
def self.raw_connect(opts)
# Create the connection:
connection = Connection.new(
:host => opts[:server],
:port => opts[:port],
:token => opts[:token],
:token => MiqPassword.try_decrypt(opts[:token])
)

# Verify that the connection works:
Expand Down

0 comments on commit 2c0567b

Please sign in to comment.