elasticgraph-admin_lambda 0.18.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a40c1208a1b9e894eaefc37344ff1a8429c7d38dc1d86335be6055db39da7af6
4
+ data.tar.gz: 0e924afdba8f88769154abeb71a776d96c627ac79330f454de1a4400f4365549
5
+ SHA512:
6
+ metadata.gz: 7cbfd53f970d50204c9799b57104a7e829f5ddf1a8d0b95c0c0cb6aaab64e0246218f67b2c703c9120b40fb9bc4a30e75866a8ae603943201195bf11694d8a9c
7
+ data.tar.gz: 23364305e45f7fdfd2b17258b9fbb27e254a94b701078ca967c817308c03f3dce5431312574f351fb4284c2221e8c90b6c7bdcf6089354b97134fef5a68a456a
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Block, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # ElasticGraph::AdminLambda
2
+
3
+ This gem wraps `elasticgraph-admin` in order to run it from an AWS Lambda.
@@ -0,0 +1,19 @@
1
+ # Copyright 2024 Block, Inc.
2
+ #
3
+ # Use of this source code is governed by an MIT-style
4
+ # license that can be found in the LICENSE file or at
5
+ # https://opensource.org/licenses/MIT.
6
+ #
7
+ # frozen_string_literal: true
8
+
9
+ require_relative "../gemspec_helper"
10
+
11
+ ElasticGraphGemspecHelper.define_elasticgraph_gem(gemspec_file: __FILE__, category: :lambda) do |spec, eg_version|
12
+ spec.summary = "ElasticGraph gem that wraps elasticgraph-admin in an AWS Lambda."
13
+
14
+ spec.add_dependency "rake", "~> 13.2"
15
+
16
+ spec.add_dependency "elasticgraph-admin", eg_version
17
+ spec.add_dependency "elasticgraph-lambda_support", eg_version
18
+ spec.add_development_dependency "httpx", ">= 1.2.6", "< 2.0"
19
+ end
@@ -0,0 +1,13 @@
1
+ # Copyright 2024 Block, Inc.
2
+ #
3
+ # Use of this source code is governed by an MIT-style
4
+ # license that can be found in the LICENSE file or at
5
+ # https://opensource.org/licenses/MIT.
6
+ #
7
+ # frozen_string_literal: true
8
+
9
+ require "elastic_graph/admin/rake_tasks"
10
+ require "elastic_graph/admin_lambda"
11
+
12
+ admin = ElasticGraph::AdminLambda.admin_from_env
13
+ ElasticGraph::Admin::RakeTasks.new { admin }
@@ -0,0 +1,35 @@
1
+ # Copyright 2024 Block, Inc.
2
+ #
3
+ # Use of this source code is governed by an MIT-style
4
+ # license that can be found in the LICENSE file or at
5
+ # https://opensource.org/licenses/MIT.
6
+ #
7
+ # frozen_string_literal: true
8
+
9
+ require "elastic_graph/lambda_support/lambda_function"
10
+
11
+ module ElasticGraph
12
+ module AdminLambda
13
+ class LambdaFunction
14
+ prepend LambdaSupport::LambdaFunction
15
+
16
+ def initialize
17
+ require "elastic_graph/admin_lambda/rake_adapter"
18
+ end
19
+
20
+ def handle_request(event:, context:)
21
+ # @type var event: ::Hash[::String, untyped]
22
+ rake_output = RakeAdapter.run_rake(event.fetch("argv"))
23
+
24
+ # Log the output of the rake task. We also want to return it so that when we invoke
25
+ # a lambda rake task from the terminal we can print the output there.
26
+ puts rake_output
27
+
28
+ {"rake_output" => rake_output}
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ # This is the constant used by the AWS Lambda function.
35
+ HandleAdminRequest = ElasticGraph::AdminLambda::LambdaFunction.new
@@ -0,0 +1,70 @@
1
+ # Copyright 2024 Block, Inc.
2
+ #
3
+ # Use of this source code is governed by an MIT-style
4
+ # license that can be found in the LICENSE file or at
5
+ # https://opensource.org/licenses/MIT.
6
+ #
7
+ # frozen_string_literal: true
8
+
9
+ require "rake"
10
+ require "tempfile"
11
+
12
+ module ElasticGraph
13
+ module AdminLambda
14
+ class RakeAdapter
15
+ RAKEFILE = File.expand_path("../Rakefile", __FILE__)
16
+
17
+ def self.run_rake(argv)
18
+ capture_output do
19
+ # We need to instantiate a new application on each invocation, because Rake is normally
20
+ # designed to run once and exit. It keeps track of tasks that have already run and will
21
+ # no-op when you try to run a task a 2nd or 3rd time. Using a new application instance
22
+ # each time avoids this issue.
23
+ ::Rake.with_application(Application.new) do |application|
24
+ application.run(argv)
25
+ end
26
+ end
27
+ end
28
+
29
+ # Captures stdout/stderr into a string so we can return it from the lambda.
30
+ # Inspired by a similar utility in RSpec:
31
+ # https://github.com/rspec/rspec-expectations/blob/v3.9.2/lib/rspec/matchers/built_in/output.rb#L172-L197
32
+ def self.capture_output
33
+ original_stdout = $stdout.clone
34
+ original_stderr = $stderr.clone
35
+ captured_stream = Tempfile.new
36
+
37
+ begin
38
+ captured_stream.sync = true
39
+ $stdout.reopen(captured_stream)
40
+ $stderr.reopen(captured_stream)
41
+
42
+ yield
43
+
44
+ captured_stream.rewind
45
+ captured_stream.read
46
+ ensure
47
+ $stdout.reopen(original_stdout)
48
+ $stderr.reopen(original_stderr)
49
+ captured_stream.close
50
+ captured_stream.unlink
51
+ end
52
+ end
53
+
54
+ # A subclass that forces rake to use our desired Rakefile, and configures Rake to act
55
+ # a bit different.
56
+ class Application < ::Rake::Application
57
+ def initialize
58
+ super
59
+ @rakefiles = [RAKEFILE]
60
+ end
61
+
62
+ # Rake defines this to catch exceptions and call `exit(false)`, but we do not want
63
+ # that behavior. We want to let lambda handle exceptions like normal.
64
+ def standard_exception_handling
65
+ yield
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,19 @@
1
+ # Copyright 2024 Block, Inc.
2
+ #
3
+ # Use of this source code is governed by an MIT-style
4
+ # license that can be found in the LICENSE file or at
5
+ # https://opensource.org/licenses/MIT.
6
+ #
7
+ # frozen_string_literal: true
8
+
9
+ require "elastic_graph/admin"
10
+ require "elastic_graph/lambda_support"
11
+
12
+ module ElasticGraph
13
+ module AdminLambda
14
+ # Builds an `ElasticGraph::Admin` instance from our lambda ENV vars.
15
+ def self.admin_from_env
16
+ LambdaSupport.build_from_env(Admin)
17
+ end
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,293 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: elasticgraph-admin_lambda
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.18.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Myron Marston
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-08-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubocop-factory_bot
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.26'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.26'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop-rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop-rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: standard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.39.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.39.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: steep
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.7'
83
+ - !ruby/object:Gem::Dependency
84
+ name: coderay
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.1'
97
+ - !ruby/object:Gem::Dependency
98
+ name: flatware-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 2.3.2
104
+ - - "<"
105
+ - !ruby/object:Gem::Version
106
+ version: '3.0'
107
+ type: :development
108
+ prerelease: false
109
+ version_requirements: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: 2.3.2
114
+ - - "<"
115
+ - !ruby/object:Gem::Version
116
+ version: '3.0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: rspec
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '3.13'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '3.13'
131
+ - !ruby/object:Gem::Dependency
132
+ name: super_diff
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: 0.12.1
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: 0.12.1
145
+ - !ruby/object:Gem::Dependency
146
+ name: simplecov
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "~>"
150
+ - !ruby/object:Gem::Version
151
+ version: '0.22'
152
+ type: :development
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - "~>"
157
+ - !ruby/object:Gem::Version
158
+ version: '0.22'
159
+ - !ruby/object:Gem::Dependency
160
+ name: simplecov-console
161
+ requirement: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: 0.9.1
166
+ - - "<"
167
+ - !ruby/object:Gem::Version
168
+ version: '1.0'
169
+ type: :development
170
+ prerelease: false
171
+ version_requirements: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ version: 0.9.1
176
+ - - "<"
177
+ - !ruby/object:Gem::Version
178
+ version: '1.0'
179
+ - !ruby/object:Gem::Dependency
180
+ name: aws_lambda_ric
181
+ requirement: !ruby/object:Gem::Requirement
182
+ requirements:
183
+ - - ">="
184
+ - !ruby/object:Gem::Version
185
+ version: 2.0.0
186
+ type: :development
187
+ prerelease: false
188
+ version_requirements: !ruby/object:Gem::Requirement
189
+ requirements:
190
+ - - ">="
191
+ - !ruby/object:Gem::Version
192
+ version: 2.0.0
193
+ - !ruby/object:Gem::Dependency
194
+ name: rake
195
+ requirement: !ruby/object:Gem::Requirement
196
+ requirements:
197
+ - - "~>"
198
+ - !ruby/object:Gem::Version
199
+ version: '13.2'
200
+ type: :runtime
201
+ prerelease: false
202
+ version_requirements: !ruby/object:Gem::Requirement
203
+ requirements:
204
+ - - "~>"
205
+ - !ruby/object:Gem::Version
206
+ version: '13.2'
207
+ - !ruby/object:Gem::Dependency
208
+ name: elasticgraph-admin
209
+ requirement: !ruby/object:Gem::Requirement
210
+ requirements:
211
+ - - '='
212
+ - !ruby/object:Gem::Version
213
+ version: 0.18.0.0
214
+ type: :runtime
215
+ prerelease: false
216
+ version_requirements: !ruby/object:Gem::Requirement
217
+ requirements:
218
+ - - '='
219
+ - !ruby/object:Gem::Version
220
+ version: 0.18.0.0
221
+ - !ruby/object:Gem::Dependency
222
+ name: elasticgraph-lambda_support
223
+ requirement: !ruby/object:Gem::Requirement
224
+ requirements:
225
+ - - '='
226
+ - !ruby/object:Gem::Version
227
+ version: 0.18.0.0
228
+ type: :runtime
229
+ prerelease: false
230
+ version_requirements: !ruby/object:Gem::Requirement
231
+ requirements:
232
+ - - '='
233
+ - !ruby/object:Gem::Version
234
+ version: 0.18.0.0
235
+ - !ruby/object:Gem::Dependency
236
+ name: httpx
237
+ requirement: !ruby/object:Gem::Requirement
238
+ requirements:
239
+ - - ">="
240
+ - !ruby/object:Gem::Version
241
+ version: 1.2.6
242
+ - - "<"
243
+ - !ruby/object:Gem::Version
244
+ version: '2.0'
245
+ type: :development
246
+ prerelease: false
247
+ version_requirements: !ruby/object:Gem::Requirement
248
+ requirements:
249
+ - - ">="
250
+ - !ruby/object:Gem::Version
251
+ version: 1.2.6
252
+ - - "<"
253
+ - !ruby/object:Gem::Version
254
+ version: '2.0'
255
+ description:
256
+ email:
257
+ - myron@squareup.com
258
+ executables: []
259
+ extensions: []
260
+ extra_rdoc_files: []
261
+ files:
262
+ - LICENSE.txt
263
+ - README.md
264
+ - elasticgraph-admin_lambda.gemspec
265
+ - lib/elastic_graph/admin_lambda.rb
266
+ - lib/elastic_graph/admin_lambda/Rakefile
267
+ - lib/elastic_graph/admin_lambda/lambda_function.rb
268
+ - lib/elastic_graph/admin_lambda/rake_adapter.rb
269
+ homepage:
270
+ licenses:
271
+ - MIT
272
+ metadata:
273
+ gem_category: lambda
274
+ post_install_message:
275
+ rdoc_options: []
276
+ require_paths:
277
+ - lib
278
+ required_ruby_version: !ruby/object:Gem::Requirement
279
+ requirements:
280
+ - - "~>"
281
+ - !ruby/object:Gem::Version
282
+ version: '3.2'
283
+ required_rubygems_version: !ruby/object:Gem::Requirement
284
+ requirements:
285
+ - - ">="
286
+ - !ruby/object:Gem::Version
287
+ version: '0'
288
+ requirements: []
289
+ rubygems_version: 3.5.9
290
+ signing_key:
291
+ specification_version: 4
292
+ summary: ElasticGraph gem that wraps elasticgraph-admin in an AWS Lambda.
293
+ test_files: []