Class: Thrift::SaslClientTransport

Inherits:
BufferedTransport
  • Object
show all
Defined in:
lib/thrift/sasl_client_transport.rb

Constant Summary collapse

STATUS_BYTES =
1
PAYLOAD_LENGTH_BYTES =
4
AUTH_MECHANISM =
'PLAIN'
NEGOTIATION_STATUS =
{
  START:    0x01,
  OK:       0x02,
  BAD:      0x03,
  ERROR:    0x04,
  COMPLETE: 0x05
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(transport, sasl_params = {}) ⇒ SaslClientTransport

Returns a new instance of SaslClientTransport



16
17
18
19
20
21
# File 'lib/thrift/sasl_client_transport.rb', line 16

def initialize(transport, sasl_params={})
  super(transport)
  @challenge = nil
  @sasl_username = sasl_params.fetch(:username, 'anonymous')
  @sasl_password = sasl_params.fetch(:password, 'anonymous')
end

Instance Attribute Details

#challengeObject (readonly)

Returns the value of attribute challenge



3
4
5
# File 'lib/thrift/sasl_client_transport.rb', line 3

def challenge
  @challenge
end

Instance Method Details

#read(sz) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/thrift/sasl_client_transport.rb', line 23

def read(sz)
  len, = @transport.read(PAYLOAD_LENGTH_BYTES).unpack('l>') if @rbuf.nil?
  sz = len if len && sz > len
  @index += sz
  ret = @rbuf.slice(@index - sz, sz) || Bytes.empty_byte_buffer
  if ret.length == 0
    @rbuf = @transport.read(len) rescue Bytes.empty_byte_buffer
    @index = sz
    ret = @rbuf.slice(0, sz) || Bytes.empty_byte_buffer
  end
  ret
end

#read_byteObject



36
37
38
39
40
# File 'lib/thrift/sasl_client_transport.rb', line 36

def read_byte
  reset_buffer! if @index >= @rbuf.size
  @index += 1
  Bytes.get_string_byte(@rbuf, @index - 1)
end

#read_into_buffer(buffer, size) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/thrift/sasl_client_transport.rb', line 42

def read_into_buffer(buffer, size)
  i = 0
  while i < size
    reset_buffer! if @index >= @rbuf.size
    byte = Bytes.get_string_byte(@rbuf, @index)
    Bytes.set_string_byte(buffer, i, byte)
    @index += 1
    i += 1
  end
  i
end

#write(buf) ⇒ Object



54
55
56
57
58
# File 'lib/thrift/sasl_client_transport.rb', line 54

def write(buf)
  initiate_hand_shake if @challenge.nil?
  header = [buf.length].pack('l>')
  @wbuf << (header + Bytes.force_binary_encoding(buf))
end