-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,14 +53,30 @@ def to_msg_hash | |
# @example | ||
# Hawkular::Operations::OperationsClient.new(credentials: {username: 'jdoe', password: 'password'}) | ||
def initialize(args) | ||
ep = args[:entrypoint] | ||
|
||
unless ep.nil? | ||
This comment has been minimized.
Sorry, something went wrong. |
||
uri = URI.parse ep | ||
args[:host] ||= "#{uri.host}:#{uri.port}" | ||
This comment has been minimized.
Sorry, something went wrong.
abonas
|
||
end | ||
|
||
args[:host] ||= 'localhost:8080' | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
args[:credentials] ||= {} | ||
args[:options] ||= {} | ||
args[:wait_time] ||= 0.5 | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
super(args[:host], args[:credentials], args[:options]) | ||
# note: if we start using the secured WS, change the protocol to wss:// | ||
url = "ws://#{entrypoint}/hawkular/command-gateway/ui/ws" | ||
@ws = Simple.connect url do |client| | ||
url = "ws://#{args[:host]}/hawkular/command-gateway/ui/ws" | ||
ws_options = {} | ||
creds = args[:credentials] | ||
incoming_opts = args[:options] | ||
This comment has been minimized.
Sorry, something went wrong.
abonas
|
||
ws_options[:headers] = { 'Authorization' => 'Basic ' + | ||
["#{creds[:username]}:#{creds[:password]}"].pack('m').delete("\r\n"), | ||
'Hawkular-Tenant' => incoming_opts[:tenant], | ||
'Accept' => 'application/json' | ||
} | ||
|
||
@ws = Simple.connect url, ws_options do |client| | ||
client.on(:message, once: true) do |msg| | ||
parsed_message = msg.data.to_msg_hash | ||
puts parsed_message if ENV['HAWKULARCLIENT_LOG_RESPONSE'] | ||
This comment has been minimized.
Sorry, something went wrong.
abonas
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,22 +14,47 @@ module Hawkular::Operations::RSpec | |
end | ||
|
||
it 'should be established' do | ||
WebSocketVCR.configure do |c| | ||
c.hook_uris = [HOST] | ||
end | ||
# WebSocketVCR.configure do |c| | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
pilhuhn
Author
Owner
|
||
# c.hook_uris = [HOST] | ||
# end | ||
|
||
WebSocketVCR.record(example, self) do | ||
# WebSocketVCR.record(example, self) do | ||
client = OperationsClient.new(host: HOST, | ||
wait_time: WebSocketVCR.live? ? 1.5 : 0, | ||
credentials: { | ||
username: 'jdoe', | ||
password: 'password' | ||
}, | ||
options: { | ||
tenant: 'hawkular' | ||
}) | ||
ws = client.ws | ||
expect(ws).not_to be nil | ||
expect(ws.open?).to be true | ||
end | ||
end | ||
# end | ||
end | ||
|
||
it 'should be established2' do | ||
# WebSocketVCR.configure do |c| | ||
# c.hook_uris = [HOST] | ||
# end | ||
|
||
# WebSocketVCR.record(example, self) do | ||
ep = URI::HTTP.build(:host => 'acme.org', :port => 42).to_s | ||
This comment has been minimized.
Sorry, something went wrong.
pilhuhn
Author
Owner
|
||
client = OperationsClient.new(entrypoint: ep, | ||
wait_time: WebSocketVCR.live? ? 1.5 : 0, | ||
credentials: { | ||
username: 'jdoe', | ||
password: 'password' | ||
}, | ||
options: { | ||
tenant: 'hawkular' | ||
}) | ||
ws = client.ws | ||
expect(ws).not_to be nil | ||
expect(ws.open?).to be true | ||
# end | ||
end | ||
end | ||
|
||
describe 'Operation/Operation', :websocket, vcr: { decode_compressed_response: true } do | ||
|
I wonder why the client doesn't accept uri type in the first place, because right now the callers are doing construct uri.to_s, and then here it is transformed back to be uri.