Class: PassaporteWeb::ServiceAccountMember
- Inherits:
-
Object
- Object
- PassaporteWeb::ServiceAccountMember
- Defined in:
- lib/passaporte_web/service_account_member.rb
Overview
Represents the membership of an Identity within a ServiceAccount on PassaporteWeb.
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#identity ⇒ Object
readonly
Returns the value of attribute identity.
-
#roles ⇒ Object
Returns the value of attribute roles.
-
#service_account ⇒ Object
readonly
Returns the value of attribute service_account.
Class Method Summary collapse
-
.find(service_account, identity) ⇒ Object
Finds the membership relation between the supplied Identity in the supplied ServiceAccount and returns an instance of ServiceAccountMember representing it.
Instance Method Summary collapse
-
#destroy ⇒ Object
Destroys the membership relation between a Identity and a ServiceAccount, e.g.
-
#destroyed? ⇒ Boolean
Returns true if the ServiceAccountMember object has been destroyed (and thus represents a membership no more valid on PassaporteWeb).
-
#initialize(service_account, identity, roles = ['user']) ⇒ ServiceAccountMember
constructor
Instanciates a new ServiceAccountMember to represent the membership of the supplied Identity in the supplied ServiceAccount.
-
#membership_details_url ⇒ Object
:nodoc:.
-
#persisted? ⇒ Boolean
Returns true if the ServiceAccountMember was loaded from PassaporteWeb or saved there successfully.
-
#save ⇒ Object
Creates or updates the ServiceAccountMember object on PassaporteWeb.
Constructor Details
#initialize(service_account, identity, roles = ['user']) ⇒ ServiceAccountMember
Instanciates a new ServiceAccountMember to represent the membership of the supplied Identity in the supplied ServiceAccount. The roles
attribute should be an array of strings. Any value is accepted, only ‘owner’ is reserved. By default uses only the value of ‘user’.
14 15 16 17 18 19 20 |
# File 'lib/passaporte_web/service_account_member.rb', line 14 def initialize(service_account, identity, roles=['user']) @service_account = service_account @identity = identity @roles = roles @membership_details_url = nil @errors = {} end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
9 10 11 |
# File 'lib/passaporte_web/service_account_member.rb', line 9 def errors @errors end |
#identity ⇒ Object (readonly)
Returns the value of attribute identity.
8 9 10 |
# File 'lib/passaporte_web/service_account_member.rb', line 8 def identity @identity end |
#roles ⇒ Object
Returns the value of attribute roles.
7 8 9 |
# File 'lib/passaporte_web/service_account_member.rb', line 7 def roles @roles end |
#service_account ⇒ Object (readonly)
Returns the value of attribute service_account.
8 9 10 |
# File 'lib/passaporte_web/service_account_member.rb', line 8 def service_account @service_account end |
Class Method Details
.find(service_account, identity) ⇒ Object
Finds the membership relation between the supplied Identity in the supplied ServiceAccount and returns an instance of ServiceAccountMember representing it.
Raises a RestClient::ResourceNotFound
exception if the supplied Identity does not have a membership within the supplied ServiceAccount, or if any of the supplied objects is invalid or not existent.
API method: GET /organizations/api/accounts/:uuid/members/:member_uuid/
API documentation: app.passaporteweb.com.br/static/docs/account_manager.html#get-organizations-api-accounts-uuid-members-member-uuid
32 33 34 35 36 37 38 39 40 |
# File 'lib/passaporte_web/service_account_member.rb', line 32 def self.find(service_account, identity) response = Http.get("/organizations/api/accounts/#{service_account.uuid}/members/#{identity.uuid}/") raise "unexpected response: #{response.code} - #{response.body}" unless response.code == 200 attributes_hash = MultiJson.decode(response.body) member = self.new(service_account, identity, attributes_hash['roles']) member.instance_variable_set(:@persisted, true) member.instance_variable_set(:@destroyed, false) member end |
Instance Method Details
#destroy ⇒ Object
Destroys the membership relation between a Identity and a ServiceAccount, e.g. the Identity no longer will be a member of the ServiceAccount. Returns true if successful of false (along with the reason for failure in the #errors method) otherwise.
If the member has a ‘owner’ role, than the membership can not be destroyed.
API method: DELETE /organizations/api/accounts/:uuid/members/:member_uuid/
API documentation: app.passaporteweb.com.br/static/docs/account_manager.html#delete-organizations-api-accounts-uuid-members-member-uuid
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/passaporte_web/service_account_member.rb', line 84 def destroy return false unless self.persisted? response = Http.delete(self.membership_details_url) raise "unexpected response: #{response.code} - #{response.body}" unless response.code == 204 @errors = {} @persisted = false @destroyed = true true rescue *[RestClient::NotAcceptable] => e @errors = MultiJson.decode(e.response.body) @persisted = true @destroyed = false false end |
#destroyed? ⇒ Boolean
Returns true if the ServiceAccountMember object has been destroyed (and thus represents a membership no more valid on PassaporteWeb)
49 50 51 |
# File 'lib/passaporte_web/service_account_member.rb', line 49 def destroyed? @destroyed == true end |
#membership_details_url ⇒ Object
:nodoc:
53 54 55 56 |
# File 'lib/passaporte_web/service_account_member.rb', line 53 def membership_details_url # :nodoc: return @membership_details_url if @membership_details_url "/organizations/api/accounts/#{self.service_account.uuid}/members/#{self.identity.uuid}/" if persisted? end |
#persisted? ⇒ Boolean
Returns true if the ServiceAccountMember was loaded from PassaporteWeb or saved there successfully.
43 44 45 |
# File 'lib/passaporte_web/service_account_member.rb', line 43 def persisted? @persisted == true end |
#save ⇒ Object
Creates or updates the ServiceAccountMember object on PassaporteWeb. Returns true if successful and false (along with the reason for failure in the #errors method) otherwise.
On update, the only attribute that can be changed is the roles
. This can be set to anything, including ‘owner’, on update (on create, the ‘owner’ role is not allowed.)
API methods:
-
POST /organizations/api/accounts/:uuid/members/
(on create) -
PUT /organizations/api/accounts/:uuid/members/:member_uuid/
(on update)
API documentation:
71 72 73 |
# File 'lib/passaporte_web/service_account_member.rb', line 71 def save self.persisted? ? update : create end |