class CodeBuildNotifier::Config

Constants

DEFAULT_WHITELIST

Attributes

additional_channel[R]
default_strategy[R]
dynamo_table[R]
region[R]
slack_admins[R]
slack_alias_table[R]
slack_secret_name[R]
whitelist_branches[R]

Public Class Methods

new( additional_channel: ENV['CBN_ADDITIONAL_CHANNEL'], default_strategy: ENV['CBN_DEFAULT_NOTIFY_STRATEGY'] || 'fail_or_status_change', dynamo_table: ENV['CBN_DYNAMO_TABLE'] || 'codebuild-history', region: ENV['CBN_AWS_REGION'] || ENV['AWS_REGION'], slack_admins: ENV['CBN_SLACK_ADMIN_USERNAMES'], slack_alias_table: ENV['CBN_SLACK_ALIAS_TABLE'], slack_secret_name: ENV['CBN_SLACK_SECRET_NAME'] || 'slack/codebuild', strategy_overrides: ENV['CBN_OVERRIDE_NOTIFY_STRATEGY'], whitelist_branches: ENV['CBN_WHITELIST_BRANCHES'] ) click to toggle source

Configuration values specific to CodeBuild Notifier. CBN_ prefix is used because ENV vars with CODEBUILD_ prefix are reserved for use by AWS.

# File lib/codebuild-notifier/config.rb, line 30
def initialize(
  additional_channel: ENV['CBN_ADDITIONAL_CHANNEL'],
  default_strategy: ENV['CBN_DEFAULT_NOTIFY_STRATEGY'] || 'fail_or_status_change',
  dynamo_table: ENV['CBN_DYNAMO_TABLE'] || 'codebuild-history',
  region: ENV['CBN_AWS_REGION'] || ENV['AWS_REGION'],
  slack_admins: ENV['CBN_SLACK_ADMIN_USERNAMES'],
  slack_alias_table: ENV['CBN_SLACK_ALIAS_TABLE'],
  slack_secret_name: ENV['CBN_SLACK_SECRET_NAME'] || 'slack/codebuild',
  strategy_overrides: ENV['CBN_OVERRIDE_NOTIFY_STRATEGY'],
  whitelist_branches: ENV['CBN_WHITELIST_BRANCHES']
)
  @additional_channel = additional_channel
  @default_strategy = default_strategy
  @dynamo_table = dynamo_table
  @region = region
  @slack_admins = slack_admins&.split(',') || []
  @slack_alias_table = slack_alias_table
  @slack_secret_name = slack_secret_name
  @strategy_overrides = strategy_overrides&.split(',') || []
  @whitelist_branches = whitelist_branches&.split(',') || DEFAULT_WHITELIST
end

Public Instance Methods

dynamo_client() click to toggle source
# File lib/codebuild-notifier/config.rb, line 52
def dynamo_client
  @dynamo_client || Aws::DynamoDB::Client.new(region: region)
end
non_pr_branch_ids() click to toggle source

Match the format of the CodeBuild trigger variable

# File lib/codebuild-notifier/config.rb, line 62
def non_pr_branch_ids
  whitelist_branches.map { |name| "branch/#{name}" }
end
strategy_for_branch(branch_name) click to toggle source
# File lib/codebuild-notifier/config.rb, line 56
def strategy_for_branch(branch_name)
  lookup = @strategy_overrides.map { |override| override.split(':') }.to_h
  lookup.fetch(branch_name, default_strategy)
end
whitelist() click to toggle source
# File lib/codebuild-notifier/config.rb, line 66
def whitelist
  whitelist_branches.join(', ')
end