Module: Stackify::Authorizable::ClassMethods
- Defined in:
- lib/stackify/authorization/authorizable.rb
Constant Summary collapse
false- @@auth_lock =
Mutex.new
- @@auth_client =
nil
Instance Method Summary collapse
- #authorize(attempts = 3) ⇒ Object
- #authorized! ⇒ Object
- #authorized? ⇒ Boolean
- #if_not_authorized(failure_msg, &block) ⇒ Object
- #response_string(r) ⇒ Object
- #successfull_authorisation(response) ⇒ Object
- #unsuccessfull_authorisation(response, caller) ⇒ Object
Instance Method Details
#authorize(attempts = 3) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/stackify/authorization/authorizable.rb', line 13 def attempts=3 # Check if the ruby version is 2.0 we get the Rails info properties such as # <Application root: e.g., /home/user/rails_app> which is required in authorization if Gem::Version.new(RUBY_VERSION) <= Gem::Version.new('2.0') Stackify::EnvDetails.instance.set_rails_info end @@auth_lock.synchronize do return unless @@auth_client.nil? @@auth_client = Stackify::Authorizable::AuthorizationClient.new @@auth_client.auth attempts end end |
#authorized! ⇒ Object
32 33 34 |
# File 'lib/stackify/authorization/authorizable.rb', line 32 def @@authorized = true end |
#authorized? ⇒ Boolean
26 27 28 29 30 |
# File 'lib/stackify/authorization/authorizable.rb', line 26 def @@auth_lock.synchronize do @@authorized end end |
#if_not_authorized(failure_msg, &block) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/stackify/authorization/authorizable.rb', line 46 def failure_msg, &block failure_msg += ', but Stackify module is not authorized' if Stackify. begin block.call rescue => e Stackify.log_internal_error e. end else Stackify.log_internal_error failure_msg end end |
#response_string(r) ⇒ Object
59 60 61 62 |
# File 'lib/stackify/authorization/authorizable.rb', line 59 def response_string r return '' if r.nil? "Status: #{r.try(:status)}, Message: '#{r.try(:body)}'" end |
#successfull_authorisation(response) ⇒ Object
36 37 38 39 |
# File 'lib/stackify/authorization/authorizable.rb', line 36 def response Stackify::EnvDetails.instance.update_auth_info JSON.parse(response.body) Stackify.internal_log :info, 'Authorization is finished successfully.' end |
#unsuccessfull_authorisation(response, caller) ⇒ Object
41 42 43 44 |
# File 'lib/stackify/authorization/authorizable.rb', line 41 def response, caller Stackify.log_internal_error "Authorization finally failed: #{response_string(response)}" Stackify.shutdown_all caller unless @@authorized end |