class WireGuard::Admin::Clients

Commands for working with clients

Public Instance Methods

add(name) click to toggle source
# File lib/wire_guard/admin/cli/clients.rb, line 21
def add(name)
  warn "Using database #{repository.path}" if options[:verbose]
  client = Client.new(name: name, ip: ip)
  client.private_key = options[:private_key] if options[:private_key]
  repository.add_peer(network, client)
  if options[:verbose]
    warn 'New client was successfully added:'
    warn ''
    warn client
  end
rescue StandardError => e
  raise Thor::Error, "Error: #{e.message}"
end
list() click to toggle source
# File lib/wire_guard/admin/cli/clients.rb, line 49
def list
  if options[:verbose]
    warn "Using database #{repository.path}"
    warn "No clients in network #{network}." if repository.networks.empty?
  end
  repository.clients(network).each do |client|
    puts client
  end
rescue StandardError => e
  raise Thor::Error, "Error: #{e.message}"
end
remove(name) click to toggle source
# File lib/wire_guard/admin/cli/clients.rb, line 38
def remove(name)
  warn "Using database #{repository.path}" if options[:verbose]
  repository.remove_peer(network, name)
  warn 'Client was successfully removed.' if options[:verbose]
rescue StandardError => e
  raise Thor::Error, "Error: #{e.message}"
end