hieraviz 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/app/apiv1.rb +6 -10
- data/app/main.rb +0 -1
- data/app/web.rb +46 -39
- data/lib/hieraviz/auth_gitlab.rb +7 -7
- data/lib/hieraviz.rb +1 -0
- data/spec/app/apiv1_spec.rb +172 -4
- data/spec/app/web_spec.rb +41 -4
- data/spec/files/config.yml +3 -0
- data/spec/files/config_gitlab.yml +25 -0
- data/spec/files/puppet/params/common/common.yaml +4 -0
- data/spec/lib/auth_gitlab_spec.rb +46 -0
- data/spec/lib/config_spec.rb +4 -0
- data/spec/oauth2_helper.rb +31 -0
- data/spec/sinatra_helper.rb +2 -0
- data/spec/spec_helper.rb +18 -1
- metadata +8 -4
- data/spec/files/puppet/params/common/common.yml +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49399d4e687c122f2333b3a02f475d5ec8d769bd
|
4
|
+
data.tar.gz: a376b1c4332bac9deddd0d60491b3ac4d4627236
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03e9edf186cd492acd366519a017fcf998d47e1a2ee083ec3344060afec06ae90134aedf364a47eff989120dfe4f48d938e252464104ec8b91a1a8c5825b1ae5
|
7
|
+
data.tar.gz: 09845cede54c3d470d4482e42be46e9efd8aaba6a9b884c219fb6bcab444b227e7f71dc32e09d8d38da163b558c4c2b63dba4267dd914d61437287e500649164
|
data/CHANGELOG.md
CHANGED
data/app/apiv1.rb
CHANGED
@@ -31,10 +31,6 @@ module HieravizApp
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
get '/test' do
|
35
|
-
json data: Time.new
|
36
|
-
end
|
37
|
-
|
38
34
|
get '/nodes' do
|
39
35
|
check_authorization
|
40
36
|
json Hieracles::Registry.nodes(settings.config)
|
@@ -69,12 +65,12 @@ module HieravizApp
|
|
69
65
|
json Hieracles::Registry.farms(settings.config)
|
70
66
|
end
|
71
67
|
|
72
|
-
get '/farm/:n' do |farm|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
end
|
68
|
+
# get '/farm/:n' do |farm|
|
69
|
+
# check_authorization
|
70
|
+
# req = Hieracles::Puppetdb::Request.new(settings.configdata['puppetdb'])
|
71
|
+
# farm_nodes = req.facts('farm', farm)
|
72
|
+
# json farm_nodes.data
|
73
|
+
# end
|
78
74
|
|
79
75
|
get '/not_logged' do
|
80
76
|
json({ error: "Not connected." })
|
data/app/main.rb
CHANGED
data/app/web.rb
CHANGED
@@ -41,8 +41,10 @@ module HieravizApp
|
|
41
41
|
end
|
42
42
|
|
43
43
|
helpers do
|
44
|
+
def get_username
|
45
|
+
settings.configdata['http_auth']['username']
|
46
|
+
end
|
44
47
|
def check_authorization
|
45
|
-
set :username, settings.configdata['http_auth']['username']
|
46
48
|
true
|
47
49
|
end
|
48
50
|
end
|
@@ -51,35 +53,37 @@ module HieravizApp
|
|
51
53
|
|
52
54
|
set :oauth, Hieraviz::AuthGitlab.new(settings.configdata['gitlab_auth'])
|
53
55
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
session_info
|
59
|
-
|
60
|
-
|
56
|
+
helpers do
|
57
|
+
def get_username
|
58
|
+
if session['access_token']
|
59
|
+
session_info = Hieraviz::Store.get(session['access_token'], settings.configdata['session_renew'])
|
60
|
+
if session_info
|
61
|
+
session_info['username']
|
62
|
+
else
|
63
|
+
''
|
64
|
+
end
|
61
65
|
end
|
62
66
|
end
|
63
|
-
end
|
64
67
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
68
|
+
def check_authorization
|
69
|
+
if !session['access_token']
|
70
|
+
redirect settings.oauth.login_url(request)
|
71
|
+
else
|
72
|
+
session_info = Hieraviz::Store.get(session['access_token'], settings.configdata['session_renew'])
|
73
|
+
if !session_info
|
74
|
+
if !settings.oauth.authorized?(session['access_token'])
|
75
|
+
flash[:fatal] = "Sorry you are not authorized to read puppet repo on gitlab."
|
76
|
+
redirect '/'
|
77
|
+
else
|
78
|
+
Hieraviz::Store.set session['access_token'], settings.oauth.user_info(session['access_token'])
|
79
|
+
session_info = Hieraviz::Store.get(session['access_token'], settings.configdata['session_renew'])
|
80
|
+
end
|
77
81
|
end
|
82
|
+
session_info['username']
|
78
83
|
end
|
79
|
-
session_info['username']
|
80
84
|
end
|
81
85
|
end
|
82
|
-
|
86
|
+
|
83
87
|
get '/login' do
|
84
88
|
redirect settings.oauth.login_url(request)
|
85
89
|
end
|
@@ -128,27 +132,30 @@ module HieravizApp
|
|
128
132
|
erb :resources
|
129
133
|
end
|
130
134
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
135
|
+
# debug pages --------------------
|
136
|
+
# get '/store' do
|
137
|
+
# # Hieraviz::Store.set 'woot', 'nada'
|
138
|
+
# erb :store
|
139
|
+
# end
|
140
|
+
|
141
|
+
# get '/user' do
|
142
|
+
# if session[:access_token]
|
143
|
+
# @data = settings.oauth.user_info(session[:access_token])
|
144
|
+
# else
|
145
|
+
# @data = 'nada'
|
146
|
+
# end
|
147
|
+
# erb :data
|
148
|
+
# end
|
149
|
+
|
150
|
+
# error 401 do
|
151
|
+
# 'Access forbidden'
|
152
|
+
# end
|
153
|
+
# debug pages --------------------
|
144
154
|
|
145
155
|
not_found do
|
146
156
|
erb :not_found, layout: :_layout
|
147
157
|
end
|
148
158
|
|
149
|
-
error 401 do
|
150
|
-
'Access forbidden'
|
151
|
-
end
|
152
159
|
|
153
160
|
end
|
154
161
|
end
|
data/lib/hieraviz/auth_gitlab.rb
CHANGED
@@ -13,28 +13,28 @@ module Hieraviz
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def access_token(request, code)
|
16
|
-
@@client.auth_code.get_token(code, :redirect_uri => redirect_uri(request))
|
16
|
+
@@client.auth_code.get_token(code, :redirect_uri => redirect_uri(request.url))
|
17
17
|
end
|
18
18
|
|
19
19
|
def get_response(url, token)
|
20
|
-
|
20
|
+
a_token = OAuth2::AccessToken.new(@@client, token)
|
21
21
|
begin
|
22
|
-
JSON.parse(
|
22
|
+
JSON.parse(a_token.get(url).body)
|
23
23
|
rescue Exception => e
|
24
24
|
{ 'error' => JSON.parse(e.message.split(/\n/)[1])['message'] }
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
uri = URI.parse(request.url)
|
28
|
+
def redirect_uri(url)
|
29
|
+
uri = URI.parse(url)
|
31
30
|
uri.path = '/logged-in'
|
32
31
|
uri.query = nil
|
32
|
+
uri.fragment = nil
|
33
33
|
uri.to_s
|
34
34
|
end
|
35
35
|
|
36
36
|
def login_url(request)
|
37
|
-
@@client.auth_code.authorize_url(:redirect_uri => redirect_uri(request))
|
37
|
+
@@client.auth_code.authorize_url(:redirect_uri => redirect_uri(request.url))
|
38
38
|
end
|
39
39
|
|
40
40
|
def authorized?(token)
|
data/lib/hieraviz.rb
CHANGED
data/spec/app/apiv1_spec.rb
CHANGED
@@ -3,12 +3,180 @@ require 'sinatra_helper'
|
|
3
3
|
|
4
4
|
describe HieravizApp::ApiV1 do
|
5
5
|
|
6
|
-
context "
|
7
|
-
|
8
|
-
|
6
|
+
context "page not found" do
|
7
|
+
describe "GET /v1/blahblah" do
|
8
|
+
let(:expected) { { 'error' => "data not found" } }
|
9
|
+
before do
|
10
|
+
get '/blahblah'
|
11
|
+
end
|
12
|
+
it { expect(last_response).not_to be_ok }
|
13
|
+
it { expect(JSON.parse last_response.body).to eq expected }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when no creds" do
|
18
|
+
describe "GET /v1/nodes" do
|
19
|
+
let(:expected) { 'http://example.org/v1/not_logged' }
|
20
|
+
before do
|
9
21
|
get '/nodes'
|
10
|
-
expect(last_response).not_to be_ok
|
11
22
|
end
|
23
|
+
it { expect(last_response).not_to be_ok }
|
24
|
+
it { expect(last_response.header['Location']).to eq expected }
|
25
|
+
end
|
26
|
+
describe 'GET /v1/not_logged' do
|
27
|
+
let(:expected) { { 'error' => "Not connected." } }
|
28
|
+
before do
|
29
|
+
get '/not_logged'
|
30
|
+
end
|
31
|
+
it { expect(last_response).to be_ok }
|
32
|
+
it { expect(JSON.parse last_response.body).to eq expected }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "with creds but no perms" do
|
37
|
+
describe "GET /v1/nodes" do
|
38
|
+
let(:expected) { 'http://example.org/v1/unauthorized' }
|
39
|
+
before do
|
40
|
+
current_session.rack_session[:access_token] = 'sada'
|
41
|
+
allow(Hieraviz::Store).
|
42
|
+
to receive(:get).
|
43
|
+
with('sada', 3600).
|
44
|
+
and_return(false)
|
45
|
+
get '/nodes'
|
46
|
+
end
|
47
|
+
it { expect(last_response).not_to be_ok }
|
48
|
+
it { expect(last_response.header['Location']).to eq expected }
|
49
|
+
end
|
50
|
+
describe 'GET /v1/unauthorized' do
|
51
|
+
let(:expected) { { 'error' => "Unauthorized" } }
|
52
|
+
before do
|
53
|
+
get '/unauthorized'
|
54
|
+
end
|
55
|
+
it { expect(last_response).to be_ok }
|
56
|
+
it { expect(JSON.parse last_response.body).to eq expected }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "with proper creds" do
|
61
|
+
before do
|
62
|
+
current_session.rack_session[:access_token] = 'sada'
|
63
|
+
allow(Hieraviz::Store).
|
64
|
+
to receive(:get).
|
65
|
+
with('sada', 3600).
|
66
|
+
and_return({})
|
67
|
+
end
|
68
|
+
describe "GET /v1/nodes" do
|
69
|
+
let(:expected) { ['node1.example.com'] }
|
70
|
+
before do
|
71
|
+
get '/nodes'
|
72
|
+
end
|
73
|
+
it { expect(last_response).to be_ok }
|
74
|
+
it { expect(JSON.parse last_response.body).to eq expected }
|
75
|
+
end
|
76
|
+
describe "GET /v1/node/node1.example.com/info" do
|
77
|
+
let(:expected) {
|
78
|
+
{
|
79
|
+
'classes' => ['farm1'],
|
80
|
+
'country' => 'fr',
|
81
|
+
'datacenter' => 'equinix',
|
82
|
+
'farm' => 'dev',
|
83
|
+
'fqdn' => 'node1.example.com'
|
84
|
+
}
|
85
|
+
}
|
86
|
+
before do
|
87
|
+
get '/node/node1.example.com/info'
|
88
|
+
end
|
89
|
+
it { expect(last_response).to be_ok }
|
90
|
+
it { expect(JSON.parse last_response.body).to eq expected }
|
91
|
+
end
|
92
|
+
describe "GET /v1/node/node1.example.com/params" do
|
93
|
+
let(:expected) {
|
94
|
+
{
|
95
|
+
"param1.subparam1" => {
|
96
|
+
"value" => "value1",
|
97
|
+
"file" => "params/nodes/node1.example.com.yaml",
|
98
|
+
"overriden" => false,
|
99
|
+
"found_in" => [
|
100
|
+
{
|
101
|
+
"value"=>"value1",
|
102
|
+
"file"=>"params/nodes/node1.example.com.yaml"
|
103
|
+
}
|
104
|
+
]
|
105
|
+
}
|
106
|
+
}
|
107
|
+
}
|
108
|
+
before do
|
109
|
+
get '/node/node1.example.com/params'
|
110
|
+
end
|
111
|
+
it { expect(last_response).to be_ok }
|
112
|
+
it { expect(JSON.parse last_response.body).to eq expected }
|
113
|
+
end
|
114
|
+
describe "GET /v1/node/node1.example.com" do
|
115
|
+
let(:expected) {
|
116
|
+
{
|
117
|
+
"param1.subparam1" => {
|
118
|
+
"value" => "value1",
|
119
|
+
"file" => "params/nodes/node1.example.com.yaml",
|
120
|
+
"overriden" => false,
|
121
|
+
"found_in" => [
|
122
|
+
{
|
123
|
+
"value"=>"value1",
|
124
|
+
"file"=>"params/nodes/node1.example.com.yaml"
|
125
|
+
}
|
126
|
+
]
|
127
|
+
}
|
128
|
+
}
|
129
|
+
}
|
130
|
+
before do
|
131
|
+
get '/node/node1.example.com'
|
132
|
+
end
|
133
|
+
it { expect(last_response).to be_ok }
|
134
|
+
it { expect(JSON.parse last_response.body).to eq expected }
|
135
|
+
end
|
136
|
+
describe "GET /v1/node/node1.example.com/allparams" do
|
137
|
+
let(:expected) {
|
138
|
+
{
|
139
|
+
"param1.subparam1" => {
|
140
|
+
"value" => "value1",
|
141
|
+
"file" => "-",
|
142
|
+
"overriden" => true,
|
143
|
+
"found_in" => [
|
144
|
+
{
|
145
|
+
"value" => "value1",
|
146
|
+
"file" => "params/nodes/node1.example.com.yaml"
|
147
|
+
},
|
148
|
+
{
|
149
|
+
"value" => "value common",
|
150
|
+
"file"=>"params/common/common.yaml"
|
151
|
+
}
|
152
|
+
]
|
153
|
+
},
|
154
|
+
"param2.subparam2" => {
|
155
|
+
"value" => "another value",
|
156
|
+
"file"=>"params/common/common.yaml",
|
157
|
+
"overriden" => false,
|
158
|
+
"found_in" => [
|
159
|
+
{
|
160
|
+
"value" => "another value",
|
161
|
+
"file"=>"params/common/common.yaml"
|
162
|
+
}
|
163
|
+
]
|
164
|
+
}
|
165
|
+
}
|
166
|
+
}
|
167
|
+
before do
|
168
|
+
get '/node/node1.example.com/allparams'
|
169
|
+
end
|
170
|
+
it { expect(last_response).to be_ok }
|
171
|
+
it { expect(JSON.parse last_response.body).to eq expected }
|
172
|
+
end
|
173
|
+
describe "GET /v1/farms" do
|
174
|
+
let(:expected) { ['farm1'] }
|
175
|
+
before do
|
176
|
+
get '/farms'
|
177
|
+
end
|
178
|
+
it { expect(last_response).to be_ok }
|
179
|
+
it { expect(JSON.parse last_response.body).to eq expected }
|
12
180
|
end
|
13
181
|
end
|
14
182
|
|
data/spec/app/web_spec.rb
CHANGED
@@ -3,11 +3,48 @@ require 'sinatra_helper'
|
|
3
3
|
|
4
4
|
describe HieravizApp::Web do
|
5
5
|
|
6
|
-
context "
|
7
|
-
|
8
|
-
get '/'
|
9
|
-
expect(last_response.status).to
|
6
|
+
context "without creds" do
|
7
|
+
describe "GET /" do
|
8
|
+
before { get '/' }
|
9
|
+
it { expect(last_response.status).to eq 401 }
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
+
context "with proper creds" do
|
14
|
+
before do
|
15
|
+
basic_authorize 'toto', 'toto'
|
16
|
+
end
|
17
|
+
describe "GET /" do
|
18
|
+
before { get '/' }
|
19
|
+
it { expect(last_response.status).to eq 200 }
|
20
|
+
it { expect(last_response.body).to include 'Welcome to hieraviz' }
|
21
|
+
end
|
22
|
+
describe "GET /logout" do
|
23
|
+
before { get '/logout' }
|
24
|
+
it { expect(last_response.body).to include 'Please login again' }
|
25
|
+
end
|
26
|
+
describe "GET /nodes" do
|
27
|
+
before { get '/nodes' }
|
28
|
+
it { expect(last_response.body).to include 'node1.example.com' }
|
29
|
+
end
|
30
|
+
describe "GET /farms" do
|
31
|
+
before { get '/farms' }
|
32
|
+
it { expect(last_response.body).to include 'farm1' }
|
33
|
+
end
|
34
|
+
describe "GET /modules" do
|
35
|
+
before { get '/modules' }
|
36
|
+
it { expect(last_response.body).to include 'Work In Progress' }
|
37
|
+
end
|
38
|
+
describe "GET /resources" do
|
39
|
+
before { get '/resources' }
|
40
|
+
it { expect(last_response.body).to include 'Work In Progress' }
|
41
|
+
end
|
42
|
+
describe "GET /toto" do
|
43
|
+
before { get '/toto' }
|
44
|
+
it { expect(last_response.status).to eq 404 }
|
45
|
+
it { expect(last_response.body).to include 'Page not found' }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
|
13
50
|
end
|
data/spec/files/config.yml
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
---
|
2
|
+
app_name: HieraViz
|
2
3
|
basepath: "spec/files/puppet"
|
3
4
|
classpath: "farm_modules/%s/manifests/init.pp"
|
4
5
|
hierafile: "hiera.yml"
|
5
6
|
session_seed: "toto"
|
6
7
|
tmpdir: "spec/files/tmp"
|
8
|
+
session_renew: 3600
|
7
9
|
usedb: false
|
10
|
+
debug: false
|
8
11
|
puppetdb:
|
9
12
|
usessl: false
|
10
13
|
host: puppetdb.example.com
|
@@ -0,0 +1,25 @@
|
|
1
|
+
---
|
2
|
+
app_name: HieraViz
|
3
|
+
basepath: "spec/files/puppet"
|
4
|
+
classpath: "farm_modules/%s/manifests/init.pp"
|
5
|
+
hierafile: "hiera.yml"
|
6
|
+
session_seed: "toto"
|
7
|
+
tmpdir: "spec/files/tmp"
|
8
|
+
session_renew: 3600
|
9
|
+
usedb: false
|
10
|
+
debug: false
|
11
|
+
puppetdb:
|
12
|
+
usessl: false
|
13
|
+
host: puppetdb.example.com
|
14
|
+
port: 8080
|
15
|
+
auth_method: gitlab
|
16
|
+
http_auth:
|
17
|
+
username: 'toto'
|
18
|
+
password: 'toto'
|
19
|
+
gitlab_auth:
|
20
|
+
host: https://gitlab.example.com
|
21
|
+
application_id: xxxid
|
22
|
+
secret: xxxsecret
|
23
|
+
resource_required: '/api/v3/projects/group%2Fpuppet'
|
24
|
+
required_response_key: 'id'
|
25
|
+
required_response_value: '42'
|
@@ -1,26 +1,72 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'oauth2_helper'
|
2
3
|
|
3
4
|
describe Hieraviz::AuthGitlab do
|
4
5
|
|
6
|
+
let(:oauth2) { Hieraviz::AuthGitlab.new({}) }
|
7
|
+
before do
|
8
|
+
allow(OAuth2::Client).
|
9
|
+
to receive(:new).
|
10
|
+
and_return(Oauth2Mock.new)
|
11
|
+
end
|
12
|
+
|
5
13
|
describe '.new' do
|
14
|
+
it { expect(oauth2).to be_a Hieraviz::AuthGitlab }
|
6
15
|
end
|
7
16
|
|
8
17
|
describe '.access_token' do
|
18
|
+
it { expect(oauth2.access_token(RequestMock.new, 'code')).to eq '123456' }
|
9
19
|
end
|
10
20
|
|
11
21
|
describe '.get_response' do
|
22
|
+
let(:url) { 'http://example.com/something' }
|
23
|
+
let(:token) { '123456' }
|
24
|
+
let(:urlfail) { 'fail' }
|
25
|
+
let(:expected) {
|
26
|
+
{
|
27
|
+
"somekey" => "somevalue"
|
28
|
+
}
|
29
|
+
}
|
30
|
+
let(:expectedfail) {
|
31
|
+
{
|
32
|
+
"error" => "message"
|
33
|
+
}
|
34
|
+
}
|
35
|
+
before do
|
36
|
+
allow(OAuth2::AccessToken).
|
37
|
+
to receive(:new).
|
38
|
+
and_return(AccessTokenMock.new)
|
39
|
+
end
|
40
|
+
context "when there is an error" do
|
41
|
+
it { expect(oauth2.get_response(urlfail, token)).to eq expectedfail }
|
42
|
+
end
|
43
|
+
context "when everything is fine" do
|
44
|
+
it { expect(oauth2.get_response(url, token)).to eq expected }
|
45
|
+
end
|
12
46
|
end
|
13
47
|
|
14
48
|
describe '.redirect_uri' do
|
49
|
+
let(:url) { 'http://example.com/something?var=value#hash' }
|
50
|
+
let(:expected) { 'http://example.com/logged-in' }
|
51
|
+
it { expect(oauth2.redirect_uri(url)).to eq expected }
|
15
52
|
end
|
16
53
|
|
17
54
|
describe '.login_url' do
|
55
|
+
it { expect(oauth2.login_url(RequestMock.new)).to eq 'authorize url' }
|
18
56
|
end
|
19
57
|
|
20
58
|
describe '.authorized?' do
|
21
59
|
end
|
22
60
|
|
23
61
|
describe '.user_info' do
|
62
|
+
let(:token) { '123456' }
|
63
|
+
let(:expected) { { "somekey" => "somevalue" } }
|
64
|
+
before do
|
65
|
+
allow(OAuth2::AccessToken).
|
66
|
+
to receive(:new).
|
67
|
+
and_return(AccessTokenMock.new)
|
68
|
+
end
|
69
|
+
it { expect(oauth2.user_info(token)).to eq expected }
|
24
70
|
end
|
25
71
|
|
26
72
|
end
|
data/spec/lib/config_spec.rb
CHANGED
@@ -2,6 +2,10 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Hieraviz::Config do
|
4
4
|
|
5
|
+
before do
|
6
|
+
ENV['HIERAVIZ_CONFIG_FILE'] = File.expand_path '../../files/config.yml', __FILE__
|
7
|
+
end
|
8
|
+
|
5
9
|
describe '.load' do
|
6
10
|
let(:expected) { "spec/files/puppet" }
|
7
11
|
it { expect(Hieraviz::Config.load['basepath']).to eq expected }
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class AuthCodeMock
|
2
|
+
def authorize_url(args)
|
3
|
+
'authorize url'
|
4
|
+
end
|
5
|
+
def get_token(code, args)
|
6
|
+
'123456'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class RequestMock
|
11
|
+
def body
|
12
|
+
'{"somekey":"somevalue"}'
|
13
|
+
end
|
14
|
+
def url
|
15
|
+
'http://example.com'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class AccessTokenMock
|
20
|
+
def get(url)
|
21
|
+
raise "\n{\"message\":\"message\"}" if url == 'fail'
|
22
|
+
RequestMock.new
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class Oauth2Mock
|
27
|
+
attr_reader :auth_code
|
28
|
+
def initialize(*args)
|
29
|
+
@auth_code = AuthCodeMock.new
|
30
|
+
end
|
31
|
+
end
|
data/spec/sinatra_helper.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -23,7 +23,7 @@ require 'rack/test'
|
|
23
23
|
require 'rspec'
|
24
24
|
|
25
25
|
ENV['RACK_ENV'] = 'test'
|
26
|
-
ENV['HIERAVIZ_CONFIG_FILE'] = File.expand_path '../files/config.yml', __FILE__
|
26
|
+
# ENV['HIERAVIZ_CONFIG_FILE'] = File.expand_path '../files/config.yml', __FILE__
|
27
27
|
|
28
28
|
require 'hieraviz'
|
29
29
|
|
@@ -33,3 +33,20 @@ RSpec.configure do |config|
|
|
33
33
|
c.syntax = :expect
|
34
34
|
end
|
35
35
|
end
|
36
|
+
|
37
|
+
module Rack
|
38
|
+
module Test
|
39
|
+
class Session
|
40
|
+
alias_method :old_env_for, :env_for
|
41
|
+
def rack_session
|
42
|
+
@rack_session ||= {}
|
43
|
+
end
|
44
|
+
def rack_session=(hash)
|
45
|
+
@rack_session = hash
|
46
|
+
end
|
47
|
+
def env_for(path, env)
|
48
|
+
old_env_for(path, env).merge({'rack.session' => rack_session})
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
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.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mose
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dotenv
|
@@ -255,16 +255,18 @@ files:
|
|
255
255
|
- spec/app/apiv1_spec.rb
|
256
256
|
- spec/app/web_spec.rb
|
257
257
|
- spec/files/config.yml
|
258
|
+
- spec/files/config_gitlab.yml
|
258
259
|
- spec/files/hiera.yml
|
259
260
|
- spec/files/puppet/enc/node1.example.com.yaml
|
260
261
|
- spec/files/puppet/farm_modules/farm1/manifests/init.pp
|
261
262
|
- spec/files/puppet/hiera.yml
|
262
263
|
- spec/files/puppet/modules/module1/init.pp
|
263
|
-
- spec/files/puppet/params/common/common.
|
264
|
+
- spec/files/puppet/params/common/common.yaml
|
264
265
|
- spec/files/puppet/params/nodes/node1.example.com.yaml
|
265
266
|
- spec/lib/auth_gitlab_spec.rb
|
266
267
|
- spec/lib/config_spec.rb
|
267
268
|
- spec/lib/store_spec.rb
|
269
|
+
- spec/oauth2_helper.rb
|
268
270
|
- spec/sinatra_helper.rb
|
269
271
|
- spec/spec_helper.rb
|
270
272
|
homepage: https://github.com/Gandi/hieraviz
|
@@ -293,12 +295,14 @@ signing_key:
|
|
293
295
|
specification_version: 4
|
294
296
|
summary: Web and API server for accessing Puppet dev and prod data.
|
295
297
|
test_files:
|
298
|
+
- spec/oauth2_helper.rb
|
296
299
|
- spec/spec_helper.rb
|
297
300
|
- spec/app/apiv1_spec.rb
|
298
301
|
- spec/app/web_spec.rb
|
302
|
+
- spec/files/config_gitlab.yml
|
299
303
|
- spec/files/hiera.yml
|
300
304
|
- spec/files/config.yml
|
301
|
-
- spec/files/puppet/params/common/common.
|
305
|
+
- spec/files/puppet/params/common/common.yaml
|
302
306
|
- spec/files/puppet/params/nodes/node1.example.com.yaml
|
303
307
|
- spec/files/puppet/enc/node1.example.com.yaml
|
304
308
|
- spec/files/puppet/farm_modules/farm1/manifests/init.pp
|