cmd

package
v0.3.0-1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2023 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Copyright © 2023 Laura Kalb <dev@lauka.net>

Copyright © 2023 Laura Kalb <dev@lauka.net>

Copyright © 2023 Laura Kalb <dev@lauka.net>

Copyright © 2023 Laura Kalb <dev@lauka.net>

Copyright © 2023 Laura Kalb <dev@lauka.net>

Copyright © 2023 Laura Kalb <dev@lauka.net>

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddDNSFqdn

func AddDNSFqdn(fqdn string, addr netip.Addr) error

AddDNSFqdn tries to create forward and reverse lookup records for given fqdn with netip.Addr addr, IF PowerDNS integration is enabled.

Returns nil on success, error otherwise

func DeleteDNSFqdn

func DeleteDNSFqdn(fqdn string, addr netip.Addr) error

DeleteDNSFqdn tries to delete the corresponding record for given fqdn with netip.Addr addr from the DNS server.

Returns nil on success, error otherwise

func DeleteSubnet

func DeleteSubnet(net netip.Prefix) error

DeleteSubnet deletes the subnet file on disk for netip.Prefix net.

Returns nil on success, or a *PathError on failure

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

func ListSubnets

func ListSubnets() []string

ListSubnets returns a list of strings containing the current subnets configured.

func SubnetExists

func SubnetExists(net netip.Prefix) bool

SubnetExists will return true if the given subnet already exists on file, false otherwise.

Types

type Address

type Address struct {
	IP        netip.Addr `json:"ip"`
	FQDN      string     `json:"fqdn"`
	ChangedAt time.Time  `json:"changedat,omitempty"`
	ChangedBy string     `json:"changedby,omitempty"`
}

func SortAddresses

func SortAddresses(list []Address) []Address

SortAddresses sorts the given list of IP addresses using netip.Addr.Less() and returns the sorted slice.

type DNSRecord

type DNSRecord struct {
	Content  string `json:"content"`
	Disabled bool   `json:"disabled,omitempty"`
	SetPTR   bool   `json:"set-ptr,omitempty"`
}

type DNSRecordSet

type DNSRecordSet struct {
	Name       string      `json:"name"`
	Type       string      `json:"type"`
	TTL        int         `json:"ttl"`
	Records    []DNSRecord `json:"records"`
	Changetype string      `json:"changetype,omitempty"`
}

type DNSZone

type DNSZone struct {
	ID         string            `json:"id"`
	Name       string            `json:"name"`
	Kind       string            `json:"kind"`
	RRsets     []DNSRecordSet    `json:"rrsets"`
	Metadata   map[string]string `json:"metadata"`
	DNSSEC     bool              `json:"dnssec"`
	NSEC3Param string            `json:"nsec3param,omitempty"`
	Account    string            `json:"account,omitempty"`
	Serial     int               `json:"serial"`
}

func GetBestDNSZone

func GetBestDNSZone(fqdn string) (DNSZone, error)

GetBestDNSZone requests a list of all zones from PowerDNS and determines the best zone, if possible.

Returns the found DNSZone and nil if a suitable zone was found, an empty DNSZone object and an error if not.

func GetDNSZone

func GetDNSZone(zone string) (DNSZone, error)

GetDNSZone retrieves the corresponding DNSZone for string zone from the DNS server.

Returns the DNSZone and nil if successful, empty DNSZone and an error otherwise

func (DNSZone) GetRecord

func (z DNSZone) GetRecord(fqdn string, rtype string, rcontent string) (DNSRecordSet, bool)

GetRecord checks if a given Record already exists in the DNSRecordSet list.

Returns the DNSRecordSet and true if record exists, empty DNSRecordSet and false if not.

func (DNSZone) SendPATCH

func (z DNSZone) SendPATCH(record string, value string, recordtype string, changetype string) error

SendPATCH sends a PATCH API request for DNSZone z. Returns error or nil

Example args for "test.example.com IN A 127.0.0.1"

z.Name = "example.com."
record = "test"
value = "127.0.0.1"
recordtype = "A"
changetype = "REPLACE"

type Patch

type Patch struct {
	Rrsets []DNSRecordSet `json:"rrsets"`
}

type Subnet

type Subnet struct {
	Subnet    netip.Prefix `json:"subnet"`
	Name      string       `json:"name"`
	Vlan      string       `json:"vlan"`
	ChangedAt time.Time    `json:"changedat,omitempty"`
	ChangedBy string       `json:"changedby,omitempty"`
	Addresses []Address    `json:"addresses"`
}

func FindBestSubnet

func FindBestSubnet(ip netip.Addr) (Subnet, bool)

FindBestSubnet tries to load the most fitting IP subnet file on disk. It takes an IP object and tries to get the best subnet (meaning the subnet with the smallest subnet size).

Returns the best subnet as Subnet object and true if a suitable subnet was found, otherwise an empty Subnet object and false.

func GetSubnet

func GetSubnet(net netip.Prefix) (Subnet, error)

GetSubnet reads the corresponding file for the given netip.Prefix net and constructs a Subnet object.

Returns the Subnet object and nil if the file read was successful, an empty Subnet object and the error otherwise.

func (Subnet) FindFirstFreeIP

func (s Subnet) FindFirstFreeIP() netip.Addr

FindFirstFreeIP finds and returns the next free netip.Addr or an invalid netip.Addr if no free IP was found

func (Subnet) GetIP

func (s Subnet) GetIP(ip netip.Addr) (Address, bool)

GetIP returns the Address object for the subnet with netip.Addr ip.

Returns the Address object and true if a corresponding object was found, an empty Address and false otherwise.

func (Subnet) GetIPCount

func (s Subnet) GetIPCount() int

GetIPCount gets the IP count for the Subnet

Returns the IP count or -1 if it's a IPv6 prefix

func (Subnet) HasIP

func (s Subnet) HasIP(ip netip.Addr) bool

HasIP checks if a Subnet already contains given netip.Addr. Returns true if the IP already is present, false otherwise.

func (Subnet) RemoveIP

func (s Subnet) RemoveIP(ip netip.Addr) (Subnet, error)

RemoveIP removes the Address object for given ip from the Address list of the subnet.

Returns the changed Subnet and nil if delete was successful, or an empty Subnet and an error if ip could not be deleted.

func (Subnet) WriteSubnet

func (s Subnet) WriteSubnet() error

WriteSubnet takes a given Subnet object and tries to write it to file.

Returns nil on success or the error that happened.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL