예제 #1
0
        /// <summary>
        /// Analyze a package by downloading it first.
        /// </summary>
        /// <param name="purl">The package-url of the package to analyze.</param>
        /// <returns>n/a</returns>
        public async Task AnalyzePackage(PackageURL purl)
        {
            Logger.Trace("AnalyzePackage({0})", purl.ToString());

            string targetDirectoryName = null;

            while (targetDirectoryName == null || Directory.Exists(targetDirectoryName))
            {
                targetDirectoryName = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            }
            Directory.CreateDirectory(targetDirectoryName);
            Logger.Trace("Creating [{0}]", targetDirectoryName);

            var downloadTool   = new DownloadTool();
            var directoryNames = await downloadTool.Download(purl, targetDirectoryName);

            if (directoryNames.Count > 0)
            {
                foreach (var directoryName in directoryNames)
                {
                    await AnalyzeDirectory(directoryName);

                    Logger.Trace("Deleting {0}", directoryName);
                    Directory.Delete(directoryName, true);
                }
            }
            else
            {
                Logger.Warn("Error downloading {0}.", purl.ToString());
            }
        }
예제 #2
0
        /// <summary>
        /// Analyze a package by downloading it first.
        /// </summary>
        /// <param name="purl">The package-url of the package to analyze.</param>
        /// <returns>n/a</returns>
        public async Task AnalyzePackage(PackageURL purl)
        {
            Logger.Trace("AnalyzePackage({0})", purl.ToString());

            var downloadTool = new DownloadTool();

            foreach (var directory in await downloadTool.Download(purl))
            {
                AnalyzeDirectory(directory);
            }
        }
예제 #3
0
        /// <summary>
        /// Analyze a package by downloading it first.
        /// </summary>
        /// <param name="purl">The package-url of the package to analyze.</param>
        /// <returns>List of tags identified</returns>
        public async Task <List <IssueRecord> > AnalyzePackage(PackageURL purl)
        {
            Logger.Trace("AnalyzePackage({0})", purl.ToString());

            var analysisResults = new List <IssueRecord>();

            string targetDirectoryName = null;

            while (targetDirectoryName == null || Directory.Exists(targetDirectoryName))
            {
                targetDirectoryName = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            }

            Logger.Trace("Creating directory [{0}]", targetDirectoryName);
            Directory.CreateDirectory(targetDirectoryName);

            var downloadTool   = new DownloadTool();
            var directoryNames = await downloadTool.Download(purl, targetDirectoryName);

            directoryNames = directoryNames.Distinct().ToList <string>();

            if (directoryNames.Count > 0)
            {
                foreach (var directoryName in directoryNames)
                {
                    Logger.Trace("Analyzing directory {0}", directoryName);
                    var singleResult = await AnalyzeDirectory(directoryName);

                    if (singleResult != default)
                    {
                        analysisResults.AddRange(singleResult);
                    }

                    Logger.Trace("Removing directory {0}", directoryName);
                    try
                    {
                        Directory.Delete(directoryName, true);
                    }
                    catch (Exception ex)
                    {
                        Logger.Warn("Error removing {0}: {1}", directoryName, ex.Message);
                    }
                }
            }
            else
            {
                Logger.Warn("Error downloading {0}.", purl.ToString());
            }


            return(analysisResults.ToList());
        }
예제 #4
0
        /// <summary>
        /// Main entrypoint for the download program.
        /// </summary>
        /// <param name="args">parameters passed in from the user</param>
        static async Task Main(string[] args)
        {
            var downloadTool = new DownloadTool();

            Logger.Info($"Microsoft OSS Gadget - {TOOL_NAME} {VERSION}");

            downloadTool.ParseOptions(args);

            if (((IList <string>)downloadTool.Options["target"]).Count > 0)
            {
                foreach (var target in (IList <string>)downloadTool.Options["target"])
                {
                    try
                    {
                        var purl = new PackageURL(target);
                        foreach (var downloadPath in await downloadTool.Download(purl))
                        {
                            if (string.IsNullOrEmpty(downloadPath))
                            {
                                Logger.Error("Unable to download {0}.", purl.ToString());
                            }
                            else
                            {
                                Logger.Info("Downloaded {0} to {1}", purl.ToString(), downloadPath);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Warn(ex, "Error processing {0}: {1}", target, ex.Message);
                        Logger.Warn(ex.StackTrace);
                    }
                }
            }
            else
            {
                Logger.Warn("No target provided; nothing to download.");
                DownloadTool.ShowUsage();
                Environment.Exit(1);
            }
        }
예제 #5
0
        /// <summary>
        ///     Main entrypoint for the download program.
        /// </summary>
        /// <param name="args"> parameters passed in from the user </param>
        static async Task <int> Main(string[] args)
        {
            ShowToolBanner();

            DownloadTool?          downloadTool = new DownloadTool();
            ParserResult <Options>?opts         = downloadTool.ParseOptions <Options>(args);

            if (opts.Value is null)
            {
                if (opts.Errors.All(x => x.Tag == ErrorType.HelpRequestedError))
                {
                    return((int)ErrorCode.Ok);
                }
                else
                {
                    return((int)ErrorCode.ErrorParsingOptions);
                }
            }
            else
            {
                return((int)(await downloadTool.RunAsync(opts.Value)));
            }
        }
예제 #6
0
 /// <summary>
 ///     Main entrypoint for the download program.
 /// </summary>
 /// <param name="args"> parameters passed in from the user </param>
 private static async Task Main(string[] args)
 {
     var downloadTool = new DownloadTool();
     await downloadTool.ParseOptions <Options>(args).WithParsedAsync(downloadTool.RunAsync);
 }