Class: Hyperb::AuthObject
- Inherits:
-
Object
- Object
- Hyperb::AuthObject
- 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
-
#email ⇒ Object
Returns the value of attribute email.
-
#password ⇒ Object
Returns the value of attribute password.
-
#serveraddress ⇒ Object
Returns the value of attribute serveraddress.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
-
#attrs ⇒ Object
preserve this order.
- #blank?(val) ⇒ Boolean
- #build ⇒ Object
- #encode ⇒ Object
-
#initialize(options = {}) ⇒ AuthObject
constructor
A new instance of AuthObject.
- #valid? ⇒ Boolean
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( = {}) @username = [:username] || '' @email = [:email] || '' @serveraddress = [:serveraddress] || '' @password = [:password].is_a?(File) ? [:password].read : [:password] end |
Instance Attribute Details
#email ⇒ Object
Returns the value of attribute email.
7 8 9 |
# File 'lib/hyperb/auth_object.rb', line 7 def email @email end |
#password ⇒ Object
Returns the value of attribute password.
7 8 9 |
# File 'lib/hyperb/auth_object.rb', line 7 def password @password end |
#serveraddress ⇒ Object
Returns the value of attribute serveraddress.
7 8 9 |
# File 'lib/hyperb/auth_object.rb', line 7 def serveraddress @serveraddress end |
#username ⇒ Object
Returns the value of attribute username.
7 8 9 |
# File 'lib/hyperb/auth_object.rb', line 7 def username @username end |
Instance Method Details
#attrs ⇒ Object
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
30 31 32 |
# File 'lib/hyperb/auth_object.rb', line 30 def blank?(val) val.respond_to?(:empty?) ? val.empty? : !val end |
#build ⇒ Object
38 39 40 |
# File 'lib/hyperb/auth_object.rb', line 38 def build { x_registry_auth: encode } end |
#encode ⇒ Object
34 35 36 |
# File 'lib/hyperb/auth_object.rb', line 34 def encode Base64.urlsafe_encode64(attrs.to_json) end |
#valid? ⇒ Boolean
26 27 28 |
# File 'lib/hyperb/auth_object.rb', line 26 def valid? attrs.values.none? { |atr| blank?(atr) } end |