class Squad
Attributes
id[RW]
metadata[RW]
name[RW]
teams[RW]
Public Class Methods
new(id, parsed_data, people, gsuite_domain, slack_domain)
click to toggle source
# File lib/terraorg/model/squad.rb, line 70 def initialize(id, parsed_data, people, gsuite_domain, slack_domain) @gsuite_domain = gsuite_domain @slack_domain = slack_domain @id = id @metadata = parsed_data.fetch('metadata', {}) @name = parsed_data.fetch('name') @people = people teams_arr = parsed_data.fetch('team', []).map do |t| Team.new(t, people) end @teams = Hash[teams_arr.map { |t| [t.location, t] }] end
Public Instance Methods
everyone(location: nil)
click to toggle source
Everyone including associates on all subteams in the squad.
# File lib/terraorg/model/squad.rb, line 85 def everyone(location: nil) @teams.select { |l, t| location == nil || l == location }.map { |_, t| t.everyone }.flatten end
generate_tf(org_id)
click to toggle source
# File lib/terraorg/model/squad.rb, line 148 def generate_tf(org_id) groups = get_acl_groups(org_id) groups.map { |id, group| description = "#{group.fetch('name')} (terraorg)" <<-EOF resource "okta_group" "#{id}" { name = "#{id}" description = "#{description}" users = #{Util.persons_tf(group.fetch('members'))} } #{Util.gsuite_group_tf(id, @gsuite_domain, group.fetch('members'), description)} EOF }.join("\n\n") end
get_acl_groups(org_id)
click to toggle source
# File lib/terraorg/model/squad.rb, line 100 def get_acl_groups(org_id) # each geographically located subteam groups = Hash[@teams.map { |location, team| [unique_name(org_id, location), {'name' => "#{@name} squad members based in #{location}", 'members' => team.everyone}] }] # combination of all subteams groups[unique_name(org_id, nil)] = {'name' => "#{@name} squad worldwide members", 'members' => everyone} groups end
manager()
click to toggle source
# File lib/terraorg/model/squad.rb, line 165 def manager m = @metadata['manager'] if m return @people.get_or_create!(m) else return nil end end
members()
click to toggle source
Full-time members of all subteams in this squad
# File lib/terraorg/model/squad.rb, line 94 def members @teams.map { |_, t| t.members }.flatten end
to_h()
click to toggle source
# File lib/terraorg/model/squad.rb, line 174 def to_h # Output a canonical (sorted, formatted) version of this Squad. # - Subteams are sorted by location lexically obj = { 'id' => @id, 'name' => @name } obj['team'] = @teams.values.sort_by { |t| t.location }.map(&:to_h) obj['metadata'] = @metadata if @metadata obj end
to_md(platoon_name, org_id)
click to toggle source
# File lib/terraorg/model/squad.rb, line 124 def to_md(platoon_name, org_id) pm = @metadata.fetch('pm', []) pm = pm.map { |p| @people.get_or_create!(p).name }.join(', ') sme = @metadata.fetch('sme', '') if !sme.empty? sme = @people.get_or_create!(sme).name end manager = @metadata.fetch('manager', '') if !manager.empty? manager = @people.get_or_create!(manager).name end subteam_members = @teams.values.map(&:to_md).join(' / ') email = "#{unique_name(org_id, nil)}@#{@gsuite_domain}" slack = @metadata.fetch('slack', '') if slack slack = "[#{slack}](https://#{@slack_domain}/app_redirect?channel=#{slack.gsub(/^#/, '')})" end # platoon name, squad name, PM, email list, SME, slack, # full time members, squad manager, members "|#{platoon_name}|#{@name}|#{pm}|[#{email}](#{email})|#{sme}|#{slack}|#{members.size}|#{manager}|#{subteam_members}|" end
unique_name(org_id, location)
click to toggle source
# File lib/terraorg/model/squad.rb, line 112 def unique_name(org_id, location) if location "#{org_id}-squad-#{@id}-#{location.downcase}" else "#{org_id}-squad-#{@id}" end end
validate!()
click to toggle source
# File lib/terraorg/model/squad.rb, line 120 def validate! @teams.each(&:validate!) end