public static PluginException CreateUnreadableResponseExceptionMessage( string path, PluginCredentialResponseExitCode status) { return(new PluginException(string.Format( Resources.PluginException_UnreadableResponse_Format, path, status))); }
public static PluginException CreatePayloadExceptionMessage( string path, PluginCredentialResponseExitCode status, string payload) { return(new PluginException(string.Format( Resources.PluginException_IncorrectPayload_Format, path, status, payload))); }
public static PluginException CreateInvalidResponseExceptionMessage( string path, PluginCredentialResponseExitCode status, PluginCredentialResponse response) { return(new PluginException(string.Format( Resources.PluginException_InvalidResponse_Format, path, status, response.Username, response.Password == null ? string.Empty : RedactedPassword, response.AuthTypes == null ? string.Empty : string.Join(", ", response.AuthTypes), response.Message))); }
private PluginCredentialResponse GetPluginResponse(PluginCredentialRequest request, CancellationToken cancellationToken) { var argumentString = $"-uri {request.Uri}" + (request.IsRetry ? " -isRetry" : string.Empty) + (request.NonInteractive ? " -nonInteractive" : string.Empty); // only apply -verbosity flag if set and != Normal // since normal is default if (PassVerbosityFlag(request)) { argumentString += $" -verbosity {request.Verbosity.ToLower()}"; } var startInfo = new ProcessStartInfo { FileName = Path, Arguments = argumentString, WindowStyle = ProcessWindowStyle.Hidden, UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, StandardOutputEncoding = Encoding.UTF8, StandardErrorEncoding = Encoding.UTF8, ErrorDialog = false }; string stdOut = null; var exitCode = Execute(startInfo, cancellationToken, out stdOut); PluginCredentialResponseExitCode status = (PluginCredentialResponseExitCode)exitCode; PluginCredentialResponse credentialResponse; try { // Mono will add utf-16 byte order mark to the start of stdOut, remove it here. credentialResponse = JsonConvert.DeserializeObject <PluginCredentialResponse>(stdOut.Trim(new char[] { '\uFEFF' })) ?? new PluginCredentialResponse(); } catch (Exception) { // Do not expose stdout message, since it may contain credentials throw PluginException.CreateUnreadableResponseExceptionMessage(Path, status); } switch (status) { case PluginCredentialResponseExitCode.Success: if (!credentialResponse.IsValid) { throw PluginException.CreateInvalidResponseExceptionMessage( Path, status, credentialResponse); } return(credentialResponse); case PluginCredentialResponseExitCode.ProviderNotApplicable: credentialResponse.Username = null; credentialResponse.Password = null; return(credentialResponse); case PluginCredentialResponseExitCode.Failure: throw PluginException.CreateAbortMessage(Path, credentialResponse.Message); default: throw PluginUnexpectedStatusException.CreateUnexpectedStatusMessage(Path, status); } }