class Bosh::Director::Models::Team

Public Class Methods

transform_admin_team_scope_to_teams(token_scopes) click to toggle source
# File lib/bosh/director/models/team.rb, line 9
def self.transform_admin_team_scope_to_teams(token_scopes)
  return [] if token_scopes.nil?
  team_scopes = token_scopes.map do |scope|
    match = scope.match(/\Abosh\.teams\.([^\.]*)\.admin\z/)
    match[1] unless match.nil?
  end
  team_names = team_scopes.compact
  team_names.map do |name|
    create_or_find(name)
  end
end

Private Class Methods

create_or_find(name) click to toggle source

this fixes potential race condition when multiple creates happen at the same time

# File lib/bosh/director/models/team.rb, line 25
def self.create_or_find(name)
  begin
    found = create(name: name)
  rescue Exception => e
    found = find(name: name)
    raise e if !found
  end
  found
end

Public Instance Methods

validate() click to toggle source
# File lib/bosh/director/models/team.rb, line 5
def validate
  validates_presence [:name]
end