rollbar-notification-rules-generator 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7741d04c00243c59a3451ae2626619c1950012aae49833d0354e65a378312eb9
4
- data.tar.gz: 2295ce6a7e025b9f51b9080bc3e39e87fbcdafdbe1798f5a7621a1078be85a96
3
+ metadata.gz: ce56e1023a93951426676ff62816edb599695be468306635a129a2632a72caec
4
+ data.tar.gz: 21d676802ff8a98c601feebc951768f4ff4272b354d05408ec3d389178953cd8
5
5
  SHA512:
6
- metadata.gz: 7b43b62215e964fbe5e3790ba57573c1a93ed56745ee1eb6adabc2add13cfde0a23decb78d0289e78fb92f97b30a47623839780cbe8ac330153f047bcb2d999d
7
- data.tar.gz: d2ee76d26ae45c3be12dcd972cc7d69b6fcd8c72d6dd96a922b364b601be90fa958609d8971cf6056bafc23ceca8cdec51611ec24bf2255a0a262c5d623fd46e
6
+ metadata.gz: a20f5505d0561574e10d6f7faa1d281b41fd44f0d4d540fb64e931df814bb90575b97a05dc89c47978e5d05257efccbb3ae827e984c3b074c88d48d16bcc9af8
7
+ data.tar.gz: 5fee029c6a281b1ba9633eaa0f143fa65e21f45192d492a4b20daa55b61c7337af64ccec3614047326e84ff9a67b9432040161b502325a9c69dd08165ee21cf7
data/README.md CHANGED
@@ -88,10 +88,12 @@ Usage: rollbar-notification-rules-generator [options] <input>
88
88
  --format FORMAT terraform|text (default: terraform)
89
89
  ```
90
90
 
91
- The input file is in YAML format like the following:
91
+ The input file is in YAML format like the following:
92
92
 
93
93
  ```yaml
94
94
  channel: "slack" # slack or pagerduty
95
+ # This optional value is used as the namespace of Terraform resources.
96
+ terraform_provider: foo_
95
97
  # This optional value is used as provider meta-argument of Terraform.
96
98
  terraform_provider: rollbar.alias_value
97
99
  # You can define variables, and they are expanded with the syntax "${{ var.variable_name }}".
@@ -4,16 +4,20 @@ require "rollbar/notification/trigger"
4
4
  module Rollbar
5
5
  class Notification
6
6
  class Channel
7
- SUPPORTED_CHANNELS = %w[slack pagerduty]
7
+ CHANNEL_TO_TEXT = {
8
+ "slack" => "Slack",
9
+ "pagerduty" => "PagerDuty",
10
+ }
8
11
 
9
12
  # @param channel [String]
10
13
  # @param triggers [Hash{String => Array<Hash>}]
11
14
  # @param variables [Hash{String => String}]
12
15
  def initialize(channel, triggers, variables)
13
- unless SUPPORTED_CHANNELS.include?(channel)
16
+ unless CHANNEL_TO_TEXT.include?(channel)
14
17
  raise ArgumentError, "Unsupported channel: #{channel}"
15
18
  end
16
19
 
20
+ @channel = channel
17
21
  @triggers = triggers.map do |trigger, rules|
18
22
  Rollbar::Notification::Trigger.new(channel, trigger, rules, variables)
19
23
  end
@@ -21,12 +25,12 @@ module Rollbar
21
25
 
22
26
  # @return [String]
23
27
  def to_s
24
- @triggers.map(&:to_s).join.chomp
28
+ "# #{CHANNEL_TO_TEXT.fetch(@channel)}\n#{@triggers.map(&:to_s).join.chomp}"
25
29
  end
26
30
 
27
31
  # @param provider [String]
28
- def to_tf(provider)
29
- @triggers.map { |t| t.to_tf(provider) }.join("\n")
32
+ def to_tf(provider, namespace)
33
+ @triggers.map { |t| t.to_tf(provider, namespace) }.join("\n")
30
34
  end
31
35
  end
32
36
  end
@@ -17,6 +17,14 @@ module Rollbar
17
17
  @value = value
18
18
  end
19
19
 
20
+ # @param other [Object]
21
+ # @return [Boolean]
22
+ def ==(other)
23
+ self.class == other.class &&
24
+ type == other.type &&
25
+ operation == other.operation &&
26
+ value == other.value
27
+ end
20
28
  def to_tf
21
29
  <<~TF
