mirror of
https://github.com/jsiebens/ionscale.git
synced 2026-03-31 15:07:49 +01:00
fix: update auto-approved advertised routes when set after registration
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package tsn
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
"slices"
|
||||
"strings"
|
||||
"tailscale.com/ipn/ipnstate"
|
||||
@@ -60,6 +61,24 @@ func HasUser(email string) Condition {
|
||||
}
|
||||
}
|
||||
|
||||
func HasAllowedIP(route netip.Prefix) Condition {
|
||||
return func(status *ipnstate.Status) bool {
|
||||
if status.Self == nil || status.Self.AllowedIPs.Len() == 0 {
|
||||
return false
|
||||
}
|
||||
return slices.Contains(status.Self.AllowedIPs.AsSlice(), route)
|
||||
}
|
||||
}
|
||||
|
||||
func IsMissingAllowedIP(route netip.Prefix) Condition {
|
||||
return func(status *ipnstate.Status) bool {
|
||||
if status.Self == nil || status.Self.AllowedIPs.Len() == 0 {
|
||||
return true
|
||||
}
|
||||
return !slices.Contains(status.Self.AllowedIPs.AsSlice(), route)
|
||||
}
|
||||
}
|
||||
|
||||
func PeerCount(expected int) Condition {
|
||||
return func(status *ipnstate.Status) bool {
|
||||
return len(status.Peers()) == expected
|
||||
|
||||
+16
-2
@@ -38,11 +38,25 @@ func (t *TailscaleNode) Hostname() string {
|
||||
return t.hostname
|
||||
}
|
||||
|
||||
func (t *TailscaleNode) Up(authkey string) error {
|
||||
t.mustExecTailscaleCmd("up", "--login-server", t.loginServer, "--authkey", authkey)
|
||||
func (t *TailscaleNode) Up(authkey string, flags ...UpFlag) error {
|
||||
cmd := []string{"up", "--login-server", t.loginServer, "--authkey", authkey}
|
||||
for _, f := range flags {
|
||||
cmd = append(cmd, f...)
|
||||
}
|
||||
|
||||
t.mustExecTailscaleCmd(cmd...)
|
||||
return t.WaitFor(Connected())
|
||||
}
|
||||
|
||||
func (t *TailscaleNode) Set(flags ...UpFlag) string {
|
||||
cmd := []string{"set"}
|
||||
for _, f := range flags {
|
||||
cmd = append(cmd, f...)
|
||||
}
|
||||
|
||||
return t.mustExecTailscaleCmd(cmd...)
|
||||
}
|
||||
|
||||
func (t *TailscaleNode) LoginWithOidc(flags ...UpFlag) (int, error) {
|
||||
check := func(stdout, stderr string) bool {
|
||||
return strings.Contains(stderr, "To authenticate, visit:")
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
package tsn
|
||||
|
||||
import "strings"
|
||||
|
||||
type UpFlag = []string
|
||||
|
||||
func WithAdvertiseTags(tags string) UpFlag {
|
||||
return []string{"--advertise-tags", tags}
|
||||
}
|
||||
|
||||
func WithAdvertiseRoutes(routes []string) UpFlag {
|
||||
return []string{"--advertise-routes", strings.Join(routes, ",")}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user