Class: ShellStrike
- Inherits:
-
Object
- Object
- ShellStrike
- Defined in:
- lib/shell_strike.rb,
lib/shell_strike/version.rb,
lib/shell_strike/exceptions.rb
Defined Under Namespace
Modules: Ssh Classes: EventBus, Host, HostsNotDefined, InvalidEvent, PasswordsNotDefined, Result, UsernamesNotDefined
Constant Summary collapse
- VERSION =
"1.0.0"
Instance Attribute Summary collapse
-
#global_actions ⇒ Object
readonly
Returns the value of attribute global_actions.
-
#hosts ⇒ Object
readonly
Returns the value of attribute hosts.
-
#passwords ⇒ Object
readonly
Returns the value of attribute passwords.
-
#usernames ⇒ Object
readonly
Returns the value of attribute usernames.
Instance Method Summary collapse
-
#failed_hosts ⇒ Object
An array of hosts for which valid credentials were not able to be identified.
-
#identified_credentials ⇒ Object
A hash of hosts and their valid credentials.
-
#identify_credentials! ⇒ Object
Identifies valid credentials for each host and populates the
identified_credentials,failed_hostsandunreachable_hostsarrays. -
#initialize(hosts, usernames, passwords, global_actions = []) ⇒ ShellStrike
constructor
Initialises a new ShellStrike instance.
-
#on(event_name) {|block| ... } ⇒ Object
Subscribe to an event.
-
#unreachable_hosts ⇒ Object
A hash of hosts which were unreachable.
Constructor Details
#initialize(hosts, usernames, passwords, global_actions = []) ⇒ ShellStrike
Initialises a new ShellStrike instance
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/shell_strike.rb', line 16 def initialize(hosts, usernames, passwords, global_actions = []) raise HostsNotDefined if hosts.nil? || hosts.empty? raise UsernamesNotDefined if usernames.nil? || usernames.empty? raise PasswordsNotDefined if passwords.nil? || passwords.empty? @hosts = hosts @usernames = usernames @passwords = passwords @global_actions = global_actions end |
Instance Attribute Details
#global_actions ⇒ Object (readonly)
Returns the value of attribute global_actions.
9 10 11 |
# File 'lib/shell_strike.rb', line 9 def global_actions @global_actions end |
#hosts ⇒ Object (readonly)
Returns the value of attribute hosts.
9 10 11 |
# File 'lib/shell_strike.rb', line 9 def hosts @hosts end |
#passwords ⇒ Object (readonly)
Returns the value of attribute passwords.
9 10 11 |
# File 'lib/shell_strike.rb', line 9 def passwords @passwords end |
#usernames ⇒ Object (readonly)
Returns the value of attribute usernames.
9 10 11 |
# File 'lib/shell_strike.rb', line 9 def usernames @usernames end |
Instance Method Details
#failed_hosts ⇒ Object
An array of hosts for which valid credentials were not able to be identified.
72 73 74 |
# File 'lib/shell_strike.rb', line 72 def failed_hosts @failed_hosts ||= [] end |
#identified_credentials ⇒ Object
A hash of hosts and their valid credentials.
58 59 60 |
# File 'lib/shell_strike.rb', line 58 def identified_credentials @identified_credentials ||= {} end |
#identify_credentials! ⇒ Object
Identifies valid credentials for each host and populates the identified_credentials, failed_hosts and unreachable_hosts arrays.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/shell_strike.rb', line 28 def identify_credentials! @hosts.each do |host| is_reachable, explanation = Ssh.check_host_reachable(host) unless is_reachable store_unreachable_host(host, explanation) next end credential_failure_count = 0 username_password_combinations.each do |username, password| if Ssh.valid_credentials?(host, username, password) store_valid_credentials(host, username, password) else credential_failure_count += 1 event_bus.emit(:credentials_failed, host, username, password) end end store_failed_host(host) if credential_failure_count == username_password_combinations.length end end |
#on(event_name) {|block| ... } ⇒ Object
Subscribe to an event
79 80 81 |
# File 'lib/shell_strike.rb', line 79 def on(event_name, &block) event_bus.on(event_name, &block) end |
#unreachable_hosts ⇒ Object
A hash of hosts which were unreachable.
66 67 68 |
# File 'lib/shell_strike.rb', line 66 def unreachable_hosts @unreachable_hosts ||= {} end |