Skip to content
Draft
Show file tree
Hide file tree
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
22 changes: 20 additions & 2 deletions lib/hammer_cli_foreman/auth_source_ldap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ class AuthSourceLdap < HammerCLIForeman::Command
command_name 'ldap'
desc _('Manage LDAP auth sources')

module CacertFileOption
def self.included(base)
base.option '--cacert-file', 'CACERT_FILE',
_('Path to a PEM file with CA certificate(s) added to the system trust store for LDAPS verification'),
:attribute_name => :option_cacert,
:format => HammerCLI::Options::Normalizers::File.new
end
end

class ListCommand < HammerCLIForeman::ListCommand
output do
field :id, _('Id')
Expand All @@ -23,6 +32,7 @@ class InfoCommand < HammerCLIForeman::InfoCommand
field :name, _('Name')
field :host, _('Server')
field :tls, _('LDAPS'), Fields::Boolean
field :cacert, _('CA certificate'), Fields::LongText, :hide_blank => true
field :port, _('Port')
field :server_type, _('Server Type')
end
Expand Down Expand Up @@ -50,10 +60,14 @@ class InfoCommand < HammerCLIForeman::InfoCommand
end

class CreateCommand < HammerCLIForeman::CreateCommand
include CacertFileOption

success_message _('Auth source [%{name}] created.')
failure_message _('Could not create the Auth Source')

build_options
build_options do |o|
o.without(:cacert)
end
end

class DeleteCommand < HammerCLIForeman::DeleteCommand
Expand All @@ -64,10 +78,14 @@ class DeleteCommand < HammerCLIForeman::DeleteCommand
end

class UpdateCommand < HammerCLIForeman::UpdateCommand
include CacertFileOption

success_message _('Auth source [%{name}] updated.')
failure_message _('Could not update the Auth Source')

build_options
build_options do |o|
o.without(:cacert)
end
end

autoload_subcommands
Expand Down
2 changes: 2 additions & 0 deletions test/unit/auth_source_ldap_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@

describe "parameters" do
it_should_accept "all required params", ["--name=arch", "--host=my.host"]
it_should_accept "cacert file", ["--name=arch", "--host=my.host", "--cacert-file=#{__FILE__}"]
# it_should_fail_with "name missing", []
# TODO: temporarily disabled, parameters are checked in the api
end
Expand Down Expand Up @@ -87,6 +88,7 @@
describe "parameters" do
it_should_accept "name", ["--name=arch", "--new-name=arch2"]
it_should_accept "id", ["--id=1", "--new-name=arch2"]
it_should_accept "cacert file", ["--id=1", "--cacert-file=#{__FILE__}"]
# it_should_fail_with "no params", [] # TODO: temporarily disabled, parameters are checked in the id resolver
# it_should_fail_with "name or id missing", ["--new-name=arch2"] # TODO: temporarily disabled, parameters are checked in the id resolver
end
Expand Down
Loading