public HttpResponseMessage Deploy(BdioContent bdioContent) { HubRequest request = new HubRequest(RestConnection); request.Path = $"api/{ApiLinks.BOM_IMPORTS_LINK}"; HttpResponseMessage response = request.ExecuteJsonLDPost(bdioContent.ToString()); return(response); }
public void ExecuteTask() { if (IsExcluded()) { Log.LogMessage("Project {0} excluded from task", HubProjectName); } else { // Creates output directory if it doesn't already exist Directory.CreateDirectory(OutputDirectory); // Define output files string bdioFilePath = $"{OutputDirectory}/{HubProjectName}.jsonld"; string flatListFilePath = $"{OutputDirectory}/{HubProjectName}_flat.txt"; // Execute task functionality if (CreateFlatDependencyList) { string[] externalIds = CreateFlatList().ToArray(); File.WriteAllLines(flatListFilePath, externalIds, Encoding.UTF8); } if (CreateHubBdio) { BdioContent bdioContent = BuildBOM(); File.WriteAllText(bdioFilePath, bdioContent.ToString()); } if (DeployHubBdio) { string bdio = File.ReadAllText(bdioFilePath); BdioContent bdioContent = BdioContent.Parse(bdio); DeployBdioDataService.Deploy(bdioContent); } // Only wait for scan if we have to if (DeployHubBdio && (CheckPolicies || CreateHubBdio || WaitForDeployment)) { WaitForHub(); } if (CreateHubReport) { ProjectView projectView = ProjectDataService.GetProjectView(HubProjectName); ProjectVersionView projectVersionView = ProjectDataService.GetMostRecentVersion(projectView); ReportData reportData = RiskReportDataService.GetReportData(projectView, projectVersionView); RiskReportDataService.WriteToRiskReport(reportData, OutputDirectory); } if (CheckPolicies) { PolicyStatus policyStatus = new PolicyStatus(GetPolicies()); LogPolicyViolations(policyStatus); } } }
private void GenerateMergedFile(List <BdioNode> components) { BdioPropertyHelper bdioPropertyHelper = new BdioPropertyHelper(); BdioNodeFactory bdioNodeFactory = new BdioNodeFactory(bdioPropertyHelper); BdioContent bdio = new BdioContent(); // solutions do not have project names or versions by default string projectName = HubProjectName; string versionName = HubVersionName; if (String.IsNullOrWhiteSpace(projectName)) { projectName = Path.GetFileNameWithoutExtension(SolutionPath); } if (String.IsNullOrWhiteSpace(versionName)) { versionName = DateTime.UtcNow.ToString(ProjectGenerator.DEFAULT_DATETIME_FORMAT); } // Create bdio bill of materials node BdioBillOfMaterials bdioBillOfMaterials = bdioNodeFactory.CreateBillOfMaterials(HubCodeLocationName, projectName, versionName); // Create bdio project node string projectBdioId = bdioPropertyHelper.CreateBdioId(projectName, versionName); BdioExternalIdentifier projectExternalIdentifier = bdioPropertyHelper.CreateNugetExternalIdentifier(projectName, versionName); // Note: Could be different. Look at config file BdioProject bdioProject = bdioNodeFactory.CreateProject(projectName, versionName, projectBdioId, projectExternalIdentifier); bdio.BillOfMaterials = bdioBillOfMaterials; bdio.Project = bdioProject; bdio.Components = components; string bdioFilePath = Path.Combine(OutputDirectory, $"{projectName}.jsonld"); File.WriteAllText(bdioFilePath, bdio.ToString()); }