logstash-output-monasca_log_api 0.3.3 → 0.4
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/LICENSE +9 -7
- data/README.md +82 -40
- data/lib/logstash/outputs/helper/url_helper.rb +15 -14
- data/lib/logstash/outputs/keystone/keystone_client.rb +49 -20
- data/lib/logstash/outputs/keystone/token.rb +47 -18
- data/lib/logstash/outputs/monasca/monasca_log_api_client.rb +32 -39
- data/lib/logstash/outputs/monasca_log_api.rb +159 -77
- data/logstash-output-monasca_log_api.gemspec +5 -4
- data/spec/outputs/helper/url_helper_spec.rb +27 -18
- data/spec/outputs/keystone/keystone_client_spec.rb +127 -39
- data/spec/outputs/keystone/token_spec.rb +31 -26
- data/spec/outputs/monasca/monasca_log_api_client_spec.rb +80 -0
- data/spec/outputs/monasca_log_api_spec.rb +433 -0
- data/spec/outputs/spec_helper.rb +13 -13
- metadata +26 -12
- data/spec/outputs/monasca/monasca_api_client_spec.rb +0 -105
- data/spec/outputs/monasca_api_spec.rb +0 -131
@@ -1,26 +1,29 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
|
9
|
-
Unless required by applicable law or agreed to in writing, software
|
10
|
-
is distributed on an "AS IS" BASIS, WITHOUT
|
11
|
-
|
12
|
-
the
|
13
|
-
|
1
|
+
# Copyright 2016 FUJITSU LIMITED
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
4
|
+
# use this file except in compliance with the License. You may obtain a copy of
|
5
|
+
# the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
11
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
12
|
+
# License for the specific language governing permissions and limitations under
|
13
|
+
# the License.
|
14
14
|
|
15
15
|
# encoding: utf-8
|
16
16
|
|
17
17
|
require 'logstash/outputs/base'
|
18
18
|
require 'logstash/namespace'
|
19
|
+
require 'logstash/codecs/base'
|
19
20
|
require 'vine'
|
21
|
+
require 'thread'
|
20
22
|
|
21
23
|
# relative requirements
|
22
24
|
require_relative 'monasca/monasca_log_api_client'
|
23
25
|
require_relative 'keystone/keystone_client'
|
26
|
+
require_relative 'keystone/token'
|
24
27
|
|
25
28
|
# This Logstash Output plugin, sends events to monasca-api.
|
26
29
|
# It authenticates against keystone and gets a token.
|
@@ -28,107 +31,186 @@ require_relative 'keystone/keystone_client'
|
|
28
31
|
class LogStash::Outputs::MonascaLogApi < LogStash::Outputs::Base
|
29
32
|
config_name 'monasca_log_api'
|
30
33
|
|
31
|
-
# monasca-api
|
34
|
+
# monasca-log-api configuration
|
32
35
|
config :monasca_log_api, :validate => :string, :required => true
|
33
|
-
config :monasca_log_api_version, :validate => :string, :required => false,
|
36
|
+
config :monasca_log_api_version, :validate => :string, :required => false,
|
37
|
+
:default => "v3.0"
|
34
38
|
|
35
|
-
# keystone
|
39
|
+
# keystone configuration
|
36
40
|
config :keystone_api, :validate => :string, :required => true
|
37
|
-
# keystone user configuration
|
38
41
|
config :project_name, :validate => :string, :required => true
|
39
42
|
config :username, :validate => :string, :required => true
|
40
43
|
config :password, :validate => :string, :required => true
|
41
44
|
config :domain_id, :validate => :string, :required => true
|
42
45
|
|
43
|
-
|
44
|
-
config :
|
46
|
+
# global dimensions
|
47
|
+
config :dimensions, :validate => :array, :required => false
|
45
48
|
|
46
|
-
|
49
|
+
config :num_of_logs, :validate => :number, :default => 125
|
50
|
+
config :elapsed_time_sec, :validate => :number, :default => 30
|
51
|
+
config :delay, :validate => :number, :default => 10
|
52
|
+
config :max_data_size_kb, :validate => :number, :default => 5120
|
53
|
+
|
54
|
+
attr_accessor :time_thread, :start_time, :logs
|
47
55
|
|
48
56
|
default :codec, 'json'
|
49
57
|
|
58
|
+
JSON_LOGS = 'logs'
|
59
|
+
JSON_DIMS = 'dimensions'
|
60
|
+
|
50
61
|
public
|
51
62
|
def register
|
52
|
-
@
|
53
|
-
@
|
54
|
-
|
55
|
-
|
56
|
-
|
63
|
+
@mutex = Mutex.new
|
64
|
+
@logger.info('Registering keystone user',
|
65
|
+
:username => username, :project_name => project_name)
|
66
|
+
@monasca_log_api_client = LogStash::Outputs::Monasca::MonascaLogApiClient
|
67
|
+
.new monasca_log_api, monasca_log_api_version
|
68
|
+
@logs = Hash.new
|
69
|
+
@start_time = nil
|
70
|
+
init_token
|
71
|
+
initialize_logs_object
|
72
|
+
start_time_check
|
73
|
+
end
|
57
74
|
|
58
|
-
|
59
|
-
|
60
|
-
|
75
|
+
def multi_receive(events)
|
76
|
+
@logger.debug("Retrieving #{events.size} events")
|
77
|
+
events.each do |event|
|
78
|
+
encode(event)
|
61
79
|
end
|
80
|
+
end
|
62
81
|
|
63
|
-
|
82
|
+
def close
|
83
|
+
stop_time_check
|
84
|
+
end
|
64
85
|
|
65
|
-
|
66
|
-
return unless output?(event)
|
67
|
-
if event == LogStash::SHUTDOWN
|
68
|
-
finished
|
69
|
-
return
|
70
|
-
end
|
71
|
-
@codec.encode(event)
|
72
|
-
end # def receive
|
86
|
+
private
|
73
87
|
|
74
|
-
def
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
end
|
79
|
-
if @plugin_state != :finished
|
80
|
-
@logger.info('Plugin is finished', :plugin => self.class.config_name)
|
81
|
-
@plugin_state = :finished
|
82
|
-
end
|
88
|
+
def init_token
|
89
|
+
token = LogStash::Outputs::Keystone::Token.instance
|
90
|
+
token.set_keystone_client(keystone_api)
|
91
|
+
check_token
|
83
92
|
end
|
84
93
|
|
85
|
-
def
|
86
|
-
|
87
|
-
|
94
|
+
def encode(event)
|
95
|
+
log = generate_log_from_event(event)
|
96
|
+
|
97
|
+
log_bytesize = bytesize_of(log)
|
98
|
+
logs_bytesize = bytesize_of(@logs)
|
99
|
+
|
100
|
+
# if new log would exceed the bytesize then send logs without the new log
|
101
|
+
if @logs[JSON_LOGS] and (logs_bytesize + log_bytesize) > max_data_size_kb
|
102
|
+
@logger.debug("bytesize reached. Sending logs")
|
103
|
+
@mutex.synchronize do
|
104
|
+
send_logs
|
105
|
+
add_log log
|
106
|
+
end
|
107
|
+
return
|
108
|
+
|
109
|
+
# if the new log would reach the maximum bytesize or the maximum allowed
|
110
|
+
# number of sendable logs is reached
|
111
|
+
elsif @logs[JSON_LOGS] and (@logs[JSON_LOGS].size + 1 >= num_of_logs)
|
112
|
+
@logger.debug("bytesize or maximum number of logs reached. Sending logs")
|
113
|
+
@mutex.synchronize do
|
114
|
+
add_log log
|
115
|
+
send_logs
|
116
|
+
end
|
117
|
+
return
|
88
118
|
|
89
|
-
|
90
|
-
if @plugin_state == :finished
|
91
|
-
finished
|
119
|
+
# still free space to collect logs
|
92
120
|
else
|
93
|
-
@
|
121
|
+
@mutex.synchronize do
|
122
|
+
add_log log
|
123
|
+
end
|
124
|
+
return
|
94
125
|
end
|
95
126
|
end
|
96
127
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
128
|
+
def generate_log_from_event(event)
|
129
|
+
message = event.to_hash['message']
|
130
|
+
path = event.to_hash['path']
|
131
|
+
local_dims = JSON.parse(event.to_hash['dimensions'].to_s) if
|
132
|
+
event.to_hash['dimensions']
|
133
|
+
type = event.to_hash['type'] if event.to_hash['type']
|
134
|
+
|
135
|
+
log = { "message" => message, "dimensions" => { "path" => path }}
|
136
|
+
log[JSON_DIMS]['type'] = type if type
|
137
|
+
if local_dims
|
138
|
+
begin
|
139
|
+
JSON.parse(local_dims[0])
|
140
|
+
local_dims.each { |dim|
|
141
|
+
parsed_dim = JSON.parse(dim)
|
142
|
+
log[JSON_DIMS][parsed_dim[0].strip] = parsed_dim[1].strip
|
143
|
+
}
|
144
|
+
rescue
|
145
|
+
log[JSON_DIMS][local_dims[0].strip] = local_dims[1].strip
|
146
|
+
end
|
103
147
|
end
|
148
|
+
log
|
104
149
|
end
|
105
150
|
|
106
|
-
def
|
107
|
-
|
151
|
+
def initialize_logs_object
|
152
|
+
if @logs.empty?
|
153
|
+
global_dims = {}
|
154
|
+
dimensions.each { |dim|
|
155
|
+
global_dims[dim.split(':')[0].strip] = dim.split(':')[1].strip
|
156
|
+
} if dimensions
|
157
|
+
@logs = {}
|
158
|
+
@logs[JSON_DIMS] = global_dims unless global_dims.empty?
|
159
|
+
@logs[JSON_LOGS] = []
|
160
|
+
end
|
108
161
|
end
|
109
162
|
|
110
|
-
def
|
163
|
+
def check_token
|
164
|
+
token = LogStash::Outputs::Keystone::Token.instance
|
165
|
+
token.request_new_token(
|
166
|
+
domain_id, username, password, project_name) unless token.valid?
|
167
|
+
end
|
111
168
|
|
112
|
-
|
113
|
-
|
114
|
-
split_key = @application_type_key.split('.')
|
115
|
-
event_value = event[split_key[0]]
|
116
|
-
access_key = split_key.slice(1..-1).join('.')
|
169
|
+
def start_time_check
|
170
|
+
@time_thread = Thread.new do
|
117
171
|
|
118
|
-
|
172
|
+
loop do
|
173
|
+
unless @start_time.nil?
|
119
174
|
|
120
|
-
|
121
|
-
|
175
|
+
if @logs[JSON_LOGS] and (@logs[JSON_LOGS].size > 0) and
|
176
|
+
((Time.now - @start_time) >= elapsed_time_sec)
|
177
|
+
@logger.debug("Time elapsed. Sending logs")
|
178
|
+
@mutex.synchronize do
|
179
|
+
send_logs
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
end
|
184
|
+
sleep delay
|
185
|
+
end
|
122
186
|
end
|
187
|
+
end
|
123
188
|
|
124
|
-
|
125
|
-
|
126
|
-
)
|
127
|
-
app_type
|
189
|
+
def stop_time_check
|
190
|
+
@time_thread.kill() if @time_thread
|
191
|
+
@logger.info('Stopped time_check thread')
|
128
192
|
end
|
129
193
|
|
130
|
-
def
|
131
|
-
|
194
|
+
def bytesize_of(entry)
|
195
|
+
entry.to_json.bytesize / 1024.0
|
196
|
+
end
|
197
|
+
|
198
|
+
def send_logs
|
199
|
+
if @logs[JSON_LOGS] and @logs[JSON_LOGS].size > 0
|
200
|
+
check_token
|
201
|
+
token_id = LogStash::Outputs::Keystone::Token.instance.id
|
202
|
+
@logger.debug("Sending #{@logs[JSON_LOGS].size} logs")
|
203
|
+
@monasca_log_api_client.send_logs(@logs, token_id)
|
204
|
+
@logs.clear
|
205
|
+
initialize_logs_object
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
def add_log log
|
210
|
+
@logs[JSON_LOGS].push(log)
|
211
|
+
if @logs[JSON_LOGS].size == 1
|
212
|
+
@start_time = Time.now
|
213
|
+
end
|
132
214
|
end
|
133
215
|
|
134
|
-
end
|
216
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'logstash-output-monasca_log_api'
|
3
|
-
s.version = '0.
|
3
|
+
s.version = '0.4'
|
4
4
|
s.licenses = ['Apache License 2.0']
|
5
5
|
s.summary = 'This gem is a logstash output plugin to connect via http to monasca-log-api.'
|
6
6
|
s.description = 'This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program'
|
@@ -19,11 +19,12 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.metadata = { 'logstash_plugin' => 'true', 'logstash_group' => 'output' }
|
20
20
|
|
21
21
|
# Gem dependencies
|
22
|
-
s.add_runtime_dependency 'logstash-core', '~>
|
23
|
-
s.add_runtime_dependency 'logstash-codec-plain', '~> 0
|
24
|
-
s.add_runtime_dependency 'logstash-codec-json', '~> 0
|
22
|
+
s.add_runtime_dependency 'logstash-core', '~> 2.0'
|
23
|
+
s.add_runtime_dependency 'logstash-codec-plain', '~> 2.0'
|
24
|
+
s.add_runtime_dependency 'logstash-codec-json', '~> 2.0'
|
25
25
|
s.add_runtime_dependency 'rest-client', '~> 1.8'
|
26
26
|
s.add_runtime_dependency 'vine', '~> 0.2'
|
27
27
|
s.add_development_dependency 'logstash-devutils', '~> 0.0.14'
|
28
28
|
s.add_development_dependency 'simplecov', '~> 0.10'
|
29
|
+
s.add_development_dependency 'rubocop', '~> 0.37.2'
|
29
30
|
end
|
@@ -1,16 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
|
9
|
-
Unless required by applicable law or agreed to in writing, software
|
10
|
-
is distributed on an "AS IS" BASIS, WITHOUT
|
11
|
-
|
12
|
-
the
|
13
|
-
|
1
|
+
# Copyright 2016 FUJITSU LIMITED
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
4
|
+
# use this file except in compliance with the License. You may obtain a copy of
|
5
|
+
# the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
11
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
12
|
+
# License for the specific language governing permissions and limitations under
|
13
|
+
# the License.
|
14
14
|
|
15
15
|
# encoding: utf-8
|
16
16
|
|
@@ -20,14 +20,23 @@ describe LogStash::Outputs::Helper::UrlHelper do
|
|
20
20
|
|
21
21
|
describe ".generate_url" do
|
22
22
|
it "generates a URI::HTTP object" do
|
23
|
-
expect(LogStash::Outputs::Helper::UrlHelper
|
23
|
+
expect(LogStash::Outputs::Helper::UrlHelper
|
24
|
+
.generate_url('http://192.168.10.5:8080', '/v2.0')).to be_a URI::HTTP
|
24
25
|
end
|
25
26
|
|
26
27
|
it "should match a http url" do
|
27
|
-
expect(LogStash::Outputs::Helper::UrlHelper
|
28
|
-
|
29
|
-
|
30
|
-
expect(LogStash::Outputs::Helper::UrlHelper
|
28
|
+
expect(LogStash::Outputs::Helper::UrlHelper
|
29
|
+
.generate_url('http://192.168.10.5:8080', '/v2.0').to_s)
|
30
|
+
.to eq('http://192.168.10.5:8080/v2.0')
|
31
|
+
expect(LogStash::Outputs::Helper::UrlHelper
|
32
|
+
.generate_url('http://est.fujitsu:40', nil).to_s)
|
33
|
+
.to eq('http://est.fujitsu:40')
|
34
|
+
expect(LogStash::Outputs::Helper::UrlHelper
|
35
|
+
.generate_url('http://est.fujitsu:80', nil).to_s)
|
36
|
+
.to eq('http://est.fujitsu')
|
37
|
+
expect(LogStash::Outputs::Helper::UrlHelper
|
38
|
+
.generate_url('https://192.168.10.5:8080', '/v2.0').to_s)
|
39
|
+
.to eq('https://192.168.10.5:8080/v2.0')
|
31
40
|
end
|
32
41
|
end
|
33
42
|
|
@@ -1,16 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
|
9
|
-
Unless required by applicable law or agreed to in writing, software
|
10
|
-
is distributed on an "AS IS" BASIS, WITHOUT
|
11
|
-
|
12
|
-
the
|
13
|
-
|
1
|
+
# Copyright 2016 FUJITSU LIMITED
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
4
|
+
# use this file except in compliance with the License. You may obtain a copy of
|
5
|
+
# the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
11
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
12
|
+
# License for the specific language governing permissions and limitations under
|
13
|
+
# the License.
|
14
14
|
|
15
15
|
# encoding: utf-8
|
16
16
|
|
@@ -18,54 +18,142 @@ require_relative '../spec_helper'
|
|
18
18
|
|
19
19
|
describe LogStash::Outputs::Keystone::KeystoneClient do
|
20
20
|
|
21
|
-
let (:
|
22
|
-
|
23
|
-
let (:
|
24
|
-
|
25
|
-
let (:
|
21
|
+
let (:valid_date) { DateTime.now + Rational(1, 1440) }
|
22
|
+
let (:token) { "f8cdafb7dce94444ad781a53ddaff693" }
|
23
|
+
let (:valid_token) { {:token => token,
|
24
|
+
:expires_at => valid_date } }
|
25
|
+
let (:domain_id) { "default" }
|
26
|
+
let (:username) { "operator" }
|
27
|
+
let (:password) { "zPrHGl<IJtn=ux;{&T/nfXh=H" }
|
28
|
+
let (:project_name) { "monasca" }
|
29
|
+
let (:auth_hash) {
|
30
|
+
{
|
31
|
+
"auth"=>{
|
32
|
+
"identity"=>{
|
33
|
+
"methods"=>["password"],
|
34
|
+
"password"=>{
|
35
|
+
"user"=>{
|
36
|
+
"domain"=>{"id"=>domain_id},
|
37
|
+
"name"=>username,
|
38
|
+
"password"=>password
|
39
|
+
}
|
40
|
+
}
|
41
|
+
},
|
42
|
+
"scope"=>{
|
43
|
+
"project"=>{
|
44
|
+
"domain"=>{"id"=>domain_id},
|
45
|
+
"name"=>project_name
|
46
|
+
}
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}.to_json
|
50
|
+
}
|
51
|
+
|
52
|
+
let (:ok_response) { stub_response(201,
|
53
|
+
{:x_subject_token => token},
|
54
|
+
{
|
55
|
+
"token"=>{
|
56
|
+
"methods"=>["password"],
|
57
|
+
"roles"=>[
|
58
|
+
{
|
59
|
+
"id"=>"9fe2ff9ee4384b1894a90878d3e92bab",
|
60
|
+
"name"=>"_member_"
|
61
|
+
},
|
62
|
+
{
|
63
|
+
"id"=>"4e9ef1ffe73446c6b02f8fce0585c307",
|
64
|
+
"name"=>"monasca-user"
|
65
|
+
}
|
66
|
+
],
|
67
|
+
"expires_at"=>valid_date.strftime("%Y-%m-%dT%H:%M:%S%z"),
|
68
|
+
"project"=>{
|
69
|
+
"domain"=>{
|
70
|
+
"id"=>"default",
|
71
|
+
"name"=>"Default"
|
72
|
+
},
|
73
|
+
"id"=>"1051bd27b9394120b26d8b08847325c0",
|
74
|
+
"name"=>project_name
|
75
|
+
},
|
76
|
+
"user"=>{
|
77
|
+
"domain"=>{
|
78
|
+
"id"=>"default",
|
79
|
+
"name"=>"Default"
|
80
|
+
},
|
81
|
+
"id"=>"06ecc9869b8e4846b2fce3e5759ba4af",
|
82
|
+
"name"=>username
|
83
|
+
},
|
84
|
+
"audit_ids"=>["ORap7R56S2S-p6tFVeMkpg"],
|
85
|
+
"issued_at"=>"2015-05-26T07:55:36.774146Z"
|
86
|
+
}
|
87
|
+
}.to_json)
|
88
|
+
}
|
89
|
+
|
90
|
+
let (:failed_response) { stub_response(401,
|
91
|
+
{:x_subject_token => ""},
|
92
|
+
{
|
93
|
+
"error"=>{
|
94
|
+
"message"=>"Could not find project: f8cdafb7dce94444ad781a53ddaff693 "\
|
95
|
+
"(Disable debug mode to suppress these details.)",
|
96
|
+
"code"=>401,
|
97
|
+
"title"=>"Unauthorized"
|
98
|
+
}
|
99
|
+
}.to_json)
|
100
|
+
}
|
26
101
|
|
27
102
|
context 'when initializing' do
|
28
103
|
it 'then it should register without exceptions' do
|
29
|
-
expect {LogStash::Outputs::Keystone::KeystoneClient.new('hostname:8080')}
|
104
|
+
expect {LogStash::Outputs::Keystone::KeystoneClient.new('hostname:8080')}
|
105
|
+
.to_not raise_error
|
30
106
|
end
|
31
107
|
|
32
108
|
it "returns a failure if arguments are missing" do
|
33
|
-
expect {LogStash::Outputs::Keystone::KeystoneClient.new}
|
109
|
+
expect {LogStash::Outputs::Keystone::KeystoneClient.new}
|
110
|
+
.to raise_exception(ArgumentError)
|
34
111
|
end
|
35
112
|
end
|
36
113
|
|
37
114
|
context 'when authenticates' do
|
38
115
|
it 'then it should request to keystone' do
|
39
116
|
expect_any_instance_of(RestClient::Resource).to receive(:post)
|
40
|
-
.with(auth_hash, :content_type => 'application/json',
|
41
|
-
|
42
|
-
|
43
|
-
keystone_client
|
117
|
+
.with(auth_hash, :content_type => 'application/json',
|
118
|
+
:accept => 'application/json').and_return(ok_response)
|
119
|
+
|
120
|
+
keystone_client = LogStash::Outputs::Keystone::KeystoneClient
|
121
|
+
.new('hostname:8080')
|
122
|
+
keystone_client.authenticate(domain_id, username, password, project_name)
|
44
123
|
end
|
45
124
|
|
46
|
-
it 'then it should
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
125
|
+
it 'then it should return a token' do
|
126
|
+
expect_any_instance_of(RestClient::Resource).to receive(:post)
|
127
|
+
.and_return(ok_response)
|
128
|
+
keystone_client = LogStash::Outputs::Keystone::KeystoneClient
|
129
|
+
.new('hostname:8080')
|
130
|
+
token = keystone_client
|
131
|
+
.authenticate(domain_id, username, password, project_name)
|
132
|
+
expect(token["token"]).to eq(valid_token["token"])
|
133
|
+
expect(token["expires_at"].to_s).to eq(valid_token["expires_at"].to_s)
|
52
134
|
end
|
53
135
|
end
|
54
136
|
|
55
137
|
context 'when authentication failed' do
|
56
|
-
it 'then it should
|
138
|
+
it 'then it should log an information' do
|
139
|
+
expect_any_instance_of(RestClient::Resource).to receive(:post)
|
140
|
+
.and_return(failed_response)
|
57
141
|
expect_any_instance_of(Cabin::Channel).to receive(:info)
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
142
|
+
|
143
|
+
keystone_client = LogStash::Outputs::Keystone::KeystoneClient
|
144
|
+
.new('hostname:8080')
|
145
|
+
keystone_client.authenticate(domain_id, username, password, project_name)
|
62
146
|
end
|
63
147
|
|
64
|
-
it 'then it should
|
148
|
+
it 'then it should return nil' do
|
149
|
+
expect_any_instance_of(RestClient::Resource).to receive(:post)
|
150
|
+
.and_return(failed_response)
|
65
151
|
expect_any_instance_of(Cabin::Channel).to receive(:info)
|
66
|
-
|
67
|
-
|
68
|
-
|
152
|
+
|
153
|
+
keystone_client = LogStash::Outputs::Keystone::KeystoneClient
|
154
|
+
.new('hostname:8080')
|
155
|
+
expect(keystone_client
|
156
|
+
.authenticate(domain_id, username, password, project_name)).to eq(nil)
|
69
157
|
end
|
70
158
|
end
|
71
159
|
|