Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support JFrog Apps Config file #405

Merged
merged 9 commits into from
Oct 12, 2023
Merged

Conversation

yahavi
Copy link
Member

@yahavi yahavi commented Sep 12, 2023

  • All tests passed. If this feature is not already covered by the tests, I added new tests.
  • I used npm run format for formatting the code before submitting the pull request.

  • Support the new .jfrog/jfrog-apps-config.yml file to allow configuring JFrog Advanced Security scanners. https://github.com/jfrog/jfrog-apps-config
  • Rename all EOS -> Sast
  • Add unit tests to Sast
  • Upgrade analyzer manager 1.3.2.2005632 -> 1.3.2.2019257

@yahavi yahavi added the safe to test Approve running integration tests on a pull request label Sep 12, 2023
@github-actions github-actions bot removed the safe to test Approve running integration tests on a pull request label Sep 12, 2023
@yahavi yahavi added the safe to test Approve running integration tests on a pull request label Sep 12, 2023
@github-actions github-actions bot removed the safe to test Approve running integration tests on a pull request label Sep 12, 2023
@yahavi yahavi added the safe to test Approve running integration tests on a pull request label Sep 12, 2023
@github-actions github-actions bot removed the safe to test Approve running integration tests on a pull request label Sep 12, 2023
@yahavi yahavi added the safe to test Approve running integration tests on a pull request label Sep 12, 2023
@github-actions github-actions bot removed the safe to test Approve running integration tests on a pull request label Sep 12, 2023
@yahavi yahavi added the safe to test Approve running integration tests on a pull request label Sep 12, 2023
@github-actions github-actions bot removed the safe to test Approve running integration tests on a pull request label Sep 12, 2023
@yahavi yahavi added the safe to test Approve running integration tests on a pull request label Sep 20, 2023
@github-actions github-actions bot removed the safe to test Approve running integration tests on a pull request label Sep 20, 2023
@yahavi yahavi force-pushed the jfrog-apps-config branch from 6a65fec to 0f91072 Compare October 9, 2023 09:26
@yahavi yahavi added the safe to test Approve running integration tests on a pull request label Oct 9, 2023
@github-actions github-actions bot removed the safe to test Approve running integration tests on a pull request label Oct 9, 2023
@yahavi yahavi added the safe to test Approve running integration tests on a pull request label Oct 9, 2023
@github-actions github-actions bot removed the safe to test Approve running integration tests on a pull request label Oct 9, 2023
@yahavi yahavi force-pushed the jfrog-apps-config branch from 894053e to ff77065 Compare October 9, 2023 15:53
@yahavi yahavi added the safe to test Approve running integration tests on a pull request label Oct 9, 2023
@github-actions github-actions bot removed the safe to test Approve running integration tests on a pull request label Oct 9, 2023
@yahavi yahavi force-pushed the jfrog-apps-config branch from ff77065 to 9706616 Compare October 9, 2023 16:08
@yahavi yahavi added the safe to test Approve running integration tests on a pull request label Oct 9, 2023
@yahavi yahavi marked this pull request as ready for review October 9, 2023 16:08
@github-actions github-actions bot removed the safe to test Approve running integration tests on a pull request label Oct 9, 2023
Copy link
Contributor

@Or-Geva Or-Geva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yahavi, excellent work!. You have significantly improved the clarity and structure of the code 🚀.

@@ -128,23 +122,16 @@ export class ScanManager implements ExtensionComponent {
return !ScanManager.lastOutdatedCheck || Date.now() - ScanManager.lastOutdatedCheck > ScanManager.RESOURCE_CHECK_UPDATE_INTERVAL_MILLISECS;
}

private getResources(supportedScans: SupportedScans): Resource[] {
private getResources(supportedScans: EntitledScans): Resource[] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'Resource' is a vague name that refers to any artifact that is downloaded from Artifactory. The 'Resource' in 'scanManager' talks about a specific resource which is the JasRunners. I suggest we use the most descriptive name we can and replace 'Resource' with 'JasRunners'

}

