Skip to content

Commit

Permalink
SP-247 Adds comments on code
Browse files Browse the repository at this point in the history
  • Loading branch information
isasmendiagus authored and francostramana committed Mar 22, 2024
1 parent 630e179 commit 017341f
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 1 deletion.
42 changes: 42 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/policies/copyleft-policy-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ import { PolicyCheck } from './policy-check';
import { Component, getComponents } from '../services/result.service';
import { generateTable } from '../utils/markdown.utils';

/**
* This class checks if any of the components identified in the scanner results are subject to copyleft licenses.
* It filters components based on their licenses and looks for those with copyleft obligations.
* It then generates a summary and detailed report of the findings.
*/
export class CopyleftPolicyCheck extends PolicyCheck {
constructor() {
super(`${CHECK_NAME}: Copyleft Policy`);
Expand Down
7 changes: 7 additions & 0 deletions src/policies/undeclared-policy-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ import * as inputs from '../app.input';
import { parseSBOM } from '../utils/sbom.utils';
import { generateTable } from '../utils/markdown.utils';

/**
* Verifies that all components identified in scanner results are declared in the project's SBOM.
* The run method compares components found by the scanner against those declared in the SBOM.
*
* It identifies and reports undeclared components, generating a summary and detailed report of the findings.
*
*/
export class UndeclaredPolicyCheck extends PolicyCheck {
constructor() {
super(`${CHECK_NAME}: Undeclared Policy`);
Expand Down
14 changes: 14 additions & 0 deletions src/services/result.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ export interface Component {
licenses: License[];
}

/**
* This function groups components by their `purl` and aggregates their licenses,
* ensuring that each unique `purl` is represented once with a comprehensive list of licenses.
*
* @param results - The raw scanner results to be processed of type {@link ScannerResults}
* @returns An array of {@link Component} objects, each representing a unique component
* with an aggregated list of licenses.
*/
export function getComponents(results: ScannerResults): Component[] {
const components = new Array<Component>();

Expand Down Expand Up @@ -99,6 +107,12 @@ export function getComponents(results: ScannerResults): Component[] {
return unqiqueComponents;
}

/**
* This function generate an array of {@link License } from raw scanner results {@link ScannerResults }
*
* @param results - The raw scanner results to be processed of type {@link ScannerResults}
* @returns An array of {@link License} objects
*/
export function getLicenses(results: ScannerResults): License[] {
const licenses = new Array<License>();

Expand Down
42 changes: 41 additions & 1 deletion src/services/scan.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,47 @@ export async function uploadResults(): Promise<void> {
}

export interface Options {
sbomType?: string;
/**
* Whether SBOM ingestion is enabled. Optional.
*/
sbomEnabled?: boolean;

/**
* Specifies the SBOM processing type: "identify" or "ignore". Optional.
*/
sbomType?: string;

/**
* Absolute path to the SBOM file. Required if sbomEnabled is set to true.
*/
sbomFilepath?: string;

/**
* Enables scanning for dependencies, utilizing scancode internally. Optional.
*/
dependenciesEnabled?: boolean;

/**
* Credentials for SCANOSS, enabling unlimited scans. Optional.
*/
apiKey?: string;
apiUrl?: string;

/**
* Absolute path where scan results are saved. Required.
*/
outputFilepath: string;

/**
* Absolute path of the folder or file to scan. Required.
*/
inputFilepath: string;
}

/**
* `ScanService` is a class that wraps the `scanoss.py` Docker image, providing a simplified interface
* for configuring and executing source code scans
*/
export class ScanService {
private options: Options;
constructor(options?: Options) {
Expand Down Expand Up @@ -83,6 +111,18 @@ export class ScanService {
${this.options.apiKey ? `--key ${this.options.apiKey}` : ''}`.replace(/\n/gm, ' ');
}

/**
* Constructs the command segment for SBOM ingestion based on the current configuration. This method checks if SBOM
* ingestion is enabled and verifies the SBOM file's existence before constructing the command.
*
* @example
* // When SBOM ingestion is enabled with a specified SBOM file and type:
* // sbomEnabled = true, sbomFilepath = "/src/SBOM.json", sbomType = "identify"
* // returns "--identify /src/SBOM.json"
*
* @returns A command string segment for SBOM ingestion or an empty string if conditions are not met.
* @private
*/
private async detectSBOM(): Promise<string> {
if (!this.options.sbomEnabled || !this.options.sbomFilepath) return '';

Expand Down

0 comments on commit 017341f

Please sign in to comment.