kyklos 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f870d6a2b3a6d353b324b572bcd4c22e708eb711
4
- data.tar.gz: 453611e97f7d6dc3c03b33ee1813c3677088d782
3
+ metadata.gz: 6478471f4b5f7051d22bc6d9df6eb3ae7c060906
4
+ data.tar.gz: b4a301e84bae1b06d792be5e3f35e04ebcc2d1a9
5
5
  SHA512:
6
- metadata.gz: 319d5f62e36281a8697b43b3bd7e3d77c069a68f5c56d910bd370ee261fb0f1c7bcc6d23eceec5dd554761b6a28ed1909695c7f37694326d00294c4646773ee7
7
- data.tar.gz: ba617a19340a3ced8079ddfe63f11647d4f432026d5732fabc3d793100e284647429f8fad9a236821c7084b8b1056b8c17c5bceedb2ece359402b44cde89b424
6
+ metadata.gz: cf037f71290ec2e74a16245ce498284ee93b4e55f6142511bc96d7ba3fdae11d49315fa4c526c378105a6a21786ab131c32b32d2aac9b8972d96a1f66104a099
7
+ data.tar.gz: a56a652c1960dd4f910fccbd961d97c9e14f3b33267949fcb625bd8330bf080c5d5b54b1a0a1dca44aa9fb0ec53f0221a9499c4edee713c7311745724c652ad5
@@ -8,12 +8,12 @@ module Kyklos
8
8
 
9
9
  end
10
10
 
11
- def assign_cloudwatchevents(job_id:, rule:)
11
+ def assign_cloudwatchevents(job_id:, rule_name_prefix:,rule:)
12
12
  raise NotImplementedError
13
13
  end
14
14
 
15
- def unassign_cloudwatchevents(rule:)
16
- raise NotImplementedError
15
+ def unassign_cloudwatchevents(rule:, rule_name_prefix:)
16
+ # no op
17
17
  end
18
18
 
19
19
  end
@@ -31,8 +31,8 @@ module Kyklos
31
31
  @queue_url = args[0]
32
32
  end
33
33
 
34
- def assign_cloudwatchevents(job_id:, rule:)
35
- assign_queue_policy(job_id, rule.arn)
34
+ def assign_cloudwatchevents(job_id:, rule_name_prefix:, rule:)
35
+ assign_queue_policy(job_id, rule_name_prefix, rule.arn)
36
36
  [
37
37
  {
38
38
  id: target_id(job_id),
@@ -44,10 +44,6 @@ module Kyklos
44
44
  ]
45
45
  end
46
46
 
47
- def unassign_cloudwatchevents(rule:)
48
- unassign_queue_policy(rule.arn)
49
- end
50
-
51
47
  private
52
48
 
53
49
  def target_id(job_id)
@@ -62,10 +58,10 @@ module Kyklos
62
58
  resp.attributes['QueueArn']
63
59
  end
64
60
 
65
- def assign_queue_policy(job_id, rule_arn)
61
+ def assign_queue_policy(job_id, rule_name_prefix, rule_arn)
66
62
  policy = get_queue_policy
67
63
  new_statement = {
68
- 'Sid' => job_id.to_s,
64
+ 'Sid' => rule_name_prefix.to_s,
69
65
  'Effect' => 'Allow',
70
66
  'Principal' => {
71
67
  "AWS" => '*'
@@ -73,8 +69,8 @@ module Kyklos
73
69
  'Action' => 'sqs:SendMessage',
74
70
  'Resource' => target_arn,
75
71
  'Condition' => {
76
- 'ArnEquals' => {
77
- 'aws:SourceArn' => rule_arn
72
+ 'ArnLike' => {
73
+ 'aws:SourceArn' => rule_arn_like(rule_name_prefix, rule_arn)
78
74
  }
79
75
  }
80
76
  }
@@ -115,32 +111,8 @@ module Kyklos
115
111
  statements
116
112
  end
117
113
 
118
- def unassign_queue_policy(rule_arn)
119
- policy = get_queue_policy
120
- policy['Statement'] = policy['Statement'].reject do |statement|
121
- statement['Effect'] == 'Allow' &&
122
- statement['Action'] == 'sqs:SendMessage' &&
123
- statement['Resource'] == target_arn &&
124
- statement['Condition'] &&
125
- statement['Condition']['ArnEquals'] &&
126
- statement['Condition']['ArnEquals']['aws:SourceArn'] == rule_arn
127
- end
128
-
129
- if policy['Statement'].empty?
130
- sqs.set_queue_attributes(
131
- queue_url: queue_url,
132
- attributes: {
133
- 'Policy' => '',
134
- },
135
- )
136
- else
137
- sqs.set_queue_attributes(
138
- queue_url: queue_url,
139
- attributes: {
140
- 'Policy' => policy.to_json,
141
- },
142
- )
143
- end
114
+ def rule_arn_like(rule_name_prefix, rule_arn)
115
+ [rule_arn.split(rule_name_prefix).first, rule_name_prefix, '*'].join
144
116
  end
145
117
 
146
118
  def sqs
@@ -55,6 +55,7 @@ module Kyklos
55
55
  rule = cloudwatchevents.describe_rule(name: rule_params[:name])
56
56
  targets = adapter.assign_cloudwatchevents(
57
57
  job_id: job_id,
58
+ rule_name_prefix: rule_name_prefix,
58
59
  rule: rule)
59
60
  cloudwatchevents.put_targets(
60
61
  rule: rule.name,
@@ -64,7 +65,7 @@ module Kyklos
64
65
  end
65
66
 
66
67
  def remove_job(rule)
67
- adapter.unassign_cloudwatchevents(rule: rule)
68
+ adapter.unassign_cloudwatchevents(rule_name_prefix: rule_name_prefix, rule: rule)
68
69
 
69
70
  target_ids = find_targets(rule.name).map(&:id)
70
71
  unless target_ids.empty?
@@ -73,12 +74,12 @@ module Kyklos
73
74
  cloudwatchevents.delete_rule(name: rule.name)
74
75
  end
75
76
 
76
- def prefix
77
+ def rule_name_prefix
77
78
  "kyslos-#{"#{@identifier}/#{Digest::MD5.hexdigest(@identifier)}".sum}-"
78
79
  end
79
80
 
80
81
  def eventname(job_id)
81
- "#{prefix}#{Digest::MD5.hexdigest(job_id.to_s)}"
82
+ "#{rule_name_prefix}#{Digest::MD5.hexdigest(job_id.to_s)}"
82
83
  end
83
84
 
84
85
  def eventnames
@@ -93,7 +94,7 @@ module Kyklos
93
94
  def find_rules
94
95
  list_rules = ->(next_token) do
95
96
  resp = cloudwatchevents.
96
- list_rules(name_prefix: prefix,
97
+ list_rules(name_prefix: rule_name_prefix,
97
98
  next_token: next_token)
98
99
  if resp.next_token
99
100
  resp.rules + list_rules.call(next_token)
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Kyklos
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kyklos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuichi Takeuchi