From 273483a310c44d6049b6c8a87e5214c0c344ec1b Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Thu, 5 Dec 2024 09:51:08 +0100 Subject: [PATCH] update user api to use IDs over names Signed-off-by: Kristoffer Dalby --- proto/headscale/v1/headscale.proto | 379 +++++++++++++++-------------- proto/headscale/v1/user.proto | 56 ++--- 2 files changed, 210 insertions(+), 225 deletions(-) diff --git a/proto/headscale/v1/headscale.proto b/proto/headscale/v1/headscale.proto index 9588bdd3..4a2867a6 100644 --- a/proto/headscale/v1/headscale.proto +++ b/proto/headscale/v1/headscale.proto @@ -1,6 +1,6 @@ syntax = "proto3"; package headscale.v1; -option go_package = "github.com/juanfont/headscale/gen/go/v1"; +option go_package = "github.com/juanfont/headscale/gen/go/v1"; import "google/api/annotations.proto"; @@ -13,225 +13,226 @@ import "headscale/v1/policy.proto"; // import "headscale/v1/device.proto"; service HeadscaleService { - // --- User start --- - rpc GetUser(GetUserRequest) returns (GetUserResponse) { - option (google.api.http) = { - get: "/api/v1/user/{name}" - }; - } + // --- User start --- + rpc CreateUser(CreateUserRequest) returns (CreateUserResponse) { + option (google.api.http) = { + post : "/api/v1/user" + body : "*" + }; + } - rpc CreateUser(CreateUserRequest) returns (CreateUserResponse) { - option (google.api.http) = { - post: "/api/v1/user" - body: "*" - }; - } + rpc RenameUser(RenameUserRequest) returns (RenameUserResponse) { + option (google.api.http) = { + post : "/api/v1/user/{old_id}/rename/{new_name}" + }; + } - rpc RenameUser(RenameUserRequest) returns (RenameUserResponse) { - option (google.api.http) = { - post: "/api/v1/user/{old_name}/rename/{new_name}" - }; - } + rpc DeleteUser(DeleteUserRequest) returns (DeleteUserResponse) { + option (google.api.http) = { + delete : "/api/v1/user/{id}" + }; + } - rpc DeleteUser(DeleteUserRequest) returns (DeleteUserResponse) { - option (google.api.http) = { - delete: "/api/v1/user/{name}" - }; - } + rpc ListUsers(ListUsersRequest) returns (ListUsersResponse) { + option (google.api.http) = { + get : "/api/v1/user" + }; + } + // --- User end --- - rpc ListUsers(ListUsersRequest) returns (ListUsersResponse) { - option (google.api.http) = { - get: "/api/v1/user" - }; - } - // --- User end --- + // --- PreAuthKeys start --- + rpc CreatePreAuthKey(CreatePreAuthKeyRequest) + returns (CreatePreAuthKeyResponse) { + option (google.api.http) = { + post : "/api/v1/preauthkey" + body : "*" + }; + } - // --- PreAuthKeys start --- - rpc CreatePreAuthKey(CreatePreAuthKeyRequest) returns (CreatePreAuthKeyResponse) { - option (google.api.http) = { - post: "/api/v1/preauthkey" - body: "*" - }; - } + rpc ExpirePreAuthKey(ExpirePreAuthKeyRequest) + returns (ExpirePreAuthKeyResponse) { + option (google.api.http) = { + post : "/api/v1/preauthkey/expire" + body : "*" + }; + } - rpc ExpirePreAuthKey(ExpirePreAuthKeyRequest) returns (ExpirePreAuthKeyResponse) { - option (google.api.http) = { - post: "/api/v1/preauthkey/expire" - body: "*" - }; - } + rpc ListPreAuthKeys(ListPreAuthKeysRequest) + returns (ListPreAuthKeysResponse) { + option (google.api.http) = { + get : "/api/v1/preauthkey" + }; + } + // --- PreAuthKeys end --- - rpc ListPreAuthKeys(ListPreAuthKeysRequest) returns (ListPreAuthKeysResponse) { - option (google.api.http) = { - get: "/api/v1/preauthkey" - }; - } - // --- PreAuthKeys end --- + // --- Node start --- + rpc DebugCreateNode(DebugCreateNodeRequest) + returns (DebugCreateNodeResponse) { + option (google.api.http) = { + post : "/api/v1/debug/node" + body : "*" + }; + } - // --- Node start --- - rpc DebugCreateNode(DebugCreateNodeRequest) returns (DebugCreateNodeResponse) { - option (google.api.http) = { - post: "/api/v1/debug/node" - body: "*" - }; - } + rpc GetNode(GetNodeRequest) returns (GetNodeResponse) { + option (google.api.http) = { + get : "/api/v1/node/{node_id}" + }; + } - rpc GetNode(GetNodeRequest) returns (GetNodeResponse) { - option (google.api.http) = { - get: "/api/v1/node/{node_id}" - }; - } + rpc SetTags(SetTagsRequest) returns (SetTagsResponse) { + option (google.api.http) = { + post : "/api/v1/node/{node_id}/tags" + body : "*" + }; + } - rpc SetTags(SetTagsRequest) returns (SetTagsResponse) { - option (google.api.http) = { - post: "/api/v1/node/{node_id}/tags" - body: "*" - }; - } + rpc RegisterNode(RegisterNodeRequest) returns (RegisterNodeResponse) { + option (google.api.http) = { + post : "/api/v1/node/register" + }; + } - rpc RegisterNode(RegisterNodeRequest) returns (RegisterNodeResponse) { - option (google.api.http) = { - post: "/api/v1/node/register" - }; - } + rpc DeleteNode(DeleteNodeRequest) returns (DeleteNodeResponse) { + option (google.api.http) = { + delete : "/api/v1/node/{node_id}" + }; + } - rpc DeleteNode(DeleteNodeRequest) returns (DeleteNodeResponse) { - option (google.api.http) = { - delete: "/api/v1/node/{node_id}" - }; - } + rpc ExpireNode(ExpireNodeRequest) returns (ExpireNodeResponse) { + option (google.api.http) = { + post : "/api/v1/node/{node_id}/expire" + }; + } - rpc ExpireNode(ExpireNodeRequest) returns (ExpireNodeResponse) { - option (google.api.http) = { - post: "/api/v1/node/{node_id}/expire" - }; - } + rpc RenameNode(RenameNodeRequest) returns (RenameNodeResponse) { + option (google.api.http) = { + post : "/api/v1/node/{node_id}/rename/{new_name}" + }; + } - rpc RenameNode(RenameNodeRequest) returns (RenameNodeResponse) { - option (google.api.http) = { - post: "/api/v1/node/{node_id}/rename/{new_name}" - }; - } + rpc ListNodes(ListNodesRequest) returns (ListNodesResponse) { + option (google.api.http) = { + get : "/api/v1/node" + }; + } - rpc ListNodes(ListNodesRequest) returns (ListNodesResponse) { - option (google.api.http) = { - get: "/api/v1/node" - }; - } + rpc MoveNode(MoveNodeRequest) returns (MoveNodeResponse) { + option (google.api.http) = { + post : "/api/v1/node/{node_id}/user", + body : "*" + }; + } - rpc MoveNode(MoveNodeRequest) returns (MoveNodeResponse) { - option (google.api.http) = { - post: "/api/v1/node/{node_id}/user", - body: "*" - }; - } + rpc BackfillNodeIPs(BackfillNodeIPsRequest) + returns (BackfillNodeIPsResponse) { + option (google.api.http) = { + post : "/api/v1/node/backfillips" + }; + } - rpc BackfillNodeIPs(BackfillNodeIPsRequest) returns (BackfillNodeIPsResponse) { - option (google.api.http) = { - post: "/api/v1/node/backfillips" - }; - } + // --- Node end --- - // --- Node end --- + // --- Route start --- + rpc GetRoutes(GetRoutesRequest) returns (GetRoutesResponse) { + option (google.api.http) = { + get : "/api/v1/routes" + }; + } - // --- Route start --- - 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 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 DisableRoute(DisableRouteRequest) returns (DisableRouteResponse) { - option (google.api.http) = { - post: "/api/v1/routes/{route_id}/disable" - }; - } + rpc GetNodeRoutes(GetNodeRoutesRequest) returns (GetNodeRoutesResponse) { + option (google.api.http) = { + get : "/api/v1/node/{node_id}/routes" + }; + } - rpc GetNodeRoutes(GetNodeRoutesRequest) returns (GetNodeRoutesResponse) { - option (google.api.http) = { - get: "/api/v1/node/{node_id}/routes" - }; - } + rpc DeleteRoute(DeleteRouteRequest) returns (DeleteRouteResponse) { + option (google.api.http) = { + delete : "/api/v1/routes/{route_id}" + }; + } - rpc DeleteRoute(DeleteRouteRequest) returns (DeleteRouteResponse) { - option (google.api.http) = { - delete: "/api/v1/routes/{route_id}" - }; - } + // --- Route end --- - // --- Route end --- + // --- ApiKeys start --- + rpc CreateApiKey(CreateApiKeyRequest) returns (CreateApiKeyResponse) { + option (google.api.http) = { + post : "/api/v1/apikey" + body : "*" + }; + } - // --- ApiKeys start --- - rpc CreateApiKey(CreateApiKeyRequest) returns (CreateApiKeyResponse) { - option (google.api.http) = { - post: "/api/v1/apikey" - body: "*" - }; - } + rpc ExpireApiKey(ExpireApiKeyRequest) returns (ExpireApiKeyResponse) { + option (google.api.http) = { + post : "/api/v1/apikey/expire" + body : "*" + }; + } - rpc ExpireApiKey(ExpireApiKeyRequest) returns (ExpireApiKeyResponse) { - option (google.api.http) = { - post: "/api/v1/apikey/expire" - body: "*" - }; - } + rpc ListApiKeys(ListApiKeysRequest) returns (ListApiKeysResponse) { + option (google.api.http) = { + get : "/api/v1/apikey" + }; + } - rpc ListApiKeys(ListApiKeysRequest) returns (ListApiKeysResponse) { - option (google.api.http) = { - get: "/api/v1/apikey" - }; - } + rpc DeleteApiKey(DeleteApiKeyRequest) returns (DeleteApiKeyResponse) { + option (google.api.http) = { + delete : "/api/v1/apikey/{prefix}" + }; + } + // --- ApiKeys end --- - rpc DeleteApiKey(DeleteApiKeyRequest) returns (DeleteApiKeyResponse) { - option (google.api.http) = { - delete: "/api/v1/apikey/{prefix}" - }; - } - // --- ApiKeys end --- + // --- Policy start --- + rpc GetPolicy(GetPolicyRequest) returns (GetPolicyResponse) { + option (google.api.http) = { + get : "/api/v1/policy" + }; + } - // --- Policy start --- - rpc GetPolicy(GetPolicyRequest) returns (GetPolicyResponse) { - option (google.api.http) = { - get: "/api/v1/policy" - }; - } + rpc SetPolicy(SetPolicyRequest) returns (SetPolicyResponse) { + option (google.api.http) = { + put : "/api/v1/policy" + body : "*" + }; + } + // --- Policy end --- - rpc SetPolicy(SetPolicyRequest) returns (SetPolicyResponse) { - option (google.api.http) = { - put: "/api/v1/policy" - body: "*" - }; - } - // --- Policy end --- + // Implement Tailscale API + // rpc GetDevice(GetDeviceRequest) returns(GetDeviceResponse) { + // option(google.api.http) = { + // get : "/api/v1/device/{id}" + // }; + // } - // Implement Tailscale API - // rpc GetDevice(GetDeviceRequest) returns(GetDeviceResponse) { - // option(google.api.http) = { - // get : "/api/v1/device/{id}" - // }; - // } + // rpc DeleteDevice(DeleteDeviceRequest) returns(DeleteDeviceResponse) { + // option(google.api.http) = { + // delete : "/api/v1/device/{id}" + // }; + // } - // rpc DeleteDevice(DeleteDeviceRequest) returns(DeleteDeviceResponse) { - // option(google.api.http) = { - // delete : "/api/v1/device/{id}" - // }; - // } + // rpc GetDeviceRoutes(GetDeviceRoutesRequest) + // returns(GetDeviceRoutesResponse) { + // option(google.api.http) = { + // get : "/api/v1/device/{id}/routes" + // }; + // } - // rpc GetDeviceRoutes(GetDeviceRoutesRequest) returns(GetDeviceRoutesResponse) { - // option(google.api.http) = { - // get : "/api/v1/device/{id}/routes" - // }; - // } - - // rpc EnableDeviceRoutes(EnableDeviceRoutesRequest) returns(EnableDeviceRoutesResponse) { - // option(google.api.http) = { - // post : "/api/v1/device/{id}/routes" - // }; - // } + // rpc EnableDeviceRoutes(EnableDeviceRoutesRequest) + // returns(EnableDeviceRoutesResponse) { + // option(google.api.http) = { + // post : "/api/v1/device/{id}/routes" + // }; + // } } diff --git a/proto/headscale/v1/user.proto b/proto/headscale/v1/user.proto index 4c43de98..591553dd 100644 --- a/proto/headscale/v1/user.proto +++ b/proto/headscale/v1/user.proto @@ -1,55 +1,39 @@ syntax = "proto3"; package headscale.v1; -option go_package = "github.com/juanfont/headscale/gen/go/v1"; +option go_package = "github.com/juanfont/headscale/gen/go/v1"; import "google/protobuf/timestamp.proto"; message User { - string id = 1; - string name = 2; - google.protobuf.Timestamp created_at = 3; - string display_name = 4; - string email = 5; - string provider_id = 6; - string provider = 7; - string profile_pic_url = 8; + uint64 id = 1; + string name = 2; + google.protobuf.Timestamp created_at = 3; + string display_name = 4; + string email = 5; + string provider_id = 6; + string provider = 7; + string profile_pic_url = 8; } -message GetUserRequest { - string name = 1; -} +message CreateUserRequest { string name = 1; } -message GetUserResponse { - User user = 1; -} - -message CreateUserRequest { - string name = 1; -} - -message CreateUserResponse { - User user = 1; -} +message CreateUserResponse { User user = 1; } message RenameUserRequest { - string old_name = 1; - string new_name = 2; + uint64 old_id = 1; + string new_name = 2; } -message RenameUserResponse { - User user = 1; -} +message RenameUserResponse { User user = 1; } -message DeleteUserRequest { - string name = 1; -} +message DeleteUserRequest { uint64 id = 1; } -message DeleteUserResponse { -} +message DeleteUserResponse {} message ListUsersRequest { + uint64 id = 1; + string name = 2; + string email = 3; } -message ListUsersResponse { - repeated User users = 1; -} +message ListUsersResponse { repeated User users = 1; }