Class: LMC::Account
Constant Summary collapse
- ROOT_ACCOUNT_UUID =
'9ec458c2-d05f-3004-96f0-ebe73fa20de8'
Instance Attribute Summary collapse
-
#cloud ⇒ Object
readonly
Returns the value of attribute cloud.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#name ⇒ Object
Returns the value of attribute name.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #authorities ⇒ Object
- #authority(authority_id) ⇒ Object
- #children ⇒ Object
- #config_updatestates ⇒ Object
- #delete! ⇒ Object
- #devices ⇒ Object
- #exists? ⇒ Boolean
- #find_member_by_name(name) ⇒ Object
-
#initialize(cloud, data) ⇒ Account
constructor
A new instance of Account.
- #logs ⇒ Object
- #members ⇒ Object
-
#remove_membership(member_id) ⇒ Object
def update_member(principal_id, data) response = @cloud.post [“cloud-service-auth”, “accounts”, id, ‘members’, principal_id], data return response end.
- #remove_membership_self ⇒ Object
-
#save ⇒ Object
returns itself, allows chaining.
- #sites ⇒ Object
- #to_json(*a) ⇒ Object
- #to_s ⇒ Object
Methods inherited from Entity
Constructor Details
#initialize(cloud, data) ⇒ Account
Returns a new instance of Account.
36 37 38 39 |
# File 'lib/lmc/Account.rb', line 36 def initialize(cloud, data) @cloud = cloud apply_data(data) end |
Instance Attribute Details
#cloud ⇒ Object (readonly)
Returns the value of attribute cloud.
9 10 11 |
# File 'lib/lmc/Account.rb', line 9 def cloud @cloud end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/lmc/Account.rb', line 9 def id @id end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
9 10 11 |
# File 'lib/lmc/Account.rb', line 9 def identifier @identifier end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/lmc/Account.rb', line 8 def name @name end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
9 10 11 |
# File 'lib/lmc/Account.rb', line 9 def state @state end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
9 10 11 |
# File 'lib/lmc/Account.rb', line 9 def type @type end |
Class Method Details
.get(id) ⇒ Object
11 12 13 14 15 |
# File 'lib/lmc/Account.rb', line 11 def self.get(id) cloud = Cloud.instance result = cloud.get ['cloud-service-auth', 'accounts', id.to_s] Account.new(cloud, result.body) end |
.get_by_name(name, type = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/lmc/Account.rb', line 22 def self.get_by_name(name, type = nil) raise 'Missing argument' if name.nil? accounts = Cloud.instance.get_accounts_objects.select do |a| (name.nil? || a.name == name) && (type.nil? || a.type == type) end if accounts.length == 1 return accounts[0] elsif accounts.length == 0 raise 'Did not find account' else raise 'Account name not unique' end end |
.get_by_uuid(uuid) ⇒ Object
17 18 19 20 |
# File 'lib/lmc/Account.rb', line 17 def self.get_by_uuid(uuid) raise 'Missing argument' if uuid.nil? get uuid end |
Instance Method Details
#authorities ⇒ Object
116 117 118 119 120 121 122 123 |
# File 'lib/lmc/Account.rb', line 116 def response = @cloud.get ['cloud-service-auth', 'accounts', id, 'authorities'] raise 'Unable to get authorities' unless response.code == 200 = response.body.map do |r| Authority.new r, self end end |
#authority(authority_id) ⇒ Object
109 110 111 112 113 114 |
# File 'lib/lmc/Account.rb', line 109 def () response = @cloud.get( ['cloud-service-auth', 'accounts', id, 'authorities', ] ) Authority.new(response, self) end |
#children ⇒ Object
125 126 127 128 129 |
# File 'lib/lmc/Account.rb', line 125 def children @cloud.auth_for_accounts([id, ROOT_ACCOUNT_UUID]) response = @cloud.get ['cloud-service-auth', 'accounts', id, 'children'] response.map {|child| Account.new @cloud, child} end |
#config_updatestates ⇒ Object
152 153 154 155 156 |
# File 'lib/lmc/Account.rb', line 152 def config_updatestates @cloud.auth_for_accounts([id]) response = @cloud.get ['cloud-service-config', 'configdevice', 'accounts', id, 'updatestates'] LMC::Configstates.new response.body end |
#delete! ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/lmc/Account.rb', line 53 def delete! if @id != nil @cloud.auth_for_accounts [@id] delete_action = AuthAction.new @cloud delete_action.type = AuthAction::ACCOUNT_DELETE delete_action.name = Cloud.user delete_action.data = {'password' => Cloud.password, 'accountId' => @id} delete_action.post @id = nil true end end |
#devices ⇒ Object
148 149 150 |
# File 'lib/lmc/Account.rb', line 148 def devices Device.get_for_account self end |
#exists? ⇒ Boolean
67 68 69 70 71 |
# File 'lib/lmc/Account.rb', line 67 def exists? # noch ungelöst: woran mache ich fest, ob das objekt in der DB schon da ist. # Bleibt wohl nix außer manuell auf @id != nil zu checken. @id != nil end |
#find_member_by_name(name) ⇒ Object
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/lmc/Account.rb', line 85 def find_member_by_name(name) if name.nil? raise 'No member name given' end member = members.find {|m| m.name == name} unless member raise "Member named #{name} not found in account #{self}" end member end |
#logs ⇒ Object
131 132 133 134 135 136 |
# File 'lib/lmc/Account.rb', line 131 def logs # https://lmctest/cloud-service-logging/accounts/6392b234-b11c-498a-a077-a5f5b23c54a0/logs?lang=DE cloud = Cloud.instance cloud.auth_for_accounts [id] cloud.get(['cloud-service-logging', 'accounts', id, 'logs?lang=DE']).body end |
#members ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/lmc/Account.rb', line 73 def members ids = Cloud.instance.get ['cloud-service-auth', 'accounts', @id, 'members'], 'select' => 'id' puts ids.inspect if Cloud.debug principals = ids.map do |principal_id| response = Cloud.instance.get ['cloud-service-auth', 'accounts', @id, 'members', principal_id] principal = response.body puts principal.inspect if Cloud.debug principal end principals end |
#remove_membership(member_id) ⇒ Object
def update_member(principal_id, data)
response = @cloud.post ["cloud-service-auth", "accounts", id, 'members', principal_id], data
return response
end
101 102 103 |
# File 'lib/lmc/Account.rb', line 101 def remove_membership(member_id) @cloud.delete ['cloud-service-auth', 'accounts', id, 'members', member_id] end |
#remove_membership_self ⇒ Object
105 106 107 |
# File 'lib/lmc/Account.rb', line 105 def remove_membership_self @cloud.delete ['cloud-service-auth', 'accounts', id, 'members', 'self'] end |
#save ⇒ Object
returns itself, allows chaining
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/lmc/Account.rb', line 42 def save response = if @id.nil? @cloud.auth_for_accounts [@parent] @cloud.post ['cloud-service-auth', 'accounts'], self else @cloud.post path, self end apply_data(response.body) self end |
#sites ⇒ Object
138 139 140 141 142 143 144 145 146 |
# File 'lib/lmc/Account.rb', line 138 def sites # private clouds can not have sites return [] if @type == 'PRIVATE_CLOUD' @cloud.auth_for_accounts([id]) response = @cloud.get ['cloud-service-devices', 'accounts', id, 'sites'], :select => :id response.body.map {|data| Site.new(UUID.new(data), self) } end |
#to_json(*a) ⇒ Object
158 159 160 161 162 163 164 165 |
# File 'lib/lmc/Account.rb', line 158 def to_json(*a) { 'name' => @name, 'state' => @state, 'type' => @type, 'parent' => @parent }.to_json(*a) end |
#to_s ⇒ Object
167 168 169 |
# File 'lib/lmc/Account.rb', line 167 def to_s "#{name}" end |