mite 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f08f44cb9c8825ddc76212e1113a59602816f1f25dc86498f8a11f09ddba3d07
4
+ data.tar.gz: 452e509ae32883e420c9d6cf62cb2bf1e95b7d9845640908124ff9e756fc0fc5
5
+ SHA512:
6
+ metadata.gz: f9b9d355a22edecf523281b45753394be1b0dcee1046b9adb5b9b142a7b3f0edb7c17c5a3cb5416745aad567001ce0b3c6bbbcddbd6623e9da368f4c7baecc1d
7
+ data.tar.gz: 0567eb00300ec08966d935d7b94ece60b6fad9fe208a4115cc927533a14c13dc311f3857f61ce0f25e4de9dd903aeb0070291e7fa8e2d8ecb096e0b18cd714bd
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,56 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mite (0.0.1)
5
+ arthropod
6
+ aws-sdk-sqs
7
+ rack
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ arthropod (0.0.5)
13
+ aws-sdk-sqs
14
+ aws-eventstream (1.0.3)
15
+ aws-partitions (1.262.0)
16
+ aws-sdk-core (3.87.0)
17
+ aws-eventstream (~> 1.0, >= 1.0.2)
18
+ aws-partitions (~> 1, >= 1.239.0)
19
+ aws-sigv4 (~> 1.1)
20
+ jmespath (~> 1.0)
21
+ aws-sdk-sqs (1.23.1)
22
+ aws-sdk-core (~> 3, >= 3.71.0)
23
+ aws-sigv4 (~> 1.1)
24
+ aws-sigv4 (1.1.0)
25
+ aws-eventstream (~> 1.0, >= 1.0.2)
26
+ byebug (11.0.1)
27
+ diff-lcs (1.3)
28
+ jmespath (1.4.0)
29
+ rack (2.0.8)
30
+ rake (13.0.1)
31
+ rspec (3.9.0)
32
+ rspec-core (~> 3.9.0)
33
+ rspec-expectations (~> 3.9.0)
34
+ rspec-mocks (~> 3.9.0)
35
+ rspec-core (3.9.0)
36
+ rspec-support (~> 3.9.0)
37
+ rspec-expectations (3.9.0)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.9.0)
40
+ rspec-mocks (3.9.0)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.9.0)
43
+ rspec-support (3.9.0)
44
+
45
+ PLATFORMS
46
+ ruby
47
+
48
+ DEPENDENCIES
49
+ bundler
50
+ byebug
51
+ mite!
52
+ rake
53
+ rspec
54
+
55
+ BUNDLED WITH
56
+ 2.0.2
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # Mite
2
+
3
+ Mite is an [Arthropod](https://github.com/victorgoya/arthropod) based Rack server. Let me try to explain:
4
+
5
+ - Arthropod is a small library that makes it easy to call remote Ruby code using Amazon SQS.
6
+ - Mite uses Arthropod to listen to SQS messages on a given and expects to get an Rack `env`.
7
+ - It will call your app with this env and respond to the Arthropod call with the usual status, headers and body.
8
+
9
+ It can probably be used to do pretty edgy stuff like building a remote Rack middleware, but I only use it in conjuction with Amazon Lambda to serve pages and API calls from Rails apps that happens to live behind a NAT and with a dynamic IP address allocation, because I do have tons of little pet projects that sometimes requires lots of CPU/lots of RAM/CUDA. Also, in those case I don't care much about latency (it's not horrible though, fast enough for pet projects).
10
+
11
+ ## Installation
12
+
13
+ ```
14
+ gem install mite
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ Just run it with the required arguments.
20
+ ```shell
21
+ $ mite -h
22
+
23
+ Usage: mite [options]
24
+ -q, --queue [string] SQS queue name
25
+ -i, --access-key-id [string] AWS access key ID, default to the AWS_ACCESS_KEY_ID environment variable
26
+ -k, --secret-access-key [string] AWS secret access key, default to the AWS_SECRET_ACCESS_KEY environment variable
27
+ -r, --region [string] AWS region, default to the AWS_REGION environment variable
28
+ -c, --config [string] The path to your config.ru file
29
+ ```
30
+
31
+ ## Rails
32
+
33
+ It should works well with Rails, just call it with `mite -c ./config.ru` in your Rails root directory.
34
+
35
+ ## Lambda
36
+
37
+ I usually use Amazon Lambda to push messages to SQS form an API Gateway resource. Take a look at [mite-lambda-proxy](https://github.com/victorgoya/mite-lambda-proxy) to see how you can setup something like that on your own.
data/bin/mite ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'aws-sdk-sqs'
5
+ require 'rack'
6
+
7
+ require 'mite'
8
+ require 'arthropod'
9
+
10
+ options = {}
11
+ OptionParser.new do |opts|
12
+ opts.banner = "Usage: #{$PROGRAM_NAME} [options]"
13
+
14
+ opts.on("-q", "--queue [string]", "SQS queue name") do |q|
15
+ options[:queue] = q
16
+ end
17
+ opts.on("-i", "--access-key-id [string]", "AWS access key ID, default to the AWS_ACCESS_KEY_ID environment variable") do |i|
18
+ options[:access_key_id] = i
19
+ end
20
+ opts.on("-k", "--secret-access-key [string]", "AWS secret access key, default to the AWS_SECRET_ACCESS_KEY environment variable") do |k|
21
+ options[:secret_access_key] = k
22
+ end
23
+ opts.on("-r", "--region [string]", "AWS region, default to the AWS_REGION environment variable") do |r|
24
+ options[:region] = r
25
+ end
26
+ opts.on("-c", "--config [string]", "Path of the config.ru file, default to ./config.ru") do |c|
27
+ options[:config] = c
28
+ end
29
+ end.parse!
30
+
31
+ access_key_id = options[:access_key_id] || ENV["AWS_ACCESS_KEY_ID"]
32
+ secret_access_key = options[:secret_access_key] || ENV["AWS_SECRET_ACCESS_KEY"]
33
+ region = options[:region] || ENV["AWS_REGION"]
34
+ config = options[:config] || './config.ru'
35
+
36
+ client = Aws::SQS::Client.new({
37
+ access_key_id: access_key_id,
38
+ secret_access_key: secret_access_key,
39
+ region: region,
40
+ })
41
+
42
+ server = Mite::Server.new(config: config)
43
+ loop do
44
+ Arthropod::Server.pull(client: client, queue_name: options[:queue] || ENV["QUEUE_NAME"]) do |request|
45
+ status, headers, chunks = server.process(request.body)
46
+ [ status, headers, chunks.map(&:to_s).join]
47
+ end
48
+ end
@@ -0,0 +1,20 @@
1
+ require 'byebug'
2
+
3
+ module Mite
4
+ class Server
5
+ attr_accessor :application
6
+
7
+ def initialize(config:)
8
+ builder = %{
9
+ Rack::Builder.new do
10
+ #{File.read(config)}
11
+ end
12
+ }
13
+ @application = eval(builder, nil, config)
14
+ end
15
+
16
+ def process(request)
17
+ application.call(request.merge("rack.errors" => $stderr, "rack.version" => Rack::VERSION))
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module Mite
2
+ VERSION = "0.0.1"
3
+ end
data/lib/mite.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'mite/version'
2
+ require 'mite/server'
data/mite.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ lib = File.expand_path("../lib", __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "mite/version"
6
+
7
+ Gem::Specification.new do |gem|
8
+ gem.name = "mite"
9
+ gem.version = Mite::VERSION
10
+ gem.authors = ["Victor Goya"]
11
+ gem.email = ["goya.victor@gmail.com"]
12
+ gem.description = "Arthropod based Rack server"
13
+ gem.summary = "This thing is probably a bad idea"
14
+
15
+ gem.files = `git ls-files -z`.split("\x0")
16
+ gem.require_paths = ["lib"]
17
+ gem.bindir = 'bin'
18
+ gem.executables = %w(mite)
19
+
20
+ gem.licenses = ["MIT"]
21
+
22
+ gem.add_dependency 'aws-sdk-sqs'
23
+ gem.add_dependency 'rack'
24
+ gem.add_dependency 'arthropod'
25
+
26
+ gem.required_ruby_version = "~> 2.0"
27
+
28
+ gem.add_development_dependency 'bundler'
29
+ gem.add_development_dependency 'rspec'
30
+ gem.add_development_dependency 'rake'
31
+ gem.add_development_dependency 'byebug'
32
+ end
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mite
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Victor Goya
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-01-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk-sqs
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: arthropod
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Arthropod based Rack server
112
+ email:
113
+ - goya.victor@gmail.com
114
+ executables:
115
+ - mite
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - Gemfile
120
+ - Gemfile.lock
121
+ - README.md
122
+ - bin/mite
123
+ - lib/mite.rb
124
+ - lib/mite/server.rb
125
+ - lib/mite/version.rb
126
+ - mite.gemspec
127
+ homepage:
128
+ licenses:
129
+ - MIT
130
+ metadata: {}
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '2.0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubygems_version: 3.0.3
147
+ signing_key:
148
+ specification_version: 4
149
+ summary: This thing is probably a bad idea
150
+ test_files: []