From 1acc8c91228eeb2dbf295787b5840b2de5344229 Mon Sep 17 00:00:00 2001 From: Benjamin Russell Date: Fri, 12 Aug 2016 17:38:41 -0700 Subject: [PATCH] Fixing up error logging Fixing issue where plaintext passwords could be written to logs Fixing up todo issues where error events needed to be passed back from the service layer when the hosting component fails. --- .../Hosting/Contracts/HostingErrorEvent.cs | 28 +++++++++++++++++++ .../Hosting/Protocol/MessageDispatcher.cs | 5 ++++ .../Hosting/Protocol/MessageReader.cs | 7 ----- .../Messaging/TestMessageTypes.cs | 2 +- 4 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 src/Microsoft.SqlTools.ServiceLayer/Hosting/Contracts/HostingErrorEvent.cs diff --git a/src/Microsoft.SqlTools.ServiceLayer/Hosting/Contracts/HostingErrorEvent.cs b/src/Microsoft.SqlTools.ServiceLayer/Hosting/Contracts/HostingErrorEvent.cs new file mode 100644 index 00000000..4d221acc --- /dev/null +++ b/src/Microsoft.SqlTools.ServiceLayer/Hosting/Contracts/HostingErrorEvent.cs @@ -0,0 +1,28 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; + +namespace Microsoft.SqlTools.ServiceLayer.Hosting.Contracts +{ + /// + /// Parameters to be used for reporting hosting-level errors, such as protocol violations + /// + public class HostingErrorParams + { + /// + /// + /// + public string Message { get; set; } + } + + public class HostingErrorEvent + { + public static readonly + EventType Type = + EventType.Create("hostingError"); + + } +} diff --git a/src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/MessageDispatcher.cs b/src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/MessageDispatcher.cs index 7cf1f2dd..d7e5812d 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/MessageDispatcher.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/MessageDispatcher.cs @@ -243,6 +243,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Hosting.Protocol // previous message. In this case, do not try to dispatch it. if (newMessage != null) { + // Verbose logging + string logMessage = String.Format("Received message of type[{0}] and method[{1}]", + newMessage.MessageType, newMessage.Method); + Logger.Write(LogLevel.Verbose, logMessage); + // Process the message await this.DispatchMessage(newMessage, this.MessageWriter); } diff --git a/src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/MessageReader.cs b/src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/MessageReader.cs index 4351361f..17d4b5e0 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/MessageReader.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/MessageReader.cs @@ -112,13 +112,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Hosting.Protocol // Get the JObject for the JSON content JObject messageObject = JObject.Parse(messageContent); - // Load the message - Logger.Write( - LogLevel.Verbose, - string.Format( - "READ MESSAGE:\r\n\r\n{0}", - messageObject.ToString(Formatting.Indented))); - // Return the parsed message return this.messageSerializer.DeserializeMessage(messageObject); } diff --git a/test/Microsoft.SqlTools.ServiceLayer.Test/Messaging/TestMessageTypes.cs b/test/Microsoft.SqlTools.ServiceLayer.Test/Messaging/TestMessageTypes.cs index 0ba08056..89238098 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.Test/Messaging/TestMessageTypes.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.Test/Messaging/TestMessageTypes.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol; -namespace Microsoft.SqlTools.ServiceLayer.Test.Message +namespace Microsoft.SqlTools.ServiceLayer.Test.Messaging { #region Request Types