Class: Spaceship::Slack2fa::MonkeyPatch Private
- Inherits:
-
Object
- Object
- Spaceship::Slack2fa::MonkeyPatch
- Defined in:
- lib/spaceship/slack2fa/monkey_patch.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Constant Summary collapse
- REQUIRED_SLACK_SCOPES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
%w[channels.history chat.write].freeze
Instance Method Summary collapse
- #disable ⇒ Object private
- #enable ⇒ Object private
-
#initialize(**options) ⇒ MonkeyPatch
constructor
private
A new instance of MonkeyPatch.
- #retrieve_2fa_code(*_args) ⇒ Object private
Constructor Details
#initialize(**options) ⇒ MonkeyPatch
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of MonkeyPatch.
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/spaceship/slack2fa/monkey_patch.rb', line 32 def initialize(**) slack_api_token = .fetch(:slack_api_token) @slack = Slack::Web::Client.new(token: slack_api_token) @channel_id = .fetch(:channel_id) @user_id = .fetch(:user_id) @referrer = .fetch(:referrer) @allow_any_users = .fetch(:allow_any_users, false) @retry_count = .fetch(:retry_count, 3) @retry_interval = .fetch(:retry_interval, 20.0) @logger = Logger.new($stderr) @logger.level = (.fetch(:verbose, false) ? Logger::DEBUG : Logger::WARN) end |
Instance Method Details
#disable ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
50 51 52 53 |
# File 'lib/spaceship/slack2fa/monkey_patch.rb', line 50 def disable Spaceship::Client.alias_method(:ask_for_2fa_code, :original_ask_for_2fa_code) Spaceship::Client.remove_method(:original_ask_for_2fa_code) end |
#enable ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
45 46 47 48 |
# File 'lib/spaceship/slack2fa/monkey_patch.rb', line 45 def enable Spaceship::Client.alias_method(:original_ask_for_2fa_code, :ask_for_2fa_code) Spaceship::Client.define_method(:ask_for_2fa_code, &public_method(:retrieve_2fa_code)) end |
#retrieve_2fa_code(*_args) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/spaceship/slack2fa/monkey_patch.rb', line 55 def retrieve_2fa_code(*_args) = Time.now.to_i do |i| @logger.debug("Attempt ##{i}.") response = @slack.conversations_history(channel: @channel_id, oldest: ) @logger.debug("Found #{response..size} messages.") = response..select { |msg| unused_2fa_code?(msg) }.max_by(&:ts) @logger.debug("Possible message: #{}.") code = &.text if code @logger.debug("Found 2FA code: #{code}.") comment_on_thread_of() return code end end raise VerificationCodeNotFound end |