Class: Person
- Inherits:
-
Object
- Object
- Person
- Defined in:
- lib/terraorg/model/person.rb
Overview
The following statuses are considered ACTIVE by terraorg, which allow PRs to continue and be merged. A DEACTIVATED account status needs to be removed from the repository before merging PRs
Constant Summary collapse
- ACTIVE_USER_STATUSES =
['ACTIVE', 'PROVISIONED', 'PASSWORD_EXPIRED', 'SUSPENDED'].freeze
Instance Attribute Summary collapse
-
#email ⇒ Object
Returns the value of attribute email.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#okta_id ⇒ Object
Returns the value of attribute okta_id.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
- #active? ⇒ Boolean
-
#initialize(uid, okta: nil, cached: nil) ⇒ Person
constructor
A new instance of Person.
- #to_json(options = nil) ⇒ Object
Constructor Details
#initialize(uid, okta: nil, cached: nil) ⇒ Person
Returns a new instance of Person.
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/terraorg/model/person.rb', line 25 def initialize(uid, okta: nil, cached: nil) @id = uid if cached @name = cached.fetch('name') @okta_id = cached.fetch('okta_id') @email = cached.fetch('email') @status = cached.fetch('status') return elsif !okta # We could just be running in fmt mode, so lie about everything @name = "real name of #{@id}" @okta_id = "fake okta id for #{@id}" @email = "#{@id}@my.domain" @status = 'PROVISIONED' return end # Retrieve from okta tries = 1 total_tries = 5 begin o = okta.get_user(uid) rescue Faraday::ConnectionFailed => e if tries <= total_tries puts "looking up user #{uid}: #{e} (try #{tries}/#{total_tries})" tries += 1 retry end raise end if tries > 1 puts "looking up user #{uid}: success!" end # NOTE: allows users in states other than ACTIVE # if you want to check that, do it outside of here obj = o[0].to_hash @name = obj.fetch(:profile).fetch(:displayName) @okta_id = obj.fetch(:id) @email = obj.fetch(:profile).fetch(:email) @status = obj.fetch(:status) end |
Instance Attribute Details
#email ⇒ Object
Returns the value of attribute email.
23 24 25 |
# File 'lib/terraorg/model/person.rb', line 23 def email @email end |
#id ⇒ Object
Returns the value of attribute id.
23 24 25 |
# File 'lib/terraorg/model/person.rb', line 23 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
23 24 25 |
# File 'lib/terraorg/model/person.rb', line 23 def name @name end |
#okta_id ⇒ Object
Returns the value of attribute okta_id.
23 24 25 |
# File 'lib/terraorg/model/person.rb', line 23 def okta_id @okta_id end |
#status ⇒ Object
Returns the value of attribute status.
23 24 25 |
# File 'lib/terraorg/model/person.rb', line 23 def status @status end |
Instance Method Details
#active? ⇒ Boolean
73 74 75 |
# File 'lib/terraorg/model/person.rb', line 73 def active? ACTIVE_USER_STATUSES.member?(@status) end |
#to_json(options = nil) ⇒ Object
77 78 79 |
# File 'lib/terraorg/model/person.rb', line 77 def to_json( = nil) {'id' => @id, 'name' => @name, 'okta_id' => @okta_id, 'email' => @email, 'status' => @status}.to_json end |