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, public_key: nil) ⇒ Client

rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity

Raises:

  • (ArgumentError)


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

#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 (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_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



54
55
56
# File 'lib/wire_guard/admin/client.rb', line 54

def ==(other)
  name == other.name
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#hashObject



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

def hash
  name.hash
end

#to_sObject

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