Class: CodeBuildNotifier::Config
- Inherits:
-
Object
- Object
- CodeBuildNotifier::Config
- Defined in:
- lib/codebuild-notifier/config.rb
Constant Summary collapse
- DEFAULT_WHITELIST =
%w[master].freeze
Instance Attribute Summary collapse
-
#additional_channel ⇒ Object
readonly
Returns the value of attribute additional_channel.
-
#default_strategy ⇒ Object
readonly
Returns the value of attribute default_strategy.
-
#dynamo_table ⇒ Object
readonly
Returns the value of attribute dynamo_table.
-
#region ⇒ Object
readonly
Returns the value of attribute region.
-
#slack_admins ⇒ Object
readonly
Returns the value of attribute slack_admins.
-
#slack_alias_table ⇒ Object
readonly
Returns the value of attribute slack_alias_table.
-
#slack_secret_name ⇒ Object
readonly
Returns the value of attribute slack_secret_name.
-
#whitelist_branches ⇒ Object
readonly
Returns the value of attribute whitelist_branches.
Instance Method Summary collapse
- #dynamo_client ⇒ Object
-
#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']) ⇒ Config
constructor
Configuration values specific to CodeBuild Notifier.
-
#non_pr_branch_ids ⇒ Object
Match the format of the CodeBuild trigger variable.
- #strategy_for_branch(branch_name) ⇒ Object
- #whitelist ⇒ Object
Constructor Details
#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']) ⇒ Config
Configuration values specific to CodeBuild Notifier. CBN_ prefix is used because ENV vars with CODEBUILD_ prefix are reserved for use by AWS.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# 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 |
Instance Attribute Details
#additional_channel ⇒ Object (readonly)
Returns the value of attribute additional_channel.
24 25 26 |
# File 'lib/codebuild-notifier/config.rb', line 24 def additional_channel @additional_channel end |
#default_strategy ⇒ Object (readonly)
Returns the value of attribute default_strategy.
24 25 26 |
# File 'lib/codebuild-notifier/config.rb', line 24 def default_strategy @default_strategy end |
#dynamo_table ⇒ Object (readonly)
Returns the value of attribute dynamo_table.
24 25 26 |
# File 'lib/codebuild-notifier/config.rb', line 24 def dynamo_table @dynamo_table end |
#region ⇒ Object (readonly)
Returns the value of attribute region.
24 25 26 |
# File 'lib/codebuild-notifier/config.rb', line 24 def region @region end |
#slack_admins ⇒ Object (readonly)
Returns the value of attribute slack_admins.
24 25 26 |
# File 'lib/codebuild-notifier/config.rb', line 24 def slack_admins @slack_admins end |
#slack_alias_table ⇒ Object (readonly)
Returns the value of attribute slack_alias_table.
24 25 26 |
# File 'lib/codebuild-notifier/config.rb', line 24 def slack_alias_table @slack_alias_table end |
#slack_secret_name ⇒ Object (readonly)
Returns the value of attribute slack_secret_name.
24 25 26 |
# File 'lib/codebuild-notifier/config.rb', line 24 def slack_secret_name @slack_secret_name end |
#whitelist_branches ⇒ Object (readonly)
Returns the value of attribute whitelist_branches.
24 25 26 |
# File 'lib/codebuild-notifier/config.rb', line 24 def whitelist_branches @whitelist_branches end |
Instance Method Details
#dynamo_client ⇒ Object
52 53 54 |
# File 'lib/codebuild-notifier/config.rb', line 52 def dynamo_client @dynamo_client || Aws::DynamoDB::Client.new(region: region) end |
#non_pr_branch_ids ⇒ Object
Match the format of the CodeBuild trigger variable
62 63 64 |
# 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) ⇒ Object
56 57 58 59 |
# 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 ⇒ Object
66 67 68 |
# File 'lib/codebuild-notifier/config.rb', line 66 def whitelist whitelist_branches.join(', ') end |