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, 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, servers)
  @client = client
  @servers = servers
  @template = self.class.template
  super(@template)
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

#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
  <<~CLIENT_TEMPLATE
    # WireGuard configuration for <%= client.name %>
    # generated by wg-admin

    [Interface]
    PrivateKey = <%= client.private_key %>
    Address = <%= client.ip %>/24

    <% servers.each do |server| %>
    [Peer]
    PublicKey = <%= server.public_key %>
    EndPoint = <%= server.name %>:<%= server.port %>
    AllowedIPs = <%= server.allowed_ips %>/<%= server.allowed_ips.prefix %>
    PersistentKeepalive = 25
    <% end %>
  CLIENT_TEMPLATE
end

Instance Method Details

#renderObject



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

def render
  result(binding)
end