Class: BigIPCookie::Decode

Inherits:
Object
  • Object
show all
Defined in:
lib/bigipcookie.rb

Overview

The class to decode BigIP cookies

Examples:

bip = BigIPCookie::Decode.new(
  'CustomeCookieName=vi20010112000000000000000000000030.20480'
)
bip.auto_decode(ipv6compression: 0)
bip.decoded_cookie
bip.pool_name
bip.cookie_type

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cookie) ⇒ Decode

A new instance of cookie

Parameters:

  • cookie (String)

    the raw cookie, either key/value or only the value



43
44
45
46
47
48
# File 'lib/bigipcookie.rb', line 43

def initialize(cookie)
  @raw_cookie = cookie
  @pool_name = nil
  @decoded_cookie = nil
  @cookie_type = nil
end

Instance Attribute Details

Returns the type of the cookie

Examples:

'IPv6 pool members in non-default route domains'

Returns:

  • (String)

    the type of the cookie



39
40
41
# File 'lib/bigipcookie.rb', line 39

def cookie_type
  @cookie_type
end

Returns the decoded cookie value

Examples:

'[2001:112::30%3]:80'

Returns:

  • (String)

    the decoded cookie value



34
35
36
# File 'lib/bigipcookie.rb', line 34

def decoded_cookie
  @decoded_cookie
end

#pool_nameString (readonly)

Returns the pool name

Returns:

  • (String)

    the pool name



29
30
31
# File 'lib/bigipcookie.rb', line 29

def pool_name
  @pool_name
end

Returns the raw cookie (as provided)

Examples:

'BIGipServer~SuperPool=rd3o20010112000000000000000000000030o80'

Returns:

  • (String)

    the raw cookie (as provided)



26
27
28
# File 'lib/bigipcookie.rb', line 26

def raw_cookie
  @raw_cookie
end

Instance Method Details

#auto_decode(opts = {}) ⇒ Object

Note:

.yardopts-dev must be used to get #decode_ip documentation

Automatically decode the raw cookie, detects if there is a cookie key

(custom or default) or only the value

Parameters:

  • opts (Hahs) (defaults to: {})

    see #decode_ip



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/bigipcookie.rb', line 223

def auto_decode(opts = {})
  if /\=/.match?(@raw_cookie) # if there is a key
    if /^BIGipServer/.match?(@raw_cookie) # if default cookie name
      pool_name = retrieve_pool_name
      cookie_value = /^BIGipServer.+=(.+)/.match(@raw_cookie).captures[0]
      decoded_cookie = decode_cookie(cookie_value, opts)
      @pool_name = pool_name
    else # custom cookie name
      cookie_value = /.+=(.+)/.match(@raw_cookie).captures[0]
      decoded_cookie = decode_cookie(cookie_value, opts)
      @pool_name = 'unknown'
    end
  else # cookie value only
    decoded_cookie = decode_cookie(@raw_cookie, opts)
    @pool_name = 'unknown'
  end
  @decoded_cookie = decoded_cookie
end