Class: WireGuard::Admin::Client

Inherits:
Object
  • Object
show all
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

Server

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, ip:, private_key: nil) ⇒ Client

Returns a new instance of Client.

Raises:

  • (ArgumentError)


27
28
29
30
31
32
33
34
35
36
# File 'lib/wire_guard/admin/client.rb', line 27

def initialize(name:, ip:, private_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?

  @name = name
  @ip = ip
  self.private_key = private_key || generate_private_key
end

Instance Attribute Details

#ipObject (readonly)

Returns the value of attribute ip.



25
26
27
# File 'lib/wire_guard/admin/client.rb', line 25

def ip
  @ip
end

#nameObject (readonly)

Returns the value of attribute name.



25
26
27
# File 'lib/wire_guard/admin/client.rb', line 25

def name
  @name
end

#private_keyObject

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_keyObject (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



55
56
57
58
59
60
61
# File 'lib/wire_guard/admin/client.rb', line 55

def ==(other)
  name == if other.respond_to?(:name)
            other.name
          else
            other
          end
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/wire_guard/admin/client.rb', line 51

def eql?(other)
  hash == other.hash
end

#hashObject



47
48
49
# File 'lib/wire_guard/admin/client.rb', line 47

def hash
  name.hash
end

#to_sObject



43
44
45
# File 'lib/wire_guard/admin/client.rb', line 43

def to_s
  "#{self.class.name.split('::').last} #{name}: #{ip}"
end