Module: Op5util
- Defined in:
- lib/op5util/monitor.rb,
lib/op5util/commit.rb,
lib/op5util/version.rb,
lib/op5util/add_host.rb,
lib/op5util/check_auth.rb,
lib/op5util/list_hosts.rb,
lib/op5util/status_host.rb,
lib/op5util/autocomplete.rb,
lib/op5util/add_hostgroups.rb,
lib/op5util/status_summary.rb,
lib/op5util/list_hostgroups.rb,
lib/op5util/method_template.rb,
lib/op5util/schedule_checks.rb,
lib/op5util/acknowledge_alarm.rb,
lib/op5util/schedule_downtime.rb
Overview
rubocop:disable Lint/UnneededDisable, LineLength, AbcSize, SymbolArray, MethodLength, HashSyntax Foo
Defined Under Namespace
Classes: ApiError, AuthenticationError, CommunicationError, Monitor, NoAuthMethodError, NoMonitorServerError, NoSuchHostError, NoSuchHostgroupError, UnacceptableAuthFilePermission
Constant Summary collapse
- VERSION =
'0.1.8'.freeze
Class Method Summary collapse
Class Method Details
.check_auth(global_opts) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/op5util/check_auth.rb', line 23 def check_auth(global_opts) authfile_path = File.(global_opts[:authfile]) if File.exist?(authfile_path) && File.stat(authfile_path).mode.to_s(8)[-2, 2] != '00' puts "Authfile must not be readable by other than owner, run \"chmod 400 #{global_opts[:authfile]}\" to set better permissions" raise UnacceptableAuthFilePermission end if !global_opts[:username].nil? && !global_opts[:password].nil? true elsif !ENV['OP5USER'].nil? && !ENV['OP5PASS'].nil? global_opts[:username] = ENV['OP5USER'] global_opts[:password] = ENV['OP5PASS'] true elsif File.exist?(File.(global_opts[:authfile])) (global_opts[:username], global_opts[:password]) = check_authfile(global_opts[:authfile]) global_opts[:username].nil? ? false : true else puts 'No method of authentication with Op5-Server given' raise NoAuthMethodError end end |
.check_authfile(file) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/op5util/check_auth.rb', line 14 def check_authfile(file) authline = File.open(File.(file)).readline.chomp rescue StandardError [nil, nil] else authinfo = authline.split(':') authinfo.count == 2 ? authinfo : [nil, nil] end |