Class: Hyperb::AuthObject

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

Overview

helper for managing auth objects used to authenticate into third party docker registries

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ AuthObject

Returns a new instance of AuthObject.



9
10
11
12
13
14
# File 'lib/hyperb/auth_object.rb', line 9

def initialize(options = {})
  @username = options[:username] || ''
  @email = options[:email] || ''
  @serveraddress = options[:serveraddress] || ''
  @password = options[:password].is_a?(File) ? options[:password].read : options[:password]
end

Instance Attribute Details

#emailObject

Returns the value of attribute email.



7
8
9
# File 'lib/hyperb/auth_object.rb', line 7

def email
  @email
end

#passwordObject

Returns the value of attribute password.



7
8
9
# File 'lib/hyperb/auth_object.rb', line 7

def password
  @password
end

#serveraddressObject

Returns the value of attribute serveraddress.



7
8
9
# File 'lib/hyperb/auth_object.rb', line 7

def serveraddress
  @serveraddress
end

#usernameObject

Returns the value of attribute username.



7
8
9
# File 'lib/hyperb/auth_object.rb', line 7

def username
  @username
end

Instance Method Details

#attrsObject

preserve this order



17
18
19
20
21
22
23
24
# File 'lib/hyperb/auth_object.rb', line 17

def attrs
  {
    username: username,
    password: password,
    email: email,
    serveraddress: serveraddress
  }
end

#blank?(val) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/hyperb/auth_object.rb', line 30

def blank?(val)
  val.respond_to?(:empty?) ? val.empty? : !val
end

#buildObject



38
39
40
# File 'lib/hyperb/auth_object.rb', line 38

def build
  { x_registry_auth: encode }
end

#encodeObject



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

def encode
  Base64.urlsafe_encode64(attrs.to_json)
end

#valid?Boolean

Returns:

  • (Boolean)


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

def valid?
  attrs.values.none? { |atr| blank?(atr) }
end