Skip to content

Conversation

@cx-ben-alvo
Copy link
Contributor

@cx-ben-alvo cx-ben-alvo commented Jun 8, 2025

Closes #

Proposed Changes

Checklist

  • I covered my changes with tests.
  • I Updated the documentation that is affected by my changes:
    • Change in the CLI arguments
    • Change in the configuration file

I submit this contribution under the Apache-2.0 license.

@cx-ben-alvo cx-ben-alvo requested a review from a team as a code owner June 8, 2025 07:23
@github-actions
Copy link

github-actions bot commented Jun 8, 2025

kics-logo

KICS version: v1.7.13

Category Results
HIGH HIGH 0
MEDIUM MEDIUM 0
LOW LOW 0
INFO INFO 0
TRACE TRACE 0
TOTAL TOTAL 0
Metric Values
Files scanned placeholder 12
Files parsed placeholder 12
Files failed to scan placeholder 0
Total executed queries placeholder 53
Queries failed to execute placeholder 0
Execution time placeholder 1

@github-actions
Copy link

github-actions bot commented Jun 8, 2025

Logo
Checkmarx One – Scan Summary & Details5d3d2486-d053-401c-b4ed-72af5e2e893e

Great job, no security vulnerabilities found in this Pull Request

@cx-ben-alvo cx-ben-alvo changed the title fix: update import paths to v3 for consistency across the codebase Add ScanWithValidation func to Scanner (AST-99448) Jun 8, 2025
@cx-ben-alvo cx-ben-alvo changed the title Add ScanWithValidation func to Scanner (AST-99448) Add ScanWithValidation func to Scanner AST-99448 Jun 8, 2025
@cx-ben-alvo cx-ben-alvo changed the title Add ScanWithValidation func to Scanner AST-99448 Add ScanWithValidation func to Scanner Jun 8, 2025
@cx-ben-alvo cx-ben-alvo changed the title Add ScanWithValidation func to Scanner feat: Add ScanWithValidation func to Scanner Jun 8, 2025
@cx-ben-alvo cx-ben-alvo changed the title feat: Add ScanWithValidation func to Scanner feat: add scanwithvalidation func to Scanner Jun 8, 2025
@cx-ben-alvo cx-ben-alvo changed the title feat: add scanwithvalidation func to Scanner feat: add scan with validation func to Scanner interface Jun 8, 2025
pkg/scan.go Outdated
return s.runScan(scanItems, scanConfig, false)
}

func (s *scanner) ScanWithValidation(scanItems []ScanItem, scanConfig ScanConfig) (*reporting.Report, error) {
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 add the validate/withValidation bool variable to the ScanConfig struct and adapt existing functions instead of creating a new function. The idea is that eventually ScanConfig will allow any configuration that the current 2ms cli allows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds good, I will make this changes

Copy link
Contributor

Choose a reason for hiding this comment

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

close(CvssScoreWithoutValidationChan)
}

func ProcessSecretsWithValidation() {
Copy link
Contributor

Choose a reason for hiding this comment

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

what is the reason to create this function? can we follow a similar strategy to the preRun function from cmd/main.go? The idea is to eventually refactor to have common logic from the 2ms cli flow instead of duplicated code, so it would be better to not create new logic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because it will require to change ProcessSecrets() signature, I dont know if it will cause breaking changes in other places that importing this repo

Copy link
Contributor

Choose a reason for hiding this comment

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

why will it require to change the ProcessSecrets() signature?

pkg/scan_test.go Outdated
}

testScanner := NewScanner()
actualReport, err := testScanner.ScanWithValidation(scanItems, ScanConfig{})
Copy link
Contributor

@cx-leonardo-fontes cx-leonardo-fontes Jun 11, 2025

Choose a reason for hiding this comment

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

As you probably know, current we have an issue if we try to call the Scan function more than 1 time in a life cycle of our program (it probably has an easy fix, we just didn't have time for it yet). We tested calling this function twice in a row and we receive "close of a closed channel", so just be aware if your use case demands calling it multiple times

Copy link
Contributor Author

@cx-ben-alvo cx-ben-alvo Jun 11, 2025

Choose a reason for hiding this comment

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

Hi it being called once in each execution of a CLI command, so i think it will be ok

Comment on lines 94 to 102
if withValidation {
go cmd.ProcessSecretsWithValidation()
go cmd.ProcessSecretsExtras()
go cmd.ProcessValidationAndScoreWithValidation(engineInstance)
} else {
go cmd.ProcessSecrets()
go cmd.ProcessSecretsExtras()
go cmd.ProcessScoreWithoutValidation(engineInstance)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if withValidation {
go cmd.ProcessSecretsWithValidation()
go cmd.ProcessSecretsExtras()
go cmd.ProcessValidationAndScoreWithValidation(engineInstance)
} else {
go cmd.ProcessSecrets()
go cmd.ProcessSecretsExtras()
go cmd.ProcessScoreWithoutValidation(engineInstance)
}
if withValidation {
go cmd.ProcessSecretsWithValidation()
go cmd.ProcessValidationAndScoreWithValidation(engineInstance)
} else {
go cmd.ProcessSecrets()
go cmd.ProcessScoreWithoutValidation(engineInstance)
}
go cmd.ProcessSecretsExtras()

@@ -1,4 +1,4 @@
module github.com/checkmarx/2ms
module github.com/checkmarx/2ms/v3
Copy link
Contributor

Choose a reason for hiding this comment

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

why are we jumping on the version here? If we don't have a strong reason to do this, we can stay here and not make people update their imports.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I needed to add to the module name the v3 suffix (this is go conventions in order to be able to import releases with major of 3..)

Copy link
Contributor

Choose a reason for hiding this comment

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

I understand that but my question is, why do we need to bump the version? If we are not making a significant change to the project and as far as I understand, we can add the suggested feature without impacting the current use of the 2ms, the version bump is not needed, right?

pkg/scan.go Outdated
return s.runScan(scanItems, scanConfig, false)
}

func (s *scanner) ScanWithValidation(scanItems []ScanItem, scanConfig ScanConfig) (*reporting.Report, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@cx-ben-alvo cx-ben-alvo merged commit c6935eb into master Jun 11, 2025
12 checks passed
@cx-ben-alvo cx-ben-alvo deleted the other/benalvo/add-scan-with-validation branch June 11, 2025 10:50
cx-rogerio-dalot pushed a commit that referenced this pull request Sep 11, 2025
<!--
Thanks for contributing to 2ms by offering a pull request.
-->

Closes #

**Proposed Changes**

<!--
Please describe the big picture of your changes here. If it fixes a bug
or resolves a feature request, be sure to link to that issue.
-->

**Checklist**

- [x] I covered my changes with tests.
- [ ] I Updated the documentation that is affected by my changes:
  - [ ] Change in the CLI arguments
  - [ ] Change in the configuration file

I submit this contribution under the Apache-2.0 license.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants