rest_shifter 0.0.10 → 0.0.11
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/CHANGES +4 -0
- data/README.md +18 -0
- data/lib/rest_shifter/commands/help.rb +6 -5
- data/lib/rest_shifter/commands/main.rb +3 -0
- data/lib/rest_shifter/commands/start.rb +26 -10
- data/lib/rest_shifter/shifter.rb +26 -0
- data/lib/rest_shifter/ssl_helper.rb +9 -0
- data/lib/rest_shifter/version.rb +1 -1
- data/rest_shifter.gemspec +1 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e5c6f62b6e629086fcd6b7445d7c7e9c0d7977b
|
4
|
+
data.tar.gz: a2d921e1a9820b0846dc92a2cfba0579d5020c02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7fba39d5774aee26ac6efa5a8b3c1acd7ba0756b157bd07281f57d1757fef68b23dd1f8d977eb7d3f6a40a7898d23b2efa81184961a959dd5f130f3e3e8473b
|
7
|
+
data.tar.gz: 44c7b1a22ebec0a5660db1399061e9903ff9c53485726998f0972f664a2fec4dbc4dde00ac002a7ca45f00e797092b0cf11a09cbedf8dffc0f296a3caebf4208
|
data/CHANGES
CHANGED
data/README.md
CHANGED
@@ -73,6 +73,10 @@ Start the service
|
|
73
73
|
|
74
74
|
$ rest_shifter -s
|
75
75
|
|
76
|
+
Optionally, you can start the service over https using captal "S":
|
77
|
+
|
78
|
+
$ rest_shifter -S /path/to/file.crt /path/to/file.key
|
79
|
+
|
76
80
|
Go to a browser and open the url: [http://localhost:4567/hello_world](http://localhost:4567/hello_world)
|
77
81
|
|
78
82
|
You should see the following JSON:
|
@@ -82,6 +86,20 @@ You should see the following JSON:
|
|
82
86
|
To edit the service you just created, go to ~/.rest_shifter/flavors/hello_world.flavor
|
83
87
|
The name of the file is the name that you used in the command -c (create).
|
84
88
|
|
89
|
+
The file looks like this:
|
90
|
+
|
91
|
+
## ! ~/.rest_shifter/flavors/hello_world.flavor
|
92
|
+
method_used = "get"
|
93
|
+
path = "/hello_world"
|
94
|
+
request_accept = ""
|
95
|
+
request_content_type = ""
|
96
|
+
response_sleep = 0
|
97
|
+
response_status = "200"
|
98
|
+
response_body = "{ \"hello_world\" : \"Your service is working fine. :D\" }"
|
99
|
+
response_content_type = "application/json"
|
100
|
+
|
101
|
+
You basically change whatever you need to make it look like the expected or desired service. For example, replacint the path by "/clients", and restart rest_shifter, so you have the desired endpoint working as a rest api.
|
102
|
+
|
85
103
|
Whatever you change in the file will change in the service as soon as you restart it.
|
86
104
|
|
87
105
|
Enjoy
|
@@ -8,14 +8,15 @@ rest_shifter version #{RestShifter::VERSION}: The ShapeShifter Rest Service
|
|
8
8
|
|
9
9
|
Available commands:
|
10
10
|
|
11
|
-
help
|
11
|
+
--help Show this help text
|
12
12
|
|
13
|
-
--start, -s:
|
13
|
+
--start, -s: Start service on port 4567
|
14
|
+
--start-secure, -S: Start https service on port 4433 (crt, key)
|
14
15
|
|
15
|
-
--create, -c:
|
16
|
+
--create, -c: Create a config file for a service (send a name as argument)
|
16
17
|
|
17
|
-
--version, -v:
|
18
|
-
--help, -h:
|
18
|
+
--version, -v: Print version and exit
|
19
|
+
--help, -h: Show this message
|
19
20
|
|
20
21
|
For more support read our api >> http://rubydoc.info/gems/rest_shifter
|
21
22
|
Have a nice day :)
|
@@ -9,6 +9,9 @@ class RestShifter::Commands::Main
|
|
9
9
|
when "-s", "--start", "start"
|
10
10
|
RestShifter::Commands::Start.run
|
11
11
|
exit 0
|
12
|
+
when "-S", "--start-secure", "start-secure"
|
13
|
+
RestShifter::Commands::Start.run_secure
|
14
|
+
exit 0
|
12
15
|
when "-c", "--create", "create"
|
13
16
|
RestShifter::Commands::Create.run
|
14
17
|
exit 0
|
@@ -1,14 +1,30 @@
|
|
1
1
|
class RestShifter::Commands::Start
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
2
|
+
class << self
|
3
|
+
def run(args=ARGV)
|
4
|
+
|
5
|
+
prepare_server
|
6
|
+
Shifter.run!
|
7
|
+
end
|
8
|
+
|
9
|
+
def run_secure(args=ARGV)
|
10
|
+
crt = args.shift
|
11
|
+
key = args.shift
|
12
|
+
|
13
|
+
prepare_server
|
14
|
+
Shifter.use Rack::SSL
|
15
|
+
Shifter.run_ssl! crt, key
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def prepare_server
|
20
|
+
begin
|
21
|
+
require 'rest_shifter/shifter.rb'
|
22
|
+
rescue LoadError => e
|
23
|
+
require 'rubygems'
|
24
|
+
path = File.expand_path '../../lib', __FILE__
|
25
|
+
$:.unshift(path) if File.directory?(path) && !$:.include?(path)
|
26
|
+
require 'rest_shifter/shifter.rb'
|
27
|
+
end
|
10
28
|
end
|
11
|
-
|
12
|
-
Shifter.run!
|
13
29
|
end
|
14
30
|
end
|
data/lib/rest_shifter/shifter.rb
CHANGED
@@ -1,10 +1,36 @@
|
|
1
1
|
require 'sinatra/base'
|
2
2
|
require 'icecream'
|
3
|
+
require 'rack/ssl'
|
3
4
|
|
4
5
|
module RestShifter; end
|
5
6
|
|
6
7
|
class Shifter < Sinatra::Base
|
7
8
|
|
9
|
+
def self.run_ssl! crt, key
|
10
|
+
require 'webrick/https'
|
11
|
+
|
12
|
+
port = 4433
|
13
|
+
certificate_content = File.open(crt).read
|
14
|
+
key_content = File.open(key).read
|
15
|
+
|
16
|
+
server_options = {
|
17
|
+
:Port => port,
|
18
|
+
:SSLEnable => true,
|
19
|
+
:SSLCertificate => OpenSSL::X509::Certificate.new(certificate_content),
|
20
|
+
:SSLPrivateKey => OpenSSL::PKey::RSA.new(key_content),
|
21
|
+
:SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE
|
22
|
+
}
|
23
|
+
|
24
|
+
Rack::Handler::WEBrick.run self, server_options do |server|
|
25
|
+
[:INT, :TERM].each { |sig| trap(sig) { server.stop } }
|
26
|
+
server.threaded = settings.threaded if server.respond_to? :threaded=
|
27
|
+
set :running, true
|
28
|
+
end
|
29
|
+
set :ssl, true
|
30
|
+
set :port, 4433
|
31
|
+
run!
|
32
|
+
end
|
33
|
+
|
8
34
|
shapes = IceCream::IceCream.new File.dirname("#{Dir.home}/.rest_shifter/flavors/*")
|
9
35
|
if ENV["RACK_ENV"] == "test"
|
10
36
|
shapes = IceCream::IceCream.new File.join(File.dirname(__FILE__), "../../spec/flavors")
|
data/lib/rest_shifter/version.rb
CHANGED
data/rest_shifter.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest_shifter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Camilo Ribeiro
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: simplecov
|
@@ -164,6 +164,20 @@ dependencies:
|
|
164
164
|
- - '>='
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: rack-ssl
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :runtime
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - '>='
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
167
181
|
description: RestShifter is a simple rest service that can shift into any kind of
|
168
182
|
service, allowing you to mock rest services with declarative configuration
|
169
183
|
email:
|
@@ -190,6 +204,7 @@ files:
|
|
190
204
|
- lib/rest_shifter/commands/start.rb
|
191
205
|
- lib/rest_shifter/commands/version.rb
|
192
206
|
- lib/rest_shifter/shifter.rb
|
207
|
+
- lib/rest_shifter/ssl_helper.rb
|
193
208
|
- lib/rest_shifter/version.rb
|
194
209
|
- rest_shifter.gemspec
|
195
210
|
- spec/flavors/notfound_get.flavor
|