utter 1.0.5 → 1.0.6
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/README.md +9 -0
- data/examples/Gemfile +4 -0
- data/examples/Gemfile.lock +34 -0
- data/examples/app.rb +2 -0
- data/examples/config.ru +8 -2
- data/lib/utter/auth.rb +74 -0
- data/lib/utter/endpoint.rb +27 -0
- data/lib/utter/model.rb +9 -0
- data/lib/utter/store.rb +10 -0
- data/lib/utter/version.rb +1 -1
- data/lib/utter.rb +7 -59
- data/utter.gemspec +4 -0
- metadata +36 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aaca52bdee87dcd076358931bbb3f331b439b609
|
4
|
+
data.tar.gz: 546fcac5095b7da7c2be234db664503cc04fce3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acb9d767cd45681d665a0407d96c37cdb9019cd23982e772e4e0e1ab3cd1cf9e5971dcedcb7ed8cdef196ccf070469dd86c67645d742f5291a18a6eea5bb7963
|
7
|
+
data.tar.gz: 7707900d5300e69d7e3909fd0ba8a6c1c0552684673a5c163dcc8dbc1f0636c5e1227576de6d61c5c751ab0ea4f9edd96a6f4ad7f2de933c19deaf078b279eef
|
data/README.md
CHANGED
@@ -3,6 +3,15 @@ Utter
|
|
3
3
|
|
4
4
|
Utter is microservies framework for building independently deployable services.
|
5
5
|
|
6
|
+
Why Utter
|
7
|
+
==========
|
8
|
+
Utter loves sinatra! thats why it is built on top of it, but make smart descions to faciliate the building of microservices.
|
9
|
+
|
10
|
+
Alternative Frameworks
|
11
|
+
=======================
|
12
|
+
Utter sees Grape as poluted framework.
|
13
|
+
Utter sees Rails as MUST-Avoid framework.
|
14
|
+
|
6
15
|
Example:
|
7
16
|
========
|
8
17
|
> utter deploy user@serverip
|
data/examples/Gemfile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
multi_json (1.12.1)
|
5
|
+
rack (1.6.4)
|
6
|
+
rack-protection (1.5.3)
|
7
|
+
rack
|
8
|
+
sinatra (1.4.7)
|
9
|
+
rack (~> 1.5)
|
10
|
+
rack-protection (~> 1.4)
|
11
|
+
tilt (>= 1.3, < 3)
|
12
|
+
sinatra-cross_origin (0.3.2)
|
13
|
+
sinatra-json (0.1.0)
|
14
|
+
multi_json (~> 1.0)
|
15
|
+
sinatra (~> 1.0)
|
16
|
+
ssd (0.1.4)
|
17
|
+
tilt (2.0.5)
|
18
|
+
utter (1.0.5)
|
19
|
+
sinatra
|
20
|
+
sinatra-cross_origin
|
21
|
+
sinatra-json
|
22
|
+
ssd
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
ruby
|
26
|
+
|
27
|
+
DEPENDENCIES
|
28
|
+
utter
|
29
|
+
|
30
|
+
RUBY VERSION
|
31
|
+
ruby 2.3.1p112
|
32
|
+
|
33
|
+
BUNDLED WITH
|
34
|
+
1.12.5
|
data/examples/app.rb
CHANGED
data/examples/config.ru
CHANGED
@@ -1,10 +1,16 @@
|
|
1
1
|
# config.ru (run with rackup)
|
2
|
+
##begin
|
3
|
+
# require 'rack/show_exceptions'
|
4
|
+
#rescue LoadError
|
5
|
+
# require 'rack/showexceptions'
|
6
|
+
#end
|
7
|
+
|
2
8
|
require './app'
|
3
9
|
|
4
10
|
map('/public') do
|
5
|
-
run PublicEndpoint
|
11
|
+
run API::V1::PublicEndpoint
|
6
12
|
end
|
7
13
|
|
8
14
|
map('/private') do
|
9
|
-
run PrivateEndpoint
|
15
|
+
run API::V1::PrivateEndpoint
|
10
16
|
end
|
data/lib/utter/auth.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
#TODO write RDoc
|
2
|
+
module Utter
|
3
|
+
|
4
|
+
class Auth < Rack::Auth::Basic
|
5
|
+
def call(env)
|
6
|
+
request = Rack::Request.new(env)
|
7
|
+
|
8
|
+
case request.path when '/docs'
|
9
|
+
@app.call(env) # skip auth to access documentation
|
10
|
+
else
|
11
|
+
super # perform auth
|
12
|
+
#TODO use json "sinatra/json" here to ensure all outcoming response are in json
|
13
|
+
|
14
|
+
#res = Rack::Response.new
|
15
|
+
|
16
|
+
# This will automatically set the Content-Length header for you
|
17
|
+
##res.write "Hello from Rack!"
|
18
|
+
|
19
|
+
# You can get/set headers with square bracket syntax:
|
20
|
+
##res["Content-Type"] = "Content-type: application/json; charset=utf-8"
|
21
|
+
|
22
|
+
# returns the standard [status, headers, body] array
|
23
|
+
##res.finish
|
24
|
+
|
25
|
+
# You can set and delete cookies
|
26
|
+
# res.set_cookie("user_id", 1)
|
27
|
+
# res.delete_cookie("user_id"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
# Any class that inherits from Endpoint, may include Utter::Token to add security
|
34
|
+
# token, a token can be used for authenticating a signed-in user or as an API for your system.
|
35
|
+
#
|
36
|
+
# Usage
|
37
|
+
#
|
38
|
+
# via curl https://api.example.com/v1/endpoint_name -u token_value:
|
39
|
+
# via Browser http://token_value@localhost:4567/
|
40
|
+
# If you need to authenticate via bearer auth (e.g., for a cross-origin request), use -H "Authorization: Bearer #{token_value}" instead of -u token_value:
|
41
|
+
#
|
42
|
+
# More Info
|
43
|
+
# - https://en.wikipedia.org/wiki/Digest_access_authentication
|
44
|
+
# - https://github.com/rack/rack/blob/master/lib/rack/auth/basic.rb
|
45
|
+
module Secured
|
46
|
+
def self.included(base)
|
47
|
+
base.class_eval do
|
48
|
+
|
49
|
+
use Auth, "#{self}" do |username, password|
|
50
|
+
|
51
|
+
$log.info "username #{username}, password #{username}"
|
52
|
+
|
53
|
+
if !username.nil? && !password.nil? then
|
54
|
+
if !User.ssd(username).nil? then
|
55
|
+
if password == User.ssd(username).password then
|
56
|
+
true # Access Granted
|
57
|
+
else
|
58
|
+
false # Access Denied
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# 404 Error!
|
65
|
+
not_found do
|
66
|
+
status 404
|
67
|
+
"404 - Check #{self} API documentation"
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#TODO write RDoc
|
2
|
+
require 'fileutils'
|
3
|
+
require 'sinatra'
|
4
|
+
require "sinatra/json"
|
5
|
+
require 'securerandom'
|
6
|
+
require 'sinatra/cross_origin'
|
7
|
+
require 'net/http' # Net::HTTP.get('example.com', '/index.html') # => String
|
8
|
+
|
9
|
+
module Utter
|
10
|
+
class Endpoint < Sinatra::Base
|
11
|
+
# if cross_origin is required\loaded then make register Sinatra::CrossOrigin
|
12
|
+
# And
|
13
|
+
#register Sinatra::CrossOrigin
|
14
|
+
|
15
|
+
#TODO set a flag to disable this in production for security
|
16
|
+
# this helps testing APIs on localmachines as CORS fucks developers time.
|
17
|
+
# But not recommended to be set while in production enviroments
|
18
|
+
before do
|
19
|
+
response.headers["Access-Control-Allow-Origin"] = "*"
|
20
|
+
response.headers["Access-Control-Allow-Methods"] = "POST"
|
21
|
+
p response.headers.inspect
|
22
|
+
end
|
23
|
+
|
24
|
+
configure { set :server, :puma }
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
data/lib/utter/model.rb
ADDED
data/lib/utter/store.rb
ADDED
data/lib/utter/version.rb
CHANGED
data/lib/utter.rb
CHANGED
@@ -1,65 +1,13 @@
|
|
1
|
-
require 'fileutils'
|
2
1
|
require 'logger'
|
3
|
-
require 'sinatra'
|
4
|
-
require "sinatra/json"
|
5
|
-
require 'securerandom'
|
6
|
-
require 'sinatra/cross_origin'
|
7
|
-
require 'net/http' # Net::HTTP.get('example.com', '/index.html') # => String
|
8
|
-
require 'ssd'
|
9
2
|
|
10
|
-
|
3
|
+
require_relative "utter/version"
|
4
|
+
require_relative "utter/store"
|
5
|
+
require_relative "utter/model"
|
6
|
+
require_relative "utter/endpoint"
|
7
|
+
require_relative "utter/auth"
|
11
8
|
|
12
|
-
$log = Logger.new(STDOUT)
|
13
|
-
|
14
|
-
module Utter
|
15
|
-
|
16
|
-
# any class that inherits from Endpoint, may include Utter::Token to add security
|
17
|
-
# token, a token can be used for authenticating a signed-in user or as an API for your system.
|
18
|
-
#
|
19
|
-
# Usage
|
20
|
-
#
|
21
|
-
# via curl https://api.example.com/v1/endpoint_name -u token_value:
|
22
|
-
# via Browser http://token_value@localhost:4567/
|
23
|
-
# If you need to authenticate via bearer auth (e.g., for a cross-origin request), use -H "Authorization: Bearer #{token_value}" instead of -u token_value:
|
24
|
-
#
|
25
|
-
# More Info
|
26
|
-
# - https://en.wikipedia.org/wiki/Digest_access_authentication
|
27
|
-
# - https://github.com/rack/rack/blob/master/lib/rack/auth/basic.rb
|
28
|
-
module Token
|
29
|
-
use Rack::Auth::Basic, "Protected Area" do |token|
|
30
|
-
token == 'foo'
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
class Endpoint < Sinatra::Base
|
35
|
-
# if cross_origin is required\loaded then make register Sinatra::CrossOrigin
|
36
|
-
# And
|
37
|
-
#register Sinatra::CrossOrigin
|
38
|
-
|
39
|
-
#TODO set a flag to disable this in production for security
|
40
|
-
# this helps testing APIs on localmachines as CORS fucks developers time.
|
41
|
-
# But not recommended to be set while in production enviroments
|
42
|
-
before do
|
43
|
-
response.headers["Access-Control-Allow-Origin"] = "*"
|
44
|
-
response.headers["Access-Control-Allow-Methods"] = "POST"
|
45
|
-
p response.headers.inspect
|
46
|
-
end
|
47
|
-
end
|
48
9
|
|
49
10
|
|
50
|
-
|
51
|
-
|
52
|
-
def self.inherited(model)
|
53
|
-
model.send :include, SSD
|
54
|
-
#model.extend SSD
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
module Store
|
59
|
-
#include SSD
|
60
|
-
def self.included(klass)
|
61
|
-
klass.send :include, SSD
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
11
|
+
module Utter
|
12
|
+
$log = Logger.new(STDOUT)
|
65
13
|
end
|
data/utter.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: utter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zotherstupidguy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -164,6 +164,34 @@ dependencies:
|
|
164
164
|
- - ">="
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: puma
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: puma
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :runtime
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
167
195
|
description:
|
168
196
|
email:
|
169
197
|
- zotherstupidguy@gmail.com
|
@@ -180,9 +208,15 @@ files:
|
|
180
208
|
- Rakefile
|
181
209
|
- bin/console
|
182
210
|
- bin/setup
|
211
|
+
- examples/Gemfile
|
212
|
+
- examples/Gemfile.lock
|
183
213
|
- examples/app.rb
|
184
214
|
- examples/config.ru
|
185
215
|
- lib/utter.rb
|
216
|
+
- lib/utter/auth.rb
|
217
|
+
- lib/utter/endpoint.rb
|
218
|
+
- lib/utter/model.rb
|
219
|
+
- lib/utter/store.rb
|
186
220
|
- lib/utter/version.rb
|
187
221
|
- utter.gemspec
|
188
222
|
homepage: https://github.com/utter-rb
|