Class: PassaporteWeb::IdentityServiceAccount
- Inherits:
-
Object
- Object
- PassaporteWeb::IdentityServiceAccount
- Includes:
- Attributable
- Defined in:
- lib/passaporte_web/identity_service_account.rb
Overview
Also represents a ServiceAccount, but uses diffetent API endpoints to list and create them from a existing Identity.
Constant Summary collapse
- ATTRIBUTES =
[:membership_details_url, :plan_slug, :roles, :url, :expiration, :service_data, :account_data, :add_member_url, :name, :uuid]
- CREATABLE_ATTRIBUTES =
[:plan_slug, :expiration, :name, :uuid]
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#identity ⇒ Object
readonly
Returns the value of attribute identity.
Class Method Summary collapse
-
.find_all(identity, include_expired_accounts = false, role = nil, include_other_services = false) ⇒ Object
Finds all service accounts of the supplied Identity on the current authenticated application.
Instance Method Summary collapse
-
#attributes ⇒ Object
Returns a hash with all attribures of the IdentityServiceAccount.
-
#initialize(identity, attributes = {}) ⇒ IdentityServiceAccount
constructor
Instanciates a new ServiceAccount to be created for the supplied Identity on the current authenticated application.
- #name ⇒ Object
-
#persisted? ⇒ Boolean
Returns true if the IdentityServiceAccount exists on PassaporteWeb.
-
#save ⇒ Object
Creates a new ServiceAccount for the supplied Identity on the current authenticated application.
- #uuid ⇒ Object
Constructor Details
#initialize(identity, attributes = {}) ⇒ IdentityServiceAccount
Instanciates a new ServiceAccount to be created for the supplied Identity on the current authenticated application. See #save
32 33 34 35 36 37 |
# File 'lib/passaporte_web/identity_service_account.rb', line 32 def initialize(identity, attributes={}) set_attributes(attributes) @identity = identity @persisted = false @errors = {} end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
14 15 16 |
# File 'lib/passaporte_web/identity_service_account.rb', line 14 def errors @errors end |
#identity ⇒ Object (readonly)
Returns the value of attribute identity.
14 15 16 |
# File 'lib/passaporte_web/identity_service_account.rb', line 14 def identity @identity end |
Class Method Details
.find_all(identity, include_expired_accounts = false, role = nil, include_other_services = false) ⇒ Object
Finds all service accounts of the supplied Identity on the current authenticated application. Returns an array of IdentityServiceAccount.
API method: GET /organizations/api/identities/:uuid/accounts/
API documentation: app.passaporteweb.com.br/static/docs/account_manager.html#get-organizations-api-identities-uuid-accounts
22 23 24 25 26 27 28 |
# File 'lib/passaporte_web/identity_service_account.rb', line 22 def self.find_all(identity, include_expired_accounts=false, role=nil, include_other_services=false) params = {include_expired_accounts: include_expired_accounts, include_other_services: include_other_services} params[:role] = role unless (role.nil? || role.to_s.empty?) response = Http.get("/organizations/api/identities/#{identity.uuid}/accounts/", params) raw_accounts = MultiJson.decode(response.body) raw_accounts.map { |raw_account| load_identity_service_account(identity, raw_account) } end |
Instance Method Details
#attributes ⇒ Object
Returns a hash with all attribures of the IdentityServiceAccount
78 79 80 81 82 83 |
# File 'lib/passaporte_web/identity_service_account.rb', line 78 def attributes ATTRIBUTES.inject({}) do |hash, attribute| hash[attribute] = self.send(attribute) hash end end |
#name ⇒ Object
39 40 41 |
# File 'lib/passaporte_web/identity_service_account.rb', line 39 def name @name || (@account_data.nil? ? nil : @account_data['name']) end |
#persisted? ⇒ Boolean
Returns true if the IdentityServiceAccount exists on PassaporteWeb
73 74 75 |
# File 'lib/passaporte_web/identity_service_account.rb', line 73 def persisted? @persisted == true end |
#save ⇒ Object
Creates a new ServiceAccount for the supplied Identity on the current authenticated application. The supplied Identity will be the ServiceAccount’s owner. You should supply either the name
or the (service account’s) uuid
attribute. If the latter is supplied, the supplied Identity must already be owner of at least one other ServiceAccount on the same group / organization.
Returns true in case of success, false otherwise (along with failure reasons on #errors).
API method: POST /organizations/api/identities/:uuid/accounts/
API documentation: app.passaporteweb.com.br/static/docs/account_manager.html#post-organizations-api-identities-uuid-accounts
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/passaporte_web/identity_service_account.rb', line 57 def save # TODO validar atributos? response = Http.post("/organizations/api/identities/#{self.identity.uuid}/accounts/", create_body) raise "unexpected response: #{response.code} - #{response.body}" unless [200,201].include?(response.code) attributes_hash = MultiJson.decode(response.body) set_attributes(attributes_hash) @persisted = true @errors = {} true rescue *[RestClient::BadRequest] => e @persisted = false @errors = MultiJson.decode(e.response.body) false end |
#uuid ⇒ Object
43 44 45 |
# File 'lib/passaporte_web/identity_service_account.rb', line 43 def uuid @uuid || (@account_data.nil? ? nil : @account_data['uuid']) end |