class Brightbox::CollaboratingAccount
A Collaborating account combines all of a users own accounts and those that they have access to via an open collaboration.
Public Class Methods
Source
# File lib/brightbox-cli/collaborating_account.rb, line 6 def self.all accounts = conn.accounts.all collaborations = conn.user_collaborations.all accepted_collaborations = collaborations.select do |col| col.status == "accepted" end pending_collaborations = collaborations.select do |col| col.status == "pending" end col_accounts = [] accepted_collaboration_ids = accepted_collaborations.map(&:account_id) accounts.each do |acc| if accepted_collaboration_ids.include?(acc.id) collab = accepted_collaborations.find { |col| col.account_id == acc.id } col_accounts << new(acc, collab) else col_accounts << new(acc) end end pending_collaborations.each do |col| col_accounts << new(col) end col_accounts end
Source
# File lib/brightbox-cli/collaborating_account.rb, line 135 def self.default_field_order %i[id cloud_ips_limit lb_limit ram_limit ram_used ram_free role name] end
Source
# File lib/brightbox-cli/collaborating_account.rb, line 43 def initialize(fog_model, collaboration = nil) @fog_model = fog_model @id = fog_model.id # Rather than merging, we have store the collaboration as a secondary item @collaboration = collaboration return unless @collaboration.nil? && @fog_model.attributes["resource_type"] == "collaboration" @collaboration = @fog_model end
Simpler initialiser than the superclass.
@param [Account,UserCollaboration] fog_model The source data @param [UserCollaboration] collaboration_status The state of the collaboration passed
in for accounts/collaborations
Public Instance Methods
Source
# File lib/brightbox-cli/collaborating_account.rb, line 55 def account? resource_type == "account" end
Is this record based on an account?
Source
# File lib/brightbox-cli/collaborating_account.rb, line 80 def cloud_ips_limit account? ? attributes[:cloud_ips_limit] : "" end
Source
# File lib/brightbox-cli/collaborating_account.rb, line 60 def collaboration? resource_type == "collaboration" end
Is this record based on a collaboration?
Source
# File lib/brightbox-cli/collaborating_account.rb, line 68 def id if collaboration? account_id else @id end end
Source
# File lib/brightbox-cli/collaborating_account.rb, line 84 def lb_limit account? ? attributes[:load_balancers_limit] : "" end
Source
# File lib/brightbox-cli/collaborating_account.rb, line 76 def name account? ? fog_model.name : acc_details(:name) end
Source
# File lib/brightbox-cli/collaborating_account.rb, line 96 def ram_free if account? [ram_limit.to_i - ram_used.to_i, 0].max else "" end end
Source
# File lib/brightbox-cli/collaborating_account.rb, line 88 def ram_limit account? ? attributes[:ram_limit] : "" end
Source
# File lib/brightbox-cli/collaborating_account.rb, line 92 def ram_used account? ? attributes[:ram_used] : "" end
Source
# File lib/brightbox-cli/collaborating_account.rb, line 64 def resource_type attributes[:resource_type] || attributes["resource_type"] end
Source
# File lib/brightbox-cli/collaborating_account.rb, line 110 def role if @collaboration if @collaboration.attributes[:status] == "accepted" "collaborator" else "(invited)" end else "owner" end end
The “role” between the requesting user and the account
It is either “owner”, “collaborator” or “(invited)”
You’d think it would be somehow related to the role but no.
Source
# File lib/brightbox-cli/collaborating_account.rb, line 122 def to_row { :id => id, :cloud_ips_limit => cloud_ips_limit, :lb_limit => lb_limit, :ram_limit => ram_limit, :ram_used => ram_used, :ram_free => ram_free, :role => role, :name => name } end
Private Instance Methods
Source
# File lib/brightbox-cli/collaborating_account.rb, line 142 def acc_details(key) # Underlying fog setup means you use [:account]["key"] but this helps attributes[:account][key.to_s] end
A collaboration has access to the accounts details by nesting