mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-04-28 07:59:47 +00:00
Fixed secret retrieval for connection testing while adding a data source
This commit is contained in:
parent
08df79ca73
commit
0cc870b614
@ -199,7 +199,7 @@ public sealed class AgentDataSourceSelection (ILogger<AgentDataSourceSelection>
|
|||||||
// Call the ERI server to get the server description:
|
// Call the ERI server to get the server description:
|
||||||
//
|
//
|
||||||
using var eriClient = ERIClientFactory.Get(eriDataSource.Version, eriDataSource)!;
|
using var eriClient = ERIClientFactory.Get(eriDataSource.Version, eriDataSource)!;
|
||||||
var authResponse = await eriClient.AuthenticateAsync(rustService, token);
|
var authResponse = await eriClient.AuthenticateAsync(rustService, cancellationToken: token);
|
||||||
if (authResponse.Successful)
|
if (authResponse.Successful)
|
||||||
{
|
{
|
||||||
var serverDescriptionResponse = await eriClient.GetDataSourceInfoAsync(token);
|
var serverDescriptionResponse = await eriClient.GetDataSourceInfoAsync(token);
|
||||||
|
@ -211,7 +211,7 @@ public partial class DataSourceERI_V1Dialog : ComponentBase, ISecretId
|
|||||||
|
|
||||||
this.availableAuthMethods = authSchemes.Data!.Select(n => n.AuthMethod).ToList();
|
this.availableAuthMethods = authSchemes.Data!.Select(n => n.AuthMethod).ToList();
|
||||||
|
|
||||||
var loginResult = await client.AuthenticateAsync(this.RustService, cts.Token);
|
var loginResult = await client.AuthenticateAsync(this.RustService, this.dataSecret, cts.Token);
|
||||||
if (!loginResult.Successful)
|
if (!loginResult.Successful)
|
||||||
{
|
{
|
||||||
await this.form.Validate();
|
await this.form.Validate();
|
||||||
|
@ -62,7 +62,7 @@ public readonly record struct DataSourceERI_V1 : IERIDataSource
|
|||||||
var logger = Program.SERVICE_PROVIDER.GetRequiredService<ILogger<DataSourceERI_V1>>();
|
var logger = Program.SERVICE_PROVIDER.GetRequiredService<ILogger<DataSourceERI_V1>>();
|
||||||
|
|
||||||
using var eriClient = ERIClientFactory.Get(this.Version, this)!;
|
using var eriClient = ERIClientFactory.Get(this.Version, this)!;
|
||||||
var authResponse = await eriClient.AuthenticateAsync(rustService, token);
|
var authResponse = await eriClient.AuthenticateAsync(rustService, cancellationToken: token);
|
||||||
if (authResponse.Successful)
|
if (authResponse.Successful)
|
||||||
{
|
{
|
||||||
var retrievalRequest = new RetrievalRequest
|
var retrievalRequest = new RetrievalRequest
|
||||||
|
@ -59,7 +59,7 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<APIResponse<AuthResponse>> AuthenticateAsync(RustService rustService, CancellationToken cancellationToken = default)
|
public async Task<APIResponse<AuthResponse>> AuthenticateAsync(RustService rustService, string? temporarySecret = null, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -99,17 +99,24 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
|
|||||||
}
|
}
|
||||||
|
|
||||||
case AuthMethod.USERNAME_PASSWORD:
|
case AuthMethod.USERNAME_PASSWORD:
|
||||||
var passwordResponse = await rustService.GetSecret(this.dataSource);
|
string password;
|
||||||
if (!passwordResponse.Success)
|
if (string.IsNullOrWhiteSpace(temporarySecret))
|
||||||
{
|
{
|
||||||
return new()
|
var passwordResponse = await rustService.GetSecret(this.dataSource);
|
||||||
|
if (!passwordResponse.Success)
|
||||||
{
|
{
|
||||||
Successful = false,
|
return new()
|
||||||
Message = "Failed to retrieve the password."
|
{
|
||||||
};
|
Successful = false,
|
||||||
}
|
Message = "Failed to retrieve the password."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
password = await passwordResponse.Secret.Decrypt(Program.ENCRYPTION);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
password = temporarySecret;
|
||||||
|
|
||||||
var password = await passwordResponse.Secret.Decrypt(Program.ENCRYPTION);
|
|
||||||
using (var request = new HttpRequestMessage(HttpMethod.Post, $"auth?authMethod={authMethod}"))
|
using (var request = new HttpRequestMessage(HttpMethod.Post, $"auth?authMethod={authMethod}"))
|
||||||
{
|
{
|
||||||
// We must send both values inside the header. The username field is named 'user'.
|
// We must send both values inside the header. The username field is named 'user'.
|
||||||
@ -146,17 +153,24 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
|
|||||||
}
|
}
|
||||||
|
|
||||||
case AuthMethod.TOKEN:
|
case AuthMethod.TOKEN:
|
||||||
var tokenResponse = await rustService.GetSecret(this.dataSource);
|
string token;
|
||||||
if (!tokenResponse.Success)
|
if (string.IsNullOrWhiteSpace(temporarySecret))
|
||||||
{
|
{
|
||||||
return new()
|
var tokenResponse = await rustService.GetSecret(this.dataSource);
|
||||||
|
if (!tokenResponse.Success)
|
||||||
{
|
{
|
||||||
Successful = false,
|
return new()
|
||||||
Message = "Failed to retrieve the access token."
|
{
|
||||||
};
|
Successful = false,
|
||||||
}
|
Message = "Failed to retrieve the access token."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
token = await tokenResponse.Secret.Decrypt(Program.ENCRYPTION);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
token = temporarySecret;
|
||||||
|
|
||||||
var token = await tokenResponse.Secret.Decrypt(Program.ENCRYPTION);
|
|
||||||
using (var request = new HttpRequestMessage(HttpMethod.Post, $"auth?authMethod={authMethod}"))
|
using (var request = new HttpRequestMessage(HttpMethod.Post, $"auth?authMethod={authMethod}"))
|
||||||
{
|
{
|
||||||
request.Headers.Add("Authorization", $"Bearer {token}");
|
request.Headers.Add("Authorization", $"Bearer {token}");
|
||||||
|
@ -19,9 +19,10 @@ public interface IERIClient : IDisposable
|
|||||||
/// Authenticate the user to the ERI server.
|
/// Authenticate the user to the ERI server.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="rustService">The Rust service.</param>
|
/// <param name="rustService">The Rust service.</param>
|
||||||
|
/// <param name="temporarySecret">The temporary secret when adding a new data source, and the secret is not yet stored in the OS.</param>
|
||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
/// <returns>The authentication response.</returns>
|
/// <returns>The authentication response.</returns>
|
||||||
public Task<APIResponse<AuthResponse>> AuthenticateAsync(RustService rustService, CancellationToken cancellationToken = default);
|
public Task<APIResponse<AuthResponse>> AuthenticateAsync(RustService rustService, string? temporarySecret = null, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieves the data source information from the ERI server.
|
/// Retrieves the data source information from the ERI server.
|
||||||
|
@ -113,7 +113,7 @@ public sealed class DataSourceService
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.logger.LogInformation($"Authenticating with ERI source '{source.Name}' (id={source.Id})...");
|
this.logger.LogInformation($"Authenticating with ERI source '{source.Name}' (id={source.Id})...");
|
||||||
var loginResult = await client.AuthenticateAsync(this.rustService, cancellationTokenSource.Token);
|
var loginResult = await client.AuthenticateAsync(this.rustService, cancellationToken: cancellationTokenSource.Token);
|
||||||
if (!loginResult.Successful)
|
if (!loginResult.Successful)
|
||||||
{
|
{
|
||||||
this.logger.LogWarning($"Authentication with ERI source '{source.Name}' (id={source.Id}) failed. We skip this source. Reason: {loginResult.Message}");
|
this.logger.LogWarning($"Authentication with ERI source '{source.Name}' (id={source.Id}) failed. We skip this source. Reason: {loginResult.Message}");
|
||||||
|
Loading…
Reference in New Issue
Block a user