Module: EvoleapLicensing::ControlManagerHelper
- Defined in:
- lib/evoleap_licensing/control_manager_helper.rb
Class Method Summary collapse
- .register(state) ⇒ Object
- .validate_instance(strategy, state) ⇒ Object
- .validate_session(strategy, user_state, session_state, web_service_call) ⇒ Object
Class Method Details
.register(state) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/evoleap_licensing/control_manager_helper.rb', line 7 def self.register(state) initialize_state(state) response = yield if response["success"] state.registered_at = Time.parse(response["first_registered_at"]) state.grace_period_for_validation_failures = response["validation_grace_period"] state.reset_registration_failures state.take_registration_params(response) RegistrationResult.new(success: true) else state.add_registration_failure(Time.now.utc) RegistrationResult.new(success: false, error_message: response["error"]) end end |
.validate_instance(strategy, state) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/evoleap_licensing/control_manager_helper.rb', line 23 def self.validate_instance(strategy, state) initialize_state(state) current_time = Time.now.utc unless state.registered? return get_unregistered_instance_validity(strategy, state, current_time) end response = yield is_server_time = false if response.key?("time") current_time = Time.parse(response["time"]) is_server_time = true end status = response["status"] if status == ValidationStatus::SUCCESS grace_period = response["validation_grace_period"].to_i state.grace_period_for_validation_failures = grace_period state.features = response["features"] || [] else grace_period = state.grace_period_for_validation_failures end if status == ValidationStatus::SERVICE_UNREACHABLE || status == ValidationStatus::GENERAL_ERROR get_server_unreachable_instance_validity(state, grace_period, current_time, is_server_time) else get_server_reached_instance_validity(state, current_time, response) end end |
.validate_session(strategy, user_state, session_state, web_service_call) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/evoleap_licensing/control_manager_helper.rb', line 56 def self.validate_session(strategy, user_state, session_state, web_service_call) initialize_state(user_state) current_time = Time.now.utc unless user_state.registered? return get_unregistered_session_validity(strategy, user_state, current_time) end response = web_service_call.call is_server_time = false if response.key?("time") current_time = Time.parse(response["time"]) is_server_time = true end status = response["status"] if status == ValidationStatus::SUCCESS grace_period = response["validation_grace_period"].to_i user_state.grace_period_for_validation_failures = grace_period user_state.features = response["features"] || [] session_state.update_from_session_response(response) if session_state.active? == false session_state.update_from_extend_response(response) if session_state.active? # Handle first session setup unless session_state.active? session_state.update_from_session_response(response) end else grace_period = user_state.grace_period_for_validation_failures end if status == ValidationStatus::SERVICE_UNREACHABLE || status == ValidationStatus::GENERAL_ERROR get_server_unreachable_session_validity(user_state, grace_period, current_time, is_server_time) else get_server_reached_session_validity(user_state, current_time, response) end end |