From 72b9803a0833dcfd5c85b71ccbbbb0b41816e76f Mon Sep 17 00:00:00 2001 From: "Orville Q. Song" Date: Fri, 4 Nov 2022 01:11:22 +0800 Subject: [PATCH 01/28] Change DBssl to string --- app.go | 9 +++++++-- config.go | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app.go b/app.go index 26a88ca7..b8a8c9c6 100644 --- a/app.go +++ b/app.go @@ -11,6 +11,7 @@ import ( "os" "os/signal" "sort" + "strconv" "strings" "sync" "syscall" @@ -127,8 +128,12 @@ func NewHeadscale(cfg *Config) (*Headscale, error) { cfg.DBuser, ) - if !cfg.DBssl { - dbString += " sslmode=disable" + if s, err := strconv.ParseBool(cfg.DBssl); err == nil { + if !s { + dbString += " sslmode=disable" + } + } else { + dbString += fmt.Sprintf(" sslmode=%s", cfg.DBssl) } if cfg.DBport != 0 { diff --git a/config.go b/config.go index b4cad5be..11883565 100644 --- a/config.go +++ b/config.go @@ -51,7 +51,7 @@ type Config struct { DBname string DBuser string DBpass string - DBssl bool + DBssl string TLS TLSConfig @@ -545,7 +545,7 @@ func GetHeadscaleConfig() (*Config, error) { DBname: viper.GetString("db_name"), DBuser: viper.GetString("db_user"), DBpass: viper.GetString("db_pass"), - DBssl: viper.GetBool("db_ssl"), + DBssl: viper.GetString("db_ssl"), TLS: GetTLSConfig(), From d29d0222af9c8d23fa3cbed10c46c8b305a2becb Mon Sep 17 00:00:00 2001 From: "Orville Q. Song" Date: Fri, 4 Nov 2022 01:28:52 +0800 Subject: [PATCH 02/28] Add a note about the db_ssl field in the example config file --- config-example.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config-example.yaml b/config-example.yaml index 2028d332..d6c3863f 100644 --- a/config-example.yaml +++ b/config-example.yaml @@ -137,6 +137,8 @@ db_path: ./db.sqlite # # Postgres config # If using a Unix socket to connect to Postgres, set the socket path in the 'host' field and leave 'port' blank. +# Also if other 'sslmode' is required instead of 'require(true)' and 'disabled(false)', set the 'sslmode' you need +# in the 'db_ssl' field. Refers to https://www.postgresql.org/docs/current/libpq-ssl.html Table 34.1. # db_type: postgres # db_host: localhost # db_port: 5432 From e69176e20017d3e4673b985b30f31fec958f85e0 Mon Sep 17 00:00:00 2001 From: "Orville Q. Song" Date: Thu, 24 Nov 2022 20:02:34 +0800 Subject: [PATCH 03/28] Tweak --- app.go | 4 ++-- config-example.yaml | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app.go b/app.go index b8a8c9c6..69d40794 100644 --- a/app.go +++ b/app.go @@ -128,8 +128,8 @@ func NewHeadscale(cfg *Config) (*Headscale, error) { cfg.DBuser, ) - if s, err := strconv.ParseBool(cfg.DBssl); err == nil { - if !s { + if sslEnabled, err := strconv.ParseBool(cfg.DBssl); err == nil { + if !sslEnabled { dbString += " sslmode=disable" } } else { diff --git a/config-example.yaml b/config-example.yaml index d6c3863f..57866785 100644 --- a/config-example.yaml +++ b/config-example.yaml @@ -137,14 +137,15 @@ db_path: ./db.sqlite # # Postgres config # If using a Unix socket to connect to Postgres, set the socket path in the 'host' field and leave 'port' blank. -# Also if other 'sslmode' is required instead of 'require(true)' and 'disabled(false)', set the 'sslmode' you need -# in the 'db_ssl' field. Refers to https://www.postgresql.org/docs/current/libpq-ssl.html Table 34.1. # db_type: postgres # db_host: localhost # db_port: 5432 # db_name: headscale # db_user: foo # db_pass: bar + +# If other 'sslmode' is required instead of 'require(true)' and 'disabled(false)', set the 'sslmode' you need +# in the 'db_ssl' field. Refers to https://www.postgresql.org/docs/current/libpq-ssl.html Table 34.1. # db_ssl: false ### TLS configuration From 25195b8d73db17e635ffebf62f8ec6d516bc6282 Mon Sep 17 00:00:00 2001 From: "Orville Q. Song" Date: Thu, 24 Nov 2022 22:33:19 +0800 Subject: [PATCH 04/28] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e92ed5b5..55331646 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ - Make it possible to disable TS2019 with build flag [#928](https://github.com/juanfont/headscale/pull/928) - Fix OIDC registration issues [#960](https://github.com/juanfont/headscale/pull/960) and [#971](https://github.com/juanfont/headscale/pull/971) - Add support for specifying NextDNS DNS-over-HTTPS resolver [#940](https://github.com/juanfont/headscale/pull/940) +- Make more sslmode available for postgresql connection [#927](https://github.com/juanfont/headscale/pull/927) ## 0.16.4 (2022-08-21) From 91559d05580f01528dfda8032042eaea84156597 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 24 Nov 2022 15:14:38 +0000 Subject: [PATCH 05/28] docs(README): update contributors --- README.md | 102 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 66 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 661895a6..943c51d1 100644 --- a/README.md +++ b/README.md @@ -269,6 +269,13 @@ make build Mike Lloyd + + + Anton +
+ Anton Schubert +
+ Niek @@ -283,6 +290,8 @@ make build Eugen Biegler + + Azz/ @@ -290,15 +299,6 @@ make build Azz - - - - - Anton -
- Anton Schubert -
- Aaron @@ -327,6 +327,15 @@ make build Fernando De Lucchi + + + Orville +
+ Orville Q. Song +
+ + + hdhoang/ @@ -334,8 +343,6 @@ make build hdhoang - - bravechamp/ @@ -371,6 +378,8 @@ make build Mevan Samaratunga + + Michael @@ -378,8 +387,6 @@ make build Michael G. - - Paul @@ -415,6 +422,8 @@ make build Artem Klevtsov + + Casey @@ -422,8 +431,6 @@ make build Casey Marshall - - LiuHanCheng/ @@ -445,6 +452,13 @@ make build Silver Bullet + + + Steven +
+ Steven Honson +
+ Victor @@ -452,6 +466,8 @@ make build Victor Freire + + lachy2849/ @@ -466,8 +482,6 @@ make build thomas - - Abraham @@ -496,6 +510,15 @@ make build Aofei Sheng + + + + + Arnar/ +
+ Arnar +
+ Arthur @@ -510,8 +533,6 @@ make build Bryan Stenson - - Carson @@ -533,6 +554,8 @@ make build Felix Kronlage-Dammers + + Felix @@ -554,8 +577,6 @@ make build Jim Tittsler - - Jonathan @@ -570,13 +591,6 @@ make build Pierre Carru - - - Pontus -
- Pontus N -
- Rasmus @@ -584,6 +598,8 @@ make build Rasmus Moorats + + rcursaru/ @@ -598,8 +614,6 @@ make build Mend Renovate - - Ryan @@ -628,6 +642,8 @@ make build sophware + + Tanner/ @@ -642,8 +658,6 @@ make build Teteros - - The @@ -672,6 +686,8 @@ make build Tjerk Woudsma + + Yang @@ -686,8 +702,6 @@ make build Yujie Xia - - Zakhar @@ -716,6 +730,8 @@ make build derelm + + henning @@ -730,8 +746,13 @@ make build ignoramous - - + + + suhelen/ +
+ suhelen +
+ sharkonet/ @@ -739,6 +760,13 @@ make build sharkonet + + + manju-rn/ +
+ manju-rn +
+ pernila/ @@ -746,6 +774,8 @@ make build pernila + + phpmalik/ From c78403691cdb3dbc16afba69894387955ab8d512 Mon Sep 17 00:00:00 2001 From: Juan Font Date: Wed, 23 Nov 2022 18:50:30 +0000 Subject: [PATCH 06/28] Add Route DB model --- routes.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/routes.go b/routes.go index 676c79b6..079c055c 100644 --- a/routes.go +++ b/routes.go @@ -3,12 +3,26 @@ package headscale import ( "fmt" "net/netip" + + "gorm.io/gorm" ) const ( ErrRouteIsNotAvailable = Error("route is not available") ) +type Route struct { + gorm.Model + + MachineID uint64 + Machine Machine + Prefix IPPrefix + + Advertised bool + Enabled bool + IsPrimary bool +} + // Deprecated: use machine function instead // GetAdvertisedNodeRoutes returns the subnet routes advertised by a node (identified by // namespace and node name). From 28ef3145c5b99a546f1a9f3486e777cf52bc5edd Mon Sep 17 00:00:00 2001 From: Juan Font Date: Wed, 23 Nov 2022 18:52:09 +0000 Subject: [PATCH 07/28] Add migration from Machine.EnabledRoutes to the new Route table --- db.go | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 85 insertions(+), 2 deletions(-) diff --git a/db.go b/db.go index fc539cc3..72386ca8 100644 --- a/db.go +++ b/db.go @@ -18,8 +18,10 @@ import ( ) const ( - dbVersion = "1" - errValueNotFound = Error("not found") + dbVersion = "1" + + errValueNotFound = Error("not found") + ErrCannotParsePrefix = Error("cannot parse prefix") ) // KV is a key-value store in a psql table. For future use... @@ -79,6 +81,65 @@ func (h *Headscale) initDB() error { } } + err = db.AutoMigrate(&Route{}) + if err != nil { + return err + } + + if db.Migrator().HasColumn(&Machine{}, "enabled_routes") { + log.Info().Msgf("Database has legacy enabled_routes column in machine, migrating...") + + type MachineAux struct { + ID uint64 + EnabledRoutes IPPrefixes + } + + machinesAux := []MachineAux{} + err := db.Table("machines").Select("id, enabled_routes").Scan(&machinesAux).Error + if err != nil { + log.Fatal().Err(err).Msg("Error accessing db") + } + for _, machine := range machinesAux { + for _, prefix := range machine.EnabledRoutes { + if err != nil { + log.Error(). + Err(err). + Str("enabled_route", prefix.String()). + Msg("Error parsing enabled_route") + continue + } + + err = db.Preload("Machine").Where("machine_id = ? AND prefix = ?", machine.ID, IPPrefix(prefix)).First(&Route{}).Error + if err == nil { + log.Info(). + Str("enabled_route", prefix.String()). + Msg("Route already migrated to new table, skipping") + continue + } + + route := Route{ + MachineID: machine.ID, + Advertised: true, + Enabled: true, + Prefix: IPPrefix(prefix), + } + if err := h.db.Create(&route).Error; err != nil { + log.Error().Err(err).Msg("Error creating route") + } else { + log.Info(). + Uint64("machine_id", route.MachineID). + Str("prefix", prefix.String()). + Msg("Route migrated") + } + } + } + + err = db.Migrator().DropColumn(&Machine{}, "enabled_routes") + if err != nil { + log.Error().Err(err).Msg("Error dropping enabled_routes column") + } + } + err = db.AutoMigrate(&Machine{}) if err != nil { return err @@ -264,6 +325,28 @@ func (hi HostInfo) Value() (driver.Value, error) { return string(bytes), err } +type IPPrefix netip.Prefix + +func (i *IPPrefix) Scan(destination interface{}) error { + switch value := destination.(type) { + case string: + prefix, err := netip.ParsePrefix(value) + if err != nil { + return err + } + *i = IPPrefix(prefix) + return nil + default: + return fmt.Errorf("%w: unexpected data type %T", ErrCannotParsePrefix, destination) + } +} + +// Value return json value, implement driver.Valuer interface. +func (i IPPrefix) Value() (driver.Value, error) { + prefixStr := netip.Prefix(i).String() + return prefixStr, nil +} + type IPPrefixes []netip.Prefix func (i *IPPrefixes) Scan(destination interface{}) error { From a76115b9e49ebee786a857ce5894d1e1064dcdb0 Mon Sep 17 00:00:00 2001 From: Juan Font Date: Thu, 24 Nov 2022 15:58:32 +0000 Subject: [PATCH 08/28] Cleanup route.go and add helper methods to process HostInfo --- routes.go | 147 ++++++++++++++++++++++-------------------------------- 1 file changed, 60 insertions(+), 87 deletions(-) diff --git a/routes.go b/routes.go index 079c055c..3ba710be 100644 --- a/routes.go +++ b/routes.go @@ -23,109 +23,82 @@ type Route struct { IsPrimary bool } -// Deprecated: use machine function instead -// GetAdvertisedNodeRoutes returns the subnet routes advertised by a node (identified by -// namespace and node name). -func (h *Headscale) GetAdvertisedNodeRoutes( - namespace string, - nodeName string, -) (*[]netip.Prefix, error) { - machine, err := h.GetMachine(namespace, nodeName) +type Routes []Route + +func (r *Route) String() string { + return fmt.Sprintf("%s:%s", r.Machine, netip.Prefix(r.Prefix).String()) +} + +func (rs Routes) toPrefixes() []netip.Prefix { + prefixes := make([]netip.Prefix, len(rs)) + for i, r := range rs { + prefixes[i] = netip.Prefix(r.Prefix) + } + return prefixes +} + +// getMachinePrimaryRoutes returns the routes that are enabled and marked as primary (for subnet failover) +// Exit nodes are not considered for this, as they are never marked as Primary +func (h *Headscale) getMachinePrimaryRoutes(m *Machine) ([]Route, error) { + var routes []Route + err := h.db. + Preload("Machine"). + Where("machine_id = ? AND advertised = ? AND enabled = ? AND is_primary = ?", m.ID, true, true, true). + Find(&routes).Error if err != nil { return nil, err } - return &machine.HostInfo.RoutableIPs, nil + return routes, nil } -// Deprecated: use machine function instead -// GetEnabledNodeRoutes returns the subnet routes enabled by a node (identified by -// namespace and node name). -func (h *Headscale) GetEnabledNodeRoutes( - namespace string, - nodeName string, -) ([]netip.Prefix, error) { - machine, err := h.GetMachine(namespace, nodeName) - if err != nil { - return nil, err - } - - return machine.EnabledRoutes, nil -} - -// Deprecated: use machine function instead -// IsNodeRouteEnabled checks if a certain route has been enabled. -func (h *Headscale) IsNodeRouteEnabled( - namespace string, - nodeName string, - routeStr string, -) bool { - route, err := netip.ParsePrefix(routeStr) - if err != nil { - return false - } - - enabledRoutes, err := h.GetEnabledNodeRoutes(namespace, nodeName) - if err != nil { - return false - } - - for _, enabledRoute := range enabledRoutes { - if route == enabledRoute { - return true - } - } - - return false -} - -// Deprecated: use EnableRoute in machine.go -// 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 { - machine, err := h.GetMachine(namespace, nodeName) +func (h *Headscale) processMachineRoutes(machine *Machine) error { + currentRoutes := []Route{} + err := h.db.Where("machine_id = ?", machine.ID).Find(¤tRoutes).Error if err != nil { return err } - route, err := netip.ParsePrefix(routeStr) - if err != nil { - return err + advertisedRoutes := map[netip.Prefix]bool{} + for _, prefix := range machine.HostInfo.RoutableIPs { + advertisedRoutes[prefix] = false } - availableRoutes, err := h.GetAdvertisedNodeRoutes(namespace, nodeName) - if err != nil { - return err - } - - enabledRoutes, err := h.GetEnabledNodeRoutes(namespace, nodeName) - if err != nil { - return err - } - - available := false - for _, availableRoute := range *availableRoutes { - // If the route is available, and not yet enabled, add it to the new routing table - if route == availableRoute { - available = true - if !h.IsNodeRouteEnabled(namespace, nodeName, routeStr) { - enabledRoutes = append(enabledRoutes, route) + for _, route := range currentRoutes { + if _, ok := advertisedRoutes[netip.Prefix(route.Prefix)]; ok { + if !route.Advertised { + route.Advertised = true + err := h.db.Save(&route).Error + if err != nil { + return err + } + } + advertisedRoutes[netip.Prefix(route.Prefix)] = true + } else { + if route.Advertised { + route.Advertised = false + route.Enabled = false + err := h.db.Save(&route).Error + if err != nil { + return err + } } } } - if !available { - return ErrRouteIsNotAvailable - } - - machine.EnabledRoutes = enabledRoutes - - if err := h.db.Save(&machine).Error; err != nil { - return fmt.Errorf("failed to update node routes in the database: %w", err) + for prefix, exists := range advertisedRoutes { + if !exists { + route := Route{ + MachineID: machine.ID, + Prefix: IPPrefix(prefix), + Advertised: true, + Enabled: false, + } + err := h.db.Create(&route).Error + if err != nil { + return err + } + } } return nil From 60be739a3bf83a8676603761cb5c05942f795cba Mon Sep 17 00:00:00 2001 From: Juan Font Date: Thu, 24 Nov 2022 15:59:37 +0000 Subject: [PATCH 09/28] Call processMachineRoutes when a new Map is received --- protocol_common_poll.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/protocol_common_poll.go b/protocol_common_poll.go index 9eebe921..7df01c86 100644 --- a/protocol_common_poll.go +++ b/protocol_common_poll.go @@ -32,6 +32,15 @@ func (h *Headscale) handlePollCommon( machine.DiscoKey = DiscoPublicKeyStripPrefix(mapRequest.DiscoKey) now := time.Now().UTC() + err := h.processMachineRoutes(machine) + if err != nil { + log.Error(). + Caller(). + Err(err). + Str("machine", machine.Hostname). + Msg("Error processing machine routes") + } + // update ACLRules with peer informations (to update server tags if necessary) if h.aclPolicy != nil { err := h.UpdateACLRules() From cf35ae94d0c1dcff70cd7ccb91975ba946cebe18 Mon Sep 17 00:00:00 2001 From: Juan Font Date: Thu, 24 Nov 2022 16:00:40 +0000 Subject: [PATCH 10/28] Remove EnabledRoutes from Machine and refactor to adapt to it --- api_common.go | 4 +- grpcv1.go | 4 +- machine.go | 197 +++++++++++++++++++++++++++++++++++--------------- 3 files changed, 141 insertions(+), 64 deletions(-) diff --git a/api_common.go b/api_common.go index 9e7ff480..1eaad57c 100644 --- a/api_common.go +++ b/api_common.go @@ -13,7 +13,7 @@ func (h *Headscale) generateMapResponse( Str("func", "generateMapResponse"). Str("machine", mapRequest.Hostinfo.Hostname). Msg("Creating Map response") - node, err := machine.toNode(h.cfg.BaseDomain, h.cfg.DNSConfig) + node, err := h.toNode(*machine, h.cfg.BaseDomain, h.cfg.DNSConfig) if err != nil { log.Error(). Caller(). @@ -37,7 +37,7 @@ func (h *Headscale) generateMapResponse( profiles := h.getMapResponseUserProfiles(*machine, peers) - nodePeers, err := peers.toNodes(h.cfg.BaseDomain, h.cfg.DNSConfig) + nodePeers, err := h.toNodes(peers, h.cfg.BaseDomain, h.cfg.DNSConfig) if err != nil { log.Error(). Caller(). diff --git a/grpcv1.go b/grpcv1.go index 25ee7777..998b9902 100644 --- a/grpcv1.go +++ b/grpcv1.go @@ -374,7 +374,7 @@ func (api headscaleV1APIServer) GetMachineRoute( } return &v1.GetMachineRouteResponse{ - Routes: machine.RoutesToProto(), + Routes: api.h.RoutesToProto(machine), }, nil } @@ -393,7 +393,7 @@ func (api headscaleV1APIServer) EnableMachineRoutes( } return &v1.EnableMachineRoutesResponse{ - Routes: machine.RoutesToProto(), + Routes: api.h.RoutesToProto(machine), }, nil } diff --git a/machine.go b/machine.go index b688be65..d3d54802 100644 --- a/machine.go +++ b/machine.go @@ -13,6 +13,7 @@ import ( v1 "github.com/juanfont/headscale/gen/go/headscale/v1" "github.com/rs/zerolog/log" "google.golang.org/protobuf/types/known/timestamppb" + "gorm.io/gorm" "tailscale.com/tailcfg" "tailscale.com/types/key" ) @@ -76,9 +77,8 @@ type Machine struct { LastSuccessfulUpdate *time.Time Expiry *time.Time - HostInfo HostInfo - Endpoints StringList - EnabledRoutes IPPrefixes + HostInfo HostInfo + Endpoints StringList CreatedAt time.Time UpdatedAt time.Time @@ -595,14 +595,15 @@ func (machines MachinesP) String() string { return fmt.Sprintf("[ %s ](%d)", strings.Join(temp, ", "), len(temp)) } -func (machines Machines) toNodes( +func (h *Headscale) toNodes( + machines Machines, baseDomain string, dnsConfig *tailcfg.DNSConfig, ) ([]*tailcfg.Node, error) { nodes := make([]*tailcfg.Node, len(machines)) for index, machine := range machines { - node, err := machine.toNode(baseDomain, dnsConfig) + node, err := h.toNode(machine, baseDomain, dnsConfig) if err != nil { return nil, err } @@ -615,7 +616,8 @@ func (machines Machines) toNodes( // toNode converts a Machine into a Tailscale Node. includeRoutes is false for shared nodes // as per the expected behaviour in the official SaaS. -func (machine Machine) toNode( +func (h *Headscale) toNode( + machine Machine, baseDomain string, dnsConfig *tailcfg.DNSConfig, ) (*tailcfg.Node, error) { @@ -663,24 +665,19 @@ func (machine Machine) toNode( []netip.Prefix{}, addrs...) // we append the node own IP, as it is required by the clients - allowedIPs = append(allowedIPs, machine.EnabledRoutes...) - - // TODO(kradalby): This is kind of a hack where we say that - // all the announced routes (except exit), is presented as primary - // routes. This might be problematic if two nodes expose the same route. - // This was added to address an issue where subnet routers stopped working - // when we only populated AllowedIPs. - primaryRoutes := []netip.Prefix{} - if len(machine.EnabledRoutes) > 0 { - for _, route := range machine.EnabledRoutes { - if route == ExitRouteV4 || route == ExitRouteV6 { - continue - } - - primaryRoutes = append(primaryRoutes, route) - } + enabledRoutes, err := h.GetEnabledRoutes(&machine) + if err != nil { + return nil, err } + allowedIPs = append(allowedIPs, enabledRoutes...) + + primaryRoutes, err := h.getMachinePrimaryRoutes(&machine) + if err != nil { + return nil, err + } + primaryPrefixes := Routes(primaryRoutes).toPrefixes() + var derp string if machine.HostInfo.NetInfo != nil { derp = fmt.Sprintf("127.3.3.40:%d", machine.HostInfo.NetInfo.PreferredDERP) @@ -733,7 +730,7 @@ func (machine Machine) toNode( DiscoKey: discoKey, Addresses: addrs, AllowedIPs: allowedIPs, - PrimaryRoutes: primaryRoutes, + PrimaryRoutes: primaryPrefixes, Endpoints: machine.Endpoints, DERP: derp, @@ -923,21 +920,66 @@ func (h *Headscale) RegisterMachine(machine Machine, return &machine, nil } -func (machine *Machine) GetAdvertisedRoutes() []netip.Prefix { - return machine.HostInfo.RoutableIPs +// GetAdvertisedRoutes returns the routes that are be advertised by the given machine. +func (h *Headscale) GetAdvertisedRoutes(machine *Machine) ([]netip.Prefix, error) { + routes := []Route{} + + err := h.db. + Preload("Machine"). + Where("machine_id = ? AND advertised = ?", machine.ID, true).Find(&routes).Error + if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { + log.Error(). + Caller(). + Err(err). + Str("machine", machine.Hostname). + Msg("Could not get advertised routes for machine") + return nil, err + } + + prefixes := []netip.Prefix{} + for _, route := range routes { + prefixes = append(prefixes, netip.Prefix(route.Prefix)) + } + + return prefixes, nil } -func (machine *Machine) GetEnabledRoutes() []netip.Prefix { - return machine.EnabledRoutes +// GetEnabledRoutes returns the routes that are enabled for the machine. +func (h *Headscale) GetEnabledRoutes(machine *Machine) ([]netip.Prefix, error) { + routes := []Route{} + + err := h.db. + Preload("Machine"). + Where("machine_id = ? AND advertised = ? AND enabled = ?", machine.ID, true, true). + Find(&routes).Error + if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { + log.Error(). + Caller(). + Err(err). + Str("machine", machine.Hostname). + Msg("Could not get enabled routes for machine") + return nil, err + } + + prefixes := []netip.Prefix{} + for _, route := range routes { + prefixes = append(prefixes, netip.Prefix(route.Prefix)) + } + + return prefixes, nil } -func (machine *Machine) IsRoutesEnabled(routeStr string) bool { +func (h *Headscale) IsRoutesEnabled(machine *Machine, routeStr string) bool { route, err := netip.ParsePrefix(routeStr) if err != nil { return false } - enabledRoutes := machine.GetEnabledRoutes() + enabledRoutes, err := h.GetEnabledRoutes(machine) + if err != nil { + log.Error().Err(err).Msg("Could not get enabled routes") + return false + } for _, enabledRoute := range enabledRoutes { if route == enabledRoute { @@ -948,8 +990,7 @@ func (machine *Machine) IsRoutesEnabled(routeStr string) bool { return false } -// EnableNodeRoute enables new routes based on a list of new routes. It will _replace_ the -// previous list of routes. +// EnableRoutes enables new routes based on a list of new routes. func (h *Headscale) EnableRoutes(machine *Machine, routeStrs ...string) error { newRoutes := make([]netip.Prefix, len(routeStrs)) for index, routeStr := range routeStrs { @@ -961,8 +1002,13 @@ func (h *Headscale) EnableRoutes(machine *Machine, routeStrs ...string) error { newRoutes[index] = route } + advertisedRoutes, err := h.GetAdvertisedRoutes(machine) + if err != nil { + return err + } + for _, newRoute := range newRoutes { - if !contains(machine.GetAdvertisedRoutes(), newRoute) { + if !contains(advertisedRoutes, newRoute) { return fmt.Errorf( "route (%s) is not available on node %s: %w", machine.Hostname, @@ -971,52 +1017,70 @@ func (h *Headscale) EnableRoutes(machine *Machine, routeStrs ...string) error { } } - machine.EnabledRoutes = newRoutes - - if err := h.db.Save(machine).Error; err != nil { - return fmt.Errorf("failed enable routes for machine in the database: %w", err) + // Separate loop so we don't leave things in a half-updated state + for _, prefix := range newRoutes { + route := Route{} + err := h.db.Preload("Machine"). + Where("machine_id = ? AND prefix = ?", machine.ID, IPPrefix(prefix)). + First(&route).Error + if err == nil { + route.Enabled = true + err = h.db.Save(&route).Error + if err != nil { + return fmt.Errorf("failed to enable route: %w", err) + } + } else { + return fmt.Errorf("failed to find route: %w", err) + } } return nil } -// Enabled any routes advertised by a machine that match the ACL autoApprovers policy. -func (h *Headscale) EnableAutoApprovedRoutes(machine *Machine) { +// EnableAutoApprovedRoutes enables any routes advertised by a machine that match the ACL autoApprovers policy. +func (h *Headscale) EnableAutoApprovedRoutes(machine *Machine) error { if len(machine.IPAddresses) == 0 { - return // This machine has no IPAddresses, so can't possibly match any autoApprovers ACLs + return nil // This machine has no IPAddresses, so can't possibly match any autoApprovers ACLs } - approvedRoutes := make([]netip.Prefix, 0, len(machine.HostInfo.RoutableIPs)) - thisMachine := []Machine{*machine} + routes := []Route{} + err := h.db. + Preload("Machine"). + Where("machine_id = ? AND advertised = true AND enabled = false", machine.ID).Find(&routes).Error + if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { + log.Error(). + Caller(). + Err(err). + Str("machine", machine.Hostname). + Msg("Could not get advertised routes for machine") - for _, advertisedRoute := range machine.HostInfo.RoutableIPs { - if contains(machine.EnabledRoutes, advertisedRoute) { - continue // Skip routes that are already enabled for the node - } + return err + } - routeApprovers, err := h.aclPolicy.AutoApprovers.GetRouteApprovers( - advertisedRoute, - ) + approvedRoutes := []Route{} + + for _, advertisedRoute := range routes { + routeApprovers, err := h.aclPolicy.AutoApprovers.GetRouteApprovers(netip.Prefix(advertisedRoute.Prefix)) if err != nil { log.Err(err). Str("advertisedRoute", advertisedRoute.String()). Uint64("machineId", machine.ID). Msg("Failed to resolve autoApprovers for advertised route") - return + return err } for _, approvedAlias := range routeApprovers { if approvedAlias == machine.Namespace.Name { approvedRoutes = append(approvedRoutes, advertisedRoute) } else { - approvedIps, err := expandAlias(thisMachine, *h.aclPolicy, approvedAlias, h.cfg.OIDC.StripEmaildomain) + approvedIps, err := expandAlias([]Machine{*machine}, *h.aclPolicy, approvedAlias, h.cfg.OIDC.StripEmaildomain) if err != nil { log.Err(err). Str("alias", approvedAlias). Msg("Failed to expand alias when processing autoApprovers policy") - return + return err } // approvedIPs should contain all of machine's IPs if it matches the rule, so check for first @@ -1028,20 +1092,33 @@ func (h *Headscale) EnableAutoApprovedRoutes(machine *Machine) { } for _, approvedRoute := range approvedRoutes { - if !contains(machine.EnabledRoutes, approvedRoute) { - log.Info(). - Str("route", approvedRoute.String()). - Uint64("client", machine.ID). - Msg("Enabling autoApproved route for client") - machine.EnabledRoutes = append(machine.EnabledRoutes, approvedRoute) + approvedRoute.Enabled = true + err = h.db.Save(&approvedRoute).Error + if err != nil { + log.Err(err). + Str("approvedRoute", approvedRoute.String()). + Uint64("machineId", machine.ID). + Msg("Failed to enable approved route") + + return err } } + + return nil } -func (machine *Machine) RoutesToProto() *v1.Routes { - availableRoutes := machine.GetAdvertisedRoutes() +func (h *Headscale) RoutesToProto(machine *Machine) *v1.Routes { + availableRoutes, err := h.GetAdvertisedRoutes(machine) + if err != nil { + log.Error().Err(err).Msg("Could not get advertised routes") + return nil + } - enabledRoutes := machine.GetEnabledRoutes() + enabledRoutes, err := h.GetEnabledRoutes(machine) + if err != nil { + log.Error().Err(err).Msg("Could not get enabled routes") + return nil + } return &v1.Routes{ AdvertisedRoutes: ipPrefixToString(availableRoutes), From 52ab2a8ffd23754644fe07305629dcd4b49730b1 Mon Sep 17 00:00:00 2001 From: Juan Font Date: Thu, 24 Nov 2022 16:06:24 +0000 Subject: [PATCH 11/28] Port routes tests to new model --- machine_test.go | 7 ++++++- routes_test.go | 50 +++++++++++++++++++++---------------------------- 2 files changed, 27 insertions(+), 30 deletions(-) diff --git a/machine_test.go b/machine_test.go index b13ecd0c..c5073233 100644 --- a/machine_test.go +++ b/machine_test.go @@ -1153,9 +1153,14 @@ func (s *Suite) TestAutoApproveRoutes(c *check.C) { app.db.Save(&machine) + err = app.processMachineRoutes(&machine) + c.Assert(err, check.IsNil) + machine0ByID, err := app.GetMachineByID(0) c.Assert(err, check.IsNil) app.EnableAutoApprovedRoutes(machine0ByID) - c.Assert(machine0ByID.GetEnabledRoutes(), check.HasLen, 3) + enabledRoutes, err := app.GetEnabledRoutes(machine0ByID) + c.Assert(err, check.IsNil) + c.Assert(enabledRoutes, check.HasLen, 3) } diff --git a/routes_test.go b/routes_test.go index 6566f3e5..2f034942 100644 --- a/routes_test.go +++ b/routes_test.go @@ -37,17 +37,17 @@ func (s *Suite) TestGetRoutes(c *check.C) { } app.db.Save(&machine) - advertisedRoutes, err := app.GetAdvertisedNodeRoutes( - "test", - "test_get_route_machine", - ) + err = app.processMachineRoutes(&machine) c.Assert(err, check.IsNil) - c.Assert(len(*advertisedRoutes), check.Equals, 1) - err = app.EnableNodeRoute("test", "test_get_route_machine", "192.168.0.0/24") + advertisedRoutes, err := app.GetAdvertisedRoutes(&machine) + c.Assert(err, check.IsNil) + c.Assert(len(advertisedRoutes), check.Equals, 1) + + err = app.EnableRoutes(&machine, "192.168.0.0/24") c.Assert(err, check.NotNil) - err = app.EnableNodeRoute("test", "test_get_route_machine", "10.0.0.0/24") + err = app.EnableRoutes(&machine, "10.0.0.0/24") c.Assert(err, check.IsNil) } @@ -88,48 +88,40 @@ func (s *Suite) TestGetEnableRoutes(c *check.C) { } app.db.Save(&machine) - availableRoutes, err := app.GetAdvertisedNodeRoutes( - "test", - "test_enable_route_machine", - ) + err = app.processMachineRoutes(&machine) c.Assert(err, check.IsNil) - c.Assert(len(*availableRoutes), check.Equals, 2) - noEnabledRoutes, err := app.GetEnabledNodeRoutes( - "test", - "test_enable_route_machine", - ) + availableRoutes, err := app.GetAdvertisedRoutes(&machine) + c.Assert(err, check.IsNil) + c.Assert(err, check.IsNil) + c.Assert(len(availableRoutes), check.Equals, 2) + + noEnabledRoutes, err := app.GetEnabledRoutes(&machine) c.Assert(err, check.IsNil) c.Assert(len(noEnabledRoutes), check.Equals, 0) - err = app.EnableNodeRoute("test", "test_enable_route_machine", "192.168.0.0/24") + err = app.EnableRoutes(&machine, "192.168.0.0/24") c.Assert(err, check.NotNil) - err = app.EnableNodeRoute("test", "test_enable_route_machine", "10.0.0.0/24") + err = app.EnableRoutes(&machine, "10.0.0.0/24") c.Assert(err, check.IsNil) - enabledRoutes, err := app.GetEnabledNodeRoutes("test", "test_enable_route_machine") + enabledRoutes, err := app.GetEnabledRoutes(&machine) c.Assert(err, check.IsNil) c.Assert(len(enabledRoutes), check.Equals, 1) // Adding it twice will just let it pass through - err = app.EnableNodeRoute("test", "test_enable_route_machine", "10.0.0.0/24") + err = app.EnableRoutes(&machine, "10.0.0.0/24") c.Assert(err, check.IsNil) - enableRoutesAfterDoubleApply, err := app.GetEnabledNodeRoutes( - "test", - "test_enable_route_machine", - ) + enableRoutesAfterDoubleApply, err := app.GetEnabledRoutes(&machine) c.Assert(err, check.IsNil) c.Assert(len(enableRoutesAfterDoubleApply), check.Equals, 1) - err = app.EnableNodeRoute("test", "test_enable_route_machine", "150.0.10.0/25") + err = app.EnableRoutes(&machine, "150.0.10.0/25") c.Assert(err, check.IsNil) - enabledRoutesWithAdditionalRoute, err := app.GetEnabledNodeRoutes( - "test", - "test_enable_route_machine", - ) + enabledRoutesWithAdditionalRoute, err := app.GetEnabledRoutes(&machine) c.Assert(err, check.IsNil) c.Assert(len(enabledRoutesWithAdditionalRoute), check.Equals, 2) } From 5e89794433972c1f23e566fedcf7a37b4aa64ce5 Mon Sep 17 00:00:00 2001 From: Juan Font Date: Thu, 24 Nov 2022 17:14:21 +0000 Subject: [PATCH 12/28] Mark as primary the first instance of subnet + tests In preparation for subnet failover, mark the initial occurrence of a subnet as the primary one. --- machine.go | 12 +++++--- routes.go | 17 ++++++++++ routes_test.go | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+), 5 deletions(-) diff --git a/machine.go b/machine.go index d3d54802..376ba5a1 100644 --- a/machine.go +++ b/machine.go @@ -38,11 +38,6 @@ const ( maxHostnameLength = 255 ) -var ( - ExitRouteV4 = netip.MustParsePrefix("0.0.0.0/0") - ExitRouteV6 = netip.MustParsePrefix("::/0") -) - // Machine is a Headscale client. type Machine struct { ID uint64 `gorm:"primary_key"` @@ -1025,6 +1020,13 @@ func (h *Headscale) EnableRoutes(machine *Machine, routeStrs ...string) error { First(&route).Error if err == nil { route.Enabled = true + + // Mark already as primary if there is only this node offering this subnet + // (and is not an exit route) + if prefix != ExitRouteV4 && prefix != ExitRouteV6 { + route.IsPrimary = h.isUniquePrefix(route) + } + err = h.db.Save(&route).Error if err != nil { return fmt.Errorf("failed to enable route: %w", err) diff --git a/routes.go b/routes.go index 3ba710be..36d67a90 100644 --- a/routes.go +++ b/routes.go @@ -11,6 +11,11 @@ const ( ErrRouteIsNotAvailable = Error("route is not available") ) +var ( + ExitRouteV4 = netip.MustParsePrefix("0.0.0.0/0") + ExitRouteV6 = netip.MustParsePrefix("::/0") +) + type Route struct { gorm.Model @@ -37,6 +42,18 @@ func (rs Routes) toPrefixes() []netip.Prefix { return prefixes } +// isUniquePrefix returns if there is another machine providing the same route already +func (h *Headscale) isUniquePrefix(route Route) bool { + var count int64 + h.db. + Model(&Route{}). + Where("prefix = ? AND machine_id != ? AND advertised = ? AND enabled = ?", + route.Prefix, + route.MachineID, + true, true).Count(&count) + return count == 0 +} + // getMachinePrimaryRoutes returns the routes that are enabled and marked as primary (for subnet failover) // Exit nodes are not considered for this, as they are never marked as Primary func (h *Headscale) getMachinePrimaryRoutes(m *Machine) ([]Route, error) { diff --git a/routes_test.go b/routes_test.go index 2f034942..2560898e 100644 --- a/routes_test.go +++ b/routes_test.go @@ -125,3 +125,87 @@ func (s *Suite) TestGetEnableRoutes(c *check.C) { c.Assert(err, check.IsNil) c.Assert(len(enabledRoutesWithAdditionalRoute), check.Equals, 2) } + +func (s *Suite) TestIsUniquePrefix(c *check.C) { + namespace, err := app.CreateNamespace("test") + c.Assert(err, check.IsNil) + + pak, err := app.CreatePreAuthKey(namespace.Name, false, false, nil, nil) + c.Assert(err, check.IsNil) + + _, err = app.GetMachine("test", "test_enable_route_machine") + c.Assert(err, check.NotNil) + + route, err := netip.ParsePrefix( + "10.0.0.0/24", + ) + c.Assert(err, check.IsNil) + + route2, err := netip.ParsePrefix( + "150.0.10.0/25", + ) + c.Assert(err, check.IsNil) + + hostInfo1 := tailcfg.Hostinfo{ + RoutableIPs: []netip.Prefix{route, route2}, + } + machine1 := Machine{ + ID: 0, + MachineKey: "foo", + NodeKey: "bar", + DiscoKey: "faa", + Hostname: "test_enable_route_machine", + NamespaceID: namespace.ID, + RegisterMethod: RegisterMethodAuthKey, + AuthKeyID: uint(pak.ID), + HostInfo: HostInfo(hostInfo1), + } + app.db.Save(&machine1) + + err = app.processMachineRoutes(&machine1) + c.Assert(err, check.IsNil) + + err = app.EnableRoutes(&machine1, route.String()) + c.Assert(err, check.IsNil) + + err = app.EnableRoutes(&machine1, route2.String()) + c.Assert(err, check.IsNil) + + hostInfo2 := tailcfg.Hostinfo{ + RoutableIPs: []netip.Prefix{route2}, + } + machine2 := Machine{ + ID: 0, + MachineKey: "foo", + NodeKey: "bar", + DiscoKey: "faa", + Hostname: "test_enable_route_machine", + NamespaceID: namespace.ID, + RegisterMethod: RegisterMethodAuthKey, + AuthKeyID: uint(pak.ID), + HostInfo: HostInfo(hostInfo2), + } + app.db.Save(&machine2) + + err = app.processMachineRoutes(&machine2) + c.Assert(err, check.IsNil) + + err = app.EnableRoutes(&machine2, route2.String()) + c.Assert(err, check.IsNil) + + enabledRoutes1, err := app.GetEnabledRoutes(&machine1) + c.Assert(err, check.IsNil) + c.Assert(len(enabledRoutes1), check.Equals, 2) + + enabledRoutes2, err := app.GetEnabledRoutes(&machine2) + c.Assert(err, check.IsNil) + c.Assert(len(enabledRoutes2), check.Equals, 1) + + routes, err := app.getMachinePrimaryRoutes(&machine1) + c.Assert(err, check.IsNil) + c.Assert(len(routes), check.Equals, 2) + + routes, err = app.getMachinePrimaryRoutes(&machine2) + c.Assert(err, check.IsNil) + c.Assert(len(routes), check.Equals, 0) +} From de4e19017fe42fb89d1f78e9f8da9f7f97d8fe3b Mon Sep 17 00:00:00 2001 From: Juan Font Date: Thu, 24 Nov 2022 22:41:11 +0000 Subject: [PATCH 13/28] Use helper methods in Machine --- machine.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/machine.go b/machine.go index 376ba5a1..0ce8671b 100644 --- a/machine.go +++ b/machine.go @@ -138,6 +138,17 @@ func (machine Machine) isExpired() bool { return time.Now().UTC().After(*machine.Expiry) } +// isOnline returns if the machine is connected to Headscale. +// This is really a naive implementation, as we don't really see +// if there is a working connection between the client and the server. +func (machine *Machine) isOnline() bool { + if machine.LastSeen == nil { + return false + } + + return machine.LastSeen.After(time.Now().Add(-keepAliveInterval)) +} + func containsAddresses(inputs []string, addrs []string) bool { for _, addr := range addrs { if contains(inputs, addr) { @@ -708,9 +719,7 @@ func (h *Headscale) toNode( hostInfo := machine.GetHostInfo() - // A node is Online if it is connected to the control server, - // and we now we update LastSeen every keepAliveInterval duration at least. - online := machine.LastSeen.After(time.Now().Add(-keepAliveInterval)) + online := machine.isOnline() node := tailcfg.Node{ ID: tailcfg.NodeID(machine.ID), // this is the actual ID @@ -1023,7 +1032,7 @@ func (h *Headscale) EnableRoutes(machine *Machine, routeStrs ...string) error { // Mark already as primary if there is only this node offering this subnet // (and is not an exit route) - if prefix != ExitRouteV4 && prefix != ExitRouteV6 { + if !route.isExitRoute() { route.IsPrimary = h.isUniquePrefix(route) } From 091ade10cf26a74161547ac353047cb660cc8613 Mon Sep 17 00:00:00 2001 From: Juan Font Date: Thu, 24 Nov 2022 23:11:05 +0000 Subject: [PATCH 14/28] Added method to perform subnet failover --- routes.go | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) diff --git a/routes.go b/routes.go index 36d67a90..221db60f 100644 --- a/routes.go +++ b/routes.go @@ -4,6 +4,7 @@ import ( "fmt" "net/netip" + "github.com/rs/zerolog/log" "gorm.io/gorm" ) @@ -34,6 +35,10 @@ func (r *Route) String() string { return fmt.Sprintf("%s:%s", r.Machine, netip.Prefix(r.Prefix).String()) } +func (r *Route) isExitRoute() bool { + return netip.Prefix(r.Prefix) == ExitRouteV4 || netip.Prefix(r.Prefix) == ExitRouteV6 +} + func (rs Routes) toPrefixes() []netip.Prefix { prefixes := make([]netip.Prefix, len(rs)) for i, r := range rs { @@ -54,6 +59,23 @@ func (h *Headscale) isUniquePrefix(route Route) bool { return count == 0 } +func (h *Headscale) getPrimaryRoute(prefix netip.Prefix) (*Route, error) { + var route Route + err := h.db. + Preload("Machine"). + Where("prefix = ? AND advertised = ? AND enabled = ? AND is_primary = ?", IPPrefix(prefix), true, true, true). + First(&route).Error + if err != nil && err != gorm.ErrRecordNotFound { + return nil, err + } + + if err == gorm.ErrRecordNotFound { + return nil, gorm.ErrRecordNotFound + } + + return &route, nil +} + // getMachinePrimaryRoutes returns the routes that are enabled and marked as primary (for subnet failover) // Exit nodes are not considered for this, as they are never marked as Primary func (h *Headscale) getMachinePrimaryRoutes(m *Machine) ([]Route, error) { @@ -120,3 +142,104 @@ func (h *Headscale) processMachineRoutes(machine *Machine) error { return nil } + +func (h *Headscale) handlePrimarySubnetFailover() error { + // first, get all the enabled routes + var routes []Route + err := h.db. + Preload("Machine"). + Where("advertised = ? AND enabled = ?", true, true). + Find(&routes).Error + if err != nil && err != gorm.ErrRecordNotFound { + log.Error().Err(err).Msg("error getting routes") + } + + for _, route := range routes { + if route.isExitRoute() { + continue + } + + if !route.IsPrimary { + _, err := h.getPrimaryRoute(netip.Prefix(route.Prefix)) + if h.isUniquePrefix(route) || err == gorm.ErrRecordNotFound { + route.IsPrimary = true + err := h.db.Save(&route).Error + if err != nil { + log.Error().Err(err).Msg("error marking route as primary") + + return err + } + continue + } + } + + if route.IsPrimary { + if route.Machine.isOnline() { + continue + } + + // machine offline, find a new primary + log.Info(). + Str("machine", route.Machine.Hostname). + Str("prefix", netip.Prefix(route.Prefix).String()). + Msgf("machine offline, finding a new primary subnet") + + // find a new primary route + var newPrimaryRoutes []Route + err := h.db. + Preload("Machine"). + Where("prefix = ? AND machine_id != ? AND advertised = ? AND enabled = ?", + route.Prefix, + route.MachineID, + true, true). + Find(&newPrimaryRoutes).Error + if err != nil && err != gorm.ErrRecordNotFound { + log.Error().Err(err).Msg("error finding new primary route") + + return err + } + + var newPrimaryRoute *Route + for _, r := range newPrimaryRoutes { + if r.Machine.isOnline() { + newPrimaryRoute = &r + break + } + } + + if newPrimaryRoute == nil { + log.Warn(). + Str("machine", route.Machine.Hostname). + Str("prefix", netip.Prefix(route.Prefix).String()). + Msgf("no alternative primary route found") + continue + } + + log.Info(). + Str("old_machine", route.Machine.Hostname). + Str("prefix", netip.Prefix(route.Prefix).String()). + Str("new_machine", newPrimaryRoute.Machine.Hostname). + Msgf("found new primary route") + + // disable the old primary route + route.IsPrimary = false + err = h.db.Save(&route).Error + if err != nil { + log.Error().Err(err).Msg("error disabling old primary route") + + return err + } + + // enable the new primary route + newPrimaryRoute.IsPrimary = true + err = h.db.Save(&newPrimaryRoute).Error + if err != nil { + log.Error().Err(err).Msg("error enabling new primary route") + + return err + } + } + } + + return nil +} From d606b5a21e8b01979cd382bae332dda997b4a4ce Mon Sep 17 00:00:00 2001 From: Juan Font Date: Thu, 24 Nov 2022 23:11:16 +0000 Subject: [PATCH 15/28] Added tests for subnet failover --- routes_test.go | 147 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 145 insertions(+), 2 deletions(-) diff --git a/routes_test.go b/routes_test.go index 2560898e..8d98cebc 100644 --- a/routes_test.go +++ b/routes_test.go @@ -2,6 +2,7 @@ package headscale import ( "net/netip" + "time" "gopkg.in/check.v1" "tailscale.com/tailcfg" @@ -150,7 +151,7 @@ func (s *Suite) TestIsUniquePrefix(c *check.C) { RoutableIPs: []netip.Prefix{route, route2}, } machine1 := Machine{ - ID: 0, + ID: 1, MachineKey: "foo", NodeKey: "bar", DiscoKey: "faa", @@ -175,7 +176,7 @@ func (s *Suite) TestIsUniquePrefix(c *check.C) { RoutableIPs: []netip.Prefix{route2}, } machine2 := Machine{ - ID: 0, + ID: 2, MachineKey: "foo", NodeKey: "bar", DiscoKey: "faa", @@ -209,3 +210,145 @@ func (s *Suite) TestIsUniquePrefix(c *check.C) { c.Assert(err, check.IsNil) c.Assert(len(routes), check.Equals, 0) } + +func (s *Suite) TestSubnetFailover(c *check.C) { + namespace, err := app.CreateNamespace("test") + c.Assert(err, check.IsNil) + + pak, err := app.CreatePreAuthKey(namespace.Name, false, false, nil, nil) + c.Assert(err, check.IsNil) + + _, err = app.GetMachine("test", "test_enable_route_machine") + c.Assert(err, check.NotNil) + + prefix, err := netip.ParsePrefix( + "10.0.0.0/24", + ) + c.Assert(err, check.IsNil) + + prefix2, err := netip.ParsePrefix( + "150.0.10.0/25", + ) + c.Assert(err, check.IsNil) + + hostInfo1 := tailcfg.Hostinfo{ + RoutableIPs: []netip.Prefix{prefix, prefix2}, + } + + now := time.Now() + machine1 := Machine{ + ID: 1, + MachineKey: "foo", + NodeKey: "bar", + DiscoKey: "faa", + Hostname: "test_enable_route_machine", + NamespaceID: namespace.ID, + RegisterMethod: RegisterMethodAuthKey, + AuthKeyID: uint(pak.ID), + HostInfo: HostInfo(hostInfo1), + LastSeen: &now, + } + app.db.Save(&machine1) + + err = app.processMachineRoutes(&machine1) + c.Assert(err, check.IsNil) + + err = app.EnableRoutes(&machine1, prefix.String()) + c.Assert(err, check.IsNil) + + err = app.EnableRoutes(&machine1, prefix2.String()) + c.Assert(err, check.IsNil) + + err = app.handlePrimarySubnetFailover() + c.Assert(err, check.IsNil) + + enabledRoutes1, err := app.GetEnabledRoutes(&machine1) + c.Assert(err, check.IsNil) + c.Assert(len(enabledRoutes1), check.Equals, 2) + + route, err := app.getPrimaryRoute(prefix) + c.Assert(err, check.IsNil) + c.Assert(route.MachineID, check.Equals, machine1.ID) + + hostInfo2 := tailcfg.Hostinfo{ + RoutableIPs: []netip.Prefix{prefix2}, + } + machine2 := Machine{ + ID: 2, + MachineKey: "foo", + NodeKey: "bar", + DiscoKey: "faa", + Hostname: "test_enable_route_machine", + NamespaceID: namespace.ID, + RegisterMethod: RegisterMethodAuthKey, + AuthKeyID: uint(pak.ID), + HostInfo: HostInfo(hostInfo2), + LastSeen: &now, + } + app.db.Save(&machine2) + + err = app.processMachineRoutes(&machine2) + c.Assert(err, check.IsNil) + + err = app.EnableRoutes(&machine2, prefix2.String()) + c.Assert(err, check.IsNil) + + err = app.handlePrimarySubnetFailover() + c.Assert(err, check.IsNil) + + enabledRoutes1, err = app.GetEnabledRoutes(&machine1) + c.Assert(err, check.IsNil) + c.Assert(len(enabledRoutes1), check.Equals, 2) + + enabledRoutes2, err := app.GetEnabledRoutes(&machine2) + c.Assert(err, check.IsNil) + c.Assert(len(enabledRoutes2), check.Equals, 1) + + routes, err := app.getMachinePrimaryRoutes(&machine1) + c.Assert(err, check.IsNil) + c.Assert(len(routes), check.Equals, 2) + + routes, err = app.getMachinePrimaryRoutes(&machine2) + c.Assert(err, check.IsNil) + c.Assert(len(routes), check.Equals, 0) + + // lets make machine1 lastseen 10 mins ago + before := now.Add(-10 * time.Minute) + machine1.LastSeen = &before + err = app.db.Save(&machine1).Error + c.Assert(err, check.IsNil) + + err = app.handlePrimarySubnetFailover() + c.Assert(err, check.IsNil) + + routes, err = app.getMachinePrimaryRoutes(&machine1) + c.Assert(err, check.IsNil) + c.Assert(len(routes), check.Equals, 1) + + routes, err = app.getMachinePrimaryRoutes(&machine2) + c.Assert(err, check.IsNil) + c.Assert(len(routes), check.Equals, 1) + + machine2.HostInfo = HostInfo(tailcfg.Hostinfo{ + RoutableIPs: []netip.Prefix{prefix, prefix2}, + }) + err = app.db.Save(&machine2).Error + c.Assert(err, check.IsNil) + + err = app.processMachineRoutes(&machine2) + c.Assert(err, check.IsNil) + + err = app.EnableRoutes(&machine2, prefix.String()) + c.Assert(err, check.IsNil) + + err = app.handlePrimarySubnetFailover() + c.Assert(err, check.IsNil) + + routes, err = app.getMachinePrimaryRoutes(&machine1) + c.Assert(err, check.IsNil) + c.Assert(len(routes), check.Equals, 0) + + routes, err = app.getMachinePrimaryRoutes(&machine2) + c.Assert(err, check.IsNil) + c.Assert(len(routes), check.Equals, 2) +} From 358ed64b9863bd477725268569a17c732bca8672 Mon Sep 17 00:00:00 2001 From: Juan Font Date: Fri, 25 Nov 2022 15:11:22 +0000 Subject: [PATCH 16/28] Run handlePrimarySubnetFailover() with a ticker when Serve --- app.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app.go b/app.go index 69d40794..d840fd78 100644 --- a/app.go +++ b/app.go @@ -218,6 +218,16 @@ func (h *Headscale) expireEphemeralNodes(milliSeconds int64) { } } +func (h *Headscale) failoverSubnetRoutes(milliSeconds int64) { + ticker := time.NewTicker(time.Duration(milliSeconds) * time.Millisecond) + for range ticker.C { + err := h.handlePrimarySubnetFailover() + if err != nil { + log.Error().Err(err).Msg("failed to handle primary subnet failover") + } + } +} + func (h *Headscale) expireEphemeralNodesWorker() { namespaces, err := h.ListNamespaces() if err != nil { @@ -496,6 +506,8 @@ func (h *Headscale) Serve() error { go h.expireEphemeralNodes(updateInterval) + go h.failoverSubnetRoutes(updateInterval) + if zl.GlobalLevel() == zl.TraceLevel { zerolog.RespLog = true } else { From b5f1ae3d90b95794b78affd51c3bf27095c1e5b7 Mon Sep 17 00:00:00 2001 From: Juan Font Date: Fri, 25 Nov 2022 15:29:45 +0000 Subject: [PATCH 17/28] A big bunch of golang-lint fixes --- db.go | 4 ++++ machine.go | 5 +++++ machine_test.go | 4 +++- protocol_common_poll.go | 10 +++++++++- routes.go | 34 +++++++++++++++++++--------------- 5 files changed, 40 insertions(+), 17 deletions(-) diff --git a/db.go b/db.go index 72386ca8..41949525 100644 --- a/db.go +++ b/db.go @@ -106,6 +106,7 @@ func (h *Headscale) initDB() error { Err(err). Str("enabled_route", prefix.String()). Msg("Error parsing enabled_route") + continue } @@ -114,6 +115,7 @@ func (h *Headscale) initDB() error { log.Info(). Str("enabled_route", prefix.String()). Msg("Route already migrated to new table, skipping") + continue } @@ -335,6 +337,7 @@ func (i *IPPrefix) Scan(destination interface{}) error { return err } *i = IPPrefix(prefix) + return nil default: return fmt.Errorf("%w: unexpected data type %T", ErrCannotParsePrefix, destination) @@ -344,6 +347,7 @@ func (i *IPPrefix) Scan(destination interface{}) error { // Value return json value, implement driver.Valuer interface. func (i IPPrefix) Value() (driver.Value, error) { prefixStr := netip.Prefix(i).String() + return prefixStr, nil } diff --git a/machine.go b/machine.go index 0ce8671b..7b83e44c 100644 --- a/machine.go +++ b/machine.go @@ -937,6 +937,7 @@ func (h *Headscale) GetAdvertisedRoutes(machine *Machine) ([]netip.Prefix, error Err(err). Str("machine", machine.Hostname). Msg("Could not get advertised routes for machine") + return nil, err } @@ -962,6 +963,7 @@ func (h *Headscale) GetEnabledRoutes(machine *Machine) ([]netip.Prefix, error) { Err(err). Str("machine", machine.Hostname). Msg("Could not get enabled routes for machine") + return nil, err } @@ -982,6 +984,7 @@ func (h *Headscale) IsRoutesEnabled(machine *Machine, routeStr string) bool { enabledRoutes, err := h.GetEnabledRoutes(machine) if err != nil { log.Error().Err(err).Msg("Could not get enabled routes") + return false } @@ -1122,12 +1125,14 @@ func (h *Headscale) RoutesToProto(machine *Machine) *v1.Routes { availableRoutes, err := h.GetAdvertisedRoutes(machine) if err != nil { log.Error().Err(err).Msg("Could not get advertised routes") + return nil } enabledRoutes, err := h.GetEnabledRoutes(machine) if err != nil { log.Error().Err(err).Msg("Could not get enabled routes") + return nil } diff --git a/machine_test.go b/machine_test.go index c5073233..6cbf2821 100644 --- a/machine_test.go +++ b/machine_test.go @@ -1159,7 +1159,9 @@ func (s *Suite) TestAutoApproveRoutes(c *check.C) { machine0ByID, err := app.GetMachineByID(0) c.Assert(err, check.IsNil) - app.EnableAutoApprovedRoutes(machine0ByID) + err = app.EnableAutoApprovedRoutes(machine0ByID) + c.Assert(err, check.IsNil) + enabledRoutes, err := app.GetEnabledRoutes(machine0ByID) c.Assert(err, check.IsNil) c.Assert(enabledRoutes, check.HasLen, 3) diff --git a/protocol_common_poll.go b/protocol_common_poll.go index 7df01c86..8732c707 100644 --- a/protocol_common_poll.go +++ b/protocol_common_poll.go @@ -53,7 +53,15 @@ func (h *Headscale) handlePollCommon( } // update routes with peer information - h.EnableAutoApprovedRoutes(machine) + err = h.EnableAutoApprovedRoutes(machine) + if err != nil { + log.Error(). + Caller(). + Bool("noise", isNoise). + Str("machine", machine.Hostname). + Err(err). + Msg("Error running auto approved routes") + } } // From Tailscale client: diff --git a/routes.go b/routes.go index 221db60f..7de728de 100644 --- a/routes.go +++ b/routes.go @@ -1,6 +1,7 @@ package headscale import ( + "errors" "fmt" "net/netip" @@ -44,10 +45,11 @@ func (rs Routes) toPrefixes() []netip.Prefix { for i, r := range rs { prefixes[i] = netip.Prefix(r.Prefix) } + return prefixes } -// isUniquePrefix returns if there is another machine providing the same route already +// isUniquePrefix returns if there is another machine providing the same route already. func (h *Headscale) isUniquePrefix(route Route) bool { var count int64 h.db. @@ -56,6 +58,7 @@ func (h *Headscale) isUniquePrefix(route Route) bool { route.Prefix, route.MachineID, true, true).Count(&count) + return count == 0 } @@ -65,11 +68,11 @@ func (h *Headscale) getPrimaryRoute(prefix netip.Prefix) (*Route, error) { Preload("Machine"). Where("prefix = ? AND advertised = ? AND enabled = ? AND is_primary = ?", IPPrefix(prefix), true, true, true). First(&route).Error - if err != nil && err != gorm.ErrRecordNotFound { + if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { return nil, err } - if err == gorm.ErrRecordNotFound { + if errors.Is(err, gorm.ErrRecordNotFound) { return nil, gorm.ErrRecordNotFound } @@ -77,7 +80,7 @@ func (h *Headscale) getPrimaryRoute(prefix netip.Prefix) (*Route, error) { } // getMachinePrimaryRoutes returns the routes that are enabled and marked as primary (for subnet failover) -// Exit nodes are not considered for this, as they are never marked as Primary +// Exit nodes are not considered for this, as they are never marked as Primary. func (h *Headscale) getMachinePrimaryRoutes(m *Machine) ([]Route, error) { var routes []Route err := h.db. @@ -113,14 +116,12 @@ func (h *Headscale) processMachineRoutes(machine *Machine) error { } } advertisedRoutes[netip.Prefix(route.Prefix)] = true - } else { - if route.Advertised { - route.Advertised = false - route.Enabled = false - err := h.db.Save(&route).Error - if err != nil { - return err - } + } else if route.Advertised { + route.Advertised = false + route.Enabled = false + err := h.db.Save(&route).Error + if err != nil { + return err } } } @@ -150,7 +151,7 @@ func (h *Headscale) handlePrimarySubnetFailover() error { Preload("Machine"). Where("advertised = ? AND enabled = ?", true, true). Find(&routes).Error - if err != nil && err != gorm.ErrRecordNotFound { + if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { log.Error().Err(err).Msg("error getting routes") } @@ -161,7 +162,7 @@ func (h *Headscale) handlePrimarySubnetFailover() error { if !route.IsPrimary { _, err := h.getPrimaryRoute(netip.Prefix(route.Prefix)) - if h.isUniquePrefix(route) || err == gorm.ErrRecordNotFound { + if h.isUniquePrefix(route) || errors.Is(err, gorm.ErrRecordNotFound) { route.IsPrimary = true err := h.db.Save(&route).Error if err != nil { @@ -169,6 +170,7 @@ func (h *Headscale) handlePrimarySubnetFailover() error { return err } + continue } } @@ -193,7 +195,7 @@ func (h *Headscale) handlePrimarySubnetFailover() error { route.MachineID, true, true). Find(&newPrimaryRoutes).Error - if err != nil && err != gorm.ErrRecordNotFound { + if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { log.Error().Err(err).Msg("error finding new primary route") return err @@ -203,6 +205,7 @@ func (h *Headscale) handlePrimarySubnetFailover() error { for _, r := range newPrimaryRoutes { if r.Machine.isOnline() { newPrimaryRoute = &r + break } } @@ -212,6 +215,7 @@ func (h *Headscale) handlePrimarySubnetFailover() error { Str("machine", route.Machine.Hostname). Str("prefix", netip.Prefix(route.Prefix).String()). Msgf("no alternative primary route found") + continue } From 37a031d13e3f1566db4aba13924b04dc7329ed4a Mon Sep 17 00:00:00 2001 From: Juan Font Date: Fri, 25 Nov 2022 15:37:10 +0000 Subject: [PATCH 18/28] Another bunch of gosec/golint related fixes --- machine.go | 6 +++--- routes.go | 26 +++++++++++++------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/machine.go b/machine.go index 7b83e44c..1d79cd96 100644 --- a/machine.go +++ b/machine.go @@ -1105,9 +1105,9 @@ func (h *Headscale) EnableAutoApprovedRoutes(machine *Machine) error { } } - for _, approvedRoute := range approvedRoutes { - approvedRoute.Enabled = true - err = h.db.Save(&approvedRoute).Error + for i, approvedRoute := range approvedRoutes { + approvedRoutes[i].Enabled = true + err = h.db.Save(&approvedRoutes[i]).Error if err != nil { log.Err(err). Str("approvedRoute", approvedRoute.String()). diff --git a/routes.go b/routes.go index 7de728de..f1b1913f 100644 --- a/routes.go +++ b/routes.go @@ -106,20 +106,20 @@ func (h *Headscale) processMachineRoutes(machine *Machine) error { advertisedRoutes[prefix] = false } - for _, route := range currentRoutes { + for pos, route := range currentRoutes { if _, ok := advertisedRoutes[netip.Prefix(route.Prefix)]; ok { if !route.Advertised { - route.Advertised = true - err := h.db.Save(&route).Error + currentRoutes[pos].Advertised = true + err := h.db.Save(¤tRoutes[pos]).Error if err != nil { return err } } advertisedRoutes[netip.Prefix(route.Prefix)] = true } else if route.Advertised { - route.Advertised = false - route.Enabled = false - err := h.db.Save(&route).Error + currentRoutes[pos].Advertised = false + currentRoutes[pos].Enabled = false + err := h.db.Save(¤tRoutes[pos]).Error if err != nil { return err } @@ -155,7 +155,7 @@ func (h *Headscale) handlePrimarySubnetFailover() error { log.Error().Err(err).Msg("error getting routes") } - for _, route := range routes { + for pos, route := range routes { if route.isExitRoute() { continue } @@ -163,8 +163,8 @@ func (h *Headscale) handlePrimarySubnetFailover() error { if !route.IsPrimary { _, err := h.getPrimaryRoute(netip.Prefix(route.Prefix)) if h.isUniquePrefix(route) || errors.Is(err, gorm.ErrRecordNotFound) { - route.IsPrimary = true - err := h.db.Save(&route).Error + routes[pos].IsPrimary = true + err := h.db.Save(&routes[pos]).Error if err != nil { log.Error().Err(err).Msg("error marking route as primary") @@ -202,9 +202,9 @@ func (h *Headscale) handlePrimarySubnetFailover() error { } var newPrimaryRoute *Route - for _, r := range newPrimaryRoutes { + for pos, r := range newPrimaryRoutes { if r.Machine.isOnline() { - newPrimaryRoute = &r + newPrimaryRoute = &newPrimaryRoutes[pos] break } @@ -226,8 +226,8 @@ func (h *Headscale) handlePrimarySubnetFailover() error { Msgf("found new primary route") // disable the old primary route - route.IsPrimary = false - err = h.db.Save(&route).Error + routes[pos].IsPrimary = false + err = h.db.Save(&routes[pos]).Error if err != nil { log.Error().Err(err).Msg("error disabling old primary route") From 1d9cd8805379d6a38d9370e3d01a2bd3efc7d892 Mon Sep 17 00:00:00 2001 From: Juan Font Date: Fri, 25 Nov 2022 17:49:46 +0000 Subject: [PATCH 19/28] Remove method no longer used --- machine.go | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/machine.go b/machine.go index 1d79cd96..8826a654 100644 --- a/machine.go +++ b/machine.go @@ -1121,27 +1121,6 @@ func (h *Headscale) EnableAutoApprovedRoutes(machine *Machine) error { return nil } -func (h *Headscale) RoutesToProto(machine *Machine) *v1.Routes { - availableRoutes, err := h.GetAdvertisedRoutes(machine) - if err != nil { - log.Error().Err(err).Msg("Could not get advertised routes") - - return nil - } - - enabledRoutes, err := h.GetEnabledRoutes(machine) - if err != nil { - log.Error().Err(err).Msg("Could not get enabled routes") - - return nil - } - - return &v1.Routes{ - AdvertisedRoutes: ipPrefixToString(availableRoutes), - EnabledRoutes: ipPrefixToString(enabledRoutes), - } -} - func (h *Headscale) generateGivenName(suppliedName string, randomSuffix bool) (string, error) { normalizedHostname, err := NormalizeToFQDNRules( suppliedName, From 347d4d0ca5d485c1a8b0d14e2f5586c679707dbe Mon Sep 17 00:00:00 2001 From: Juan Font Date: Fri, 25 Nov 2022 17:50:12 +0000 Subject: [PATCH 20/28] Add support methods for the API --- routes.go | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/routes.go b/routes.go index f1b1913f..95d93ac1 100644 --- a/routes.go +++ b/routes.go @@ -5,7 +5,9 @@ import ( "fmt" "net/netip" + v1 "github.com/juanfont/headscale/gen/go/headscale/v1" "github.com/rs/zerolog/log" + "google.golang.org/protobuf/types/known/timestamppb" "gorm.io/gorm" ) @@ -49,6 +51,64 @@ func (rs Routes) toPrefixes() []netip.Prefix { return prefixes } +func (h *Headscale) GetRoutes() ([]Route, error) { + var routes []Route + err := h.db.Preload("Machine").Find(&routes).Error + if err != nil { + return nil, err + } + + return routes, nil +} + +func (h *Headscale) GetMachineRoutes(m *Machine) ([]Route, error) { + var routes []Route + err := h.db. + Preload("Machine"). + Where("machine_id = ?", m.ID). + Find(&routes).Error + if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { + return nil, err + } + + return routes, nil +} + +func (h *Headscale) GetRoute(id uint64) (*Route, error) { + var route Route + err := h.db.Preload("Machine").First(&route, id).Error + if err != nil { + return nil, err + } + + return &route, nil +} + +func (h *Headscale) EnableRoute(id uint64) error { + route, err := h.GetRoute(id) + if err != nil { + return err + } + + return h.EnableRoutes(&route.Machine, netip.Prefix(route.Prefix).String()) +} + +func (h *Headscale) DisableRoute(id uint64) error { + route, err := h.GetRoute(id) + if err != nil { + return err + } + + route.Enabled = false + route.IsPrimary = false + err = h.db.Save(route).Error + if err != nil { + return err + } + + return h.handlePrimarySubnetFailover() +} + // isUniquePrefix returns if there is another machine providing the same route already. func (h *Headscale) isUniquePrefix(route Route) bool { var count int64 @@ -247,3 +307,28 @@ func (h *Headscale) handlePrimarySubnetFailover() error { return nil } + +func (rs Routes) toProto() []*v1.Route { + protoRoutes := []*v1.Route{} + + for _, route := range rs { + protoRoute := v1.Route{ + Id: uint64(route.ID), + Machine: route.Machine.toProto(), + Prefix: netip.Prefix(route.Prefix).String(), + Advertised: route.Advertised, + Enabled: route.Enabled, + IsPrimary: route.IsPrimary, + CreatedAt: timestamppb.New(route.CreatedAt), + UpdatedAt: timestamppb.New(route.UpdatedAt), + } + + if route.DeletedAt.Valid { + protoRoute.DeletedAt = timestamppb.New(route.DeletedAt.Time) + } + + protoRoutes = append(protoRoutes, &protoRoute) + } + + return protoRoutes +} From 20d599ae34d860036f66d9fa7b07c0c3b742734d Mon Sep 17 00:00:00 2001 From: Juan Font Date: Sat, 26 Nov 2022 00:01:51 +0000 Subject: [PATCH 21/28] Add more logging --- routes.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/routes.go b/routes.go index 95d93ac1..f59a6039 100644 --- a/routes.go +++ b/routes.go @@ -223,6 +223,10 @@ func (h *Headscale) handlePrimarySubnetFailover() error { if !route.IsPrimary { _, err := h.getPrimaryRoute(netip.Prefix(route.Prefix)) if h.isUniquePrefix(route) || errors.Is(err, gorm.ErrRecordNotFound) { + log.Info(). + Str("prefix", netip.Prefix(route.Prefix).String()). + Str("machine", route.Machine.GivenName). + Msg("Setting primary route") routes[pos].IsPrimary = true err := h.db.Save(&routes[pos]).Error if err != nil { From 1ce3d95d954fc756e6a6dd7a3e0550fd751213a8 Mon Sep 17 00:00:00 2001 From: Juan Font Date: Sat, 26 Nov 2022 00:02:40 +0000 Subject: [PATCH 22/28] Updated protos with new routes API --- proto/headscale/v1/headscale.proto | 26 ++++++++++---- proto/headscale/v1/routes.proto | 55 +++++++++++++++++++++--------- 2 files changed, 59 insertions(+), 22 deletions(-) diff --git a/proto/headscale/v1/headscale.proto b/proto/headscale/v1/headscale.proto index 40d9be2a..4464cf2f 100644 --- a/proto/headscale/v1/headscale.proto +++ b/proto/headscale/v1/headscale.proto @@ -126,17 +126,31 @@ service HeadscaleService { // --- Machine end --- // --- Route start --- - rpc GetMachineRoute(GetMachineRouteRequest) returns (GetMachineRouteResponse) { + rpc GetRoutes(GetRoutesRequest) returns (GetRoutesResponse) { + option (google.api.http) = { + get: "/api/v1/routes" + }; + } + + rpc EnableRoute(EnableRouteRequest) returns (EnableRouteResponse) { + option (google.api.http) = { + post: "/api/v1/routes/{route_id}/enable" + }; + } + + rpc DisableRoute(DisableRouteRequest) returns (DisableRouteResponse) { + option (google.api.http) = { + post: "/api/v1/routes/{route_id}/disable" + }; + } + + + rpc GetMachineRoutes(GetMachineRoutesRequest) returns (GetMachineRoutesResponse) { option (google.api.http) = { get: "/api/v1/machine/{machine_id}/routes" }; } - rpc EnableMachineRoutes(EnableMachineRoutesRequest) returns (EnableMachineRoutesResponse) { - option (google.api.http) = { - post: "/api/v1/machine/{machine_id}/routes" - }; - } // --- Route end --- // --- ApiKeys start --- diff --git a/proto/headscale/v1/routes.proto b/proto/headscale/v1/routes.proto index 353c4294..e55e7694 100644 --- a/proto/headscale/v1/routes.proto +++ b/proto/headscale/v1/routes.proto @@ -2,24 +2,47 @@ syntax = "proto3"; package headscale.v1; option go_package = "github.com/juanfont/headscale/gen/go/v1"; -message Routes { - repeated string advertised_routes = 1; - repeated string enabled_routes = 2; +import "google/protobuf/timestamp.proto"; +import "headscale/v1/machine.proto"; + +message Route { + uint64 id = 1; + Machine machine = 2; + string prefix = 3; + bool advertised = 4; + bool enabled = 5; + bool is_primary = 6; + + google.protobuf.Timestamp created_at = 7; + google.protobuf.Timestamp updated_at = 8; + google.protobuf.Timestamp deleted_at = 9; } -message GetMachineRouteRequest { +message GetRoutesRequest { +} + +message GetRoutesResponse { + repeated Route routes = 1; +} + +message EnableRouteRequest { + uint64 route_id = 1; +} + +message EnableRouteResponse { +} + +message DisableRouteRequest { + uint64 route_id = 1; +} + +message DisableRouteResponse { +} + +message GetMachineRoutesRequest { uint64 machine_id = 1; } -message GetMachineRouteResponse { - Routes routes = 1; -} - -message EnableMachineRoutesRequest { - uint64 machine_id = 1; - repeated string routes = 2; -} - -message EnableMachineRoutesResponse { - Routes routes = 1; -} +message GetMachineRoutesResponse { + repeated Route routes = 1; +} \ No newline at end of file From cd2d2ef7e5737e15d84a071760955cd3f2555ed2 Mon Sep 17 00:00:00 2001 From: Juan Font Date: Sat, 26 Nov 2022 00:03:01 +0000 Subject: [PATCH 23/28] Updated generated pb code --- gen/go/headscale/v1/headscale.pb.go | 239 ++++--- gen/go/headscale/v1/headscale.pb.gw.go | 822 ++++++++++++----------- gen/go/headscale/v1/headscale_grpc.pb.go | 128 +++- gen/go/headscale/v1/routes.pb.go | 531 +++++++++++---- 4 files changed, 1083 insertions(+), 637 deletions(-) diff --git a/gen/go/headscale/v1/headscale.pb.go b/gen/go/headscale/v1/headscale.pb.go index eeb2c7cc..ca0b9764 100644 --- a/gen/go/headscale/v1/headscale.pb.go +++ b/gen/go/headscale/v1/headscale.pb.go @@ -36,7 +36,7 @@ var file_headscale_v1_headscale_proto_rawDesc = []byte{ 0x6f, 0x74, 0x6f, 0x1a, 0x19, 0x68, 0x65, 0x61, 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2f, 0x76, 0x31, 0x2f, 0x72, 0x6f, 0x75, 0x74, 0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x19, 0x68, 0x65, 0x61, 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2f, 0x76, 0x31, 0x2f, 0x61, 0x70, 0x69, - 0x6b, 0x65, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x32, 0xb1, 0x16, 0x0a, 0x10, 0x48, 0x65, + 0x6b, 0x65, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x32, 0x81, 0x18, 0x0a, 0x10, 0x48, 0x65, 0x61, 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x77, 0x0a, 0x0c, 0x47, 0x65, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x12, 0x21, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, @@ -51,9 +51,9 @@ var file_headscale_v1_headscale_proto_rawDesc = []byte{ 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x25, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1c, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x16, 0x22, - 0x11, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x2f, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, - 0x63, 0x65, 0x3a, 0x01, 0x2a, 0x12, 0x96, 0x01, 0x0a, 0x0f, 0x52, 0x65, 0x6e, 0x61, 0x6d, 0x65, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1c, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x16, 0x3a, + 0x01, 0x2a, 0x22, 0x11, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x2f, 0x6e, 0x61, 0x6d, 0x65, + 0x73, 0x70, 0x61, 0x63, 0x65, 0x12, 0x96, 0x01, 0x0a, 0x0f, 0x52, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x12, 0x24, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x52, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, @@ -85,17 +85,17 @@ var file_headscale_v1_headscale_proto_rawDesc = []byte{ 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x26, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x72, 0x65, 0x41, 0x75, 0x74, 0x68, 0x4b, 0x65, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1d, 0x82, - 0xd3, 0xe4, 0x93, 0x02, 0x17, 0x22, 0x12, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x2f, 0x70, - 0x72, 0x65, 0x61, 0x75, 0x74, 0x68, 0x6b, 0x65, 0x79, 0x3a, 0x01, 0x2a, 0x12, 0x87, 0x01, 0x0a, + 0xd3, 0xe4, 0x93, 0x02, 0x17, 0x3a, 0x01, 0x2a, 0x22, 0x12, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, + 0x31, 0x2f, 0x70, 0x72, 0x65, 0x61, 0x75, 0x74, 0x68, 0x6b, 0x65, 0x79, 0x12, 0x87, 0x01, 0x0a, 0x10, 0x45, 0x78, 0x70, 0x69, 0x72, 0x65, 0x50, 0x72, 0x65, 0x41, 0x75, 0x74, 0x68, 0x4b, 0x65, 0x79, 0x12, 0x25, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x78, 0x70, 0x69, 0x72, 0x65, 0x50, 0x72, 0x65, 0x41, 0x75, 0x74, 0x68, 0x4b, 0x65, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x26, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x78, 0x70, 0x69, 0x72, 0x65, 0x50, 0x72, 0x65, 0x41, 0x75, 0x74, 0x68, 0x4b, 0x65, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x22, 0x24, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1e, 0x22, 0x19, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, - 0x31, 0x2f, 0x70, 0x72, 0x65, 0x61, 0x75, 0x74, 0x68, 0x6b, 0x65, 0x79, 0x2f, 0x65, 0x78, 0x70, - 0x69, 0x72, 0x65, 0x3a, 0x01, 0x2a, 0x12, 0x7a, 0x0a, 0x0f, 0x4c, 0x69, 0x73, 0x74, 0x50, 0x72, + 0x22, 0x24, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1e, 0x3a, 0x01, 0x2a, 0x22, 0x19, 0x2f, 0x61, 0x70, + 0x69, 0x2f, 0x76, 0x31, 0x2f, 0x70, 0x72, 0x65, 0x61, 0x75, 0x74, 0x68, 0x6b, 0x65, 0x79, 0x2f, + 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x12, 0x7a, 0x0a, 0x0f, 0x4c, 0x69, 0x73, 0x74, 0x50, 0x72, 0x65, 0x41, 0x75, 0x74, 0x68, 0x4b, 0x65, 0x79, 0x73, 0x12, 0x24, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x50, 0x72, 0x65, 0x41, 0x75, 0x74, 0x68, 0x4b, 0x65, 0x79, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, @@ -110,8 +110,8 @@ var file_headscale_v1_headscale_proto_rawDesc = []byte{ 0x73, 0x74, 0x1a, 0x28, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x62, 0x75, 0x67, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x20, 0x82, 0xd3, - 0xe4, 0x93, 0x02, 0x1a, 0x22, 0x15, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x2f, 0x64, 0x65, - 0x62, 0x75, 0x67, 0x2f, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x3a, 0x01, 0x2a, 0x12, 0x75, + 0xe4, 0x93, 0x02, 0x1a, 0x3a, 0x01, 0x2a, 0x22, 0x15, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, + 0x2f, 0x64, 0x65, 0x62, 0x75, 0x67, 0x2f, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x12, 0x75, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x12, 0x1f, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x20, 0x2e, @@ -124,9 +124,9 @@ var file_headscale_v1_headscale_proto_rawDesc = []byte{ 0x53, 0x65, 0x74, 0x54, 0x61, 0x67, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x74, 0x54, 0x61, 0x67, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x2c, 0x82, - 0xd3, 0xe4, 0x93, 0x02, 0x26, 0x22, 0x21, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x2f, 0x6d, - 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x2f, 0x7b, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x5f, - 0x69, 0x64, 0x7d, 0x2f, 0x74, 0x61, 0x67, 0x73, 0x3a, 0x01, 0x2a, 0x12, 0x80, 0x01, 0x0a, 0x0f, + 0xd3, 0xe4, 0x93, 0x02, 0x26, 0x3a, 0x01, 0x2a, 0x22, 0x21, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, + 0x31, 0x2f, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x2f, 0x7b, 0x6d, 0x61, 0x63, 0x68, 0x69, + 0x6e, 0x65, 0x5f, 0x69, 0x64, 0x7d, 0x2f, 0x74, 0x61, 0x67, 0x73, 0x12, 0x80, 0x01, 0x0a, 0x0f, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x12, 0x24, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x52, 0x65, @@ -175,24 +175,37 @@ var file_headscale_v1_headscale_proto_rawDesc = []byte{ 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x2e, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x28, 0x22, 0x26, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x2f, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x2f, 0x7b, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, - 0x5f, 0x69, 0x64, 0x7d, 0x2f, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x12, 0x8b, - 0x01, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x52, 0x6f, 0x75, - 0x74, 0x65, 0x12, 0x24, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2e, 0x76, - 0x31, 0x2e, 0x47, 0x65, 0x74, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x52, 0x6f, 0x75, 0x74, - 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x25, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x73, - 0x63, 0x61, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x4d, 0x61, 0x63, 0x68, 0x69, - 0x6e, 0x65, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, - 0x2b, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x25, 0x12, 0x23, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, - 0x2f, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x2f, 0x7b, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, - 0x65, 0x5f, 0x69, 0x64, 0x7d, 0x2f, 0x72, 0x6f, 0x75, 0x74, 0x65, 0x73, 0x12, 0x97, 0x01, 0x0a, - 0x13, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x52, 0x6f, - 0x75, 0x74, 0x65, 0x73, 0x12, 0x28, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, - 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, - 0x65, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x29, - 0x2e, 0x68, 0x65, 0x61, 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x6e, - 0x61, 0x62, 0x6c, 0x65, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x52, 0x6f, 0x75, 0x74, 0x65, + 0x5f, 0x69, 0x64, 0x7d, 0x2f, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x12, 0x64, + 0x0a, 0x09, 0x47, 0x65, 0x74, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x73, 0x12, 0x1e, 0x2e, 0x68, 0x65, + 0x61, 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x6f, + 0x75, 0x74, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x68, 0x65, + 0x61, 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x6f, + 0x75, 0x74, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x16, 0x82, 0xd3, + 0xe4, 0x93, 0x02, 0x10, 0x12, 0x0e, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x2f, 0x72, 0x6f, + 0x75, 0x74, 0x65, 0x73, 0x12, 0x7c, 0x0a, 0x0b, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x52, 0x6f, + 0x75, 0x74, 0x65, 0x12, 0x20, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2e, + 0x76, 0x31, 0x2e, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x21, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x73, 0x63, 0x61, 0x6c, + 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x52, 0x6f, 0x75, 0x74, 0x65, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x28, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x22, + 0x22, 0x20, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x2f, 0x72, 0x6f, 0x75, 0x74, 0x65, 0x73, + 0x2f, 0x7b, 0x72, 0x6f, 0x75, 0x74, 0x65, 0x5f, 0x69, 0x64, 0x7d, 0x2f, 0x65, 0x6e, 0x61, 0x62, + 0x6c, 0x65, 0x12, 0x80, 0x01, 0x0a, 0x0c, 0x44, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x52, 0x6f, + 0x75, 0x74, 0x65, 0x12, 0x21, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2e, + 0x76, 0x31, 0x2e, 0x44, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x22, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x73, 0x63, 0x61, + 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x52, 0x6f, 0x75, + 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x29, 0x82, 0xd3, 0xe4, 0x93, + 0x02, 0x23, 0x22, 0x21, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x2f, 0x72, 0x6f, 0x75, 0x74, + 0x65, 0x73, 0x2f, 0x7b, 0x72, 0x6f, 0x75, 0x74, 0x65, 0x5f, 0x69, 0x64, 0x7d, 0x2f, 0x64, 0x69, + 0x73, 0x61, 0x62, 0x6c, 0x65, 0x12, 0x8e, 0x01, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x4d, 0x61, 0x63, + 0x68, 0x69, 0x6e, 0x65, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x73, 0x12, 0x25, 0x2e, 0x68, 0x65, 0x61, + 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x4d, 0x61, 0x63, + 0x68, 0x69, 0x6e, 0x65, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x26, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2e, 0x76, 0x31, + 0x2e, 0x47, 0x65, 0x74, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x2b, 0x82, 0xd3, 0xe4, 0x93, 0x02, - 0x25, 0x22, 0x23, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x2f, 0x6d, 0x61, 0x63, 0x68, 0x69, + 0x25, 0x12, 0x23, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x2f, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x2f, 0x7b, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x5f, 0x69, 0x64, 0x7d, 0x2f, 0x72, 0x6f, 0x75, 0x74, 0x65, 0x73, 0x12, 0x70, 0x0a, 0x0c, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, 0x70, 0x69, 0x4b, 0x65, 0x79, 0x12, 0x21, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x73, 0x63, 0x61, @@ -200,16 +213,16 @@ var file_headscale_v1_headscale_proto_rawDesc = []byte{ 0x65, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x22, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, 0x70, 0x69, 0x4b, 0x65, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x19, 0x82, - 0xd3, 0xe4, 0x93, 0x02, 0x13, 0x22, 0x0e, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x2f, 0x61, - 0x70, 0x69, 0x6b, 0x65, 0x79, 0x3a, 0x01, 0x2a, 0x12, 0x77, 0x0a, 0x0c, 0x45, 0x78, 0x70, 0x69, + 0xd3, 0xe4, 0x93, 0x02, 0x13, 0x3a, 0x01, 0x2a, 0x22, 0x0e, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, + 0x31, 0x2f, 0x61, 0x70, 0x69, 0x6b, 0x65, 0x79, 0x12, 0x77, 0x0a, 0x0c, 0x45, 0x78, 0x70, 0x69, 0x72, 0x65, 0x41, 0x70, 0x69, 0x4b, 0x65, 0x79, 0x12, 0x21, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x78, 0x70, 0x69, 0x72, 0x65, 0x41, 0x70, 0x69, 0x4b, 0x65, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x22, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x78, 0x70, 0x69, 0x72, 0x65, 0x41, 0x70, 0x69, 0x4b, 0x65, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, - 0x20, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1a, 0x22, 0x15, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, - 0x2f, 0x61, 0x70, 0x69, 0x6b, 0x65, 0x79, 0x2f, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x3a, 0x01, - 0x2a, 0x12, 0x6a, 0x0a, 0x0b, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x70, 0x69, 0x4b, 0x65, 0x79, 0x73, + 0x20, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1a, 0x3a, 0x01, 0x2a, 0x22, 0x15, 0x2f, 0x61, 0x70, 0x69, + 0x2f, 0x76, 0x31, 0x2f, 0x61, 0x70, 0x69, 0x6b, 0x65, 0x79, 0x2f, 0x65, 0x78, 0x70, 0x69, 0x72, + 0x65, 0x12, 0x6a, 0x0a, 0x0b, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x70, 0x69, 0x4b, 0x65, 0x79, 0x73, 0x12, 0x20, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x70, 0x69, 0x4b, 0x65, 0x79, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x21, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2e, 0x76, @@ -222,50 +235,54 @@ var file_headscale_v1_headscale_proto_rawDesc = []byte{ } var file_headscale_v1_headscale_proto_goTypes = []interface{}{ - (*GetNamespaceRequest)(nil), // 0: headscale.v1.GetNamespaceRequest - (*CreateNamespaceRequest)(nil), // 1: headscale.v1.CreateNamespaceRequest - (*RenameNamespaceRequest)(nil), // 2: headscale.v1.RenameNamespaceRequest - (*DeleteNamespaceRequest)(nil), // 3: headscale.v1.DeleteNamespaceRequest - (*ListNamespacesRequest)(nil), // 4: headscale.v1.ListNamespacesRequest - (*CreatePreAuthKeyRequest)(nil), // 5: headscale.v1.CreatePreAuthKeyRequest - (*ExpirePreAuthKeyRequest)(nil), // 6: headscale.v1.ExpirePreAuthKeyRequest - (*ListPreAuthKeysRequest)(nil), // 7: headscale.v1.ListPreAuthKeysRequest - (*DebugCreateMachineRequest)(nil), // 8: headscale.v1.DebugCreateMachineRequest - (*GetMachineRequest)(nil), // 9: headscale.v1.GetMachineRequest - (*SetTagsRequest)(nil), // 10: headscale.v1.SetTagsRequest - (*RegisterMachineRequest)(nil), // 11: headscale.v1.RegisterMachineRequest - (*DeleteMachineRequest)(nil), // 12: headscale.v1.DeleteMachineRequest - (*ExpireMachineRequest)(nil), // 13: headscale.v1.ExpireMachineRequest - (*RenameMachineRequest)(nil), // 14: headscale.v1.RenameMachineRequest - (*ListMachinesRequest)(nil), // 15: headscale.v1.ListMachinesRequest - (*MoveMachineRequest)(nil), // 16: headscale.v1.MoveMachineRequest - (*GetMachineRouteRequest)(nil), // 17: headscale.v1.GetMachineRouteRequest - (*EnableMachineRoutesRequest)(nil), // 18: headscale.v1.EnableMachineRoutesRequest - (*CreateApiKeyRequest)(nil), // 19: headscale.v1.CreateApiKeyRequest - (*ExpireApiKeyRequest)(nil), // 20: headscale.v1.ExpireApiKeyRequest - (*ListApiKeysRequest)(nil), // 21: headscale.v1.ListApiKeysRequest - (*GetNamespaceResponse)(nil), // 22: headscale.v1.GetNamespaceResponse - (*CreateNamespaceResponse)(nil), // 23: headscale.v1.CreateNamespaceResponse - (*RenameNamespaceResponse)(nil), // 24: headscale.v1.RenameNamespaceResponse - (*DeleteNamespaceResponse)(nil), // 25: headscale.v1.DeleteNamespaceResponse - (*ListNamespacesResponse)(nil), // 26: headscale.v1.ListNamespacesResponse - (*CreatePreAuthKeyResponse)(nil), // 27: headscale.v1.CreatePreAuthKeyResponse - (*ExpirePreAuthKeyResponse)(nil), // 28: headscale.v1.ExpirePreAuthKeyResponse - (*ListPreAuthKeysResponse)(nil), // 29: headscale.v1.ListPreAuthKeysResponse - (*DebugCreateMachineResponse)(nil), // 30: headscale.v1.DebugCreateMachineResponse - (*GetMachineResponse)(nil), // 31: headscale.v1.GetMachineResponse - (*SetTagsResponse)(nil), // 32: headscale.v1.SetTagsResponse - (*RegisterMachineResponse)(nil), // 33: headscale.v1.RegisterMachineResponse - (*DeleteMachineResponse)(nil), // 34: headscale.v1.DeleteMachineResponse - (*ExpireMachineResponse)(nil), // 35: headscale.v1.ExpireMachineResponse - (*RenameMachineResponse)(nil), // 36: headscale.v1.RenameMachineResponse - (*ListMachinesResponse)(nil), // 37: headscale.v1.ListMachinesResponse - (*MoveMachineResponse)(nil), // 38: headscale.v1.MoveMachineResponse - (*GetMachineRouteResponse)(nil), // 39: headscale.v1.GetMachineRouteResponse - (*EnableMachineRoutesResponse)(nil), // 40: headscale.v1.EnableMachineRoutesResponse - (*CreateApiKeyResponse)(nil), // 41: headscale.v1.CreateApiKeyResponse - (*ExpireApiKeyResponse)(nil), // 42: headscale.v1.ExpireApiKeyResponse - (*ListApiKeysResponse)(nil), // 43: headscale.v1.ListApiKeysResponse + (*GetNamespaceRequest)(nil), // 0: headscale.v1.GetNamespaceRequest + (*CreateNamespaceRequest)(nil), // 1: headscale.v1.CreateNamespaceRequest + (*RenameNamespaceRequest)(nil), // 2: headscale.v1.RenameNamespaceRequest + (*DeleteNamespaceRequest)(nil), // 3: headscale.v1.DeleteNamespaceRequest + (*ListNamespacesRequest)(nil), // 4: headscale.v1.ListNamespacesRequest + (*CreatePreAuthKeyRequest)(nil), // 5: headscale.v1.CreatePreAuthKeyRequest + (*ExpirePreAuthKeyRequest)(nil), // 6: headscale.v1.ExpirePreAuthKeyRequest + (*ListPreAuthKeysRequest)(nil), // 7: headscale.v1.ListPreAuthKeysRequest + (*DebugCreateMachineRequest)(nil), // 8: headscale.v1.DebugCreateMachineRequest + (*GetMachineRequest)(nil), // 9: headscale.v1.GetMachineRequest + (*SetTagsRequest)(nil), // 10: headscale.v1.SetTagsRequest + (*RegisterMachineRequest)(nil), // 11: headscale.v1.RegisterMachineRequest + (*DeleteMachineRequest)(nil), // 12: headscale.v1.DeleteMachineRequest + (*ExpireMachineRequest)(nil), // 13: headscale.v1.ExpireMachineRequest + (*RenameMachineRequest)(nil), // 14: headscale.v1.RenameMachineRequest + (*ListMachinesRequest)(nil), // 15: headscale.v1.ListMachinesRequest + (*MoveMachineRequest)(nil), // 16: headscale.v1.MoveMachineRequest + (*GetRoutesRequest)(nil), // 17: headscale.v1.GetRoutesRequest + (*EnableRouteRequest)(nil), // 18: headscale.v1.EnableRouteRequest + (*DisableRouteRequest)(nil), // 19: headscale.v1.DisableRouteRequest + (*GetMachineRoutesRequest)(nil), // 20: headscale.v1.GetMachineRoutesRequest + (*CreateApiKeyRequest)(nil), // 21: headscale.v1.CreateApiKeyRequest + (*ExpireApiKeyRequest)(nil), // 22: headscale.v1.ExpireApiKeyRequest + (*ListApiKeysRequest)(nil), // 23: headscale.v1.ListApiKeysRequest + (*GetNamespaceResponse)(nil), // 24: headscale.v1.GetNamespaceResponse + (*CreateNamespaceResponse)(nil), // 25: headscale.v1.CreateNamespaceResponse + (*RenameNamespaceResponse)(nil), // 26: headscale.v1.RenameNamespaceResponse + (*DeleteNamespaceResponse)(nil), // 27: headscale.v1.DeleteNamespaceResponse + (*ListNamespacesResponse)(nil), // 28: headscale.v1.ListNamespacesResponse + (*CreatePreAuthKeyResponse)(nil), // 29: headscale.v1.CreatePreAuthKeyResponse + (*ExpirePreAuthKeyResponse)(nil), // 30: headscale.v1.ExpirePreAuthKeyResponse + (*ListPreAuthKeysResponse)(nil), // 31: headscale.v1.ListPreAuthKeysResponse + (*DebugCreateMachineResponse)(nil), // 32: headscale.v1.DebugCreateMachineResponse + (*GetMachineResponse)(nil), // 33: headscale.v1.GetMachineResponse + (*SetTagsResponse)(nil), // 34: headscale.v1.SetTagsResponse + (*RegisterMachineResponse)(nil), // 35: headscale.v1.RegisterMachineResponse + (*DeleteMachineResponse)(nil), // 36: headscale.v1.DeleteMachineResponse + (*ExpireMachineResponse)(nil), // 37: headscale.v1.ExpireMachineResponse + (*RenameMachineResponse)(nil), // 38: headscale.v1.RenameMachineResponse + (*ListMachinesResponse)(nil), // 39: headscale.v1.ListMachinesResponse + (*MoveMachineResponse)(nil), // 40: headscale.v1.MoveMachineResponse + (*GetRoutesResponse)(nil), // 41: headscale.v1.GetRoutesResponse + (*EnableRouteResponse)(nil), // 42: headscale.v1.EnableRouteResponse + (*DisableRouteResponse)(nil), // 43: headscale.v1.DisableRouteResponse + (*GetMachineRoutesResponse)(nil), // 44: headscale.v1.GetMachineRoutesResponse + (*CreateApiKeyResponse)(nil), // 45: headscale.v1.CreateApiKeyResponse + (*ExpireApiKeyResponse)(nil), // 46: headscale.v1.ExpireApiKeyResponse + (*ListApiKeysResponse)(nil), // 47: headscale.v1.ListApiKeysResponse } var file_headscale_v1_headscale_proto_depIdxs = []int32{ 0, // 0: headscale.v1.HeadscaleService.GetNamespace:input_type -> headscale.v1.GetNamespaceRequest @@ -285,35 +302,39 @@ var file_headscale_v1_headscale_proto_depIdxs = []int32{ 14, // 14: headscale.v1.HeadscaleService.RenameMachine:input_type -> headscale.v1.RenameMachineRequest 15, // 15: headscale.v1.HeadscaleService.ListMachines:input_type -> headscale.v1.ListMachinesRequest 16, // 16: headscale.v1.HeadscaleService.MoveMachine:input_type -> headscale.v1.MoveMachineRequest - 17, // 17: headscale.v1.HeadscaleService.GetMachineRoute:input_type -> headscale.v1.GetMachineRouteRequest - 18, // 18: headscale.v1.HeadscaleService.EnableMachineRoutes:input_type -> headscale.v1.EnableMachineRoutesRequest - 19, // 19: headscale.v1.HeadscaleService.CreateApiKey:input_type -> headscale.v1.CreateApiKeyRequest - 20, // 20: headscale.v1.HeadscaleService.ExpireApiKey:input_type -> headscale.v1.ExpireApiKeyRequest - 21, // 21: headscale.v1.HeadscaleService.ListApiKeys:input_type -> headscale.v1.ListApiKeysRequest - 22, // 22: headscale.v1.HeadscaleService.GetNamespace:output_type -> headscale.v1.GetNamespaceResponse - 23, // 23: headscale.v1.HeadscaleService.CreateNamespace:output_type -> headscale.v1.CreateNamespaceResponse - 24, // 24: headscale.v1.HeadscaleService.RenameNamespace:output_type -> headscale.v1.RenameNamespaceResponse - 25, // 25: headscale.v1.HeadscaleService.DeleteNamespace:output_type -> headscale.v1.DeleteNamespaceResponse - 26, // 26: headscale.v1.HeadscaleService.ListNamespaces:output_type -> headscale.v1.ListNamespacesResponse - 27, // 27: headscale.v1.HeadscaleService.CreatePreAuthKey:output_type -> headscale.v1.CreatePreAuthKeyResponse - 28, // 28: headscale.v1.HeadscaleService.ExpirePreAuthKey:output_type -> headscale.v1.ExpirePreAuthKeyResponse - 29, // 29: headscale.v1.HeadscaleService.ListPreAuthKeys:output_type -> headscale.v1.ListPreAuthKeysResponse - 30, // 30: headscale.v1.HeadscaleService.DebugCreateMachine:output_type -> headscale.v1.DebugCreateMachineResponse - 31, // 31: headscale.v1.HeadscaleService.GetMachine:output_type -> headscale.v1.GetMachineResponse - 32, // 32: headscale.v1.HeadscaleService.SetTags:output_type -> headscale.v1.SetTagsResponse - 33, // 33: headscale.v1.HeadscaleService.RegisterMachine:output_type -> headscale.v1.RegisterMachineResponse - 34, // 34: headscale.v1.HeadscaleService.DeleteMachine:output_type -> headscale.v1.DeleteMachineResponse - 35, // 35: headscale.v1.HeadscaleService.ExpireMachine:output_type -> headscale.v1.ExpireMachineResponse - 36, // 36: headscale.v1.HeadscaleService.RenameMachine:output_type -> headscale.v1.RenameMachineResponse - 37, // 37: headscale.v1.HeadscaleService.ListMachines:output_type -> headscale.v1.ListMachinesResponse - 38, // 38: headscale.v1.HeadscaleService.MoveMachine:output_type -> headscale.v1.MoveMachineResponse - 39, // 39: headscale.v1.HeadscaleService.GetMachineRoute:output_type -> headscale.v1.GetMachineRouteResponse - 40, // 40: headscale.v1.HeadscaleService.EnableMachineRoutes:output_type -> headscale.v1.EnableMachineRoutesResponse - 41, // 41: headscale.v1.HeadscaleService.CreateApiKey:output_type -> headscale.v1.CreateApiKeyResponse - 42, // 42: headscale.v1.HeadscaleService.ExpireApiKey:output_type -> headscale.v1.ExpireApiKeyResponse - 43, // 43: headscale.v1.HeadscaleService.ListApiKeys:output_type -> headscale.v1.ListApiKeysResponse - 22, // [22:44] is the sub-list for method output_type - 0, // [0:22] is the sub-list for method input_type + 17, // 17: headscale.v1.HeadscaleService.GetRoutes:input_type -> headscale.v1.GetRoutesRequest + 18, // 18: headscale.v1.HeadscaleService.EnableRoute:input_type -> headscale.v1.EnableRouteRequest + 19, // 19: headscale.v1.HeadscaleService.DisableRoute:input_type -> headscale.v1.DisableRouteRequest + 20, // 20: headscale.v1.HeadscaleService.GetMachineRoutes:input_type -> headscale.v1.GetMachineRoutesRequest + 21, // 21: headscale.v1.HeadscaleService.CreateApiKey:input_type -> headscale.v1.CreateApiKeyRequest + 22, // 22: headscale.v1.HeadscaleService.ExpireApiKey:input_type -> headscale.v1.ExpireApiKeyRequest + 23, // 23: headscale.v1.HeadscaleService.ListApiKeys:input_type -> headscale.v1.ListApiKeysRequest + 24, // 24: headscale.v1.HeadscaleService.GetNamespace:output_type -> headscale.v1.GetNamespaceResponse + 25, // 25: headscale.v1.HeadscaleService.CreateNamespace:output_type -> headscale.v1.CreateNamespaceResponse + 26, // 26: headscale.v1.HeadscaleService.RenameNamespace:output_type -> headscale.v1.RenameNamespaceResponse + 27, // 27: headscale.v1.HeadscaleService.DeleteNamespace:output_type -> headscale.v1.DeleteNamespaceResponse + 28, // 28: headscale.v1.HeadscaleService.ListNamespaces:output_type -> headscale.v1.ListNamespacesResponse + 29, // 29: headscale.v1.HeadscaleService.CreatePreAuthKey:output_type -> headscale.v1.CreatePreAuthKeyResponse + 30, // 30: headscale.v1.HeadscaleService.ExpirePreAuthKey:output_type -> headscale.v1.ExpirePreAuthKeyResponse + 31, // 31: headscale.v1.HeadscaleService.ListPreAuthKeys:output_type -> headscale.v1.ListPreAuthKeysResponse + 32, // 32: headscale.v1.HeadscaleService.DebugCreateMachine:output_type -> headscale.v1.DebugCreateMachineResponse + 33, // 33: headscale.v1.HeadscaleService.GetMachine:output_type -> headscale.v1.GetMachineResponse + 34, // 34: headscale.v1.HeadscaleService.SetTags:output_type -> headscale.v1.SetTagsResponse + 35, // 35: headscale.v1.HeadscaleService.RegisterMachine:output_type -> headscale.v1.RegisterMachineResponse + 36, // 36: headscale.v1.HeadscaleService.DeleteMachine:output_type -> headscale.v1.DeleteMachineResponse + 37, // 37: headscale.v1.HeadscaleService.ExpireMachine:output_type -> headscale.v1.ExpireMachineResponse + 38, // 38: headscale.v1.HeadscaleService.RenameMachine:output_type -> headscale.v1.RenameMachineResponse + 39, // 39: headscale.v1.HeadscaleService.ListMachines:output_type -> headscale.v1.ListMachinesResponse + 40, // 40: headscale.v1.HeadscaleService.MoveMachine:output_type -> headscale.v1.MoveMachineResponse + 41, // 41: headscale.v1.HeadscaleService.GetRoutes:output_type -> headscale.v1.GetRoutesResponse + 42, // 42: headscale.v1.HeadscaleService.EnableRoute:output_type -> headscale.v1.EnableRouteResponse + 43, // 43: headscale.v1.HeadscaleService.DisableRoute:output_type -> headscale.v1.DisableRouteResponse + 44, // 44: headscale.v1.HeadscaleService.GetMachineRoutes:output_type -> headscale.v1.GetMachineRoutesResponse + 45, // 45: headscale.v1.HeadscaleService.CreateApiKey:output_type -> headscale.v1.CreateApiKeyResponse + 46, // 46: headscale.v1.HeadscaleService.ExpireApiKey:output_type -> headscale.v1.ExpireApiKeyResponse + 47, // 47: headscale.v1.HeadscaleService.ListApiKeys:output_type -> headscale.v1.ListApiKeysResponse + 24, // [24:48] is the sub-list for method output_type + 0, // [0:24] is the sub-list for method input_type 0, // [0:0] is the sub-list for extension type_name 0, // [0:0] is the sub-list for extension extendee 0, // [0:0] is the sub-list for field type_name diff --git a/gen/go/headscale/v1/headscale.pb.gw.go b/gen/go/headscale/v1/headscale.pb.gw.go index 13d5f938..8b9ea866 100644 --- a/gen/go/headscale/v1/headscale.pb.gw.go +++ b/gen/go/headscale/v1/headscale.pb.gw.go @@ -835,64 +835,26 @@ func local_request_HeadscaleService_MoveMachine_0(ctx context.Context, marshaler } -func request_HeadscaleService_GetMachineRoute_0(ctx context.Context, marshaler runtime.Marshaler, client HeadscaleServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq GetMachineRouteRequest +func request_HeadscaleService_GetRoutes_0(ctx context.Context, marshaler runtime.Marshaler, client HeadscaleServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq GetRoutesRequest var metadata runtime.ServerMetadata - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["machine_id"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "machine_id") - } - - protoReq.MachineId, err = runtime.Uint64(val) - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "machine_id", err) - } - - msg, err := client.GetMachineRoute(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + msg, err := client.GetRoutes(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } -func local_request_HeadscaleService_GetMachineRoute_0(ctx context.Context, marshaler runtime.Marshaler, server HeadscaleServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq GetMachineRouteRequest +func local_request_HeadscaleService_GetRoutes_0(ctx context.Context, marshaler runtime.Marshaler, server HeadscaleServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq GetRoutesRequest var metadata runtime.ServerMetadata - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["machine_id"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "machine_id") - } - - protoReq.MachineId, err = runtime.Uint64(val) - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "machine_id", err) - } - - msg, err := server.GetMachineRoute(ctx, &protoReq) + msg, err := server.GetRoutes(ctx, &protoReq) return msg, metadata, err } -var ( - filter_HeadscaleService_EnableMachineRoutes_0 = &utilities.DoubleArray{Encoding: map[string]int{"machine_id": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} -) - -func request_HeadscaleService_EnableMachineRoutes_0(ctx context.Context, marshaler runtime.Marshaler, client HeadscaleServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq EnableMachineRoutesRequest +func request_HeadscaleService_EnableRoute_0(ctx context.Context, marshaler runtime.Marshaler, client HeadscaleServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq EnableRouteRequest var metadata runtime.ServerMetadata var ( @@ -902,30 +864,101 @@ func request_HeadscaleService_EnableMachineRoutes_0(ctx context.Context, marshal _ = err ) - val, ok = pathParams["machine_id"] + val, ok = pathParams["route_id"] if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "machine_id") + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "route_id") } - protoReq.MachineId, err = runtime.Uint64(val) + protoReq.RouteId, err = runtime.Uint64(val) if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "machine_id", err) + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "route_id", err) } - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_HeadscaleService_EnableMachineRoutes_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.EnableMachineRoutes(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + msg, err := client.EnableRoute(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } -func local_request_HeadscaleService_EnableMachineRoutes_0(ctx context.Context, marshaler runtime.Marshaler, server HeadscaleServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq EnableMachineRoutesRequest +func local_request_HeadscaleService_EnableRoute_0(ctx context.Context, marshaler runtime.Marshaler, server HeadscaleServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq EnableRouteRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["route_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "route_id") + } + + protoReq.RouteId, err = runtime.Uint64(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "route_id", err) + } + + msg, err := server.EnableRoute(ctx, &protoReq) + return msg, metadata, err + +} + +func request_HeadscaleService_DisableRoute_0(ctx context.Context, marshaler runtime.Marshaler, client HeadscaleServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq DisableRouteRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["route_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "route_id") + } + + protoReq.RouteId, err = runtime.Uint64(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "route_id", err) + } + + msg, err := client.DisableRoute(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_HeadscaleService_DisableRoute_0(ctx context.Context, marshaler runtime.Marshaler, server HeadscaleServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq DisableRouteRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["route_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "route_id") + } + + protoReq.RouteId, err = runtime.Uint64(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "route_id", err) + } + + msg, err := server.DisableRoute(ctx, &protoReq) + return msg, metadata, err + +} + +func request_HeadscaleService_GetMachineRoutes_0(ctx context.Context, marshaler runtime.Marshaler, client HeadscaleServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq GetMachineRoutesRequest var metadata runtime.ServerMetadata var ( @@ -945,14 +978,33 @@ func local_request_HeadscaleService_EnableMachineRoutes_0(ctx context.Context, m return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "machine_id", err) } - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_HeadscaleService_EnableMachineRoutes_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + msg, err := client.GetMachineRoutes(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_HeadscaleService_GetMachineRoutes_0(ctx context.Context, marshaler runtime.Marshaler, server HeadscaleServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq GetMachineRoutesRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["machine_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "machine_id") } - msg, err := server.EnableMachineRoutes(ctx, &protoReq) + protoReq.MachineId, err = runtime.Uint64(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "machine_id", err) + } + + msg, err := server.GetMachineRoutes(ctx, &protoReq) return msg, metadata, err } @@ -1055,22 +1107,20 @@ func RegisterHeadscaleServiceHandlerServer(ctx context.Context, mux *runtime.Ser var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/GetNamespace", runtime.WithHTTPPathPattern("/api/v1/namespace/{name}")) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/GetNamespace", runtime.WithHTTPPathPattern("/api/v1/namespace/{name}")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_HeadscaleService_GetNamespace_0(annotatedContext, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_HeadscaleService_GetNamespace_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_GetNamespace_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_GetNamespace_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1080,22 +1130,20 @@ func RegisterHeadscaleServiceHandlerServer(ctx context.Context, mux *runtime.Ser var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/CreateNamespace", runtime.WithHTTPPathPattern("/api/v1/namespace")) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/CreateNamespace", runtime.WithHTTPPathPattern("/api/v1/namespace")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_HeadscaleService_CreateNamespace_0(annotatedContext, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_HeadscaleService_CreateNamespace_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_CreateNamespace_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_CreateNamespace_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1105,22 +1153,20 @@ func RegisterHeadscaleServiceHandlerServer(ctx context.Context, mux *runtime.Ser var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/RenameNamespace", runtime.WithHTTPPathPattern("/api/v1/namespace/{old_name}/rename/{new_name}")) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/RenameNamespace", runtime.WithHTTPPathPattern("/api/v1/namespace/{old_name}/rename/{new_name}")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_HeadscaleService_RenameNamespace_0(annotatedContext, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_HeadscaleService_RenameNamespace_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_RenameNamespace_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_RenameNamespace_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1130,22 +1176,20 @@ func RegisterHeadscaleServiceHandlerServer(ctx context.Context, mux *runtime.Ser var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/DeleteNamespace", runtime.WithHTTPPathPattern("/api/v1/namespace/{name}")) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/DeleteNamespace", runtime.WithHTTPPathPattern("/api/v1/namespace/{name}")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_HeadscaleService_DeleteNamespace_0(annotatedContext, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_HeadscaleService_DeleteNamespace_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_DeleteNamespace_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_DeleteNamespace_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1155,22 +1199,20 @@ func RegisterHeadscaleServiceHandlerServer(ctx context.Context, mux *runtime.Ser var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/ListNamespaces", runtime.WithHTTPPathPattern("/api/v1/namespace")) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/ListNamespaces", runtime.WithHTTPPathPattern("/api/v1/namespace")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_HeadscaleService_ListNamespaces_0(annotatedContext, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_HeadscaleService_ListNamespaces_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_ListNamespaces_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_ListNamespaces_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1180,22 +1222,20 @@ func RegisterHeadscaleServiceHandlerServer(ctx context.Context, mux *runtime.Ser var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/CreatePreAuthKey", runtime.WithHTTPPathPattern("/api/v1/preauthkey")) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/CreatePreAuthKey", runtime.WithHTTPPathPattern("/api/v1/preauthkey")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_HeadscaleService_CreatePreAuthKey_0(annotatedContext, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_HeadscaleService_CreatePreAuthKey_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_CreatePreAuthKey_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_CreatePreAuthKey_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1205,22 +1245,20 @@ func RegisterHeadscaleServiceHandlerServer(ctx context.Context, mux *runtime.Ser var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/ExpirePreAuthKey", runtime.WithHTTPPathPattern("/api/v1/preauthkey/expire")) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/ExpirePreAuthKey", runtime.WithHTTPPathPattern("/api/v1/preauthkey/expire")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_HeadscaleService_ExpirePreAuthKey_0(annotatedContext, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_HeadscaleService_ExpirePreAuthKey_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_ExpirePreAuthKey_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_ExpirePreAuthKey_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1230,22 +1268,20 @@ func RegisterHeadscaleServiceHandlerServer(ctx context.Context, mux *runtime.Ser var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/ListPreAuthKeys", runtime.WithHTTPPathPattern("/api/v1/preauthkey")) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/ListPreAuthKeys", runtime.WithHTTPPathPattern("/api/v1/preauthkey")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_HeadscaleService_ListPreAuthKeys_0(annotatedContext, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_HeadscaleService_ListPreAuthKeys_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_ListPreAuthKeys_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_ListPreAuthKeys_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1255,22 +1291,20 @@ func RegisterHeadscaleServiceHandlerServer(ctx context.Context, mux *runtime.Ser var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/DebugCreateMachine", runtime.WithHTTPPathPattern("/api/v1/debug/machine")) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/DebugCreateMachine", runtime.WithHTTPPathPattern("/api/v1/debug/machine")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_HeadscaleService_DebugCreateMachine_0(annotatedContext, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_HeadscaleService_DebugCreateMachine_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_DebugCreateMachine_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_DebugCreateMachine_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1280,22 +1314,20 @@ func RegisterHeadscaleServiceHandlerServer(ctx context.Context, mux *runtime.Ser var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/GetMachine", runtime.WithHTTPPathPattern("/api/v1/machine/{machine_id}")) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/GetMachine", runtime.WithHTTPPathPattern("/api/v1/machine/{machine_id}")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_HeadscaleService_GetMachine_0(annotatedContext, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_HeadscaleService_GetMachine_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_GetMachine_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_GetMachine_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1305,22 +1337,20 @@ func RegisterHeadscaleServiceHandlerServer(ctx context.Context, mux *runtime.Ser var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/SetTags", runtime.WithHTTPPathPattern("/api/v1/machine/{machine_id}/tags")) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/SetTags", runtime.WithHTTPPathPattern("/api/v1/machine/{machine_id}/tags")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_HeadscaleService_SetTags_0(annotatedContext, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_HeadscaleService_SetTags_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_SetTags_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_SetTags_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1330,22 +1360,20 @@ func RegisterHeadscaleServiceHandlerServer(ctx context.Context, mux *runtime.Ser var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/RegisterMachine", runtime.WithHTTPPathPattern("/api/v1/machine/register")) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/RegisterMachine", runtime.WithHTTPPathPattern("/api/v1/machine/register")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_HeadscaleService_RegisterMachine_0(annotatedContext, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_HeadscaleService_RegisterMachine_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_RegisterMachine_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_RegisterMachine_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1355,22 +1383,20 @@ func RegisterHeadscaleServiceHandlerServer(ctx context.Context, mux *runtime.Ser var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/DeleteMachine", runtime.WithHTTPPathPattern("/api/v1/machine/{machine_id}")) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/DeleteMachine", runtime.WithHTTPPathPattern("/api/v1/machine/{machine_id}")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_HeadscaleService_DeleteMachine_0(annotatedContext, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_HeadscaleService_DeleteMachine_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_DeleteMachine_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_DeleteMachine_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1380,22 +1406,20 @@ func RegisterHeadscaleServiceHandlerServer(ctx context.Context, mux *runtime.Ser var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/ExpireMachine", runtime.WithHTTPPathPattern("/api/v1/machine/{machine_id}/expire")) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/ExpireMachine", runtime.WithHTTPPathPattern("/api/v1/machine/{machine_id}/expire")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_HeadscaleService_ExpireMachine_0(annotatedContext, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_HeadscaleService_ExpireMachine_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_ExpireMachine_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_ExpireMachine_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1405,22 +1429,20 @@ func RegisterHeadscaleServiceHandlerServer(ctx context.Context, mux *runtime.Ser var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/RenameMachine", runtime.WithHTTPPathPattern("/api/v1/machine/{machine_id}/rename/{new_name}")) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/RenameMachine", runtime.WithHTTPPathPattern("/api/v1/machine/{machine_id}/rename/{new_name}")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_HeadscaleService_RenameMachine_0(annotatedContext, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_HeadscaleService_RenameMachine_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_RenameMachine_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_RenameMachine_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1430,22 +1452,20 @@ func RegisterHeadscaleServiceHandlerServer(ctx context.Context, mux *runtime.Ser var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/ListMachines", runtime.WithHTTPPathPattern("/api/v1/machine")) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/ListMachines", runtime.WithHTTPPathPattern("/api/v1/machine")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_HeadscaleService_ListMachines_0(annotatedContext, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_HeadscaleService_ListMachines_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_ListMachines_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_ListMachines_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1455,72 +1475,112 @@ func RegisterHeadscaleServiceHandlerServer(ctx context.Context, mux *runtime.Ser var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/MoveMachine", runtime.WithHTTPPathPattern("/api/v1/machine/{machine_id}/namespace")) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/MoveMachine", runtime.WithHTTPPathPattern("/api/v1/machine/{machine_id}/namespace")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_HeadscaleService_MoveMachine_0(annotatedContext, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_HeadscaleService_MoveMachine_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_MoveMachine_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_MoveMachine_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) - mux.Handle("GET", pattern_HeadscaleService_GetMachineRoute_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_HeadscaleService_GetRoutes_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/GetMachineRoute", runtime.WithHTTPPathPattern("/api/v1/machine/{machine_id}/routes")) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/GetRoutes", runtime.WithHTTPPathPattern("/api/v1/routes")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_HeadscaleService_GetMachineRoute_0(annotatedContext, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_HeadscaleService_GetRoutes_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_GetMachineRoute_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_GetRoutes_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) - mux.Handle("POST", pattern_HeadscaleService_EnableMachineRoutes_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("POST", pattern_HeadscaleService_EnableRoute_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/EnableMachineRoutes", runtime.WithHTTPPathPattern("/api/v1/machine/{machine_id}/routes")) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/EnableRoute", runtime.WithHTTPPathPattern("/api/v1/routes/{route_id}/enable")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_HeadscaleService_EnableMachineRoutes_0(annotatedContext, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_HeadscaleService_EnableRoute_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_EnableMachineRoutes_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_EnableRoute_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_HeadscaleService_DisableRoute_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/DisableRoute", runtime.WithHTTPPathPattern("/api/v1/routes/{route_id}/disable")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_HeadscaleService_DisableRoute_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_HeadscaleService_DisableRoute_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_HeadscaleService_GetMachineRoutes_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/GetMachineRoutes", runtime.WithHTTPPathPattern("/api/v1/machine/{machine_id}/routes")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_HeadscaleService_GetMachineRoutes_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_HeadscaleService_GetMachineRoutes_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1530,22 +1590,20 @@ func RegisterHeadscaleServiceHandlerServer(ctx context.Context, mux *runtime.Ser var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/CreateApiKey", runtime.WithHTTPPathPattern("/api/v1/apikey")) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/CreateApiKey", runtime.WithHTTPPathPattern("/api/v1/apikey")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_HeadscaleService_CreateApiKey_0(annotatedContext, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_HeadscaleService_CreateApiKey_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_CreateApiKey_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_CreateApiKey_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1555,22 +1613,20 @@ func RegisterHeadscaleServiceHandlerServer(ctx context.Context, mux *runtime.Ser var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/ExpireApiKey", runtime.WithHTTPPathPattern("/api/v1/apikey/expire")) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/ExpireApiKey", runtime.WithHTTPPathPattern("/api/v1/apikey/expire")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_HeadscaleService_ExpireApiKey_0(annotatedContext, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_HeadscaleService_ExpireApiKey_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_ExpireApiKey_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_ExpireApiKey_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1580,22 +1636,20 @@ func RegisterHeadscaleServiceHandlerServer(ctx context.Context, mux *runtime.Ser var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/ListApiKeys", runtime.WithHTTPPathPattern("/api/v1/apikey")) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/headscale.v1.HeadscaleService/ListApiKeys", runtime.WithHTTPPathPattern("/api/v1/apikey")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_HeadscaleService_ListApiKeys_0(annotatedContext, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_HeadscaleService_ListApiKeys_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_ListApiKeys_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_ListApiKeys_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1644,21 +1698,19 @@ func RegisterHeadscaleServiceHandlerClient(ctx context.Context, mux *runtime.Ser ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/GetNamespace", runtime.WithHTTPPathPattern("/api/v1/namespace/{name}")) + rctx, err := runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/GetNamespace", runtime.WithHTTPPathPattern("/api/v1/namespace/{name}")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_HeadscaleService_GetNamespace_0(annotatedContext, inboundMarshaler, client, req, pathParams) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + resp, md, err := request_HeadscaleService_GetNamespace_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_GetNamespace_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_GetNamespace_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1666,21 +1718,19 @@ func RegisterHeadscaleServiceHandlerClient(ctx context.Context, mux *runtime.Ser ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/CreateNamespace", runtime.WithHTTPPathPattern("/api/v1/namespace")) + rctx, err := runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/CreateNamespace", runtime.WithHTTPPathPattern("/api/v1/namespace")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_HeadscaleService_CreateNamespace_0(annotatedContext, inboundMarshaler, client, req, pathParams) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + resp, md, err := request_HeadscaleService_CreateNamespace_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_CreateNamespace_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_CreateNamespace_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1688,21 +1738,19 @@ func RegisterHeadscaleServiceHandlerClient(ctx context.Context, mux *runtime.Ser ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/RenameNamespace", runtime.WithHTTPPathPattern("/api/v1/namespace/{old_name}/rename/{new_name}")) + rctx, err := runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/RenameNamespace", runtime.WithHTTPPathPattern("/api/v1/namespace/{old_name}/rename/{new_name}")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_HeadscaleService_RenameNamespace_0(annotatedContext, inboundMarshaler, client, req, pathParams) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + resp, md, err := request_HeadscaleService_RenameNamespace_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_RenameNamespace_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_RenameNamespace_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1710,21 +1758,19 @@ func RegisterHeadscaleServiceHandlerClient(ctx context.Context, mux *runtime.Ser ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/DeleteNamespace", runtime.WithHTTPPathPattern("/api/v1/namespace/{name}")) + rctx, err := runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/DeleteNamespace", runtime.WithHTTPPathPattern("/api/v1/namespace/{name}")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_HeadscaleService_DeleteNamespace_0(annotatedContext, inboundMarshaler, client, req, pathParams) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + resp, md, err := request_HeadscaleService_DeleteNamespace_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_DeleteNamespace_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_DeleteNamespace_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1732,21 +1778,19 @@ func RegisterHeadscaleServiceHandlerClient(ctx context.Context, mux *runtime.Ser ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/ListNamespaces", runtime.WithHTTPPathPattern("/api/v1/namespace")) + rctx, err := runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/ListNamespaces", runtime.WithHTTPPathPattern("/api/v1/namespace")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_HeadscaleService_ListNamespaces_0(annotatedContext, inboundMarshaler, client, req, pathParams) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + resp, md, err := request_HeadscaleService_ListNamespaces_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_ListNamespaces_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_ListNamespaces_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1754,21 +1798,19 @@ func RegisterHeadscaleServiceHandlerClient(ctx context.Context, mux *runtime.Ser ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/CreatePreAuthKey", runtime.WithHTTPPathPattern("/api/v1/preauthkey")) + rctx, err := runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/CreatePreAuthKey", runtime.WithHTTPPathPattern("/api/v1/preauthkey")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_HeadscaleService_CreatePreAuthKey_0(annotatedContext, inboundMarshaler, client, req, pathParams) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + resp, md, err := request_HeadscaleService_CreatePreAuthKey_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_CreatePreAuthKey_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_CreatePreAuthKey_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1776,21 +1818,19 @@ func RegisterHeadscaleServiceHandlerClient(ctx context.Context, mux *runtime.Ser ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/ExpirePreAuthKey", runtime.WithHTTPPathPattern("/api/v1/preauthkey/expire")) + rctx, err := runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/ExpirePreAuthKey", runtime.WithHTTPPathPattern("/api/v1/preauthkey/expire")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_HeadscaleService_ExpirePreAuthKey_0(annotatedContext, inboundMarshaler, client, req, pathParams) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + resp, md, err := request_HeadscaleService_ExpirePreAuthKey_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_ExpirePreAuthKey_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_ExpirePreAuthKey_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1798,21 +1838,19 @@ func RegisterHeadscaleServiceHandlerClient(ctx context.Context, mux *runtime.Ser ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/ListPreAuthKeys", runtime.WithHTTPPathPattern("/api/v1/preauthkey")) + rctx, err := runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/ListPreAuthKeys", runtime.WithHTTPPathPattern("/api/v1/preauthkey")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_HeadscaleService_ListPreAuthKeys_0(annotatedContext, inboundMarshaler, client, req, pathParams) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + resp, md, err := request_HeadscaleService_ListPreAuthKeys_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_ListPreAuthKeys_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_ListPreAuthKeys_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1820,21 +1858,19 @@ func RegisterHeadscaleServiceHandlerClient(ctx context.Context, mux *runtime.Ser ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/DebugCreateMachine", runtime.WithHTTPPathPattern("/api/v1/debug/machine")) + rctx, err := runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/DebugCreateMachine", runtime.WithHTTPPathPattern("/api/v1/debug/machine")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_HeadscaleService_DebugCreateMachine_0(annotatedContext, inboundMarshaler, client, req, pathParams) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + resp, md, err := request_HeadscaleService_DebugCreateMachine_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_DebugCreateMachine_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_DebugCreateMachine_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1842,21 +1878,19 @@ func RegisterHeadscaleServiceHandlerClient(ctx context.Context, mux *runtime.Ser ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/GetMachine", runtime.WithHTTPPathPattern("/api/v1/machine/{machine_id}")) + rctx, err := runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/GetMachine", runtime.WithHTTPPathPattern("/api/v1/machine/{machine_id}")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_HeadscaleService_GetMachine_0(annotatedContext, inboundMarshaler, client, req, pathParams) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + resp, md, err := request_HeadscaleService_GetMachine_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_GetMachine_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_GetMachine_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1864,21 +1898,19 @@ func RegisterHeadscaleServiceHandlerClient(ctx context.Context, mux *runtime.Ser ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/SetTags", runtime.WithHTTPPathPattern("/api/v1/machine/{machine_id}/tags")) + rctx, err := runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/SetTags", runtime.WithHTTPPathPattern("/api/v1/machine/{machine_id}/tags")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_HeadscaleService_SetTags_0(annotatedContext, inboundMarshaler, client, req, pathParams) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + resp, md, err := request_HeadscaleService_SetTags_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_SetTags_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_SetTags_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1886,21 +1918,19 @@ func RegisterHeadscaleServiceHandlerClient(ctx context.Context, mux *runtime.Ser ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/RegisterMachine", runtime.WithHTTPPathPattern("/api/v1/machine/register")) + rctx, err := runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/RegisterMachine", runtime.WithHTTPPathPattern("/api/v1/machine/register")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_HeadscaleService_RegisterMachine_0(annotatedContext, inboundMarshaler, client, req, pathParams) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + resp, md, err := request_HeadscaleService_RegisterMachine_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_RegisterMachine_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_RegisterMachine_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1908,21 +1938,19 @@ func RegisterHeadscaleServiceHandlerClient(ctx context.Context, mux *runtime.Ser ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/DeleteMachine", runtime.WithHTTPPathPattern("/api/v1/machine/{machine_id}")) + rctx, err := runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/DeleteMachine", runtime.WithHTTPPathPattern("/api/v1/machine/{machine_id}")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_HeadscaleService_DeleteMachine_0(annotatedContext, inboundMarshaler, client, req, pathParams) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + resp, md, err := request_HeadscaleService_DeleteMachine_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_DeleteMachine_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_DeleteMachine_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1930,21 +1958,19 @@ func RegisterHeadscaleServiceHandlerClient(ctx context.Context, mux *runtime.Ser ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/ExpireMachine", runtime.WithHTTPPathPattern("/api/v1/machine/{machine_id}/expire")) + rctx, err := runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/ExpireMachine", runtime.WithHTTPPathPattern("/api/v1/machine/{machine_id}/expire")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_HeadscaleService_ExpireMachine_0(annotatedContext, inboundMarshaler, client, req, pathParams) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + resp, md, err := request_HeadscaleService_ExpireMachine_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_ExpireMachine_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_ExpireMachine_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1952,21 +1978,19 @@ func RegisterHeadscaleServiceHandlerClient(ctx context.Context, mux *runtime.Ser ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/RenameMachine", runtime.WithHTTPPathPattern("/api/v1/machine/{machine_id}/rename/{new_name}")) + rctx, err := runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/RenameMachine", runtime.WithHTTPPathPattern("/api/v1/machine/{machine_id}/rename/{new_name}")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_HeadscaleService_RenameMachine_0(annotatedContext, inboundMarshaler, client, req, pathParams) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + resp, md, err := request_HeadscaleService_RenameMachine_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_RenameMachine_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_RenameMachine_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1974,21 +1998,19 @@ func RegisterHeadscaleServiceHandlerClient(ctx context.Context, mux *runtime.Ser ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/ListMachines", runtime.WithHTTPPathPattern("/api/v1/machine")) + rctx, err := runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/ListMachines", runtime.WithHTTPPathPattern("/api/v1/machine")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_HeadscaleService_ListMachines_0(annotatedContext, inboundMarshaler, client, req, pathParams) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + resp, md, err := request_HeadscaleService_ListMachines_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_ListMachines_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_ListMachines_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1996,65 +2018,99 @@ func RegisterHeadscaleServiceHandlerClient(ctx context.Context, mux *runtime.Ser ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/MoveMachine", runtime.WithHTTPPathPattern("/api/v1/machine/{machine_id}/namespace")) + rctx, err := runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/MoveMachine", runtime.WithHTTPPathPattern("/api/v1/machine/{machine_id}/namespace")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_HeadscaleService_MoveMachine_0(annotatedContext, inboundMarshaler, client, req, pathParams) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + resp, md, err := request_HeadscaleService_MoveMachine_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_MoveMachine_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_MoveMachine_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) - mux.Handle("GET", pattern_HeadscaleService_GetMachineRoute_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_HeadscaleService_GetRoutes_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/GetMachineRoute", runtime.WithHTTPPathPattern("/api/v1/machine/{machine_id}/routes")) + rctx, err := runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/GetRoutes", runtime.WithHTTPPathPattern("/api/v1/routes")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_HeadscaleService_GetMachineRoute_0(annotatedContext, inboundMarshaler, client, req, pathParams) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + resp, md, err := request_HeadscaleService_GetRoutes_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_GetMachineRoute_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_GetRoutes_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) - mux.Handle("POST", pattern_HeadscaleService_EnableMachineRoutes_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("POST", pattern_HeadscaleService_EnableRoute_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/EnableMachineRoutes", runtime.WithHTTPPathPattern("/api/v1/machine/{machine_id}/routes")) + rctx, err := runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/EnableRoute", runtime.WithHTTPPathPattern("/api/v1/routes/{route_id}/enable")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_HeadscaleService_EnableMachineRoutes_0(annotatedContext, inboundMarshaler, client, req, pathParams) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + resp, md, err := request_HeadscaleService_EnableRoute_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_EnableMachineRoutes_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_EnableRoute_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_HeadscaleService_DisableRoute_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/DisableRoute", runtime.WithHTTPPathPattern("/api/v1/routes/{route_id}/disable")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_HeadscaleService_DisableRoute_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_HeadscaleService_DisableRoute_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_HeadscaleService_GetMachineRoutes_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/GetMachineRoutes", runtime.WithHTTPPathPattern("/api/v1/machine/{machine_id}/routes")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_HeadscaleService_GetMachineRoutes_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_HeadscaleService_GetMachineRoutes_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -2062,21 +2118,19 @@ func RegisterHeadscaleServiceHandlerClient(ctx context.Context, mux *runtime.Ser ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/CreateApiKey", runtime.WithHTTPPathPattern("/api/v1/apikey")) + rctx, err := runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/CreateApiKey", runtime.WithHTTPPathPattern("/api/v1/apikey")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_HeadscaleService_CreateApiKey_0(annotatedContext, inboundMarshaler, client, req, pathParams) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + resp, md, err := request_HeadscaleService_CreateApiKey_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_CreateApiKey_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_CreateApiKey_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -2084,21 +2138,19 @@ func RegisterHeadscaleServiceHandlerClient(ctx context.Context, mux *runtime.Ser ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/ExpireApiKey", runtime.WithHTTPPathPattern("/api/v1/apikey/expire")) + rctx, err := runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/ExpireApiKey", runtime.WithHTTPPathPattern("/api/v1/apikey/expire")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_HeadscaleService_ExpireApiKey_0(annotatedContext, inboundMarshaler, client, req, pathParams) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + resp, md, err := request_HeadscaleService_ExpireApiKey_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_ExpireApiKey_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_ExpireApiKey_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -2106,21 +2158,19 @@ func RegisterHeadscaleServiceHandlerClient(ctx context.Context, mux *runtime.Ser ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/ListApiKeys", runtime.WithHTTPPathPattern("/api/v1/apikey")) + rctx, err := runtime.AnnotateContext(ctx, mux, req, "/headscale.v1.HeadscaleService/ListApiKeys", runtime.WithHTTPPathPattern("/api/v1/apikey")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_HeadscaleService_ListApiKeys_0(annotatedContext, inboundMarshaler, client, req, pathParams) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + resp, md, err := request_HeadscaleService_ListApiKeys_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_HeadscaleService_ListApiKeys_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_HeadscaleService_ListApiKeys_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -2162,9 +2212,13 @@ var ( pattern_HeadscaleService_MoveMachine_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3, 2, 4}, []string{"api", "v1", "machine", "machine_id", "namespace"}, "")) - pattern_HeadscaleService_GetMachineRoute_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3, 2, 4}, []string{"api", "v1", "machine", "machine_id", "routes"}, "")) + pattern_HeadscaleService_GetRoutes_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v1", "routes"}, "")) - pattern_HeadscaleService_EnableMachineRoutes_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3, 2, 4}, []string{"api", "v1", "machine", "machine_id", "routes"}, "")) + pattern_HeadscaleService_EnableRoute_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3, 2, 4}, []string{"api", "v1", "routes", "route_id", "enable"}, "")) + + pattern_HeadscaleService_DisableRoute_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3, 2, 4}, []string{"api", "v1", "routes", "route_id", "disable"}, "")) + + pattern_HeadscaleService_GetMachineRoutes_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3, 2, 4}, []string{"api", "v1", "machine", "machine_id", "routes"}, "")) pattern_HeadscaleService_CreateApiKey_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v1", "apikey"}, "")) @@ -2208,9 +2262,13 @@ var ( forward_HeadscaleService_MoveMachine_0 = runtime.ForwardResponseMessage - forward_HeadscaleService_GetMachineRoute_0 = runtime.ForwardResponseMessage + forward_HeadscaleService_GetRoutes_0 = runtime.ForwardResponseMessage - forward_HeadscaleService_EnableMachineRoutes_0 = runtime.ForwardResponseMessage + forward_HeadscaleService_EnableRoute_0 = runtime.ForwardResponseMessage + + forward_HeadscaleService_DisableRoute_0 = runtime.ForwardResponseMessage + + forward_HeadscaleService_GetMachineRoutes_0 = runtime.ForwardResponseMessage forward_HeadscaleService_CreateApiKey_0 = runtime.ForwardResponseMessage diff --git a/gen/go/headscale/v1/headscale_grpc.pb.go b/gen/go/headscale/v1/headscale_grpc.pb.go index 7884423a..d82daee1 100644 --- a/gen/go/headscale/v1/headscale_grpc.pb.go +++ b/gen/go/headscale/v1/headscale_grpc.pb.go @@ -43,8 +43,10 @@ type HeadscaleServiceClient interface { ListMachines(ctx context.Context, in *ListMachinesRequest, opts ...grpc.CallOption) (*ListMachinesResponse, error) MoveMachine(ctx context.Context, in *MoveMachineRequest, opts ...grpc.CallOption) (*MoveMachineResponse, error) // --- Route start --- - GetMachineRoute(ctx context.Context, in *GetMachineRouteRequest, opts ...grpc.CallOption) (*GetMachineRouteResponse, error) - EnableMachineRoutes(ctx context.Context, in *EnableMachineRoutesRequest, opts ...grpc.CallOption) (*EnableMachineRoutesResponse, error) + GetRoutes(ctx context.Context, in *GetRoutesRequest, opts ...grpc.CallOption) (*GetRoutesResponse, error) + EnableRoute(ctx context.Context, in *EnableRouteRequest, opts ...grpc.CallOption) (*EnableRouteResponse, error) + DisableRoute(ctx context.Context, in *DisableRouteRequest, opts ...grpc.CallOption) (*DisableRouteResponse, error) + GetMachineRoutes(ctx context.Context, in *GetMachineRoutesRequest, opts ...grpc.CallOption) (*GetMachineRoutesResponse, error) // --- ApiKeys start --- CreateApiKey(ctx context.Context, in *CreateApiKeyRequest, opts ...grpc.CallOption) (*CreateApiKeyResponse, error) ExpireApiKey(ctx context.Context, in *ExpireApiKeyRequest, opts ...grpc.CallOption) (*ExpireApiKeyResponse, error) @@ -212,18 +214,36 @@ func (c *headscaleServiceClient) MoveMachine(ctx context.Context, in *MoveMachin return out, nil } -func (c *headscaleServiceClient) GetMachineRoute(ctx context.Context, in *GetMachineRouteRequest, opts ...grpc.CallOption) (*GetMachineRouteResponse, error) { - out := new(GetMachineRouteResponse) - err := c.cc.Invoke(ctx, "/headscale.v1.HeadscaleService/GetMachineRoute", in, out, opts...) +func (c *headscaleServiceClient) GetRoutes(ctx context.Context, in *GetRoutesRequest, opts ...grpc.CallOption) (*GetRoutesResponse, error) { + out := new(GetRoutesResponse) + err := c.cc.Invoke(ctx, "/headscale.v1.HeadscaleService/GetRoutes", in, out, opts...) if err != nil { return nil, err } return out, nil } -func (c *headscaleServiceClient) EnableMachineRoutes(ctx context.Context, in *EnableMachineRoutesRequest, opts ...grpc.CallOption) (*EnableMachineRoutesResponse, error) { - out := new(EnableMachineRoutesResponse) - err := c.cc.Invoke(ctx, "/headscale.v1.HeadscaleService/EnableMachineRoutes", in, out, opts...) +func (c *headscaleServiceClient) EnableRoute(ctx context.Context, in *EnableRouteRequest, opts ...grpc.CallOption) (*EnableRouteResponse, error) { + out := new(EnableRouteResponse) + err := c.cc.Invoke(ctx, "/headscale.v1.HeadscaleService/EnableRoute", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *headscaleServiceClient) DisableRoute(ctx context.Context, in *DisableRouteRequest, opts ...grpc.CallOption) (*DisableRouteResponse, error) { + out := new(DisableRouteResponse) + err := c.cc.Invoke(ctx, "/headscale.v1.HeadscaleService/DisableRoute", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *headscaleServiceClient) GetMachineRoutes(ctx context.Context, in *GetMachineRoutesRequest, opts ...grpc.CallOption) (*GetMachineRoutesResponse, error) { + out := new(GetMachineRoutesResponse) + err := c.cc.Invoke(ctx, "/headscale.v1.HeadscaleService/GetMachineRoutes", in, out, opts...) if err != nil { return nil, err } @@ -282,8 +302,10 @@ type HeadscaleServiceServer interface { ListMachines(context.Context, *ListMachinesRequest) (*ListMachinesResponse, error) MoveMachine(context.Context, *MoveMachineRequest) (*MoveMachineResponse, error) // --- Route start --- - GetMachineRoute(context.Context, *GetMachineRouteRequest) (*GetMachineRouteResponse, error) - EnableMachineRoutes(context.Context, *EnableMachineRoutesRequest) (*EnableMachineRoutesResponse, error) + GetRoutes(context.Context, *GetRoutesRequest) (*GetRoutesResponse, error) + EnableRoute(context.Context, *EnableRouteRequest) (*EnableRouteResponse, error) + DisableRoute(context.Context, *DisableRouteRequest) (*DisableRouteResponse, error) + GetMachineRoutes(context.Context, *GetMachineRoutesRequest) (*GetMachineRoutesResponse, error) // --- ApiKeys start --- CreateApiKey(context.Context, *CreateApiKeyRequest) (*CreateApiKeyResponse, error) ExpireApiKey(context.Context, *ExpireApiKeyRequest) (*ExpireApiKeyResponse, error) @@ -346,11 +368,17 @@ func (UnimplementedHeadscaleServiceServer) ListMachines(context.Context, *ListMa func (UnimplementedHeadscaleServiceServer) MoveMachine(context.Context, *MoveMachineRequest) (*MoveMachineResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method MoveMachine not implemented") } -func (UnimplementedHeadscaleServiceServer) GetMachineRoute(context.Context, *GetMachineRouteRequest) (*GetMachineRouteResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetMachineRoute not implemented") +func (UnimplementedHeadscaleServiceServer) GetRoutes(context.Context, *GetRoutesRequest) (*GetRoutesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetRoutes not implemented") } -func (UnimplementedHeadscaleServiceServer) EnableMachineRoutes(context.Context, *EnableMachineRoutesRequest) (*EnableMachineRoutesResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method EnableMachineRoutes not implemented") +func (UnimplementedHeadscaleServiceServer) EnableRoute(context.Context, *EnableRouteRequest) (*EnableRouteResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method EnableRoute not implemented") +} +func (UnimplementedHeadscaleServiceServer) DisableRoute(context.Context, *DisableRouteRequest) (*DisableRouteResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method DisableRoute not implemented") +} +func (UnimplementedHeadscaleServiceServer) GetMachineRoutes(context.Context, *GetMachineRoutesRequest) (*GetMachineRoutesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetMachineRoutes not implemented") } func (UnimplementedHeadscaleServiceServer) CreateApiKey(context.Context, *CreateApiKeyRequest) (*CreateApiKeyResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method CreateApiKey not implemented") @@ -680,38 +708,74 @@ func _HeadscaleService_MoveMachine_Handler(srv interface{}, ctx context.Context, return interceptor(ctx, in, info, handler) } -func _HeadscaleService_GetMachineRoute_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(GetMachineRouteRequest) +func _HeadscaleService_GetRoutes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetRoutesRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(HeadscaleServiceServer).GetMachineRoute(ctx, in) + return srv.(HeadscaleServiceServer).GetRoutes(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/headscale.v1.HeadscaleService/GetMachineRoute", + FullMethod: "/headscale.v1.HeadscaleService/GetRoutes", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(HeadscaleServiceServer).GetMachineRoute(ctx, req.(*GetMachineRouteRequest)) + return srv.(HeadscaleServiceServer).GetRoutes(ctx, req.(*GetRoutesRequest)) } return interceptor(ctx, in, info, handler) } -func _HeadscaleService_EnableMachineRoutes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(EnableMachineRoutesRequest) +func _HeadscaleService_EnableRoute_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(EnableRouteRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(HeadscaleServiceServer).EnableMachineRoutes(ctx, in) + return srv.(HeadscaleServiceServer).EnableRoute(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/headscale.v1.HeadscaleService/EnableMachineRoutes", + FullMethod: "/headscale.v1.HeadscaleService/EnableRoute", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(HeadscaleServiceServer).EnableMachineRoutes(ctx, req.(*EnableMachineRoutesRequest)) + return srv.(HeadscaleServiceServer).EnableRoute(ctx, req.(*EnableRouteRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _HeadscaleService_DisableRoute_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DisableRouteRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(HeadscaleServiceServer).DisableRoute(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/headscale.v1.HeadscaleService/DisableRoute", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(HeadscaleServiceServer).DisableRoute(ctx, req.(*DisableRouteRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _HeadscaleService_GetMachineRoutes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetMachineRoutesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(HeadscaleServiceServer).GetMachineRoutes(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/headscale.v1.HeadscaleService/GetMachineRoutes", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(HeadscaleServiceServer).GetMachineRoutes(ctx, req.(*GetMachineRoutesRequest)) } return interceptor(ctx, in, info, handler) } @@ -846,12 +910,20 @@ var HeadscaleService_ServiceDesc = grpc.ServiceDesc{ Handler: _HeadscaleService_MoveMachine_Handler, }, { - MethodName: "GetMachineRoute", - Handler: _HeadscaleService_GetMachineRoute_Handler, + MethodName: "GetRoutes", + Handler: _HeadscaleService_GetRoutes_Handler, }, { - MethodName: "EnableMachineRoutes", - Handler: _HeadscaleService_EnableMachineRoutes_Handler, + MethodName: "EnableRoute", + Handler: _HeadscaleService_EnableRoute_Handler, + }, + { + MethodName: "DisableRoute", + Handler: _HeadscaleService_DisableRoute_Handler, + }, + { + MethodName: "GetMachineRoutes", + Handler: _HeadscaleService_GetMachineRoutes_Handler, }, { MethodName: "CreateApiKey", diff --git a/gen/go/headscale/v1/routes.pb.go b/gen/go/headscale/v1/routes.pb.go index 2e977c65..0032dd29 100644 --- a/gen/go/headscale/v1/routes.pb.go +++ b/gen/go/headscale/v1/routes.pb.go @@ -9,6 +9,7 @@ package v1 import ( protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" + timestamppb "google.golang.org/protobuf/types/known/timestamppb" reflect "reflect" sync "sync" ) @@ -20,17 +21,24 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -type Routes struct { +type Route struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - AdvertisedRoutes []string `protobuf:"bytes,1,rep,name=advertised_routes,json=advertisedRoutes,proto3" json:"advertised_routes,omitempty"` - EnabledRoutes []string `protobuf:"bytes,2,rep,name=enabled_routes,json=enabledRoutes,proto3" json:"enabled_routes,omitempty"` + Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Machine *Machine `protobuf:"bytes,2,opt,name=machine,proto3" json:"machine,omitempty"` + Prefix string `protobuf:"bytes,3,opt,name=prefix,proto3" json:"prefix,omitempty"` + Advertised bool `protobuf:"varint,4,opt,name=advertised,proto3" json:"advertised,omitempty"` + Enabled bool `protobuf:"varint,5,opt,name=enabled,proto3" json:"enabled,omitempty"` + IsPrimary bool `protobuf:"varint,6,opt,name=is_primary,json=isPrimary,proto3" json:"is_primary,omitempty"` + CreatedAt *timestamppb.Timestamp `protobuf:"bytes,7,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"` + UpdatedAt *timestamppb.Timestamp `protobuf:"bytes,8,opt,name=updated_at,json=updatedAt,proto3" json:"updated_at,omitempty"` + DeletedAt *timestamppb.Timestamp `protobuf:"bytes,9,opt,name=deleted_at,json=deletedAt,proto3" json:"deleted_at,omitempty"` } -func (x *Routes) Reset() { - *x = Routes{} +func (x *Route) Reset() { + *x = Route{} if protoimpl.UnsafeEnabled { mi := &file_headscale_v1_routes_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -38,13 +46,13 @@ func (x *Routes) Reset() { } } -func (x *Routes) String() string { +func (x *Route) String() string { return protoimpl.X.MessageStringOf(x) } -func (*Routes) ProtoMessage() {} +func (*Route) ProtoMessage() {} -func (x *Routes) ProtoReflect() protoreflect.Message { +func (x *Route) ProtoReflect() protoreflect.Message { mi := &file_headscale_v1_routes_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -56,35 +64,82 @@ func (x *Routes) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use Routes.ProtoReflect.Descriptor instead. -func (*Routes) Descriptor() ([]byte, []int) { +// Deprecated: Use Route.ProtoReflect.Descriptor instead. +func (*Route) Descriptor() ([]byte, []int) { return file_headscale_v1_routes_proto_rawDescGZIP(), []int{0} } -func (x *Routes) GetAdvertisedRoutes() []string { +func (x *Route) GetId() uint64 { if x != nil { - return x.AdvertisedRoutes + return x.Id + } + return 0 +} + +func (x *Route) GetMachine() *Machine { + if x != nil { + return x.Machine } return nil } -func (x *Routes) GetEnabledRoutes() []string { +func (x *Route) GetPrefix() string { if x != nil { - return x.EnabledRoutes + return x.Prefix + } + return "" +} + +func (x *Route) GetAdvertised() bool { + if x != nil { + return x.Advertised + } + return false +} + +func (x *Route) GetEnabled() bool { + if x != nil { + return x.Enabled + } + return false +} + +func (x *Route) GetIsPrimary() bool { + if x != nil { + return x.IsPrimary + } + return false +} + +func (x *Route) GetCreatedAt() *timestamppb.Timestamp { + if x != nil { + return x.CreatedAt } return nil } -type GetMachineRouteRequest struct { +func (x *Route) GetUpdatedAt() *timestamppb.Timestamp { + if x != nil { + return x.UpdatedAt + } + return nil +} + +func (x *Route) GetDeletedAt() *timestamppb.Timestamp { + if x != nil { + return x.DeletedAt + } + return nil +} + +type GetRoutesRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - - MachineId uint64 `protobuf:"varint,1,opt,name=machine_id,json=machineId,proto3" json:"machine_id,omitempty"` } -func (x *GetMachineRouteRequest) Reset() { - *x = GetMachineRouteRequest{} +func (x *GetRoutesRequest) Reset() { + *x = GetRoutesRequest{} if protoimpl.UnsafeEnabled { mi := &file_headscale_v1_routes_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -92,13 +147,13 @@ func (x *GetMachineRouteRequest) Reset() { } } -func (x *GetMachineRouteRequest) String() string { +func (x *GetRoutesRequest) String() string { return protoimpl.X.MessageStringOf(x) } -func (*GetMachineRouteRequest) ProtoMessage() {} +func (*GetRoutesRequest) ProtoMessage() {} -func (x *GetMachineRouteRequest) ProtoReflect() protoreflect.Message { +func (x *GetRoutesRequest) ProtoReflect() protoreflect.Message { mi := &file_headscale_v1_routes_proto_msgTypes[1] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -110,28 +165,21 @@ func (x *GetMachineRouteRequest) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use GetMachineRouteRequest.ProtoReflect.Descriptor instead. -func (*GetMachineRouteRequest) Descriptor() ([]byte, []int) { +// Deprecated: Use GetRoutesRequest.ProtoReflect.Descriptor instead. +func (*GetRoutesRequest) Descriptor() ([]byte, []int) { return file_headscale_v1_routes_proto_rawDescGZIP(), []int{1} } -func (x *GetMachineRouteRequest) GetMachineId() uint64 { - if x != nil { - return x.MachineId - } - return 0 -} - -type GetMachineRouteResponse struct { +type GetRoutesResponse struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Routes *Routes `protobuf:"bytes,1,opt,name=routes,proto3" json:"routes,omitempty"` + Routes []*Route `protobuf:"bytes,1,rep,name=routes,proto3" json:"routes,omitempty"` } -func (x *GetMachineRouteResponse) Reset() { - *x = GetMachineRouteResponse{} +func (x *GetRoutesResponse) Reset() { + *x = GetRoutesResponse{} if protoimpl.UnsafeEnabled { mi := &file_headscale_v1_routes_proto_msgTypes[2] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -139,13 +187,13 @@ func (x *GetMachineRouteResponse) Reset() { } } -func (x *GetMachineRouteResponse) String() string { +func (x *GetRoutesResponse) String() string { return protoimpl.X.MessageStringOf(x) } -func (*GetMachineRouteResponse) ProtoMessage() {} +func (*GetRoutesResponse) ProtoMessage() {} -func (x *GetMachineRouteResponse) ProtoReflect() protoreflect.Message { +func (x *GetRoutesResponse) ProtoReflect() protoreflect.Message { mi := &file_headscale_v1_routes_proto_msgTypes[2] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -157,29 +205,28 @@ func (x *GetMachineRouteResponse) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use GetMachineRouteResponse.ProtoReflect.Descriptor instead. -func (*GetMachineRouteResponse) Descriptor() ([]byte, []int) { +// Deprecated: Use GetRoutesResponse.ProtoReflect.Descriptor instead. +func (*GetRoutesResponse) Descriptor() ([]byte, []int) { return file_headscale_v1_routes_proto_rawDescGZIP(), []int{2} } -func (x *GetMachineRouteResponse) GetRoutes() *Routes { +func (x *GetRoutesResponse) GetRoutes() []*Route { if x != nil { return x.Routes } return nil } -type EnableMachineRoutesRequest struct { +type EnableRouteRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - MachineId uint64 `protobuf:"varint,1,opt,name=machine_id,json=machineId,proto3" json:"machine_id,omitempty"` - Routes []string `protobuf:"bytes,2,rep,name=routes,proto3" json:"routes,omitempty"` + RouteId uint64 `protobuf:"varint,1,opt,name=route_id,json=routeId,proto3" json:"route_id,omitempty"` } -func (x *EnableMachineRoutesRequest) Reset() { - *x = EnableMachineRoutesRequest{} +func (x *EnableRouteRequest) Reset() { + *x = EnableRouteRequest{} if protoimpl.UnsafeEnabled { mi := &file_headscale_v1_routes_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -187,13 +234,13 @@ func (x *EnableMachineRoutesRequest) Reset() { } } -func (x *EnableMachineRoutesRequest) String() string { +func (x *EnableRouteRequest) String() string { return protoimpl.X.MessageStringOf(x) } -func (*EnableMachineRoutesRequest) ProtoMessage() {} +func (*EnableRouteRequest) ProtoMessage() {} -func (x *EnableMachineRoutesRequest) ProtoReflect() protoreflect.Message { +func (x *EnableRouteRequest) ProtoReflect() protoreflect.Message { mi := &file_headscale_v1_routes_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -205,35 +252,26 @@ func (x *EnableMachineRoutesRequest) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use EnableMachineRoutesRequest.ProtoReflect.Descriptor instead. -func (*EnableMachineRoutesRequest) Descriptor() ([]byte, []int) { +// Deprecated: Use EnableRouteRequest.ProtoReflect.Descriptor instead. +func (*EnableRouteRequest) Descriptor() ([]byte, []int) { return file_headscale_v1_routes_proto_rawDescGZIP(), []int{3} } -func (x *EnableMachineRoutesRequest) GetMachineId() uint64 { +func (x *EnableRouteRequest) GetRouteId() uint64 { if x != nil { - return x.MachineId + return x.RouteId } return 0 } -func (x *EnableMachineRoutesRequest) GetRoutes() []string { - if x != nil { - return x.Routes - } - return nil -} - -type EnableMachineRoutesResponse struct { +type EnableRouteResponse struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - - Routes *Routes `protobuf:"bytes,1,opt,name=routes,proto3" json:"routes,omitempty"` } -func (x *EnableMachineRoutesResponse) Reset() { - *x = EnableMachineRoutesResponse{} +func (x *EnableRouteResponse) Reset() { + *x = EnableRouteResponse{} if protoimpl.UnsafeEnabled { mi := &file_headscale_v1_routes_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -241,13 +279,13 @@ func (x *EnableMachineRoutesResponse) Reset() { } } -func (x *EnableMachineRoutesResponse) String() string { +func (x *EnableRouteResponse) String() string { return protoimpl.X.MessageStringOf(x) } -func (*EnableMachineRoutesResponse) ProtoMessage() {} +func (*EnableRouteResponse) ProtoMessage() {} -func (x *EnableMachineRoutesResponse) ProtoReflect() protoreflect.Message { +func (x *EnableRouteResponse) ProtoReflect() protoreflect.Message { mi := &file_headscale_v1_routes_proto_msgTypes[4] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -259,12 +297,184 @@ func (x *EnableMachineRoutesResponse) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use EnableMachineRoutesResponse.ProtoReflect.Descriptor instead. -func (*EnableMachineRoutesResponse) Descriptor() ([]byte, []int) { +// Deprecated: Use EnableRouteResponse.ProtoReflect.Descriptor instead. +func (*EnableRouteResponse) Descriptor() ([]byte, []int) { return file_headscale_v1_routes_proto_rawDescGZIP(), []int{4} } -func (x *EnableMachineRoutesResponse) GetRoutes() *Routes { +type DisableRouteRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + RouteId uint64 `protobuf:"varint,1,opt,name=route_id,json=routeId,proto3" json:"route_id,omitempty"` +} + +func (x *DisableRouteRequest) Reset() { + *x = DisableRouteRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_headscale_v1_routes_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DisableRouteRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DisableRouteRequest) ProtoMessage() {} + +func (x *DisableRouteRequest) ProtoReflect() protoreflect.Message { + mi := &file_headscale_v1_routes_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DisableRouteRequest.ProtoReflect.Descriptor instead. +func (*DisableRouteRequest) Descriptor() ([]byte, []int) { + return file_headscale_v1_routes_proto_rawDescGZIP(), []int{5} +} + +func (x *DisableRouteRequest) GetRouteId() uint64 { + if x != nil { + return x.RouteId + } + return 0 +} + +type DisableRouteResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *DisableRouteResponse) Reset() { + *x = DisableRouteResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_headscale_v1_routes_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DisableRouteResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DisableRouteResponse) ProtoMessage() {} + +func (x *DisableRouteResponse) ProtoReflect() protoreflect.Message { + mi := &file_headscale_v1_routes_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DisableRouteResponse.ProtoReflect.Descriptor instead. +func (*DisableRouteResponse) Descriptor() ([]byte, []int) { + return file_headscale_v1_routes_proto_rawDescGZIP(), []int{6} +} + +type GetMachineRoutesRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + MachineId uint64 `protobuf:"varint,1,opt,name=machine_id,json=machineId,proto3" json:"machine_id,omitempty"` +} + +func (x *GetMachineRoutesRequest) Reset() { + *x = GetMachineRoutesRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_headscale_v1_routes_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetMachineRoutesRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetMachineRoutesRequest) ProtoMessage() {} + +func (x *GetMachineRoutesRequest) ProtoReflect() protoreflect.Message { + mi := &file_headscale_v1_routes_proto_msgTypes[7] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetMachineRoutesRequest.ProtoReflect.Descriptor instead. +func (*GetMachineRoutesRequest) Descriptor() ([]byte, []int) { + return file_headscale_v1_routes_proto_rawDescGZIP(), []int{7} +} + +func (x *GetMachineRoutesRequest) GetMachineId() uint64 { + if x != nil { + return x.MachineId + } + return 0 +} + +type GetMachineRoutesResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Routes []*Route `protobuf:"bytes,1,rep,name=routes,proto3" json:"routes,omitempty"` +} + +func (x *GetMachineRoutesResponse) Reset() { + *x = GetMachineRoutesResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_headscale_v1_routes_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetMachineRoutesResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetMachineRoutesResponse) ProtoMessage() {} + +func (x *GetMachineRoutesResponse) ProtoReflect() protoreflect.Message { + mi := &file_headscale_v1_routes_proto_msgTypes[8] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetMachineRoutesResponse.ProtoReflect.Descriptor instead. +func (*GetMachineRoutesResponse) Descriptor() ([]byte, []int) { + return file_headscale_v1_routes_proto_rawDescGZIP(), []int{8} +} + +func (x *GetMachineRoutesResponse) GetRoutes() []*Route { if x != nil { return x.Routes } @@ -276,34 +486,60 @@ var File_headscale_v1_routes_proto protoreflect.FileDescriptor var file_headscale_v1_routes_proto_rawDesc = []byte{ 0x0a, 0x19, 0x68, 0x65, 0x61, 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2f, 0x76, 0x31, 0x2f, 0x72, 0x6f, 0x75, 0x74, 0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0c, 0x68, 0x65, 0x61, - 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x22, 0x5c, 0x0a, 0x06, 0x52, 0x6f, 0x75, - 0x74, 0x65, 0x73, 0x12, 0x2b, 0x0a, 0x11, 0x61, 0x64, 0x76, 0x65, 0x72, 0x74, 0x69, 0x73, 0x65, - 0x64, 0x5f, 0x72, 0x6f, 0x75, 0x74, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x10, - 0x61, 0x64, 0x76, 0x65, 0x72, 0x74, 0x69, 0x73, 0x65, 0x64, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x73, - 0x12, 0x25, 0x0a, 0x0e, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x5f, 0x72, 0x6f, 0x75, 0x74, - 0x65, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0d, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, - 0x64, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x73, 0x22, 0x37, 0x0a, 0x16, 0x47, 0x65, 0x74, 0x4d, 0x61, - 0x63, 0x68, 0x69, 0x6e, 0x65, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x5f, 0x69, 0x64, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x09, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x49, 0x64, - 0x22, 0x47, 0x0a, 0x17, 0x47, 0x65, 0x74, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x52, 0x6f, - 0x75, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2c, 0x0a, 0x06, 0x72, - 0x6f, 0x75, 0x74, 0x65, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x68, 0x65, - 0x61, 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x52, 0x6f, 0x75, 0x74, 0x65, - 0x73, 0x52, 0x06, 0x72, 0x6f, 0x75, 0x74, 0x65, 0x73, 0x22, 0x53, 0x0a, 0x1a, 0x45, 0x6e, 0x61, - 0x62, 0x6c, 0x65, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x73, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x6d, 0x61, 0x63, 0x68, 0x69, - 0x6e, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x09, 0x6d, 0x61, 0x63, - 0x68, 0x69, 0x6e, 0x65, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x6f, 0x75, 0x74, 0x65, 0x73, - 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x06, 0x72, 0x6f, 0x75, 0x74, 0x65, 0x73, 0x22, 0x4b, - 0x0a, 0x1b, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x52, - 0x6f, 0x75, 0x74, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2c, 0x0a, - 0x06, 0x72, 0x6f, 0x75, 0x74, 0x65, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, - 0x68, 0x65, 0x61, 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x52, 0x6f, 0x75, - 0x74, 0x65, 0x73, 0x52, 0x06, 0x72, 0x6f, 0x75, 0x74, 0x65, 0x73, 0x42, 0x29, 0x5a, 0x27, 0x67, - 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6a, 0x75, 0x61, 0x6e, 0x66, 0x6f, - 0x6e, 0x74, 0x2f, 0x68, 0x65, 0x61, 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2f, 0x67, 0x65, 0x6e, - 0x2f, 0x67, 0x6f, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, + 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, + 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1a, 0x68, 0x65, 0x61, 0x64, + 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2f, 0x76, 0x31, 0x2f, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xea, 0x02, 0x0a, 0x05, 0x52, 0x6f, 0x75, 0x74, 0x65, + 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x02, 0x69, 0x64, + 0x12, 0x2f, 0x0a, 0x07, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x15, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2e, 0x76, 0x31, + 0x2e, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x52, 0x07, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, + 0x65, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x06, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x12, 0x1e, 0x0a, 0x0a, 0x61, 0x64, 0x76, + 0x65, 0x72, 0x74, 0x69, 0x73, 0x65, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x61, + 0x64, 0x76, 0x65, 0x72, 0x74, 0x69, 0x73, 0x65, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x65, 0x6e, 0x61, + 0x62, 0x6c, 0x65, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x65, 0x6e, 0x61, 0x62, + 0x6c, 0x65, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x69, 0x73, 0x5f, 0x70, 0x72, 0x69, 0x6d, 0x61, 0x72, + 0x79, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x69, 0x73, 0x50, 0x72, 0x69, 0x6d, 0x61, + 0x72, 0x79, 0x12, 0x39, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, + 0x18, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, + 0x6d, 0x70, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x12, 0x39, 0x0a, + 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x08, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x75, + 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x12, 0x39, 0x0a, 0x0a, 0x64, 0x65, 0x6c, 0x65, + 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x09, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, + 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, + 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, + 0x64, 0x41, 0x74, 0x22, 0x12, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x73, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x40, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x52, 0x6f, + 0x75, 0x74, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2b, 0x0a, 0x06, + 0x72, 0x6f, 0x75, 0x74, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x68, + 0x65, 0x61, 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x52, 0x6f, 0x75, 0x74, + 0x65, 0x52, 0x06, 0x72, 0x6f, 0x75, 0x74, 0x65, 0x73, 0x22, 0x2f, 0x0a, 0x12, 0x45, 0x6e, 0x61, + 0x62, 0x6c, 0x65, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x19, 0x0a, 0x08, 0x72, 0x6f, 0x75, 0x74, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x04, 0x52, 0x07, 0x72, 0x6f, 0x75, 0x74, 0x65, 0x49, 0x64, 0x22, 0x15, 0x0a, 0x13, 0x45, 0x6e, + 0x61, 0x62, 0x6c, 0x65, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x22, 0x30, 0x0a, 0x13, 0x44, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x52, 0x6f, 0x75, 0x74, + 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x19, 0x0a, 0x08, 0x72, 0x6f, 0x75, 0x74, + 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x07, 0x72, 0x6f, 0x75, 0x74, + 0x65, 0x49, 0x64, 0x22, 0x16, 0x0a, 0x14, 0x44, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x52, 0x6f, + 0x75, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x38, 0x0a, 0x17, 0x47, + 0x65, 0x74, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x73, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, + 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x09, 0x6d, 0x61, 0x63, 0x68, + 0x69, 0x6e, 0x65, 0x49, 0x64, 0x22, 0x47, 0x0a, 0x18, 0x47, 0x65, 0x74, 0x4d, 0x61, 0x63, 0x68, + 0x69, 0x6e, 0x65, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x2b, 0x0a, 0x06, 0x72, 0x6f, 0x75, 0x74, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, + 0x0b, 0x32, 0x13, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2e, 0x76, 0x31, + 0x2e, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x52, 0x06, 0x72, 0x6f, 0x75, 0x74, 0x65, 0x73, 0x42, 0x29, + 0x5a, 0x27, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6a, 0x75, 0x61, + 0x6e, 0x66, 0x6f, 0x6e, 0x74, 0x2f, 0x68, 0x65, 0x61, 0x64, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2f, + 0x67, 0x65, 0x6e, 0x2f, 0x67, 0x6f, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, } var ( @@ -318,22 +554,32 @@ func file_headscale_v1_routes_proto_rawDescGZIP() []byte { return file_headscale_v1_routes_proto_rawDescData } -var file_headscale_v1_routes_proto_msgTypes = make([]protoimpl.MessageInfo, 5) +var file_headscale_v1_routes_proto_msgTypes = make([]protoimpl.MessageInfo, 9) var file_headscale_v1_routes_proto_goTypes = []interface{}{ - (*Routes)(nil), // 0: headscale.v1.Routes - (*GetMachineRouteRequest)(nil), // 1: headscale.v1.GetMachineRouteRequest - (*GetMachineRouteResponse)(nil), // 2: headscale.v1.GetMachineRouteResponse - (*EnableMachineRoutesRequest)(nil), // 3: headscale.v1.EnableMachineRoutesRequest - (*EnableMachineRoutesResponse)(nil), // 4: headscale.v1.EnableMachineRoutesResponse + (*Route)(nil), // 0: headscale.v1.Route + (*GetRoutesRequest)(nil), // 1: headscale.v1.GetRoutesRequest + (*GetRoutesResponse)(nil), // 2: headscale.v1.GetRoutesResponse + (*EnableRouteRequest)(nil), // 3: headscale.v1.EnableRouteRequest + (*EnableRouteResponse)(nil), // 4: headscale.v1.EnableRouteResponse + (*DisableRouteRequest)(nil), // 5: headscale.v1.DisableRouteRequest + (*DisableRouteResponse)(nil), // 6: headscale.v1.DisableRouteResponse + (*GetMachineRoutesRequest)(nil), // 7: headscale.v1.GetMachineRoutesRequest + (*GetMachineRoutesResponse)(nil), // 8: headscale.v1.GetMachineRoutesResponse + (*Machine)(nil), // 9: headscale.v1.Machine + (*timestamppb.Timestamp)(nil), // 10: google.protobuf.Timestamp } var file_headscale_v1_routes_proto_depIdxs = []int32{ - 0, // 0: headscale.v1.GetMachineRouteResponse.routes:type_name -> headscale.v1.Routes - 0, // 1: headscale.v1.EnableMachineRoutesResponse.routes:type_name -> headscale.v1.Routes - 2, // [2:2] is the sub-list for method output_type - 2, // [2:2] is the sub-list for method input_type - 2, // [2:2] is the sub-list for extension type_name - 2, // [2:2] is the sub-list for extension extendee - 0, // [0:2] is the sub-list for field type_name + 9, // 0: headscale.v1.Route.machine:type_name -> headscale.v1.Machine + 10, // 1: headscale.v1.Route.created_at:type_name -> google.protobuf.Timestamp + 10, // 2: headscale.v1.Route.updated_at:type_name -> google.protobuf.Timestamp + 10, // 3: headscale.v1.Route.deleted_at:type_name -> google.protobuf.Timestamp + 0, // 4: headscale.v1.GetRoutesResponse.routes:type_name -> headscale.v1.Route + 0, // 5: headscale.v1.GetMachineRoutesResponse.routes:type_name -> headscale.v1.Route + 6, // [6:6] is the sub-list for method output_type + 6, // [6:6] is the sub-list for method input_type + 6, // [6:6] is the sub-list for extension type_name + 6, // [6:6] is the sub-list for extension extendee + 0, // [0:6] is the sub-list for field type_name } func init() { file_headscale_v1_routes_proto_init() } @@ -341,9 +587,10 @@ func file_headscale_v1_routes_proto_init() { if File_headscale_v1_routes_proto != nil { return } + file_headscale_v1_machine_proto_init() if !protoimpl.UnsafeEnabled { file_headscale_v1_routes_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Routes); i { + switch v := v.(*Route); i { case 0: return &v.state case 1: @@ -355,7 +602,7 @@ func file_headscale_v1_routes_proto_init() { } } file_headscale_v1_routes_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetMachineRouteRequest); i { + switch v := v.(*GetRoutesRequest); i { case 0: return &v.state case 1: @@ -367,7 +614,7 @@ func file_headscale_v1_routes_proto_init() { } } file_headscale_v1_routes_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetMachineRouteResponse); i { + switch v := v.(*GetRoutesResponse); i { case 0: return &v.state case 1: @@ -379,7 +626,7 @@ func file_headscale_v1_routes_proto_init() { } } file_headscale_v1_routes_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*EnableMachineRoutesRequest); i { + switch v := v.(*EnableRouteRequest); i { case 0: return &v.state case 1: @@ -391,7 +638,55 @@ func file_headscale_v1_routes_proto_init() { } } file_headscale_v1_routes_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*EnableMachineRoutesResponse); i { + switch v := v.(*EnableRouteResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_headscale_v1_routes_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DisableRouteRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_headscale_v1_routes_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DisableRouteResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_headscale_v1_routes_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetMachineRoutesRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_headscale_v1_routes_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetMachineRoutesResponse); i { case 0: return &v.state case 1: @@ -409,7 +704,7 @@ func file_headscale_v1_routes_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_headscale_v1_routes_proto_rawDesc, NumEnums: 0, - NumMessages: 5, + NumMessages: 9, NumExtensions: 0, NumServices: 0, }, From 68d2eaaaa6f0362f01c24824acc40748270c2ebb Mon Sep 17 00:00:00 2001 From: Juan Font Date: Sat, 26 Nov 2022 00:03:20 +0000 Subject: [PATCH 24/28] Update swagger --- .../headscale/v1/headscale.swagger.json | 200 ++++++++++++------ 1 file changed, 138 insertions(+), 62 deletions(-) diff --git a/gen/openapiv2/headscale/v1/headscale.swagger.json b/gen/openapiv2/headscale/v1/headscale.swagger.json index 9b8d471d..1060b29e 100644 --- a/gen/openapiv2/headscale/v1/headscale.swagger.json +++ b/gen/openapiv2/headscale/v1/headscale.swagger.json @@ -367,13 +367,12 @@ }, "/api/v1/machine/{machineId}/routes": { "get": { - "summary": "--- Route start ---", - "operationId": "HeadscaleService_GetMachineRoute", + "operationId": "HeadscaleService_GetMachineRoutes", "responses": { "200": { "description": "A successful response.", "schema": { - "$ref": "#/definitions/v1GetMachineRouteResponse" + "$ref": "#/definitions/v1GetMachineRoutesResponse" } }, "default": { @@ -395,45 +394,6 @@ "tags": [ "HeadscaleService" ] - }, - "post": { - "operationId": "HeadscaleService_EnableMachineRoutes", - "responses": { - "200": { - "description": "A successful response.", - "schema": { - "$ref": "#/definitions/v1EnableMachineRoutesResponse" - } - }, - "default": { - "description": "An unexpected error response.", - "schema": { - "$ref": "#/definitions/rpcStatus" - } - } - }, - "parameters": [ - { - "name": "machineId", - "in": "path", - "required": true, - "type": "string", - "format": "uint64" - }, - { - "name": "routes", - "in": "query", - "required": false, - "type": "array", - "items": { - "type": "string" - }, - "collectionFormat": "multi" - } - ], - "tags": [ - "HeadscaleService" - ] } }, "/api/v1/machine/{machineId}/tags": { @@ -722,6 +682,91 @@ "HeadscaleService" ] } + }, + "/api/v1/routes": { + "get": { + "summary": "--- Route start ---", + "operationId": "HeadscaleService_GetRoutes", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/v1GetRoutesResponse" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "tags": [ + "HeadscaleService" + ] + } + }, + "/api/v1/routes/{routeId}/disable": { + "post": { + "operationId": "HeadscaleService_DisableRoute", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/v1DisableRouteResponse" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "parameters": [ + { + "name": "routeId", + "in": "path", + "required": true, + "type": "string", + "format": "uint64" + } + ], + "tags": [ + "HeadscaleService" + ] + } + }, + "/api/v1/routes/{routeId}/enable": { + "post": { + "operationId": "HeadscaleService_EnableRoute", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/v1EnableRouteResponse" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "parameters": [ + { + "name": "routeId", + "in": "path", + "required": true, + "type": "string", + "format": "uint64" + } + ], + "tags": [ + "HeadscaleService" + ] + } } }, "definitions": { @@ -875,13 +920,11 @@ "v1DeleteNamespaceResponse": { "type": "object" }, - "v1EnableMachineRoutesResponse": { - "type": "object", - "properties": { - "routes": { - "$ref": "#/definitions/v1Routes" - } - } + "v1DisableRouteResponse": { + "type": "object" + }, + "v1EnableRouteResponse": { + "type": "object" }, "v1ExpireApiKeyRequest": { "type": "object", @@ -924,11 +967,14 @@ } } }, - "v1GetMachineRouteResponse": { + "v1GetMachineRoutesResponse": { "type": "object", "properties": { "routes": { - "$ref": "#/definitions/v1Routes" + "type": "array", + "items": { + "$ref": "#/definitions/v1Route" + } } } }, @@ -940,6 +986,17 @@ } } }, + "v1GetRoutesResponse": { + "type": "object", + "properties": { + "routes": { + "type": "array", + "items": { + "$ref": "#/definitions/v1Route" + } + } + } + }, "v1ListApiKeysResponse": { "type": "object", "properties": { @@ -1151,20 +1208,39 @@ } } }, - "v1Routes": { + "v1Route": { "type": "object", "properties": { - "advertisedRoutes": { - "type": "array", - "items": { - "type": "string" - } + "id": { + "type": "string", + "format": "uint64" }, - "enabledRoutes": { - "type": "array", - "items": { - "type": "string" - } + "machine": { + "$ref": "#/definitions/v1Machine" + }, + "prefix": { + "type": "string" + }, + "advertised": { + "type": "boolean" + }, + "enabled": { + "type": "boolean" + }, + "isPrimary": { + "type": "boolean" + }, + "createdAt": { + "type": "string", + "format": "date-time" + }, + "updatedAt": { + "type": "string", + "format": "date-time" + }, + "deletedAt": { + "type": "string", + "format": "date-time" } } }, From fad43760efac999f7c73d1f0eaadb6c12b481e5c Mon Sep 17 00:00:00 2001 From: Juan Font Date: Sat, 26 Nov 2022 00:03:39 +0000 Subject: [PATCH 25/28] Refactored route grpc glue code --- grpcv1.go | 48 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/grpcv1.go b/grpcv1.go index 998b9902..0c14a5ee 100644 --- a/grpcv1.go +++ b/grpcv1.go @@ -364,36 +364,60 @@ func (api headscaleV1APIServer) MoveMachine( return &v1.MoveMachineResponse{Machine: machine.toProto()}, nil } -func (api headscaleV1APIServer) GetMachineRoute( +func (api headscaleV1APIServer) GetRoutes( ctx context.Context, - request *v1.GetMachineRouteRequest, -) (*v1.GetMachineRouteResponse, error) { - machine, err := api.h.GetMachineByID(request.GetMachineId()) + request *v1.GetRoutesRequest, +) (*v1.GetRoutesResponse, error) { + routes, err := api.h.GetRoutes() if err != nil { return nil, err } - return &v1.GetMachineRouteResponse{ - Routes: api.h.RoutesToProto(machine), + return &v1.GetRoutesResponse{ + Routes: Routes(routes).toProto(), }, nil } -func (api headscaleV1APIServer) EnableMachineRoutes( +func (api headscaleV1APIServer) EnableRoute( ctx context.Context, - request *v1.EnableMachineRoutesRequest, -) (*v1.EnableMachineRoutesResponse, error) { + request *v1.EnableRouteRequest, +) (*v1.EnableRouteResponse, error) { + err := api.h.EnableRoute(request.GetRouteId()) + if err != nil { + return nil, err + } + + return &v1.EnableRouteResponse{}, nil +} + +func (api headscaleV1APIServer) DisableRoute( + ctx context.Context, + request *v1.DisableRouteRequest, +) (*v1.DisableRouteResponse, error) { + err := api.h.DisableRoute(request.GetRouteId()) + if err != nil { + return nil, err + } + + return &v1.DisableRouteResponse{}, nil +} + +func (api headscaleV1APIServer) GetMachineRoutes( + ctx context.Context, + request *v1.GetMachineRoutesRequest, +) (*v1.GetMachineRoutesResponse, error) { machine, err := api.h.GetMachineByID(request.GetMachineId()) if err != nil { return nil, err } - err = api.h.EnableRoutes(machine, request.GetRoutes()...) + routes, err := api.h.GetMachineRoutes(machine) if err != nil { return nil, err } - return &v1.EnableMachineRoutesResponse{ - Routes: api.h.RoutesToProto(machine), + return &v1.GetMachineRoutesResponse{ + Routes: Routes(routes).toProto(), }, nil } From 635027038f39ef3566a3352b6fa9af7035dd8314 Mon Sep 17 00:00:00 2001 From: Juan Font Date: Sat, 26 Nov 2022 00:04:02 +0000 Subject: [PATCH 26/28] Use new routes API in CLI --- cmd/headscale/cli/routes.go | 202 +++++++++++++++++------------------- integration_cli_test.go | 123 +++++++++------------- 2 files changed, 142 insertions(+), 183 deletions(-) diff --git a/cmd/headscale/cli/routes.go b/cmd/headscale/cli/routes.go index 105175a1..3f0c2086 100644 --- a/cmd/headscale/cli/routes.go +++ b/cmd/headscale/cli/routes.go @@ -13,27 +13,22 @@ import ( func init() { rootCmd.AddCommand(routesCmd) - listRoutesCmd.Flags().Uint64P("identifier", "i", 0, "Node identifier (ID)") - err := listRoutesCmd.MarkFlagRequired("identifier") - if err != nil { - log.Fatalf(err.Error()) - } routesCmd.AddCommand(listRoutesCmd) - enableRouteCmd.Flags(). - StringSliceP("route", "r", []string{}, "List (or repeated flags) of routes to enable") - enableRouteCmd.Flags().Uint64P("identifier", "i", 0, "Node identifier (ID)") - enableRouteCmd.Flags().BoolP("all", "a", false, "All routes from host") - - err = enableRouteCmd.MarkFlagRequired("identifier") + enableRouteCmd.Flags().Uint64P("route", "r", 0, "Route identifier (ID)") + err := enableRouteCmd.MarkFlagRequired("route") if err != nil { log.Fatalf(err.Error()) } - routesCmd.AddCommand(enableRouteCmd) - nodeCmd.AddCommand(routesCmd) + disableRouteCmd.Flags().Uint64P("route", "r", 0, "Route identifier (ID)") + err = disableRouteCmd.MarkFlagRequired("route") + if err != nil { + log.Fatalf(err.Error()) + } + routesCmd.AddCommand(disableRouteCmd) } var routesCmd = &cobra.Command{ @@ -44,7 +39,7 @@ var routesCmd = &cobra.Command{ var listRoutesCmd = &cobra.Command{ Use: "list", - Short: "List routes advertised and enabled by a given node", + Short: "List all routes", Aliases: []string{"ls", "show"}, Run: func(cmd *cobra.Command, args []string) { output, _ := cmd.Flags().GetString("output") @@ -64,28 +59,39 @@ var listRoutesCmd = &cobra.Command{ defer cancel() defer conn.Close() - request := &v1.GetMachineRouteRequest{ - MachineId: machineID, + var routes []*v1.Route + + if machineID == 0 { + response, err := client.GetRoutes(ctx, &v1.GetRoutesRequest{}) + if err != nil { + ErrorOutput( + err, + fmt.Sprintf("Cannot get nodes: %s", status.Convert(err).Message()), + output, + ) + + return + } + + routes = response.Routes + } else { + response, err := client.GetMachineRoutes(ctx, &v1.GetMachineRoutesRequest{ + MachineId: machineID, + }) + if err != nil { + ErrorOutput( + err, + fmt.Sprintf("Cannot get routes for machine %d: %s", machineID, status.Convert(err).Message()), + output, + ) + + return + } + + routes = response.Routes } - response, err := client.GetMachineRoute(ctx, request) - if err != nil { - ErrorOutput( - err, - fmt.Sprintf("Cannot get nodes: %s", status.Convert(err).Message()), - output, - ) - - return - } - - if output != "" { - SuccessOutput(response.Routes, "", output) - - return - } - - tableData := routesToPtables(response.Routes) + tableData := routesToPtables(routes) if err != nil { ErrorOutput(err, fmt.Sprintf("Error converting to table: %s", err), output) @@ -107,16 +113,12 @@ var listRoutesCmd = &cobra.Command{ var enableRouteCmd = &cobra.Command{ Use: "enable", - Short: "Set the enabled routes for a given node", - Long: `This command will take a list of routes that will _replace_ -the current set of routes on a given node. -If you would like to disable a route, simply run the command again, but -omit the route you do not want to enable. - `, + Short: "Set a route as enabled", + Long: `This command will make as enabled a given route.`, Run: func(cmd *cobra.Command, args []string) { output, _ := cmd.Flags().GetString("output") - machineID, err := cmd.Flags().GetUint64("identifier") + routeID, err := cmd.Flags().GetUint64("route") if err != nil { ErrorOutput( err, @@ -131,52 +133,13 @@ omit the route you do not want to enable. defer cancel() defer conn.Close() - var routes []string - - isAll, _ := cmd.Flags().GetBool("all") - if isAll { - response, err := client.GetMachineRoute(ctx, &v1.GetMachineRouteRequest{ - MachineId: machineID, - }) - if err != nil { - ErrorOutput( - err, - fmt.Sprintf( - "Cannot get machine routes: %s\n", - status.Convert(err).Message(), - ), - output, - ) - - return - } - routes = response.GetRoutes().GetAdvertisedRoutes() - } else { - routes, err = cmd.Flags().GetStringSlice("route") - if err != nil { - ErrorOutput( - err, - fmt.Sprintf("Error getting routes from flag: %s", err), - output, - ) - - return - } - } - - request := &v1.EnableMachineRoutesRequest{ - MachineId: machineID, - Routes: routes, - } - - response, err := client.EnableMachineRoutes(ctx, request) + response, err := client.EnableRoute(ctx, &v1.EnableRouteRequest{ + RouteId: routeID, + }) if err != nil { ErrorOutput( err, - fmt.Sprintf( - "Cannot register machine: %s\n", - status.Convert(err).Message(), - ), + fmt.Sprintf("Cannot enable route %d: %s", routeID, status.Convert(err).Message()), output, ) @@ -184,50 +147,71 @@ omit the route you do not want to enable. } if output != "" { - SuccessOutput(response.Routes, "", output) + SuccessOutput(response, "", output) return } + }, +} - tableData := routesToPtables(response.Routes) - if err != nil { - ErrorOutput(err, fmt.Sprintf("Error converting to table: %s", err), output) +var disableRouteCmd = &cobra.Command{ + Use: "disable", + Short: "Set as disabled a given route", + Long: `This command will make as disabled a given route.`, + Run: func(cmd *cobra.Command, args []string) { + output, _ := cmd.Flags().GetString("output") - return - } - - err = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render() + routeID, err := cmd.Flags().GetUint64("route") if err != nil { ErrorOutput( err, - fmt.Sprintf("Failed to render pterm table: %s", err), + fmt.Sprintf("Error getting machine id from flag: %s", err), output, ) return } + + ctx, client, conn, cancel := getHeadscaleCLIClient() + defer cancel() + defer conn.Close() + + response, err := client.DisableRoute(ctx, &v1.DisableRouteRequest{ + RouteId: routeID, + }) + if err != nil { + ErrorOutput( + err, + fmt.Sprintf("Cannot enable route %d: %s", routeID, status.Convert(err).Message()), + output, + ) + + return + } + + if output != "" { + SuccessOutput(response, "", output) + + return + } }, } // routesToPtables converts the list of routes to a nice table. -func routesToPtables(routes *v1.Routes) pterm.TableData { - tableData := pterm.TableData{{"Route", "Enabled"}} +func routesToPtables(routes []*v1.Route) pterm.TableData { + tableData := pterm.TableData{{"ID", "Machine", "Prefix", "Advertised", "Enabled", "Primary"}} - for _, route := range routes.GetAdvertisedRoutes() { - enabled := isStringInSlice(routes.EnabledRoutes, route) - - tableData = append(tableData, []string{route, strconv.FormatBool(enabled)}) + for _, route := range routes { + tableData = append(tableData, + []string{ + strconv.FormatUint(route.Id, 10), + route.Machine.GivenName, + route.Prefix, + strconv.FormatBool(route.Advertised), + strconv.FormatBool(route.Enabled), + strconv.FormatBool(route.IsPrimary), + }) } return tableData } - -func isStringInSlice(strs []string, s string) bool { - for _, s2 := range strs { - if s == s2 { - return true - } - } - - return false -} diff --git a/integration_cli_test.go b/integration_cli_test.go index 5a5cb0c8..62df6b31 100644 --- a/integration_cli_test.go +++ b/integration_cli_test.go @@ -7,6 +7,7 @@ import ( "log" "net/http" "os" + "strconv" "testing" "time" @@ -1305,24 +1306,22 @@ func (s *IntegrationCLITestSuite) TestRouteCommand() { "list", "--output", "json", - "--identifier", - "0", }, []string{}, ) assert.Nil(s.T(), err) - var listAll v1.Routes - err = json.Unmarshal([]byte(listAllResult), &listAll) + var routes []v1.Route + err = json.Unmarshal([]byte(listAllResult), &routes) assert.Nil(s.T(), err) - assert.Len(s.T(), listAll.AdvertisedRoutes, 2) - assert.Contains(s.T(), listAll.AdvertisedRoutes, "10.0.0.0/8") - assert.Contains(s.T(), listAll.AdvertisedRoutes, "192.168.1.0/24") + assert.Len(s.T(), routes, 2) + assert.Equal(s.T(), routes[0].Enabled, false) + assert.Equal(s.T(), routes[1].Enabled, false) - assert.Empty(s.T(), listAll.EnabledRoutes) + routeIDToEnable := routes[1].Id - enableTwoRoutesResult, _, err := ExecuteCommand( + _, _, err = ExecuteCommand( &s.headscale, []string{ "headscale", @@ -1330,110 +1329,86 @@ func (s *IntegrationCLITestSuite) TestRouteCommand() { "enable", "--output", "json", - "--identifier", - "0", "--route", - "10.0.0.0/8", - "--route", - "192.168.1.0/24", + strconv.FormatUint(routeIDToEnable, 10), }, []string{}, ) assert.Nil(s.T(), err) - var enableTwoRoutes v1.Routes - err = json.Unmarshal([]byte(enableTwoRoutesResult), &enableTwoRoutes) + listAllResult, _, err = ExecuteCommand( + &s.headscale, + []string{ + "headscale", + "routes", + "list", + "--output", + "json", + }, + []string{}, + ) assert.Nil(s.T(), err) - assert.Len(s.T(), enableTwoRoutes.AdvertisedRoutes, 2) - assert.Contains(s.T(), enableTwoRoutes.AdvertisedRoutes, "10.0.0.0/8") - assert.Contains(s.T(), enableTwoRoutes.AdvertisedRoutes, "192.168.1.0/24") + assert.Nil(s.T(), err) - assert.Len(s.T(), enableTwoRoutes.EnabledRoutes, 2) - assert.Contains(s.T(), enableTwoRoutes.EnabledRoutes, "10.0.0.0/8") - assert.Contains(s.T(), enableTwoRoutes.EnabledRoutes, "192.168.1.0/24") + err = json.Unmarshal([]byte(listAllResult), &routes) + assert.Nil(s.T(), err) + + assert.Len(s.T(), routes, 2) + + for _, route := range routes { + if route.Id == routeIDToEnable { + assert.Equal(s.T(), route.Enabled, true) + assert.Equal(s.T(), route.IsPrimary, true) + } else { + assert.Equal(s.T(), route.Enabled, false) + } + } // Enable only one route, effectively disabling one of the routes - enableOneRouteResult, _, err := ExecuteCommand( + _, _, err = ExecuteCommand( &s.headscale, []string{ "headscale", "routes", - "enable", + "disable", "--output", "json", - "--identifier", - "0", "--route", - "10.0.0.0/8", + strconv.FormatUint(routeIDToEnable, 10), }, []string{}, ) assert.Nil(s.T(), err) - var enableOneRoute v1.Routes - err = json.Unmarshal([]byte(enableOneRouteResult), &enableOneRoute) - assert.Nil(s.T(), err) - - assert.Len(s.T(), enableOneRoute.AdvertisedRoutes, 2) - assert.Contains(s.T(), enableOneRoute.AdvertisedRoutes, "10.0.0.0/8") - assert.Contains(s.T(), enableOneRoute.AdvertisedRoutes, "192.168.1.0/24") - - assert.Len(s.T(), enableOneRoute.EnabledRoutes, 1) - assert.Contains(s.T(), enableOneRoute.EnabledRoutes, "10.0.0.0/8") - - // Enable only one route, effectively disabling one of the routes - failEnableNonAdvertisedRoute, _, err := ExecuteCommand( + listAllResult, _, err = ExecuteCommand( &s.headscale, []string{ "headscale", "routes", - "enable", + "list", "--output", "json", - "--identifier", - "0", - "--route", - "11.0.0.0/8", }, []string{}, ) assert.Nil(s.T(), err) - assert.Contains( - s.T(), - string(failEnableNonAdvertisedRoute), - "route (route-machine) is not available on node", - ) - - // Enable all routes on host - enableAllRouteResult, _, err := ExecuteCommand( - &s.headscale, - []string{ - "headscale", - "routes", - "enable", - "--output", - "json", - "--identifier", - "0", - "--all", - }, - []string{}, - ) assert.Nil(s.T(), err) - var enableAllRoute v1.Routes - err = json.Unmarshal([]byte(enableAllRouteResult), &enableAllRoute) + err = json.Unmarshal([]byte(listAllResult), &routes) assert.Nil(s.T(), err) - assert.Len(s.T(), enableAllRoute.AdvertisedRoutes, 2) - assert.Contains(s.T(), enableAllRoute.AdvertisedRoutes, "10.0.0.0/8") - assert.Contains(s.T(), enableAllRoute.AdvertisedRoutes, "192.168.1.0/24") + assert.Len(s.T(), routes, 2) - assert.Len(s.T(), enableAllRoute.EnabledRoutes, 2) - assert.Contains(s.T(), enableAllRoute.EnabledRoutes, "10.0.0.0/8") - assert.Contains(s.T(), enableAllRoute.EnabledRoutes, "192.168.1.0/24") + for _, route := range routes { + if route.Id == routeIDToEnable { + assert.Equal(s.T(), route.Enabled, false) + assert.Equal(s.T(), route.IsPrimary, false) + } else { + assert.Equal(s.T(), route.Enabled, false) + } + } } func (s *IntegrationCLITestSuite) TestApiKeyCommand() { From b49e46a4c36c102b76072054badf220b631a3e51 Mon Sep 17 00:00:00 2001 From: Juan Font Date: Sat, 26 Nov 2022 09:59:56 +0000 Subject: [PATCH 27/28] Remove unused function --- utils.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/utils.go b/utils.go index c0599c99..8bdb2b3f 100644 --- a/utils.go +++ b/utils.go @@ -254,16 +254,6 @@ func GrpcSocketDialer(ctx context.Context, addr string) (net.Conn, error) { return d.DialContext(ctx, "unix", addr) } -func ipPrefixToString(prefixes []netip.Prefix) []string { - result := make([]string, len(prefixes)) - - for index, prefix := range prefixes { - result[index] = prefix.String() - } - - return result -} - func stringToIPPrefix(prefixes []string) ([]netip.Prefix, error) { result := make([]netip.Prefix, len(prefixes)) From a9e2179b9f5f2889bb73d260e5429cbdf76f8315 Mon Sep 17 00:00:00 2001 From: Juan Font Date: Sat, 26 Nov 2022 10:14:48 +0000 Subject: [PATCH 28/28] Remove magic number (base10...) --- cmd/headscale/cli/routes.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/headscale/cli/routes.go b/cmd/headscale/cli/routes.go index 3f0c2086..e238b62e 100644 --- a/cmd/headscale/cli/routes.go +++ b/cmd/headscale/cli/routes.go @@ -11,6 +11,10 @@ import ( "google.golang.org/grpc/status" ) +const ( + Base10 = 10 +) + func init() { rootCmd.AddCommand(routesCmd) listRoutesCmd.Flags().Uint64P("identifier", "i", 0, "Node identifier (ID)") @@ -204,7 +208,7 @@ func routesToPtables(routes []*v1.Route) pterm.TableData { for _, route := range routes { tableData = append(tableData, []string{ - strconv.FormatUint(route.Id, 10), + strconv.FormatUint(route.Id, Base10), route.Machine.GivenName, route.Prefix, strconv.FormatBool(route.Advertised),