hieraviz 0.2.1 → 0.2.2
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 +5 -0
- data/README.md +1 -1
- data/app/apiv1.rb +30 -12
- data/app/web.rb +0 -6
- data/lib/hieraviz/config.rb +1 -1
- data/lib/hieraviz.rb +1 -0
- data/lib/sinatra/cross-origin.rb +82 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecd646feab7d0eb2b8f2e4ed17b7417bad5e1539
|
4
|
+
data.tar.gz: ede3db1196637027b576e6180b972d8311f0c5b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6b1383225fdd48cff661db970b4a2ae217bfb852cd11a9d7196c2e8e507ec8f3d169552dde470d8ff2ef2850b7bdaab744317a594df4c7665275c17b6fc5fbf
|
7
|
+
data.tar.gz: a97c8a77ad48a4cd2ed204c8113433783e4a85f12d9fff0210381597d4899ccd5afc080a42cd15107143e39288ae94ff6baaba06aaa14cb3dd2e7c144265eb80
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
Hieraviz Changelog
|
2
2
|
========================
|
3
3
|
|
4
|
+
### v0.2.2 - 2016-04-05
|
5
|
+
- sort branches order
|
6
|
+
- prepare debian package
|
7
|
+
- add a filter on farm api calls
|
8
|
+
|
4
9
|
### v0.2.1 - 2016-04-04
|
5
10
|
- replaced sinatra-flash (weird license, no debian package) with rack-flash3
|
6
11
|
|
data/README.md
CHANGED
data/app/apiv1.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'sinatra/json'
|
2
|
+
require 'sinatra/cross-origin'
|
2
3
|
|
3
4
|
require 'digest/sha1'
|
4
5
|
require 'dotenv'
|
@@ -11,11 +12,18 @@ require File.expand_path '../common.rb', __FILE__
|
|
11
12
|
|
12
13
|
module HieravizApp
|
13
14
|
class ApiV1 < Common
|
15
|
+
register Sinatra::CrossOrigin
|
14
16
|
|
15
17
|
configure do
|
16
18
|
set :session_secret, settings.configdata['session_seed']
|
17
19
|
set :protection, :origin_whitelist => ['http://web.example.com']
|
18
20
|
enable :sessions
|
21
|
+
enable :cross_origin
|
22
|
+
set :allow_origin, :any
|
23
|
+
set :allow_methods, [:get, :post, :options]
|
24
|
+
set :allow_credentials, true
|
25
|
+
set :max_age, "1728000"
|
26
|
+
set :expose_headers, ['Content-Type']
|
19
27
|
end
|
20
28
|
|
21
29
|
case settings.configdata['auth_method']
|
@@ -53,11 +61,17 @@ module HieravizApp
|
|
53
61
|
def get_facts(base, node)
|
54
62
|
Hieraviz::Facts.new(settings.configdata['tmpdir'], base, node, username)
|
55
63
|
end
|
56
|
-
def cors_headers()
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
end
|
64
|
+
# def cors_headers()
|
65
|
+
# headers 'Access-Control-Allow-Origin' => '*'
|
66
|
+
# headers 'Access-Control-Allow-Headers' => 'Authorization,Accepts,Content-Type,X-CSRF-Token,X-Requested-With,X-AUTH'
|
67
|
+
# headers 'Access-Control-Allow-Methods' => 'GET,POST,PUT,DELETE,OPTIONS'
|
68
|
+
# end
|
69
|
+
end
|
70
|
+
|
71
|
+
options '*' do
|
72
|
+
response.headers["Allow"] = "HEAD,GET,PUT,POST,DELETE,OPTIONS"
|
73
|
+
response.headers["Access-Control-Allow-Headers"] = "X-Requested-With, X-HTTP-Method-Override, Content-Type, Cache-Control, Accept"
|
74
|
+
200
|
61
75
|
end
|
62
76
|
|
63
77
|
get %r{^/?([-_\.a-zA-Z0-9]+)?/nodes} do |base|
|
@@ -115,7 +129,7 @@ module HieravizApp
|
|
115
129
|
|
116
130
|
get %r{^/?([-_\.a-zA-Z0-9]+)?/farms} do |base|
|
117
131
|
check_authorization
|
118
|
-
|
132
|
+
cross_origin
|
119
133
|
hieracles_config = prepare_config(base)
|
120
134
|
json Hieracles::Registry.farms_counted(hieracles_config, base)
|
121
135
|
end
|
@@ -144,18 +158,22 @@ module HieravizApp
|
|
144
158
|
json res
|
145
159
|
end
|
146
160
|
|
147
|
-
options %r{^/.*/$} do
|
148
|
-
cors_headers
|
149
|
-
halt 200
|
150
|
-
end
|
151
|
-
|
152
161
|
get %r{^/?([-_\.a-zA-Z0-9]+)?/farm/([-_\.a-zA-Z0-9]+)$} do |base, farm|
|
153
162
|
# check_authorization
|
154
|
-
|
163
|
+
cross_origin
|
155
164
|
hieracles_config = prepare_config(base)
|
156
165
|
nodes = Hieracles::Registry.nodes_data(hieracles_config, base).each_with_object({}) do |(key, val), acc|
|
157
166
|
acc[key] = val if val['farm'] == farm
|
158
167
|
end
|
168
|
+
params = request.env['rack.request.query_hash']
|
169
|
+
if params.count > 0
|
170
|
+
puts params
|
171
|
+
params.each do |k, v|
|
172
|
+
nodes = nodes.keep_if do |key, item|
|
173
|
+
item[k] == v
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
159
177
|
json nodes
|
160
178
|
end
|
161
179
|
|
data/app/web.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'sinatra/content_for'
|
2
2
|
|
3
|
-
require 'better_errors'
|
4
3
|
require 'rack-flash'
|
5
4
|
require 'dotenv'
|
6
5
|
require 'oauth2'
|
@@ -24,11 +23,6 @@ module HieravizApp
|
|
24
23
|
enable :sessions
|
25
24
|
end
|
26
25
|
|
27
|
-
configure :development do
|
28
|
-
use BetterErrors::Middleware
|
29
|
-
BetterErrors.application_root = File.expand_path('../../', __FILE__)
|
30
|
-
end
|
31
|
-
|
32
26
|
case settings.configdata['auth_method']
|
33
27
|
when 'dummy'
|
34
28
|
|
data/lib/hieraviz/config.rb
CHANGED
@@ -12,7 +12,7 @@ module Hieraviz
|
|
12
12
|
def basepaths
|
13
13
|
basepath_dir = @_config['basepath_dir']
|
14
14
|
if @_config && basepath_dir
|
15
|
-
Dir.glob(root_path(basepath_dir)).map { |path| File.expand_path(path) }
|
15
|
+
Dir.glob(root_path(basepath_dir)).map { |path| File.expand_path(path) }.sort
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
data/lib/hieraviz.rb
CHANGED
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
|
3
|
+
# Helper to enable cross origin requests.
|
4
|
+
# More on Cross Origin Resource Sharing here:
|
5
|
+
# https://developer.mozilla.org/En/HTTP_access_control
|
6
|
+
#
|
7
|
+
# To enable cross origin requests for all routes:
|
8
|
+
# configure do
|
9
|
+
# enable :cross_origin
|
10
|
+
# ...
|
11
|
+
#
|
12
|
+
# To enable cross origin requests for a single domain:
|
13
|
+
# get '/' do
|
14
|
+
# cross_origin
|
15
|
+
# ...
|
16
|
+
#
|
17
|
+
# More info at:
|
18
|
+
# http://github.com/britg/sinatra-cross_origin
|
19
|
+
#
|
20
|
+
|
21
|
+
module Sinatra
|
22
|
+
module CrossOrigin
|
23
|
+
module Helpers
|
24
|
+
|
25
|
+
# Apply cross origin headers either
|
26
|
+
# from global config or custom config passed
|
27
|
+
# as a hash
|
28
|
+
def cross_origin(hash=nil)
|
29
|
+
request_origin = request.env['HTTP_ORIGIN']
|
30
|
+
return unless request_origin
|
31
|
+
settings.set hash if hash
|
32
|
+
|
33
|
+
if settings.allow_origin == :any
|
34
|
+
origin = request_origin
|
35
|
+
else
|
36
|
+
allowed_origins = *settings.allow_origin # make sure its an array
|
37
|
+
origin = allowed_origins.join('|') # we'll return this unless allowed
|
38
|
+
|
39
|
+
allowed_origins.each do |allowed_origin|
|
40
|
+
if allowed_origin.is_a?(Regexp) ?
|
41
|
+
request_origin =~ allowed_origin :
|
42
|
+
request_origin == allowed_origin
|
43
|
+
origin = request_origin
|
44
|
+
break
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
methods = settings.allow_methods.map{ |m| m.to_s.upcase! }.join(', ')
|
50
|
+
|
51
|
+
headers_list = {
|
52
|
+
'Access-Control-Allow-Origin' => origin,
|
53
|
+
'Access-Control-Allow-Methods' => methods,
|
54
|
+
'Access-Control-Allow-Headers' => settings.allow_headers.map(&:to_s).join(', '),
|
55
|
+
'Access-Control-Allow-Credentials' => settings.allow_credentials.to_s,
|
56
|
+
'Access-Control-Max-Age' => settings.max_age.to_s,
|
57
|
+
'Access-Control-Expose-Headers' => settings.expose_headers.join(', ')
|
58
|
+
}
|
59
|
+
|
60
|
+
headers headers_list
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.registered(app)
|
65
|
+
|
66
|
+
app.helpers CrossOrigin::Helpers
|
67
|
+
|
68
|
+
app.set :cross_origin, false
|
69
|
+
app.set :allow_origin, :any
|
70
|
+
app.set :allow_methods, [:post, :get, :options]
|
71
|
+
app.set :allow_credentials, true
|
72
|
+
app.set :allow_headers, ["*", "Content-Type", "Accept", "AUTHORIZATION", "Cache-Control"]
|
73
|
+
app.set :max_age, 1728000
|
74
|
+
app.set :expose_headers, ['Cache-Control', 'Content-Language', 'Content-Type', 'Expires', 'Last-Modified', 'Pragma']
|
75
|
+
|
76
|
+
app.before do
|
77
|
+
cross_origin if settings.cross_origin
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hieraviz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mose
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dotenv
|
@@ -301,6 +301,7 @@ files:
|
|
301
301
|
- lib/hieraviz/store.rb
|
302
302
|
- lib/hieraviz/utilities.rb
|
303
303
|
- lib/hieraviz/version.rb
|
304
|
+
- lib/sinatra/cross-origin.rb
|
304
305
|
- spec/app/apiv1_spec.rb
|
305
306
|
- spec/app/web_dummy_auth_spec.rb
|
306
307
|
- spec/app/web_spec.rb
|