Class: Hexspace::SaslTransport

Inherits:
Thrift::FramedTransport
  • Object
show all
Defined in:
lib/hexspace/sasl_transport.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(transport, **options) ⇒ SaslTransport

Returns a new instance of SaslTransport.



5
6
7
8
# File 'lib/hexspace/sasl_transport.rb', line 5

def initialize(transport, **options)
  super(transport)
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/hexspace/sasl_transport.rb', line 3

def options
  @options
end

Instance Method Details

#openObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/hexspace/sasl_transport.rb', line 10

def open
  super

  step = [options[:authzid], options[:username], options[:password]].map(&:to_s).join("\x00".b)

  write_sasl("\x01", "PLAIN")
  write_sasl("\x02", step)

  resp = @transport.read(5)
  case resp[0]
  when "\x03"
    len = resp[1..-1].unpack1("N")
    raise Error, @transport.read(len)
  when "\x05"
    # success
  else
    raise Error, "Unknown response: #{resp.inspect}"
  end
end

#write_sasl(status, body) ⇒ Object



30
31
32
33
# File 'lib/hexspace/sasl_transport.rb', line 30

def write_sasl(status, body)
  @transport.write("#{status}#{[body.bytesize].pack("N")}#{body}")
  @transport.flush
end