NAME
Class for parsing the output of wg show dump
.
SYNOPSIS
use Wireguard::WGmeta::Wrapper::Show;
my $wg_show = Wireguard::WGmeta::Wrapper::Show->new(<wg show dump output as string>);
DESCRIPTION
This class contains a parser for the output of wg show dump
together with an interface to retrieve the parsed data. An important note tough: This class does not perform the necessary I/O by itself and therefore the actual output of the command wg show dump
has to be captured into a string externally (e.g using "get_wg_show([$cmd])" in Wireguard::WGmeta::Wrapper::Bridge).
EXAMPLES
use Wireguard::WGmeta::Wrapper::Show;
use Wireguard::WGmeta::Wrapper::Bridge;
my ($out, $err) = get_wg_show();
my $wg_show = Wireguard::WGmeta::Wrapper::Show->new($out);
# get a specfic interface section
wg_show->get_interface_section('wg0', '<interface_public_key>')
# the parser is also exported as standalone
my $ref_hash_parsed_show = wg_show_dump_parser($out)
METHODS
new($wg_show_dump)
Creates a new instance of the show parser
Parameters
$wg_show_dump
Output of the (external) commandwg show dump
.
Returns
Instance
wg_show_dump_parser($input)
Parser for the output of wg show dump
. Aims to create a compatible structure as "read_wg_configs($wireguard_home, $wg_meta_prefix, $disabled_prefix)" in Wireguard::WGmeta::Wrapper::Config:
{
'interface_name' => {
'a_peer_pub_key' => {
'interface' => <parent_interface>,
'public-key' => <interface_public_key>,
'preshared-key' => <interface_preshared_key>,
'and_so_on' => <value_of_attr>
},
'an_interface_name => {
'interface' => <parent_interface>,
'private-key' => <interface_private_key>,
'and_so_on' => <value_of_attr>
}
},
'an_other_interface' => {
[...]
}
}
An important remark: This parser is relatively intolerant when it comes to formatting due to the input is already in a "machine readable" format. It expects one peer/interface per line, the values in the exact same order as defined in @keys_peer/@keys_interface, separated by a whitespace character. Usually, you don't have to worry about this - it is just meant as word of warning.
Parameters
$input
Output ofwg show dump
Returns
A reference to a hash with the structure described above.
get_interface_list()
Returns a list with all available interface names
Parameters
Returns
A list with valid interface names.
iface_exists($interface)
Simply checks if data is available for a specific interface. Useful to check if an interface is up.
Parameters
$interface
An interface name
Returns
If yes, returns True else False
get_interface_section($interface, $identifier)
Returns a specific section of an interface
Parameters
$interface
A valid interface name, optimally retrieved through "get_interface_list()".$identifier
A valid identifier, if the requested section is a peer this is its public-key, otherwise the interface name again.
Returns
A hash of the requested section. If non-existent, empty hash.
get_section_list($interface)
Returns a sorted list of all peers belonging to given interface
Parameters
$interface
A valid interface name, optimally retrieved through "get_interface_list()".
Returns
A list of peer public-keys (identifiers), if the interface does not exist -> empty list.
dump()
Simple dumper method to print contents of $self->{parsed_show}
.