mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-22 01:13:48 +00:00
Migrated the deletion of secrets from Tauri JS to the runtime API
This commit is contained in:
25 files changed
+99
-137
No files matched your search
@@ -0,0 +1,9 @@
|
||||
namespace AIStudio.Tools.Rust;
|
||||
|
||||
/// <summary>
|
||||
/// Data structure for deleting a secret response.
|
||||
/// </summary>
|
||||
/// <param name="Success">True, when the secret was successfully deleted or not found.</param>
|
||||
/// <param name="Issue">The issue, when the secret could not be deleted.</param>
|
||||
/// <param name="WasEntryFound">True, when the entry was found and deleted.</param>
|
||||
public readonly record struct DeleteSecretResponse(bool Success, string Issue, bool WasEntryFound);
|
||||
@@ -1,6 +0,0 @@
|
||||
namespace AIStudio.Tools.Rust;
|
||||
|
||||
public readonly record struct GetSecretRequest(
|
||||
string Destination,
|
||||
string UserName
|
||||
);
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace AIStudio.Tools.Rust;
|
||||
|
||||
public readonly record struct SelectSecretRequest(string Destination, string UserName);
|
||||
@@ -170,7 +170,7 @@ public sealed class RustService(string apiPort) : IDisposable
|
||||
/// <returns>The requested secret.</returns>
|
||||
public async Task<RequestedSecret> GetAPIKey(IProvider provider)
|
||||
{
|
||||
var secretRequest = new GetSecretRequest($"provider::{provider.Id}::{provider.InstanceName}::api_key", Environment.UserName);
|
||||
var secretRequest = new SelectSecretRequest($"provider::{provider.Id}::{provider.InstanceName}::api_key", Environment.UserName);
|
||||
var result = await this.http.PostAsJsonAsync("/secrets/get", secretRequest, this.jsonRustSerializerOptions);
|
||||
if (!result.IsSuccessStatusCode)
|
||||
{
|
||||
@@ -208,7 +208,28 @@ public sealed class RustService(string apiPort) : IDisposable
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Tries to delete the API key for the given provider.
|
||||
/// </summary>
|
||||
/// <param name="provider">The provider to delete the API key for.</param>
|
||||
/// <returns>The delete secret response.</returns>
|
||||
public async Task<DeleteSecretResponse> DeleteAPIKey(IProvider provider)
|
||||
{
|
||||
var request = new SelectSecretRequest($"provider::{provider.Id}::{provider.InstanceName}::api_key", Environment.UserName);
|
||||
var result = await this.http.PostAsJsonAsync("/secrets/delete", request, this.jsonRustSerializerOptions);
|
||||
if (!result.IsSuccessStatusCode)
|
||||
{
|
||||
this.logger!.LogError($"Failed to delete the API key for provider '{provider.Id}' due to an API issue: '{result.StatusCode}'");
|
||||
return new DeleteSecretResponse{Success = false, WasEntryFound = false, Issue = "Failed to delete the API key due to an API issue."};
|
||||
}
|
||||
|
||||
var state = await result.Content.ReadFromJsonAsync<DeleteSecretResponse>();
|
||||
if (!state.Success)
|
||||
this.logger!.LogError($"Failed to delete the API key for provider '{provider.Id}': '{state.Issue}'");
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
#region IDisposable
|
||||
|
||||
|
||||
Reference in new issue
Block a user