Class: WireGuard::Admin::Templates::Client

Inherits:
ERB
  • Object
show all
Defined in:
lib/wire_guard/admin/templates/client.rb

Overview

Configuration template for a WireGuard::Admin::Client

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:, network:, servers:) ⇒ Client

Returns a new instance of Client.



33
34
35
36
37
38
# File 'lib/wire_guard/admin/templates/client.rb', line 33

def initialize(client:, network:, servers:)
  @client = client
  @network = network
  @servers = servers
  super(self.class.template, trim_mode: '<>')
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



31
32
33
# File 'lib/wire_guard/admin/templates/client.rb', line 31

def client
  @client
end

#networkObject (readonly)

Returns the value of attribute network.



31
32
33
# File 'lib/wire_guard/admin/templates/client.rb', line 31

def network
  @network
end

#serversObject (readonly)

Returns the value of attribute servers.



31
32
33
# File 'lib/wire_guard/admin/templates/client.rb', line 31

def servers
  @servers
end

Class Method Details

.templateObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/wire_guard/admin/templates/client.rb', line 12

def self.template
  "    # WireGuard configuration for <%= client.name %>\n    # generated by wg-admin\n\n    [Interface]\n    PrivateKey = <%= client.private_key %>\n    Address = <%= client.ip %>/<%= network.prefix %>\n    <% servers.each do |server| %>\n\n    [Peer]\n    PublicKey = <%= server.public_key %>\n    EndPoint = <%= server.name %>:<%= server.port %>\n    AllowedIPs = <%= server.allowed_ips %>/<%= server.allowed_ips.prefix %>\n    PersistentKeepalive = 25\n    <% end %>\n  CLIENT_TEMPLATE\nend\n"

Instance Method Details

#renderObject



40
41
42
# File 'lib/wire_guard/admin/templates/client.rb', line 40

def render
  result(binding)
end