Class: WireGuard::Admin::Client
- Inherits:
-
Object
- Object
- WireGuard::Admin::Client
- Defined in:
- lib/wire_guard/admin/client.rb
Overview
A host that connects to the VPN and registers a VPN subnet address such as 192.0.2.3 for itself.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#ip ⇒ Object
readonly
Returns the value of attribute ip.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#private_key ⇒ Object
readonly
Returns the value of attribute private_key.
-
#public_key ⇒ Object
readonly
Returns the value of attribute public_key.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(name:, ip:, private_key: nil, public_key: nil) ⇒ Client
constructor
rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity.
-
#to_s ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity.
Constructor Details
#initialize(name:, ip:, private_key: nil, public_key: nil) ⇒ Client
rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/wire_guard/admin/client.rb', line 28 def initialize(name:, ip:, private_key: nil, public_key: nil) raise ArgumentError, 'name must be present' if name.nil? raise ArgumentError, 'name must not be empty' if name.empty? raise ArgumentError, 'ip must be present' if ip.nil? raise ArgumentError, 'private_key must not be empty' if private_key&.empty? raise ArgumentError, 'public_key must not be empty' if public_key&.empty? @name = name @ip = ip @private_key = private_key || generate_private_key @public_key = public_key || generate_public_key end |
Instance Attribute Details
#ip ⇒ Object (readonly)
Returns the value of attribute ip.
25 26 27 |
# File 'lib/wire_guard/admin/client.rb', line 25 def ip @ip end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
25 26 27 |
# File 'lib/wire_guard/admin/client.rb', line 25 def name @name end |
#private_key ⇒ Object (readonly)
Returns the value of attribute private_key.
25 26 27 |
# File 'lib/wire_guard/admin/client.rb', line 25 def private_key @private_key end |
#public_key ⇒ Object (readonly)
Returns the value of attribute public_key.
25 26 27 |
# File 'lib/wire_guard/admin/client.rb', line 25 def public_key @public_key end |
Instance Method Details
#==(other) ⇒ Object
54 55 56 |
# File 'lib/wire_guard/admin/client.rb', line 54 def ==(other) name == other.name end |
#eql?(other) ⇒ Boolean
50 51 52 |
# File 'lib/wire_guard/admin/client.rb', line 50 def eql?(other) hash == other.hash end |
#hash ⇒ Object
46 47 48 |
# File 'lib/wire_guard/admin/client.rb', line 46 def hash name.hash end |
#to_s ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
42 43 44 |
# File 'lib/wire_guard/admin/client.rb', line 42 def to_s "#{self.class.name.split('::').last} #{name}: #{ip}" end |