Class: OpenC3::AuthModel
Constant Summary collapse
- PRIMARY_KEY =
'OPENC3__TOKEN'
- SERVICE_KEY =
'OPENC3__SERVICE__TOKEN'
Class Method Summary collapse
- .is_set?(key = PRIMARY_KEY) ⇒ Boolean
- .set(token, old_token, key = PRIMARY_KEY) ⇒ Object
- .verify(token, permission: nil) ⇒ Object
Class Method Details
.is_set?(key = PRIMARY_KEY) ⇒ Boolean
31 32 33 |
# File 'lib/openc3/models/auth_model.rb', line 31 def self.is_set?(key = PRIMARY_KEY) Store.exists(key) == 1 end |
.set(token, old_token, key = PRIMARY_KEY) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/openc3/models/auth_model.rb', line 51 def self.set(token, old_token, key = PRIMARY_KEY) raise "token must not be nil or empty" if token.nil? or token.empty? if is_set?(key) raise "old_token must not be nil or empty" if old_token.nil? or old_token.empty? raise "old_token incorrect" unless verify(old_token) end Store.set(key, hash(token)) end |
.verify(token, permission: nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/openc3/models/auth_model.rb', line 35 def self.verify(token, permission: nil) return false if token.nil? or token.empty? token_hash = hash(token) return true if Store.get(PRIMARY_KEY) == token_hash service_hash = Store.get(SERVICE_KEY) if ENV['OPENC3_SERVICE_PASSWORD'] and hash(ENV['OPENC3_SERVICE_PASSWORD']) != service_hash set_hash = hash(ENV['OPENC3_SERVICE_PASSWORD']) OpenC3::Store.set(SERVICE_KEY, set_hash) service_hash = set_hash end return true if service_hash == token_hash and != 'admin' return false end |