Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 19 additions & 0 deletions lib/hammer_cli_foreman/auth_source_ldap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ 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 containing CA certificate(s) for LDAPS verification. Ignored if --cacert is set'),
:format => HammerCLI::Options::Normalizers::File.new
end

def request_params
params = super
params['auth_source_ldap']['cacert'] ||= options['option_cacert_file'] if options['option_cacert_file']
Comment thread
adamruzicka marked this conversation as resolved.
Outdated
params
end
end

class ListCommand < HammerCLIForeman::ListCommand
output do
field :id, _('Id')
Expand All @@ -23,6 +37,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,6 +65,8 @@ 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')

Expand All @@ -64,6 +81,8 @@ 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')

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