/**
* Updates all the resources that are outdated.
* @param supportedScans - the supported scan to get the needed resources. if default, should call getSupportedScans before calling this method.
* @returns true if all the outdated resources updated successfully, false otherwise
*/
public async updateResources(supportedScans: SupportedScans = this._supportedScans): Promise<boolean> {
public async updateResources(supportedScans: EntitledScans = this._entitledScans): Promise<boolean> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a couple of quistions regarding the param:

  1. Given that its name suggests that ScanManager is responsible for managing all scans, why is it necessary to pass in the supported scan as a parameter? As a manager, one would expect it to handle all aspects of the scan without revealing internal implementation details to other functions. A manager should inherently know what is supported or not.

  2. The only reference I could find, calling this func is at 'IssuesTreeDataProvider'. Why data providers should care about scan manager updates? again, no one can tell a manager what to do regarding internal details that are being used for scans operations.

let resources: Resource[] = [];
if (supportedScans.applicability || supportedScans.iac || supportedScans.secrets) {
resources.push(BinaryRunner.getAnalyzerManagerResource(this._logManager));
resources.push(JasRunner.getAnalyzerManagerResource(this._logManager));
} else {
this.logManager.logMessage('You are not entitled to run Advanced Security scans', 'DEBUG');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we identify if we are not entitled before calling getResources at getSupportedScans?

src/main/scanLogic/scanRunners/analyzerModels.ts Outdated Show resolved Hide resolved
}

/**
* Get all the entitlement status for each type of scan the manager offers
*/
public async getSupportedScans(): Promise<SupportedScans> {
let supportedScans: SupportedScans = {} as SupportedScans;
public async getSupportedScans(): Promise<EntitledScans> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest that we change it to be private, and each support check will be response to update it own property
For example:

    public async isApplicabilitySupported(): Promise<boolean> {
        return await ConnectionUtils.testXrayEntitlementForFeature(this._connectionManager.createJfrogClient(), EntitlementScanFeature.Applicability);
    }

--->

        public async setApplicabilityEntitled(): Promise<void> {
        ConnectionUtils.testXrayEntitlementForFeature(this._connectionManager.createJfrogClient(), EntitlementScanFeature.Applicability)
        .then(res => (this.entitledScans.applicability = res))
        .catch(err => ScanUtils.onScanError(err, this._logManager, true))
    }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the suggestion is not related to Apps Config and not to the changes I did in this PR.
This PR has already become too big.

src/main/scanLogic/scanRunners/jasRunner.ts Outdated Show resolved Hide resolved
src/main/scanLogic/scanRunners/jasRunner.ts Outdated Show resolved Hide resolved
src/test/tests/mavenUpdate.test.ts Outdated Show resolved Hide resolved
describe('JFrog Apps Config Tests', () => {
const jfrogAppsConfigDir: string = path.join(__dirname, '..', 'resources', 'jfrogAppsConfig');

it('Load full config', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can break the test into two separate tests, each with its own particular assertion. for example, a check sast scanner can be encapsulated in its own it().

It will be clearer what fails in the config and it will enable us to scale if we would like to add additional specific module tests

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bond between the tests is too strong to split them into subtests - it reads one file and parses it. This is the result of the parsing. If we add more tests, it will require creating another input yaml and by that a new it.

I do agree that the test method was too long and therefore I shorted the test.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can move the file read logic into the before section, each it will check a specific configuration section. Adding a new section to the config file in the future will make us add a single it test case.

@yahavi yahavi added the safe to test Approve running integration tests on a pull request label Oct 12, 2023
@github-actions github-actions bot removed the safe to test Approve running integration tests on a pull request label Oct 12, 2023
@yahavi yahavi merged commit 065c8b1 into jfrog:master Oct 12, 2023
1 check failed
@yahavi yahavi deleted the jfrog-apps-config branch October 12, 2023 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Automatically generated release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants