diff --git a/api.go b/api.go index a8b7af09..b02790b7 100644 --- a/api.go +++ b/api.go @@ -104,7 +104,7 @@ func (h *Headscale) RegistrationHandler(c *gin.Context) { return } - log.Println("Hey! Not registered. Not asking for key rotation. Send a passive-agressive authurl to register") + log.Println("Hey! Not registered. Not asking for key rotation. Send a passive-aggressive authurl to register") resp.AuthURL = fmt.Sprintf("%s/register?key=%s", h.cfg.ServerURL, mKey.HexString()) respBody, err := encode(resp, &mKey, h.privateKey) diff --git a/app.go b/app.go index df895ec1..9047c9b2 100644 --- a/app.go +++ b/app.go @@ -114,10 +114,10 @@ func (h *Headscale) Serve() error { go func() { log.Fatal(http.ListenAndServe(":http", m.HTTPHandler(http.HandlerFunc(h.redirect)))) }() + err = s.ListenAndServeTLS("", "") } else { return errors.New("Unknown value for TLSLetsEncryptChallengeType") } - err = s.ListenAndServeTLS("", "") } else if h.cfg.TLSCertPath == "" { if !strings.HasPrefix(h.cfg.ServerURL, "http://") { fmt.Println("WARNING: listening without TLS but ServerURL does not start with http://") diff --git a/cli.go b/cli.go index 90acb427..7ae6e6c6 100644 --- a/cli.go +++ b/cli.go @@ -51,6 +51,8 @@ func (h *Headscale) RegisterMachine(key string, namespace string) error { return nil } +// ListNodeRoutes prints the subnet routes advertised by a node (identified by +// namespace and node name) func (h *Headscale) ListNodeRoutes(namespace string, nodeName string) error { m, err := h.GetMachine(namespace, nodeName) if err != nil { @@ -65,6 +67,8 @@ func (h *Headscale) ListNodeRoutes(namespace string, nodeName string) error { return nil } +// EnableNodeRoute enables a subnet route advertised by a node (identified by +// namespace and node name) func (h *Headscale) EnableNodeRoute(namespace string, nodeName string, routeStr string) error { m, err := h.GetMachine(namespace, nodeName) if err != nil { diff --git a/db.go b/db.go index a1005568..2b865b78 100644 --- a/db.go +++ b/db.go @@ -4,7 +4,7 @@ import ( "errors" "github.com/jinzhu/gorm" - _ "github.com/jinzhu/gorm/dialects/postgres" + _ "github.com/jinzhu/gorm/dialects/postgres" // sql driver ) const dbVersion = "1" diff --git a/machine.go b/machine.go index 40023779..d72e660b 100644 --- a/machine.go +++ b/machine.go @@ -176,6 +176,7 @@ func (h *Headscale) getPeers(m Machine) (*[]*tailcfg.Node, error) { return &peers, nil } +// GetMachine finds a Machine by name and namespace and returns the Machine struct func (h *Headscale) GetMachine(namespace string, name string) (*Machine, error) { machines, err := h.ListMachinesInNamespace(namespace) if err != nil { @@ -190,6 +191,7 @@ func (h *Headscale) GetMachine(namespace string, name string) (*Machine, error) return nil, fmt.Errorf("not found") } +// GetHostInfo returns a Hostinfo struct for the machine func (m *Machine) GetHostInfo() (*tailcfg.Hostinfo, error) { hostinfo := tailcfg.Hostinfo{} if len(m.HostInfo.RawMessage) != 0 { diff --git a/namespaces.go b/namespaces.go index 4c9132b9..94ea2881 100644 --- a/namespaces.go +++ b/namespaces.go @@ -91,6 +91,7 @@ func (h *Headscale) ListMachinesInNamespace(name string) (*[]Machine, error) { return &machines, nil } +// SetMachineNamespace assigns a Machine to a namespace func (h *Headscale) SetMachineNamespace(m *Machine, namespaceName string) error { n, err := h.GetNamespace(namespaceName) if err != nil { diff --git a/preauth_keys.go b/preauth_keys.go index 14fcdbb8..50db149e 100644 --- a/preauth_keys.go +++ b/preauth_keys.go @@ -7,6 +7,7 @@ import ( "time" ) +// PreAuthKey describes a pre-authorization key usable in a particular namespace type PreAuthKey struct { ID uint64 `gorm:"primary_key"` Key string @@ -18,6 +19,7 @@ type PreAuthKey struct { Expiration *time.Time } +// CreatePreAuthKey creates a new PreAuthKey in a namespace, and returns it func (h *Headscale) CreatePreAuthKey(namespaceName string, reusable bool, expiration *time.Time) (*PreAuthKey, error) { n, err := h.GetNamespace(namespaceName) if err != nil { @@ -49,6 +51,7 @@ func (h *Headscale) CreatePreAuthKey(namespaceName string, reusable bool, expira return &k, nil } +// GetPreAuthKeys returns the list of PreAuthKeys for a namespace func (h *Headscale) GetPreAuthKeys(namespaceName string) (*[]PreAuthKey, error) { n, err := h.GetNamespace(namespaceName) if err != nil {