22
30
  filters {
@@ -28,6 +28,12 @@ module Rollbar
28
28
  @path = path
29
29
  end
30
30
 
31
+ # @param other [Object]
32
+ # @return [Boolean]
33
+ def ==(other)
34
+ super && path == other.path
35
+ end
36
+
31
37
  def to_tf
32
38
  <<~TF
33
39
  filters {
@@ -40,6 +40,14 @@ module Rollbar
40
40
  super
41
41
  end
42
42
 
43
+ # @param other [Object]
44
+ # @return [Boolean]
45
+ def ==(other)
46
+ self.class == other.class &&
47
+ conditions == other.conditions &&
48
+ configs == other.configs
49
+ end
50
+
43
51
  # @return [Rule]
44
52
  def remove_redundant_conditions!
45
53
  @conditions.delete_if do |condition|
@@ -101,37 +109,33 @@ module Rollbar
101
109
  # @param new_conditions [Condition::Base, Array<Condition::Base>]
102
110
  # @return [Rule]
103
111
  def add_conditions!(new_conditions)
104
- Array(new_conditions).each do |new_condition|
105
- @conditions << new_condition
106
- end
112
+ @conditions.concat(Array(new_conditions))
107
113
  self
108
114
  end
109
115
 
110
- # @return [Hash{String => Array<Condition::Base>}]
116
+ # @return [Hash{String => Array<Array<Condition::Base>>}]
111
117
  def build_additional_conditions_set_for_subsequent_rules
112
118
  target_levels = level_condition&.target_level_values || Rollbar::Notification::Condition::Level::SUPPORTED_VALUES
113
119
 
114
120
  conditions_with_complement = @conditions.select { |c| c.respond_to?(:build_complement_condition) }
115
121
  return {} if conditions_with_complement.empty?
116
122
 
117
- if conditions_with_complement.size == 1
118
- additional_conditions = [[conditions_with_complement.first.build_complement_condition]]
119
- else
120
- # [cond1, cond2, cond3]
121
- # => [
122
- # [cond1, cond2, not-cond3],
123
- # [cond1, not-cond2, cond3],
124
- # [cond1, not-cond2, not-cond3],
125
- # [not-cond1, cond2, cond3],
126
- # [not-cond1, cond2, not-cond3],
127
- # [not-cond1, not-cond2, cond3],
128
- # [not-cond1, not-cond2, not-cond3],
129
- # ]
130
- additional_conditions = conditions_with_complement.map do |condition|
131
- [condition, condition.build_complement_condition]
132
- end.reduce(&:product).map(&:flatten) - [conditions_with_complement]
123
+ # [cond1, cond2, cond3]
124
+ # => [
125
+ # [cond1, cond2, not-cond3],
126
+ # [cond1, not-cond2, cond3],
127
+ # [cond1, not-cond2, not-cond3],
128
+ # [not-cond1, cond2, cond3],
129
+ # [not-cond1, cond2, not-cond3],
130
+ # [not-cond1, not-cond2, cond3],
131
+ # [not-cond1, not-cond2, not-cond3],
132
+ # ]
133
+ first_cond, *other_conds = conditions_with_complement.map do |condition|
134
+ [condition, condition.build_complement_condition]
133
135
  end
134
- target_levels.zip([additional_conditions].cycle).to_h
136
+ additional_conditions_set = first_cond.product(*other_conds) - [conditions_with_complement]
137
+
138
+ target_levels.zip([additional_conditions_set].cycle).to_h
135
139
  end
136
140
 
137
141
  private
@@ -71,13 +71,13 @@ module Rollbar
71
71
  str
72
72
  end
73
73
 
74
- def to_tf(provider)
74
+ def to_tf(provider, namespace)
75
75
  i = -1
76
76
  build_mutually_exclusive_rules.flat_map do |rule|
77
77
  rule.configs.map do |config|
78
78
  i += 1
79
79
  TF_TEMPLATE.result_with_hash({
80
- resource_name: "#{@channel}_#{@name}_#{i}",
80
+ resource_name: "#{namespace}#{@channel}_#{@name}_#{i}",
81
81
  provider: provider,
82
82
  channel: @channel,
83
83
  trigger: @name,
@@ -5,11 +5,6 @@ require "rollbar/notification/channel"
5
5
 
6
6
  module Rollbar
7
7
  class Notification
8
- CHANNEL_TO_TEXT = {
9
- "slack" => "Slack",
10
- "pagerduty" => "PagerDuty",
11
- }
12
-
13
8
  # @param config_file [String]
14
9
  def initialize(config_file)
15
10
  @config = YAML.load_file(config_file)
@@ -22,12 +17,12 @@ module Rollbar
22
17
 
23
18
  # @return [String]
24
19
  def to_s
25
- "# #{CHANNEL_TO_TEXT.fetch(@config.fetch("channel"))}\n#{@channel.to_s}"
20
+ @channel.to_s
26
21
  end
27
22
 
28
23
  # @return [String]
29
24
  def to_tf
30
- @channel.to_tf(@config["terraform_provider"])
25
+ @channel.to_tf(@config["terraform_provider"], @config["terraform_namespace"])
31
26
  end
32
27
  end
33
28
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "rollbar-notification-rules-generator"
5
- spec.version = "0.2.0"
5
+ spec.version = "0.2.1"
6
6
  spec.authors = ["abicky"]
7
7
  spec.email = ["takeshi.arabiki@gmail.com"]
8
8
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rollbar-notification-rules-generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - abicky
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-14 00:00:00.000000000 Z
11
+ date: 2022-12-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: This tool generates Rollbar notification rules that are mutually exclusive
14
14
  from a simple YAML file.