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 schema error results to be output in JSON format including custom format flags #40

Merged
merged 28 commits into from
Jun 26, 2023

Conversation

mrutkows
Copy link
Contributor

@mrutkows mrutkows commented Jun 21, 2023

Provides requested JSON format for issue/fixes: #36
and goes beyond that preparing for customized error handlers to better format verbose errors (and lay the foundation for de-duplication) which is part of this issue: #37

@mrutkows mrutkows added the enhancement New feature or request label Jun 21, 2023
@mrutkows mrutkows self-assigned this Jun 21, 2023
cmd/errors.go Outdated
func (base BaseError) AppendMessage(addendum string) {
// Ignore (invalid) static linting message:
// "ineffective assignment to field (SA4005)"
base.Message += addendum
base.Message += addendum //nolint:staticcheck
Copy link

Choose a reason for hiding this comment

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

SA4005: ineffective assignment to field BaseError.Message


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.

cmd/resource.go Outdated
@@ -187,7 +188,7 @@ func resourceCmdImpl(cmd *cobra.Command, args []string) (err error) {
var resourceType string
resourceType, err = retrieveResourceType(cmd)

ListResources(writer, utils.GlobalFlags.OutputFormat, resourceType, whereFilters)
ListResources(writer, utils.GlobalFlags.PersistentFlags.OutputFormat, resourceType, whereFilters)
Copy link

Choose a reason for hiding this comment

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

27% of developers fix this issue

G104: Errors unhandled.


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.

cmd/validate.go Outdated
@@ -142,7 +165,7 @@ func processValidationResults(document *schema.Sbom, valid bool, err error) {
// Note: InvalidSBOMError type errors include schema errors which have already
// been added to the error type and will shown with the Error() interface
if valid {
getLogger().Errorf("invalid state: error (%T) returned, but SBOM valid !!!", t)
getLogger().Errorf("invalid state: error (%T) returned, but SBOM valid!", t)
Copy link

Choose a reason for hiding this comment

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

27% of developers fix this issue

G104: Errors unhandled.


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.

@mrutkows mrutkows merged commit 5c10806 into main Jun 26, 2023
@mrutkows mrutkows deleted the schema-errs branch June 26, 2023 20:56
@mrutkows
Copy link
Contributor Author

Fixes #26

ajistrying pushed a commit to ajistrying/sbom-utility that referenced this pull request Jun 29, 2023
…stom format flags (CycloneDX#40)

* Create a framework for validation error special case handling

Signed-off-by: Matt Rutkowski <[email protected]>

* Create a framework for validation error special case handling

Signed-off-by: Matt Rutkowski <[email protected]>

* Adjust JSON output formatting as an array

Signed-off-by: Matt Rutkowski <[email protected]>

* Use an ordered map to control JSON output marshaling order

Signed-off-by: Matt Rutkowski <[email protected]>

* Use an ordered map to control JSON output marshaling order

Signed-off-by: Matt Rutkowski <[email protected]>

* Use an ordered map to control JSON output marshaling order

Signed-off-by: Matt Rutkowski <[email protected]>

* Use an ordered map to control JSON output marshaling order

Signed-off-by: Matt Rutkowski <[email protected]>

* Separate format related functions into their own file

Signed-off-by: Matt Rutkowski <[email protected]>

* Separate format related functions into their own file

Signed-off-by: Matt Rutkowski <[email protected]>

* Format value for unique item error

Signed-off-by: Matt Rutkowski <[email protected]>

* Consolidate validation flags and use on top-level API call

Signed-off-by: Matt Rutkowski <[email protected]>

* Adjust JSON error result output prefix and indent

Signed-off-by: Matt Rutkowski <[email protected]>

* Add validation test case for bad iri-format

Signed-off-by: Matt Rutkowski <[email protected]>

* Add validation test case for bad iri-format

Signed-off-by: Matt Rutkowski <[email protected]>

* Consolidate persistent command flags into a struct

Signed-off-by: Matt Rutkowski <[email protected]>

* represent array type, index and item as a map in json error results

Signed-off-by: Matt Rutkowski <[email protected]>

* Support flag  true|false on validate command

Signed-off-by: Matt Rutkowski <[email protected]>

* Fix even more Sonatype errors that seem to chnage every time I touch an old file

Signed-off-by: Matt Rutkowski <[email protected]>

* Adjust help for validate given new formats/flags

Signed-off-by: Matt Rutkowski <[email protected]>

* Update README to show validate JSON output and new flags

Signed-off-by: Matt Rutkowski <[email protected]>

* buffer JSON output for unit tests

Signed-off-by: Matt Rutkowski <[email protected]>

* Update the text format logic to mirror new json formatting

Signed-off-by: Matt Rutkowski <[email protected]>

* Update the text format logic to mirror new json formatting

Signed-off-by: Matt Rutkowski <[email protected]>

* Update the text format logic to mirror new json formatting

Signed-off-by: Matt Rutkowski <[email protected]>

* Streamline json and text formatting paths

Signed-off-by: Matt Rutkowski <[email protected]>

* Adjust colorized indent to match normal indent

Signed-off-by: Matt Rutkowski <[email protected]>

* Add additional test assertions to validate # errs and error conext

Signed-off-by: Matt Rutkowski <[email protected]>

* Assure forced schema file tests reset to default schema

Signed-off-by: Matt Rutkowski <[email protected]>

---------

Signed-off-by: Matt Rutkowski <[email protected]>
mrutkows added a commit that referenced this pull request Jun 29, 2023
* replace deprecated ioutil functions

Signed-off-by: ajistrying <[email protected]>

* remove comments

Signed-off-by: ajistrying <[email protected]>

* G304 suppress warnings
Signed-off-by: ajistrying <[email protected]>

Signed-off-by: ajistrying <[email protected]>

* Support schema error results to be ouptut in JSON format including custom format flags (#40)

* Create a framework for validation error special case handling

Signed-off-by: Matt Rutkowski <[email protected]>

* Create a framework for validation error special case handling

Signed-off-by: Matt Rutkowski <[email protected]>

* Adjust JSON output formatting as an array

Signed-off-by: Matt Rutkowski <[email protected]>

* Use an ordered map to control JSON output marshaling order

Signed-off-by: Matt Rutkowski <[email protected]>

* Use an ordered map to control JSON output marshaling order

Signed-off-by: Matt Rutkowski <[email protected]>

* Use an ordered map to control JSON output marshaling order

Signed-off-by: Matt Rutkowski <[email protected]>

* Use an ordered map to control JSON output marshaling order

Signed-off-by: Matt Rutkowski <[email protected]>

* Separate format related functions into their own file

Signed-off-by: Matt Rutkowski <[email protected]>

* Separate format related functions into their own file

Signed-off-by: Matt Rutkowski <[email protected]>

* Format value for unique item error

Signed-off-by: Matt Rutkowski <[email protected]>

* Consolidate validation flags and use on top-level API call

Signed-off-by: Matt Rutkowski <[email protected]>

* Adjust JSON error result output prefix and indent

Signed-off-by: Matt Rutkowski <[email protected]>

* Add validation test case for bad iri-format

Signed-off-by: Matt Rutkowski <[email protected]>

* Add validation test case for bad iri-format

Signed-off-by: Matt Rutkowski <[email protected]>

* Consolidate persistent command flags into a struct

Signed-off-by: Matt Rutkowski <[email protected]>

* represent array type, index and item as a map in json error results

Signed-off-by: Matt Rutkowski <[email protected]>

* Support flag  true|false on validate command

Signed-off-by: Matt Rutkowski <[email protected]>

* Fix even more Sonatype errors that seem to chnage every time I touch an old file

Signed-off-by: Matt Rutkowski <[email protected]>

* Adjust help for validate given new formats/flags

Signed-off-by: Matt Rutkowski <[email protected]>

* Update README to show validate JSON output and new flags

Signed-off-by: Matt Rutkowski <[email protected]>

* buffer JSON output for unit tests

Signed-off-by: Matt Rutkowski <[email protected]>

* Update the text format logic to mirror new json formatting

Signed-off-by: Matt Rutkowski <[email protected]>

* Update the text format logic to mirror new json formatting

Signed-off-by: Matt Rutkowski <[email protected]>

* Update the text format logic to mirror new json formatting

Signed-off-by: Matt Rutkowski <[email protected]>

* Streamline json and text formatting paths

Signed-off-by: Matt Rutkowski <[email protected]>

* Adjust colorized indent to match normal indent

Signed-off-by: Matt Rutkowski <[email protected]>

* Add additional test assertions to validate # errs and error conext

Signed-off-by: Matt Rutkowski <[email protected]>

* Assure forced schema file tests reset to default schema

Signed-off-by: Matt Rutkowski <[email protected]>

---------

Signed-off-by: Matt Rutkowski <[email protected]>

* Add CycloneDX v1.5 JSON schema and update resource config (#41)

* Add CycloneDX v1.5 JSON schema and update resource config

Signed-off-by: Matt Rutkowski <[email protected]>

* Add minimal tests for 1.5 schema

Signed-off-by: Matt Rutkowski <[email protected]>

* Add minimal tests for 1.5 schema

Signed-off-by: Matt Rutkowski <[email protected]>

---------

Signed-off-by: Matt Rutkowski <[email protected]>
Signed-off-by: ajistrying <[email protected]>

* Remove invalid output file warning (#42)

Signed-off-by: Matt Rutkowski <[email protected]>
Signed-off-by: ajistrying <[email protected]>

* Put back inputFilename as parm. in os.ReadFile() call

Signed-off-by: Matt Rutkowski <[email protected]>

* Attempt to ignore underlying golang sonatype error

Signed-off-by: Matt Rutkowski <[email protected]>

* Attempt to ignore underlying golang sonatype error

Signed-off-by: Matt Rutkowski <[email protected]>

* Attempt to ignore underlying golang sonatype error

Signed-off-by: Matt Rutkowski <[email protected]>

---------

Signed-off-by: ajistrying <[email protected]>
Signed-off-by: Matt Rutkowski <[email protected]>
Co-authored-by: Matt Rutkowski <[email protected]>
@mrutkows mrutkows changed the title Support schema error results to be ouptut in JSON format including custom format flags Support schema error results to be output in JSON format including custom format flags Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JSON output format for SBOM validation
1 participant