mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-04 22:47:21 +00:00
Added importing of configurations exported from AI Studio (#1007)
Co-authored-by: Thorsten Sommer <SommerEngineering@users.noreply.github.com>
This commit is contained in:
1 parent
f8c0232cfd
commit
22065783c2
49 files changed
+3257
-263
No files matched your search
@@ -24,6 +24,11 @@ public readonly record struct DataSourceERI_V1 : IERIDataSource
|
||||
{
|
||||
private static readonly ILogger<DataSourceERI_V1> LOGGER = Program.LOGGER_FACTORY.CreateLogger<DataSourceERI_V1>();
|
||||
|
||||
/// <summary>
|
||||
/// What an export writes as the shared username when the data source has none to export.
|
||||
/// </summary>
|
||||
public const string SHARED_USERNAME_PLACEHOLDER = "<shared username>";
|
||||
|
||||
public DataSourceERI_V1()
|
||||
{
|
||||
}
|
||||
@@ -319,7 +324,7 @@ public readonly record struct DataSourceERI_V1 : IERIDataSource
|
||||
switch (this.AuthMethod)
|
||||
{
|
||||
case AuthMethod.TOKEN:
|
||||
secretLine = CreateSecretLine("Token", encryptedSecret);
|
||||
secretLine = CreateSecretLine(GetSecretFieldName(AuthMethod.TOKEN), encryptedSecret);
|
||||
break;
|
||||
|
||||
case AuthMethod.USERNAME_PASSWORD:
|
||||
@@ -332,13 +337,13 @@ public readonly record struct DataSourceERI_V1 : IERIDataSource
|
||||
|
||||
if (usernamePasswordMode is DataSourceERIUsernamePasswordMode.SHARED_USERNAME_AND_PASSWORD)
|
||||
{
|
||||
var username = string.IsNullOrWhiteSpace(this.Username) ? "<shared username>" : this.Username;
|
||||
var username = string.IsNullOrWhiteSpace(this.Username) ? SHARED_USERNAME_PLACEHOLDER : this.Username;
|
||||
usernameLine = $"""
|
||||
["Username"] = "{LuaTools.EscapeLuaString(username)}",
|
||||
""";
|
||||
}
|
||||
|
||||
secretLine = CreateSecretLine("Password", encryptedSecret);
|
||||
secretLine = CreateSecretLine(GetSecretFieldName(AuthMethod.USERNAME_PASSWORD), encryptedSecret);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -360,15 +365,21 @@ public readonly record struct DataSourceERI_V1 : IERIDataSource
|
||||
""";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The field of a configuration which holds the encrypted secret of an auth method.
|
||||
/// </summary>
|
||||
/// <param name="authMethod">How the data source signs in.</param>
|
||||
/// <returns>The name of the field, or an empty string for an auth method without a secret.</returns>
|
||||
public static string GetSecretFieldName(AuthMethod authMethod) => authMethod switch
|
||||
{
|
||||
AuthMethod.TOKEN => "Token",
|
||||
AuthMethod.USERNAME_PASSWORD => "Password",
|
||||
_ => string.Empty,
|
||||
};
|
||||
|
||||
private static bool TryQueueEnterpriseSecret(int idx, LuaTable table, Guid configPluginId, DataSourceERI_V1 dataSource, bool dryRun)
|
||||
{
|
||||
var secretFieldName = dataSource.AuthMethod switch
|
||||
{
|
||||
AuthMethod.TOKEN => "Token",
|
||||
AuthMethod.USERNAME_PASSWORD => "Password",
|
||||
_ => string.Empty,
|
||||
};
|
||||
|
||||
var secretFieldName = GetSecretFieldName(dataSource.AuthMethod);
|
||||
if (string.IsNullOrWhiteSpace(secretFieldName))
|
||||
return true;
|
||||
|
||||
@@ -428,4 +439,4 @@ public readonly record struct DataSourceERI_V1 : IERIDataSource
|
||||
var cleanedHostname = hostname.Trim();
|
||||
return cleanedHostname.EndsWith('/') ? cleanedHostname[..^1] : cleanedHostname;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user