jets 1.8.2 → 1.8.3
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/jets/job/base.rb +2 -0
- data/lib/jets/job/dsl.rb +7 -77
- data/lib/jets/job/dsl/cloudwatch_event.rb +81 -0
- data/lib/jets/job/dsl/iot_event.rb +24 -0
- data/lib/jets/job/dsl/log_event.rb +15 -0
- data/lib/jets/job/log_event_helper.rb +17 -0
- data/lib/jets/resource.rb +2 -0
- data/lib/jets/resource/iot.rb +3 -0
- data/lib/jets/resource/iot/topic_rule.rb +34 -0
- data/lib/jets/resource/logs.rb +3 -0
- data/lib/jets/resource/logs/subscription_filter.rb +31 -0
- data/lib/jets/version.rb +1 -1
- metadata +9 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de55bb3691c185a3d173c346d0e9ad2ccfbcd069a5758bfe39b3c52b0fe913ea
|
4
|
+
data.tar.gz: 07077cbd6b524a2f21206a31ab44872a56af82768224db56ece2692626a5608a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7cf3f6787af8fd219275bfb05cf190a6dc2bfb84787317c3ecbd761582593af015731899d4325bc2df22d30d2d24abccf1a7e653c508c3acfda5d75d9be58488
|
7
|
+
data.tar.gz: 17ed838650b0dd77e9a74a67ba90652991d40fb785fc888bff7877bcc329f5ed1821945d2723c8893fd89436d2bc17711aed485ed0885b11897a8d2a161aa483
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,10 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
|
5
5
|
|
6
|
+
## [1.8.3]
|
7
|
+
- #196 CloudWatch Log Event support
|
8
|
+
- #197 IoT Event Support
|
9
|
+
|
6
10
|
## [1.8.2]
|
7
11
|
- fix Jets.on_exception reporting
|
8
12
|
|
data/lib/jets/job/base.rb
CHANGED
@@ -6,12 +6,14 @@ require 'json'
|
|
6
6
|
# Both Jets::Job::Base and Jets::Lambda::Functions have Dsl modules included.
|
7
7
|
# So the Jets::Job::Dsl overrides some of the Jets::Lambda::Functions behavior.
|
8
8
|
class Jets::Job
|
9
|
+
autoload :LogEventHelper, "jets/job/log_event_helper"
|
9
10
|
autoload :S3EventHelper, "jets/job/s3_event_helper"
|
10
11
|
|
11
12
|
class Base < Jets::Lambda::Functions
|
12
13
|
include Dsl
|
13
14
|
|
14
15
|
# non-DSL methods
|
16
|
+
include LogEventHelper
|
15
17
|
include S3EventHelper
|
16
18
|
|
17
19
|
# Tracks bucket each time an s3_event is declared
|
data/lib/jets/job/dsl.rb
CHANGED
@@ -8,91 +8,25 @@
|
|
8
8
|
#
|
9
9
|
module Jets::Job::Dsl
|
10
10
|
extend ActiveSupport::Concern
|
11
|
+
autoload :CloudwatchEvent, "jets/job/dsl/cloudwatch_event"
|
11
12
|
autoload :EventSourceMapping, "jets/job/dsl/event_source_mapping" # base for sqs_event, etc
|
13
|
+
autoload :IotEvent, "jets/job/dsl/iot_event"
|
14
|
+
autoload :LogEvent, "jets/job/dsl/log_event"
|
12
15
|
autoload :S3Event, "jets/job/dsl/s3_event"
|
13
16
|
autoload :SnsEvent, "jets/job/dsl/sns_event"
|
14
17
|
autoload :SqsEvent, "jets/job/dsl/sqs_event"
|
15
18
|
|
16
19
|
included do
|
17
20
|
class << self
|
21
|
+
include CloudwatchEvent
|
18
22
|
include EventSourceMapping
|
23
|
+
include IotEvent
|
24
|
+
include LogEvent
|
19
25
|
include S3Event
|
20
26
|
include SnsEvent
|
21
27
|
include SqsEvent
|
22
28
|
|
23
|
-
#
|
24
|
-
#
|
25
|
-
# expression - The rate expression.
|
26
|
-
#
|
27
|
-
# Examples
|
28
|
-
#
|
29
|
-
# rate("10 minutes")
|
30
|
-
# rate("10 minutes", description: "Hard job")
|
31
|
-
#
|
32
|
-
def rate(expression, props={})
|
33
|
-
schedule_job("rate(#{expression})", props)
|
34
|
-
end
|
35
|
-
|
36
|
-
# Public: Creates CloudWatch Event Rule
|
37
|
-
#
|
38
|
-
# expression - The cron expression.
|
39
|
-
#
|
40
|
-
# Examples
|
41
|
-
#
|
42
|
-
# cron("0 */12 * * ? *")
|
43
|
-
# cron("0 */12 * * ? *", description: "Hard job")
|
44
|
-
#
|
45
|
-
def cron(expression, props={})
|
46
|
-
schedule_job("cron(#{expression})", props)
|
47
|
-
end
|
48
|
-
|
49
|
-
def schedule_job(expression, props={})
|
50
|
-
with_fresh_properties(multiple_resources: false) do
|
51
|
-
props = props.merge(schedule_expression: expression)
|
52
|
-
associated_properties(props)
|
53
|
-
resource(events_rule_definition) # add associated resource immediately
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def event_pattern(details={}, props={})
|
58
|
-
with_fresh_properties(multiple_resources: false) do
|
59
|
-
props = props.merge(event_pattern: details)
|
60
|
-
associated_properties(props)
|
61
|
-
resource(events_rule_definition) # add associated resource immediately
|
62
|
-
end
|
63
|
-
add_descriptions # useful: generic description in the Event Rule console
|
64
|
-
end
|
65
|
-
|
66
|
-
def events_rule(props={})
|
67
|
-
with_fresh_properties(multiple_resources: false) do
|
68
|
-
associated_properties(props)
|
69
|
-
resource(events_rule_definition) # add associated resource immediately
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
# Works with eager definitions
|
74
|
-
def add_descriptions
|
75
|
-
numbered_resources = []
|
76
|
-
n = 1
|
77
|
-
@associated_resources.map do |associated|
|
78
|
-
# definition = associated.definition
|
79
|
-
# puts "associated #{associated.inspect}"
|
80
|
-
# puts "definition #{definition.inspect}"
|
81
|
-
|
82
|
-
# logical_id = definition.keys.first
|
83
|
-
# attributes = definition.values.first
|
84
|
-
|
85
|
-
logical_id = associated.logical_id
|
86
|
-
attributes = associated.attributes
|
87
|
-
|
88
|
-
attributes[:properties][:description] ||= "#{self.name} Event Rule #{n}"
|
89
|
-
new_definition = { "#{logical_id}" => attributes }
|
90
|
-
numbered_resources << Jets::Resource::Associated.new(new_definition)
|
91
|
-
n += 1
|
92
|
-
end
|
93
|
-
@associated_resources = numbered_resources
|
94
|
-
end
|
95
|
-
|
29
|
+
# Need to be in here
|
96
30
|
ASSOCIATED_PROPERTIES = %W[
|
97
31
|
description
|
98
32
|
state
|
@@ -105,10 +39,6 @@ module Jets::Job::Dsl
|
|
105
39
|
events_rule_definition
|
106
40
|
end
|
107
41
|
|
108
|
-
def events_rule_definition
|
109
|
-
resource = Jets::Resource::Events::Rule.new(associated_properties)
|
110
|
-
resource.definition # returns a definition to be added by associated_resources
|
111
|
-
end
|
112
42
|
end
|
113
43
|
end
|
114
44
|
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module Jets::Job::Dsl
|
2
|
+
module CloudwatchEvent
|
3
|
+
# Public: Creates CloudWatch Event Rule
|
4
|
+
#
|
5
|
+
# expression - The rate expression.
|
6
|
+
#
|
7
|
+
# Examples
|
8
|
+
#
|
9
|
+
# rate("10 minutes")
|
10
|
+
# rate("10 minutes", description: "Hard job")
|
11
|
+
#
|
12
|
+
def rate(expression, props={})
|
13
|
+
schedule_job("rate(#{expression})", props)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Public: Creates CloudWatch Event Rule
|
17
|
+
#
|
18
|
+
# expression - The cron expression.
|
19
|
+
#
|
20
|
+
# Examples
|
21
|
+
#
|
22
|
+
# cron("0 */12 * * ? *")
|
23
|
+
# cron("0 */12 * * ? *", description: "Hard job")
|
24
|
+
#
|
25
|
+
def cron(expression, props={})
|
26
|
+
schedule_job("cron(#{expression})", props)
|
27
|
+
end
|
28
|
+
|
29
|
+
def schedule_job(expression, props={})
|
30
|
+
with_fresh_properties(multiple_resources: false) do
|
31
|
+
props = props.merge(schedule_expression: expression)
|
32
|
+
associated_properties(props)
|
33
|
+
resource(events_rule_definition) # add associated resource immediately
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def event_pattern(details={}, props={})
|
38
|
+
with_fresh_properties(multiple_resources: false) do
|
39
|
+
props = props.merge(event_pattern: details)
|
40
|
+
associated_properties(props)
|
41
|
+
resource(events_rule_definition) # add associated resource immediately
|
42
|
+
end
|
43
|
+
add_descriptions # useful: generic description in the Event Rule console
|
44
|
+
end
|
45
|
+
|
46
|
+
def events_rule(props={})
|
47
|
+
with_fresh_properties(multiple_resources: false) do
|
48
|
+
associated_properties(props)
|
49
|
+
resource(events_rule_definition) # add associated resource immediately
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Works with eager definitions
|
54
|
+
def add_descriptions
|
55
|
+
numbered_resources = []
|
56
|
+
n = 1
|
57
|
+
@associated_resources.map do |associated|
|
58
|
+
# definition = associated.definition
|
59
|
+
# puts "associated #{associated.inspect}"
|
60
|
+
# puts "definition #{definition.inspect}"
|
61
|
+
|
62
|
+
# logical_id = definition.keys.first
|
63
|
+
# attributes = definition.values.first
|
64
|
+
|
65
|
+
logical_id = associated.logical_id
|
66
|
+
attributes = associated.attributes
|
67
|
+
|
68
|
+
attributes[:properties][:description] ||= "#{self.name} Event Rule #{n}"
|
69
|
+
new_definition = { "#{logical_id}" => attributes }
|
70
|
+
numbered_resources << Jets::Resource::Associated.new(new_definition)
|
71
|
+
n += 1
|
72
|
+
end
|
73
|
+
@associated_resources = numbered_resources
|
74
|
+
end
|
75
|
+
|
76
|
+
def events_rule_definition
|
77
|
+
resource = Jets::Resource::Events::Rule.new(associated_properties)
|
78
|
+
resource.definition # returns a definition to be added by associated_resources
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Jets::Job::Dsl
|
2
|
+
module IotEvent
|
3
|
+
# The user must at least pass in an SQL statement
|
4
|
+
def iot_event(props={})
|
5
|
+
if props.is_a?(String) # SQL Statement
|
6
|
+
props = {sql: props}
|
7
|
+
topic_props = {topic_rule_payload: props}
|
8
|
+
elsif props.key?(:topic_rule_payload) # full properties structure
|
9
|
+
topic_props = props
|
10
|
+
else # just the topic_rule_payload
|
11
|
+
topic_props = {topic_rule_payload: props}
|
12
|
+
end
|
13
|
+
|
14
|
+
declare_iot_topic(topic_props)
|
15
|
+
end
|
16
|
+
|
17
|
+
def declare_iot_topic(props={})
|
18
|
+
r = Jets::Resource::Iot::TopicRule.new(props)
|
19
|
+
with_fresh_properties do
|
20
|
+
resource(r.definition) # add associated resource immediately
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Jets::Job::Dsl
|
2
|
+
module LogEvent
|
3
|
+
def log_event(log_group_name, props={})
|
4
|
+
props.merge!(log_group_name: log_group_name)
|
5
|
+
declare_log_subscription_filter(props)
|
6
|
+
end
|
7
|
+
|
8
|
+
def declare_log_subscription_filter(props={})
|
9
|
+
r = Jets::Resource::Logs::SubscriptionFilter.new(props)
|
10
|
+
with_fresh_properties do
|
11
|
+
resource(r.definition) # add associated resource immediately
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'json'
|
3
|
+
require 'stringio'
|
4
|
+
require 'zlib'
|
5
|
+
|
6
|
+
class Jets::Job
|
7
|
+
module LogEventHelper
|
8
|
+
def log_event
|
9
|
+
encoded = event["awslogs"]["data"]
|
10
|
+
compressed_string = Base64.decode64(encoded)
|
11
|
+
gz = Zlib::GzipReader.new(StringIO.new(compressed_string))
|
12
|
+
uncompressed_string = gz.read
|
13
|
+
data = JSON.load(uncompressed_string)
|
14
|
+
ActiveSupport::HashWithIndifferentAccess.new(data)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/jets/resource.rb
CHANGED
@@ -8,7 +8,9 @@ class Jets::Resource
|
|
8
8
|
autoload :Config, 'jets/resource/config'
|
9
9
|
autoload :Events, 'jets/resource/events'
|
10
10
|
autoload :Iam, 'jets/resource/iam'
|
11
|
+
autoload :Iot, 'jets/resource/iot'
|
11
12
|
autoload :Lambda, 'jets/resource/lambda'
|
13
|
+
autoload :Logs, 'jets/resource/logs'
|
12
14
|
autoload :Permission, 'jets/resource/permission'
|
13
15
|
autoload :Replacer, 'jets/resource/replacer'
|
14
16
|
autoload :Route53, 'jets/resource/route53'
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# CloudFormation AWS::IoT::TopicRule docs: https://amzn.to/2SMBOVm
|
2
|
+
module Jets::Resource::Iot
|
3
|
+
class TopicRule < Jets::Resource::Base
|
4
|
+
def initialize(props={})
|
5
|
+
@props = props # associated_properties from dsl.rb
|
6
|
+
end
|
7
|
+
|
8
|
+
def definition
|
9
|
+
{
|
10
|
+
topic_logical_id => {
|
11
|
+
type: "AWS::IoT::TopicRule",
|
12
|
+
properties: merged_properties,
|
13
|
+
}
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
# Do not name this method properties, that is a computed method of `Jets::Resource::Base`
|
18
|
+
def merged_properties
|
19
|
+
{
|
20
|
+
# required properties
|
21
|
+
topic_rule_payload: {
|
22
|
+
actions: [{
|
23
|
+
lambda: { function_arn: "!GetAtt {namespace}LambdaFunction.Arn" }
|
24
|
+
}],
|
25
|
+
rule_disabled: 'false',
|
26
|
+
}
|
27
|
+
}.deep_merge(@props)
|
28
|
+
end
|
29
|
+
|
30
|
+
def topic_logical_id
|
31
|
+
"{namespace}_iot_topic_rule"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# CloudFormation Log Subscription docs: https://amzn.to/2SNiSpr
|
2
|
+
module Jets::Resource::Logs
|
3
|
+
class SubscriptionFilter < Jets::Resource::Base
|
4
|
+
def initialize(props={})
|
5
|
+
@props = props # associated_properties from dsl.rb
|
6
|
+
end
|
7
|
+
|
8
|
+
def definition
|
9
|
+
{
|
10
|
+
log_logical_id => {
|
11
|
+
type: "AWS::Logs::SubscriptionFilter",
|
12
|
+
properties: merged_properties,
|
13
|
+
}
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
# Do not name this method properties, that is a computed method of `Jets::Resource::Base`
|
18
|
+
def merged_properties
|
19
|
+
{
|
20
|
+
destination_arn: "!GetAtt {namespace}LambdaFunction.Arn",
|
21
|
+
filter_pattern: "", # matches everything https://amzn.to/2N3b39I
|
22
|
+
# log_group_name: string # will be set by log_event
|
23
|
+
# role_arn: string # only required for kinensis, we dont use this for Lambda
|
24
|
+
}.deep_merge(@props)
|
25
|
+
end
|
26
|
+
|
27
|
+
def log_logical_id
|
28
|
+
"{namespace}_subscription_filter"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/jets/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tung Nguyen
|
@@ -687,10 +687,14 @@ files:
|
|
687
687
|
- lib/jets/job.rb
|
688
688
|
- lib/jets/job/base.rb
|
689
689
|
- lib/jets/job/dsl.rb
|
690
|
+
- lib/jets/job/dsl/cloudwatch_event.rb
|
690
691
|
- lib/jets/job/dsl/event_source_mapping.rb
|
692
|
+
- lib/jets/job/dsl/iot_event.rb
|
693
|
+
- lib/jets/job/dsl/log_event.rb
|
691
694
|
- lib/jets/job/dsl/s3_event.rb
|
692
695
|
- lib/jets/job/dsl/sns_event.rb
|
693
696
|
- lib/jets/job/dsl/sqs_event.rb
|
697
|
+
- lib/jets/job/log_event_helper.rb
|
694
698
|
- lib/jets/job/s3_event_helper.rb
|
695
699
|
- lib/jets/klass.rb
|
696
700
|
- lib/jets/lambda.rb
|
@@ -772,12 +776,16 @@ files:
|
|
772
776
|
- lib/jets/resource/iam/function_role.rb
|
773
777
|
- lib/jets/resource/iam/managed_policy.rb
|
774
778
|
- lib/jets/resource/iam/policy_document.rb
|
779
|
+
- lib/jets/resource/iot.rb
|
780
|
+
- lib/jets/resource/iot/topic_rule.rb
|
775
781
|
- lib/jets/resource/lambda.rb
|
776
782
|
- lib/jets/resource/lambda/event_source_mapping.rb
|
777
783
|
- lib/jets/resource/lambda/function.rb
|
778
784
|
- lib/jets/resource/lambda/function/environment.rb
|
779
785
|
- lib/jets/resource/lambda/gem_layer.rb
|
780
786
|
- lib/jets/resource/lambda/layer_version.rb
|
787
|
+
- lib/jets/resource/logs.rb
|
788
|
+
- lib/jets/resource/logs/subscription_filter.rb
|
781
789
|
- lib/jets/resource/permission.rb
|
782
790
|
- lib/jets/resource/replacer.rb
|
783
791
|
- lib/jets/resource/route53.rb
|