From 1aa0a0eeb4dbd6df4d2a5009c79d3e2b627822b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C2=8DAmitla=20Vannikumar?= Date: Tue, 23 Aug 2022 10:20:45 -0700 Subject: [PATCH 01/11] Fix for Bug 196 --- .../dockerfile/DockerfileComponentDetector.cs | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs index 7818e4dc5..e705e1b02 100644 --- a/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Composition; using System.IO; @@ -36,19 +36,26 @@ public class DockerfileComponentDetector : FileComponentDetector, IDefaultOffCom protected override async Task OnFileFound(ProcessRequest processRequest, IDictionary detectorArgs) { - var singleFileComponentRecorder = processRequest.SingleFileComponentRecorder; - var file = processRequest.ComponentStream; - var filePath = file.Location; - this.Logger.LogInfo($"Discovered dockerfile: {file.Location}"); + try + { + var singleFileComponentRecorder = processRequest.SingleFileComponentRecorder; + var file = processRequest.ComponentStream; + var filePath = file.Location; + this.Logger.LogInfo($"Discovered dockerfile: {file.Location}"); + + string contents; + using (var reader = new StreamReader(file.Stream)) + { + contents = await reader.ReadToEndAsync(); + } - string contents; - using (var reader = new StreamReader(file.Stream)) + var stageNameMap = new Dictionary(); + var dockerFileComponent = this.ParseDockerFile(contents, file.Location, singleFileComponentRecorder, stageNameMap); + } catch (Exception e) { - contents = await reader.ReadToEndAsync(); + this.Logger.LogError($"The file is not a Dockerfile it just has 'Docker' in the name. \n Error Message: <{e.Message}>"); + this.Logger.LogException(e, isError: true, printException: true); } - - var stageNameMap = new Dictionary(); - var dockerFileComponent = this.ParseDockerFile(contents, file.Location, singleFileComponentRecorder, stageNameMap); } private Task ParseDockerFile(string fileContents, string fileLocation, ISingleFileComponentRecorder singleFileComponentRecorder, Dictionary stageNameMap) From 5a01569bb63fa09202e1df71a3456bc4fa71ecd8 Mon Sep 17 00:00:00 2001 From: amitla1 <46578839+amitla1@users.noreply.github.com> Date: Tue, 23 Aug 2022 16:13:24 -0700 Subject: [PATCH 02/11] Update src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs Co-authored-by: Jamie Magee --- .../dockerfile/DockerfileComponentDetector.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs index e705e1b02..3c19e4008 100644 --- a/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs @@ -54,7 +54,7 @@ protected override async Task OnFileFound(ProcessRequest processRequest, IDictio } catch (Exception e) { this.Logger.LogError($"The file is not a Dockerfile it just has 'Docker' in the name. \n Error Message: <{e.Message}>"); - this.Logger.LogException(e, isError: true, printException: true); + this.Logger.LogException(e); } } From 1e6e7ae313d91e3e9b1e2f8e07631493bf2dbfae Mon Sep 17 00:00:00 2001 From: amitla1 <46578839+amitla1@users.noreply.github.com> Date: Tue, 23 Aug 2022 16:13:39 -0700 Subject: [PATCH 03/11] Update src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs Co-authored-by: Jamie Magee --- .../dockerfile/DockerfileComponentDetector.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs index 3c19e4008..9ba4c9832 100644 --- a/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs @@ -53,7 +53,7 @@ protected override async Task OnFileFound(ProcessRequest processRequest, IDictio var dockerFileComponent = this.ParseDockerFile(contents, file.Location, singleFileComponentRecorder, stageNameMap); } catch (Exception e) { - this.Logger.LogError($"The file is not a Dockerfile it just has 'Docker' in the name. \n Error Message: <{e.Message}>"); + this.Logger.LogError($"The file doesn't appear to be a Dockerfile: '{file.Location}'"); this.Logger.LogException(e); } } From 460d4defdbd9ca627a390b49a7f4c075e930a809 Mon Sep 17 00:00:00 2001 From: amitla1 <46578839+amitla1@users.noreply.github.com> Date: Tue, 23 Aug 2022 16:34:04 -0700 Subject: [PATCH 04/11] Update DockerfileComponentDetector.cs --- .../dockerfile/DockerfileComponentDetector.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs index 9ba4c9832..e89174062 100644 --- a/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs @@ -54,7 +54,7 @@ protected override async Task OnFileFound(ProcessRequest processRequest, IDictio } catch (Exception e) { this.Logger.LogError($"The file doesn't appear to be a Dockerfile: '{file.Location}'"); - this.Logger.LogException(e); + this.Logger.LogException(e, false); } } From deb51b92637d06df03e54d1f04a7dbe7ab0d6d5f Mon Sep 17 00:00:00 2001 From: amitla1 <46578839+amitla1@users.noreply.github.com> Date: Tue, 23 Aug 2022 16:36:29 -0700 Subject: [PATCH 05/11] Update DockerfileComponentDetector.cs --- .../dockerfile/DockerfileComponentDetector.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs index e89174062..20bb6ff33 100644 --- a/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs @@ -53,7 +53,7 @@ protected override async Task OnFileFound(ProcessRequest processRequest, IDictio var dockerFileComponent = this.ParseDockerFile(contents, file.Location, singleFileComponentRecorder, stageNameMap); } catch (Exception e) { - this.Logger.LogError($"The file doesn't appear to be a Dockerfile: '{file.Location}'"); + this.Logger.LogError($"The file doesn't appear to be a Dockerfile: '{filePath}'"); this.Logger.LogException(e, false); } } From 75b2b8654072ad8ba3229fd6a64f2cdf3e4eca9e Mon Sep 17 00:00:00 2001 From: amitla1 <46578839+amitla1@users.noreply.github.com> Date: Tue, 23 Aug 2022 16:39:36 -0700 Subject: [PATCH 06/11] Update DockerfileComponentDetector.cs --- .../dockerfile/DockerfileComponentDetector.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs index 20bb6ff33..f68d2ae1f 100644 --- a/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs @@ -36,11 +36,11 @@ public class DockerfileComponentDetector : FileComponentDetector, IDefaultOffCom protected override async Task OnFileFound(ProcessRequest processRequest, IDictionary detectorArgs) { + var singleFileComponentRecorder = processRequest.SingleFileComponentRecorder; + file = processRequest.ComponentStream; + var filePath = file.Location; try { - var singleFileComponentRecorder = processRequest.SingleFileComponentRecorder; - var file = processRequest.ComponentStream; - var filePath = file.Location; this.Logger.LogInfo($"Discovered dockerfile: {file.Location}"); string contents; From 9971be81f6052c0257bcb78cd6f99cd2f7b704fe Mon Sep 17 00:00:00 2001 From: amitla1 <46578839+amitla1@users.noreply.github.com> Date: Tue, 23 Aug 2022 16:47:46 -0700 Subject: [PATCH 07/11] Update DockerfileComponentDetector.cs --- .../dockerfile/DockerfileComponentDetector.cs | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs index f68d2ae1f..c58131cb1 100644 --- a/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs @@ -36,26 +36,26 @@ public class DockerfileComponentDetector : FileComponentDetector, IDefaultOffCom protected override async Task OnFileFound(ProcessRequest processRequest, IDictionary detectorArgs) { - var singleFileComponentRecorder = processRequest.SingleFileComponentRecorder; - file = processRequest.ComponentStream; - var filePath = file.Location; - try - { - this.Logger.LogInfo($"Discovered dockerfile: {file.Location}"); + var singleFileComponentRecorder = processRequest.SingleFileComponentRecorder; + file = processRequest.ComponentStream; + var filePath = file.Location; + try + { + this.Logger.LogInfo($"Discovered dockerfile: {file.Location}"); + + string contents; + using (var reader = new StreamReader(file.Stream)) + { + contents = await reader.ReadToEndAsync(); + } - string contents; - using (var reader = new StreamReader(file.Stream)) + var stageNameMap = new Dictionary(); + var dockerFileComponent = this.ParseDockerFile(contents, file.Location, singleFileComponentRecorder, stageNameMap); + } catch (Exception e) { - contents = await reader.ReadToEndAsync(); + this.Logger.LogError($"The file doesn't appear to be a Dockerfile: '{file.location}'"); + this.Logger.LogException(e, false); } - - var stageNameMap = new Dictionary(); - var dockerFileComponent = this.ParseDockerFile(contents, file.Location, singleFileComponentRecorder, stageNameMap); - } catch (Exception e) - { - this.Logger.LogError($"The file doesn't appear to be a Dockerfile: '{filePath}'"); - this.Logger.LogException(e, false); - } } private Task ParseDockerFile(string fileContents, string fileLocation, ISingleFileComponentRecorder singleFileComponentRecorder, Dictionary stageNameMap) From dfbe0037a92da777096e0e73247dcadeadbc3e32 Mon Sep 17 00:00:00 2001 From: amitla1 <46578839+amitla1@users.noreply.github.com> Date: Tue, 23 Aug 2022 16:54:07 -0700 Subject: [PATCH 08/11] Update DockerfileComponentDetector.cs --- .../dockerfile/DockerfileComponentDetector.cs | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs index c58131cb1..4b594d227 100644 --- a/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs @@ -36,26 +36,26 @@ public class DockerfileComponentDetector : FileComponentDetector, IDefaultOffCom protected override async Task OnFileFound(ProcessRequest processRequest, IDictionary detectorArgs) { - var singleFileComponentRecorder = processRequest.SingleFileComponentRecorder; - file = processRequest.ComponentStream; - var filePath = file.Location; - try - { - this.Logger.LogInfo($"Discovered dockerfile: {file.Location}"); - - string contents; - using (var reader = new StreamReader(file.Stream)) - { - contents = await reader.ReadToEndAsync(); - } + try + { + var singleFileComponentRecorder = processRequest.SingleFileComponentRecorder; + var file = processRequest.ComponentStream; + var filePath = file.Location; + this.Logger.LogInfo($"Discovered dockerfile: {file.Location}"); - var stageNameMap = new Dictionary(); - var dockerFileComponent = this.ParseDockerFile(contents, file.Location, singleFileComponentRecorder, stageNameMap); - } catch (Exception e) + string contents; + using (var reader = new StreamReader(file.Stream)) { - this.Logger.LogError($"The file doesn't appear to be a Dockerfile: '{file.location}'"); - this.Logger.LogException(e, false); + contents = await reader.ReadToEndAsync(); } + + var stageNameMap = new Dictionary(); + var dockerFileComponent = this.ParseDockerFile(contents, file.Location, singleFileComponentRecorder, stageNameMap); + } catch (Exception e) + { + this.Logger.LogError($"The file doesn't appear to be a Dockerfile: '{file.location}'"); + this.Logger.LogException(e, false); + } } private Task ParseDockerFile(string fileContents, string fileLocation, ISingleFileComponentRecorder singleFileComponentRecorder, Dictionary stageNameMap) From 4778beb2b58c5a2995abe620ca35bced11440666 Mon Sep 17 00:00:00 2001 From: amitla1 <46578839+amitla1@users.noreply.github.com> Date: Tue, 23 Aug 2022 16:58:29 -0700 Subject: [PATCH 09/11] Update DockerfileComponentDetector.cs --- .../dockerfile/DockerfileComponentDetector.cs | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs index 4b594d227..795d2bca9 100644 --- a/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs @@ -36,26 +36,26 @@ public class DockerfileComponentDetector : FileComponentDetector, IDefaultOffCom protected override async Task OnFileFound(ProcessRequest processRequest, IDictionary detectorArgs) { - try - { - var singleFileComponentRecorder = processRequest.SingleFileComponentRecorder; - var file = processRequest.ComponentStream; - var filePath = file.Location; - this.Logger.LogInfo($"Discovered dockerfile: {file.Location}"); + var singleFileComponentRecorder = processRequest.SingleFileComponentRecorder; + var file = processRequest.ComponentStream; + var filePath = file.Location; + try + { + this.Logger.LogInfo($"Discovered dockerfile: {file.Location}"); + + string contents; + using (var reader = new StreamReader(file.Stream)) + { + contents = await reader.ReadToEndAsync(); + } - string contents; - using (var reader = new StreamReader(file.Stream)) + var stageNameMap = new Dictionary(); + var dockerFileComponent = this.ParseDockerFile(contents, file.Location, singleFileComponentRecorder, stageNameMap); + } catch (Exception e) { - contents = await reader.ReadToEndAsync(); + this.Logger.LogError($"The file doesn't appear to be a Dockerfile: '{file.location}'"); + this.Logger.LogException(e, false); } - - var stageNameMap = new Dictionary(); - var dockerFileComponent = this.ParseDockerFile(contents, file.Location, singleFileComponentRecorder, stageNameMap); - } catch (Exception e) - { - this.Logger.LogError($"The file doesn't appear to be a Dockerfile: '{file.location}'"); - this.Logger.LogException(e, false); - } } private Task ParseDockerFile(string fileContents, string fileLocation, ISingleFileComponentRecorder singleFileComponentRecorder, Dictionary stageNameMap) From 78c034e378d81c195f44012cc35e36f75949e19d Mon Sep 17 00:00:00 2001 From: amitla1 <46578839+amitla1@users.noreply.github.com> Date: Tue, 23 Aug 2022 17:02:39 -0700 Subject: [PATCH 10/11] Update DockerfileComponentDetector.cs --- .../dockerfile/DockerfileComponentDetector.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs index 795d2bca9..4b39f8d82 100644 --- a/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs @@ -53,7 +53,7 @@ protected override async Task OnFileFound(ProcessRequest processRequest, IDictio var dockerFileComponent = this.ParseDockerFile(contents, file.Location, singleFileComponentRecorder, stageNameMap); } catch (Exception e) { - this.Logger.LogError($"The file doesn't appear to be a Dockerfile: '{file.location}'"); + this.Logger.LogError($"The file doesn't appear to be a Dockerfile: '{file.Location}'"); this.Logger.LogException(e, false); } } From bd43bbc95ce543ea5852bd819a1df7e5ee984943 Mon Sep 17 00:00:00 2001 From: amitla1 <46578839+amitla1@users.noreply.github.com> Date: Wed, 24 Aug 2022 11:47:19 -0700 Subject: [PATCH 11/11] Update DockerfileComponentDetector.cs --- .../dockerfile/DockerfileComponentDetector.cs | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs index 4b39f8d82..715cff6ba 100644 --- a/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs @@ -39,23 +39,23 @@ protected override async Task OnFileFound(ProcessRequest processRequest, IDictio var singleFileComponentRecorder = processRequest.SingleFileComponentRecorder; var file = processRequest.ComponentStream; var filePath = file.Location; - try - { - this.Logger.LogInfo($"Discovered dockerfile: {file.Location}"); - - string contents; - using (var reader = new StreamReader(file.Stream)) - { - contents = await reader.ReadToEndAsync(); - } + try + { + this.Logger.LogInfo($"Discovered dockerfile: {file.Location}"); - var stageNameMap = new Dictionary(); - var dockerFileComponent = this.ParseDockerFile(contents, file.Location, singleFileComponentRecorder, stageNameMap); - } catch (Exception e) + string contents; + using (var reader = new StreamReader(file.Stream)) { - this.Logger.LogError($"The file doesn't appear to be a Dockerfile: '{file.Location}'"); - this.Logger.LogException(e, false); + contents = await reader.ReadToEndAsync(); } + + var stageNameMap = new Dictionary(); + var dockerFileComponent = this.ParseDockerFile(contents, file.Location, singleFileComponentRecorder, stageNameMap); + } catch (Exception e) + { + this.Logger.LogError($"The file doesn't appear to be a Dockerfile: '{file.Location}'"); + this.Logger.LogException(e, false); + } } private Task ParseDockerFile(string fileContents, string fileLocation, ISingleFileComponentRecorder singleFileComponentRecorder, Dictionary stageNameMap)