Account bot basis

This commit is contained in:
2025-08-19 15:16:25 +08:00
parent c056938b6e
commit bf181b88ec
13 changed files with 512 additions and 31 deletions

View File

@@ -32,12 +32,9 @@ public static class GrpcClientHelper
private static async Task<string> GetServiceUrlFromEtcd(IEtcdClient etcdClient, string serviceName)
{
var response = await etcdClient.GetAsync($"/services/{serviceName}");
if (response.Kvs.Count == 0)
{
throw new InvalidOperationException($"Service '{serviceName}' not found in Etcd.");
}
return response.Kvs[0].Value.ToStringUtf8();
return response.Kvs.Count == 0
? throw new InvalidOperationException($"Service '{serviceName}' not found in Etcd.")
: response.Kvs[0].Value.ToStringUtf8();
}
public static async Task<AccountService.AccountServiceClient> CreateAccountServiceClient(
@@ -51,7 +48,21 @@ public static class GrpcClientHelper
return new AccountService.AccountServiceClient(CreateCallInvoker(url, clientCertPath, clientKeyPath,
clientCertPassword));
}
public static async Task<BotAccountReceiverService.BotAccountReceiverServiceClient>
CreateBotAccountReceiverServiceClient(
IEtcdClient etcdClient,
string clientCertPath,
string clientKeyPath,
string? clientCertPassword = null
)
{
var url = await GetServiceUrlFromEtcd(etcdClient, "DysonNetwork.Pass");
return new BotAccountReceiverService.BotAccountReceiverServiceClient(CreateCallInvoker(url, clientCertPath,
clientKeyPath,
clientCertPassword));
}
public static async Task<ActionLogService.ActionLogServiceClient> CreateActionLogServiceClient(
IEtcdClient etcdClient,
string clientCertPath,
@@ -75,7 +86,7 @@ public static class GrpcClientHelper
return new AuthService.AuthServiceClient(CreateCallInvoker(url, clientCertPath, clientKeyPath,
clientCertPassword));
}
public static async Task<PermissionService.PermissionServiceClient> CreatePermissionServiceClient(
IEtcdClient etcdClient,
string clientCertPath,
@@ -99,7 +110,7 @@ public static class GrpcClientHelper
return new PusherService.PusherServiceClient(CreateCallInvoker(url, clientCertPath, clientKeyPath,
clientCertPassword));
}
public static async Task<FileService.FileServiceClient> CreateFileServiceClient(
IEtcdClient etcdClient,
string clientCertPath,
@@ -111,7 +122,7 @@ public static class GrpcClientHelper
return new FileService.FileServiceClient(CreateCallInvoker(url, clientCertPath, clientKeyPath,
clientCertPassword));
}
public static async Task<FileReferenceService.FileReferenceServiceClient> CreateFileReferenceServiceClient(
IEtcdClient etcdClient,
string clientCertPath,
@@ -123,7 +134,7 @@ public static class GrpcClientHelper
return new FileReferenceService.FileReferenceServiceClient(CreateCallInvoker(url, clientCertPath, clientKeyPath,
clientCertPassword));
}
public static async Task<PublisherService.PublisherServiceClient> CreatePublisherServiceClient(
IEtcdClient etcdClient,
string clientCertPath,
@@ -147,4 +158,4 @@ public static class GrpcClientHelper
return new CustomAppService.CustomAppServiceClient(CreateCallInvoker(url, clientCertPath, clientKeyPath,
clientCertPassword));
}
}
}

View File

@@ -5,6 +5,7 @@ package proto;
option csharp_namespace = "DysonNetwork.Shared.Proto";
import "google/protobuf/timestamp.proto";
import "account.proto";
import "file.proto";
message CustomAppOauthConfig {
@@ -25,7 +26,7 @@ enum CustomAppStatus {
SUSPENDED = 4;
}
message CustomApp {
message CustomApp {
string id = 1;
string slug = 2;
string name = 3;
@@ -43,7 +44,7 @@ enum CustomAppStatus {
google.protobuf.Timestamp created_at = 11;
google.protobuf.Timestamp updated_at = 12;
}
}
message CustomAppSecret {
string id = 1;
@@ -85,4 +86,61 @@ message CheckCustomAppSecretResponse {
service CustomAppService {
rpc GetCustomApp(GetCustomAppRequest) returns (GetCustomAppResponse);
rpc CheckCustomAppSecret(CheckCustomAppSecretRequest) returns (CheckCustomAppSecretResponse);
}
}
// BotAccount represents a bot account in the system
// It extends the base Account with bot-specific fields
message BotAccount {
// Base account information
Account account = 1;
// Bot-specific information
string slug = 2; // Unique identifier for the bot
bool is_active = 3; // Whether the bot is currently active
string automated_id = 5; // The bot ID
// Timestamps
google.protobuf.Timestamp created_at = 6;
google.protobuf.Timestamp updated_at = 7;
}
// Request/Response messages for BotAccount operations
message CreateBotAccountRequest {
Account account = 1;
string automated_id = 2;
}
message CreateBotAccountResponse {
BotAccount bot = 1; // The created bot account
}
message UpdateBotAccountRequest {
string automated_id = 1; // ID of the bot account to update
Account account = 2; // Updated account information
}
message UpdateBotAccountResponse {
BotAccount bot = 1; // The updated bot account
}
message DeleteBotAccountRequest {
string automated_id = 1; // ID of the bot account to delete
bool force = 2; // Whether to force delete (bypass soft delete)
}
message DeleteBotAccountResponse {
bool success = 1; // Whether the deletion was successful
}
// This service should be implemented by the Pass service to handle the creation, update, and deletion of bot accounts
service BotAccountReceiverService {
// Create a new bot account
rpc CreateBotAccount(CreateBotAccountRequest) returns (CreateBotAccountResponse);
// Update an existing bot account
rpc UpdateBotAccount(UpdateBotAccountRequest) returns (UpdateBotAccountResponse);
// Delete a bot account
rpc DeleteBotAccount(DeleteBotAccountRequest) returns (DeleteBotAccountResponse);
}