mirror of
https://github.com/tailscale/tailscale.git
synced 2025-05-01 21:21:04 +00:00
tsnet: add CertDomains helper (#7533)
Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
parent
e109cf9fdd
commit
958c89470b
@ -34,6 +34,8 @@ func main() {
|
|||||||
}
|
}
|
||||||
defer ln.Close()
|
defer ln.Close()
|
||||||
|
|
||||||
|
fmt.Printf("Listening on https://%v\n", s.CertDomains()[0])
|
||||||
|
|
||||||
err = http.Serve(ln, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
err = http.Serve(ln, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
fmt.Fprintln(w, "<html><body><h1>Hello, internet!</h1>")
|
fmt.Fprintln(w, "<html><body><h1>Hello, internet!</h1>")
|
||||||
}))
|
}))
|
||||||
|
@ -26,6 +26,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/exp/slices"
|
||||||
"tailscale.com/client/tailscale"
|
"tailscale.com/client/tailscale"
|
||||||
"tailscale.com/control/controlclient"
|
"tailscale.com/control/controlclient"
|
||||||
"tailscale.com/envknob"
|
"tailscale.com/envknob"
|
||||||
@ -366,11 +367,26 @@ func (s *Server) doInit() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CertDomains returns the list of domains for which the server can
|
||||||
|
// provide TLS certificates. These are also the DNS names for the
|
||||||
|
// Server.
|
||||||
|
// If the server is not running, it returns nil.
|
||||||
|
func (s *Server) CertDomains() []string {
|
||||||
|
nm := s.lb.NetMap()
|
||||||
|
if nm == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return slices.Clone(nm.DNS.CertDomains)
|
||||||
|
}
|
||||||
|
|
||||||
// TailscaleIPs returns IPv4 and IPv6 addresses for this node. If the node
|
// TailscaleIPs returns IPv4 and IPv6 addresses for this node. If the node
|
||||||
// has not yet joined a tailnet or is otherwise unaware of its own IP addresses,
|
// has not yet joined a tailnet or is otherwise unaware of its own IP addresses,
|
||||||
// the returned ip4, ip6 will be !netip.IsValid().
|
// the returned ip4, ip6 will be !netip.IsValid().
|
||||||
func (s *Server) TailscaleIPs() (ip4, ip6 netip.Addr) {
|
func (s *Server) TailscaleIPs() (ip4, ip6 netip.Addr) {
|
||||||
nm := s.lb.NetMap()
|
nm := s.lb.NetMap()
|
||||||
|
if nm == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
for _, addr := range nm.Addresses {
|
for _, addr := range nm.Addresses {
|
||||||
ip := addr.Addr()
|
ip := addr.Addr()
|
||||||
if ip.Is6() {
|
if ip.Is6() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user