Merge pull request #2883 from heing/v1.78.2-dev

Improve 1Password logging
This commit is contained in:
Dimitrij
2025-10-09 10:47:55 +01:00
committed by GitHub
5 changed files with 40 additions and 13 deletions

View File

@@ -5,11 +5,9 @@ using System.Web;
namespace ExternalConnectors.OP;
public class OnePasswordCliException : Exception
public class OnePasswordCliException(string message, string arguments) : Exception(message)
{
public OnePasswordCliException(string message) : base(message)
{
}
public string Arguments { get; set; } = arguments;
}
public class OnePasswordCli
@@ -68,11 +66,13 @@ public class OnePasswordCli
password = string.Empty;
privateKey = string.Empty;
domain = string.Empty;
throw new OnePasswordCliException($"Error running op item get: {error}");
throw new OnePasswordCliException($"Error running op item get: {error}",
OnePasswordCliExecutable + " " + string.Join(' ', args));
}
var items = JsonSerializer.Deserialize<VaultItem>(output, JsonSerializerOptions) ??
throw new OnePasswordCliException("1Password returned null");
throw new OnePasswordCliException("1Password returned null",
OnePasswordCliExecutable + " " + string.Join(' ', args));
username = items.Fields?.FirstOrDefault(x => x.Purpose == UserNamePurpose)?.Value ?? string.Empty;
password = items.Fields?.FirstOrDefault(x => x.Purpose == PasswordPurpose)?.Value ?? string.Empty;
privateKey = items.Fields?.FirstOrDefault(x => x.Type == SshKeyType)?.Value ?? string.Empty;

View File

@@ -156,9 +156,10 @@ namespace mRemoteNG.Connection.Protocol
{
ExternalConnectors.OP.OnePasswordCli.ReadPassword($"{UserViaAPI}", out username, out password, out domain, out privatekey);
}
catch (Exception ex)
catch (ExternalConnectors.OP.OnePasswordCliException ex)
{
Event_ErrorOccured(this, "1Password Interface Error: " + ex.Message, 0);
Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, Language.ECPOnePasswordCommandLine + ": " + ex.Arguments);
Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, Language.ECPOnePasswordReadFailed + Environment.NewLine + ex.Message);
}
}

View File

@@ -477,9 +477,10 @@ namespace mRemoteNG.Connection.Protocol.RDP
string RDGUserViaAPI = InterfaceControl.Info.RDGatewayUserViaAPI;
ExternalConnectors.OP.OnePasswordCli.ReadPassword($"{RDGUserViaAPI}", out gwu, out gwp, out gwd, out pkey);
}
catch (Exception ex)
catch (ExternalConnectors.OP.OnePasswordCliException ex)
{
Event_ErrorOccured(this, "1Password Interface Error: " + ex.Message, 0);
Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, Language.ECPOnePasswordCommandLine + ": " + ex.Arguments);
Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, Language.ECPOnePasswordReadFailed + Environment.NewLine + ex.Message);
}
}
@@ -588,9 +589,10 @@ namespace mRemoteNG.Connection.Protocol.RDP
{
ExternalConnectors.OP.OnePasswordCli.ReadPassword($"{userViaApi}", out userName, out password, out domain, out pkey);
}
catch (Exception ex)
catch (ExternalConnectors.OP.OnePasswordCliException ex)
{
Event_ErrorOccured(this, "1Password Interface Error: " + ex.Message, 0);
Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, Language.ECPOnePasswordCommandLine + ": " + ex.Arguments);
Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, Language.ECPOnePasswordReadFailed + Environment.NewLine + ex.Message);
}
}

View File

@@ -19,7 +19,7 @@ namespace mRemoteNG.Resources.Language {
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "18.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Language {
@@ -1879,6 +1879,24 @@ namespace mRemoteNG.Resources.Language {
}
}
/// <summary>
/// Looks up a localized string similar to 1Password command line.
/// </summary>
internal static string ECPOnePasswordCommandLine {
get {
return ResourceManager.GetString("ECPOnePasswordCommandLine", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 1Password read failed.
/// </summary>
internal static string ECPOnePasswordReadFailed {
get {
return ResourceManager.GetString("ECPOnePasswordReadFailed", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Do you want to continue with no password?.
/// </summary>

View File

@@ -2311,6 +2311,12 @@ Nightly Channel includes Alphas, Betas &amp; Release Candidates.</value>
<data name="ECPOnePassword" xml:space="preserve">
<value>1Password</value>
</data>
<data name="ECPOnePasswordReadFailed" xml:space="preserve">
<value>1Password read failed</value>
</data>
<data name="ECPOnePasswordCommandLine" xml:space="preserve">
<value>1Password command line</value>
</data>
<data name="ECPNone" xml:space="preserve">
<value>None</value>
</data>