From a00093ffc10b920936aa107ed2fd10bb12ac1bb6 Mon Sep 17 00:00:00 2001 From: Nikolai Rodionov Date: Sun, 10 May 2026 22:10:05 +0200 Subject: [PATCH] Add a token service Signed-off-by: Nikolai Rodionov --- proto/accounts/v1/accounts_v1.proto | 2 + proto/applications/v1/applications_v1.proto | 93 --------------- proto/email/v1/email_v1.proto | 21 ---- proto/environments/v1/environments_v1.proto | 125 -------------------- proto/tokens/v1/tokens_v1.proto | 94 +++++++++++++++ 5 files changed, 96 insertions(+), 239 deletions(-) delete mode 100644 proto/applications/v1/applications_v1.proto delete mode 100644 proto/email/v1/email_v1.proto delete mode 100644 proto/environments/v1/environments_v1.proto create mode 100644 proto/tokens/v1/tokens_v1.proto diff --git a/proto/accounts/v1/accounts_v1.proto b/proto/accounts/v1/accounts_v1.proto index ef6b27e..0d45249 100644 --- a/proto/accounts/v1/accounts_v1.proto +++ b/proto/accounts/v1/accounts_v1.proto @@ -18,6 +18,8 @@ service AccountsService { // Is email for the current account verified rpc IsEmailVerified (IsEmailVerifiedRequest) returns (IsEmailVerifiedResponse) {} rpc RefreshSession (google.protobuf.Empty) returns (google.protobuf.Empty) {} + // Authorize using long living tokens + rpc TokenAuthorization (google.protobuf.Empty) returns (google.protobuf.Empty) {} } message AccountPassword { diff --git a/proto/applications/v1/applications_v1.proto b/proto/applications/v1/applications_v1.proto deleted file mode 100644 index d663279..0000000 --- a/proto/applications/v1/applications_v1.proto +++ /dev/null @@ -1,93 +0,0 @@ -/// This file has messages for describing applications -syntax = "proto3"; -package applications; -import "google/protobuf/empty.proto"; -option go_package = "gitea.badhouseplants.net/softplayer/softplayer-go-proto/pkg/applications"; - -/** - * Service for handling applications - */ -service Applications { - rpc Create(CreateOptions) returns (ApplicationFull) {} - rpc Update(UpdateOptions) returns (ApplicationFull) {} - rpc Delete(DeleteOptions) returns (google.protobuf.Empty) {} - rpc Get(GetOptions) returns (ApplicationFull) {} - rpc List(ListOptions) returns (stream ApplicationFull) {} -} - -/** - User related messages - */ - -message OwnerId { - string uuid = 1; // UUID of a user that is creating an environemnt -} - -message Token { - string token = 1; // Token that should be used to create an environment -} - -/** - Services options - */ - -message CreateOptions { - ApplicationMetadata metadata = 1; - ApplicationSpec spec = 2; - OwnerId owner_id = 3; - Token token = 4; -} - -message UpdateOptions { - ApplicationId id = 1; - ApplicationMetadata metadata = 2; - ApplicationSpec spec = 3; - OwnerId owner_id = 4; - Token token = 5; -} - -message DeleteOptions { - ApplicationId id = 1; - ApplicationMetadata metadata = 2; - OwnerId owner_id = 3; - Token token = 4; -} - -message GetOptions { - ApplicationId id = 1; - ApplicationMetadata metadata = 2; - OwnerId owner_id = 3; - Token token = 4; -} - -message ListOptions { - ApplicationMetadata metadata = 1; - OwnerId owner_id = 2; - Token token = 3; -} -/** - Environment related messages - */ - -message ApplicationId { - string uuid = 1; -} - -message ApplicationMetadata { - string name = 1; - string description = 2; -} - -message ApplicationSpec { - string application = 1; - string version = 2; - string environemnt_id = 3; - map config = 4; - string raw_config = 5; -} - -message ApplicationFull { - ApplicationMetadata metadata = 1; - ApplicationSpec spec = 2; - ApplicationId id = 3; -} diff --git a/proto/email/v1/email_v1.proto b/proto/email/v1/email_v1.proto deleted file mode 100644 index 0e7c13f..0000000 --- a/proto/email/v1/email_v1.proto +++ /dev/null @@ -1,21 +0,0 @@ -syntax = "proto3"; -package email; -import "google/protobuf/empty.proto"; -option go_package = "gitea.badhouseplants.net/softplayer/softplayer-go-proto/pkg/email"; - -/* - * A service that should handle email validation - */ -service EmailValidation { - rpc SendRequest (RequestValidation) returns (google.protobuf.Empty) {} - rpc ValidateEmail (ConfirmValidation) returns (google.protobuf.Empty) {} -} - -message RequestValidation { - string user_id = 1; -} - -message ConfirmValidation { - string user_id = 1; - int32 code = 2; -} diff --git a/proto/environments/v1/environments_v1.proto b/proto/environments/v1/environments_v1.proto deleted file mode 100644 index f6148a9..0000000 --- a/proto/environments/v1/environments_v1.proto +++ /dev/null @@ -1,125 +0,0 @@ -/// This file has messages for describing environments -syntax = "proto3"; -package environments; -import "google/protobuf/empty.proto"; -option go_package = "gitea.badhouseplants.net/softplayer/softplayer-go-proto/pkg/environments"; - -/** - * Service for handling environments - */ -service Environments { - rpc Create(CreateOptions) returns (EnvironmentFull) {} - rpc Update(UpdateOptions) returns (EnvironmentFull) {} - rpc Delete(DeleteOptions) returns (google.protobuf.Empty) {} - rpc Get(GetOptions) returns (EnvironmentFull) {} - rpc List(ListOptions) returns (stream EnvironmentFull) {} -} - -/** - User related messages - */ - -message OwnerId { - string uuid = 1; // UUID of a user that is creating an environemnt -} - -message Token { - string token = 1; // Token that should be used to create an environment -} - -/** - Services options - */ - -message CreateOptions { - EnvironmentMetadata metadata = 1; - EnvironmentSpec spec = 2; - OwnerId owner_id = 3; - Token token = 4; -} - -message UpdateOptions { - EnvironmentId id = 1; - EnvironmentMetadata metadata = 2; - EnvironmentSpec spec = 3; - OwnerId owner_id = 4; - Token token = 5; -} - -message DeleteOptions { - EnvironmentId id = 1; - EnvironmentMetadata metadata = 2; - OwnerId owner_id = 3; - Token token = 4; -} - -message GetOptions { - EnvironmentId id = 1; - EnvironmentMetadata metadata = 2; - OwnerId owner_id = 3; - Token token = 4; -} - -message ListOptions { - EnvironmentMetadata metadata = 1; - string search_string = 2; - OwnerId owner_id = 3; - Token token = 4; -} -/** - Environment related messages - */ - -message EnvironmentId { - string uuid = 1; -} -message EnvironmentMetadata { - string name = 1; // A name of the environment - string description = 2; -} - -message EnvironmentSpec { - Provider provider = 1; // Provide - Kubernetes kubernetes = 2; - ServerType server_type = 3; - Location server_location = 4; - int32 disk_size = 5; -} - -message EnvironmentFull { - EnvironmentMetadata metadata = 1; - EnvironmentSpec spec = 2; - EnvironmentId id = 3; -} - - -/** - Helpers and other messages - */ -enum Provider { - PROVIDER_UNSPECIFIED = 0; - PROVIDER_HETZNER = 1; -} - -enum ServerType { - SERVER_TYPE_UNSPECIFIED = 0; - SERVER_TYPE_STARTER = 1; - SERVER_TYPE_REGULAR = 2; - SERVER_TYPE_PLUS = 3; - SERVER_TYPE_PRO = 4; - SERVER_TYPE_CUSTOM = 5; -} - -enum Location { - LOCATION_UNSPECIFIED = 0; - LOCATION_HETZNER_NUREMBERG = 1; - LOCATION_HETZNER_FALKENSTEIN = 2; - LOCATION_HETZNER_HELSINKI = 3; - LOCATION_HETZNER_HILLSBORO = 4; - LOCATION_HETZNER_ASHBURN = 5; -} - -enum Kubernetes { - KUBERNETES_UNSPECIFIED = 0; - KUBERNETES_K3S = 1; -} diff --git a/proto/tokens/v1/tokens_v1.proto b/proto/tokens/v1/tokens_v1.proto new file mode 100644 index 0000000..560c123 --- /dev/null +++ b/proto/tokens/v1/tokens_v1.proto @@ -0,0 +1,94 @@ +/// Protobuf definitions for the accounts service. +syntax = "proto3"; +package tokens.v1; +import "google/protobuf/empty.proto"; +import "google/protobuf/timestamp.proto"; +option go_package = "gitea.badhouseplants.net/softplayer/softplayer-go-proto/pkg/tokens/v1"; + +// Tokens should be used for programmatic access +// For example CLI or terraform modules +service TokensService { + // Create a new token + rpc CreateToken (CreateTokenRequest) returns (CreateTokenResponse) {} + // Update an existing token + rpc UpdateToken (UpdateTokenRequest) returns (UpdateTokenResponse) {} + // Expire an existing token + rpc ForceTokenExpiration (ForceTokenExpirationRequest) returns (google.protobuf.Empty) {} + // Create a new token with the same UUID + rpc RegenerateToken (RegenerateTokenRequest) returns (RegenerateTokenResponse) {} + // Get an existing token + rpc GetToken (GetTokenRequest) returns (GetTokenResponse) {} + // List all existing tokens + rpc ListTokens (google.protobuf.Empty) returns (stream ListTokensResponse) {} +} + +message TokenMetadata { + // A token name + string name = 1; + // Token expiration timestamp + google.protobuf.Timestamp expires_at = 2; +} + +message TokenUUID { + // An ID of a token + string uuid = 1; +} + +message TokenValue { + // Token value + // Can be only retrieved once after the generation + string token = 1; +} + +message TokenPermissions {} + +message CreateTokenRequest { + TokenMetadata token_metadata = 1; + TokenPermissions token_permissions = 2; +} + +message CreateTokenResponse { + TokenUUID token_uuid = 1; + TokenMetadata token_metadata = 2; + TokenPermissions token_permissions = 3; + TokenValue token_value = 4; +} + +message UpdateTokenRequest { + TokenUUID token_uuid = 1; + TokenMetadata token_metadata = 2; + TokenPermissions token_permissions = 3; +} + +message UpdateTokenResponse { + TokenUUID token_uuid = 1; + TokenMetadata token_metadata = 2; + TokenPermissions token_permissions = 3; +} + +message ForceTokenExpirationRequest { + TokenUUID token_uuid = 1; +} + +message RegenerateTokenRequest { + TokenUUID token_uuid = 1; +} + +message RegenerateTokenResponse { + TokenValue token_value = 1; +} + +message GetTokenRequest { + TokenUUID token_uuid = 1; +} +message GetTokenResponse { + TokenUUID token_uuid = 1; + TokenMetadata token_metadata = 2; + TokenPermissions token_permissions = 3; +} + +message ListTokensResponse { + TokenUUID token_uuid = 1; + TokenMetadata token_metadata = 2; + TokenPermissions token_permissions = 3; +}