-
Notifications
You must be signed in to change notification settings - Fork 20
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
19 configurable scoring criteria #75
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
Copyright © 2023 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/interlynk-io/sbomqs/pkg/logger" | ||
"github.com/interlynk-io/sbomqs/pkg/scorer" | ||
"github.com/samber/lo" | ||
"github.com/spf13/cobra" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
const features_file_name = "features.yaml" | ||
const features = "features" | ||
// generateCmd represents the generate command | ||
var generateCmd = &cobra.Command{ | ||
Use: "generate", | ||
kchetans marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Short: "provides a comprehensive config generate for your sbom to get specific criteria", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
ctx := logger.WithLogger(context.Background()) | ||
|
||
if len(args) > 0 { | ||
if args[0] == features{ | ||
return generateYaml(ctx) | ||
} | ||
}else{ | ||
return fmt.Errorf(fmt.Sprintf("arguments missing%s","list of valid command eg. features")) | ||
} | ||
return fmt.Errorf(fmt.Sprintf("invalid arguments%s","list of valid command eg. features")) | ||
|
||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(generateCmd) | ||
} | ||
|
||
type Record struct { | ||
Name string `yaml:"name" json:"name"` | ||
Enabled bool `yaml:"enabled" json:"enabled"` | ||
Criteria []criteria `yaml:"criteria" json:"criteria"` | ||
} | ||
|
||
type criteria struct { | ||
Name string `yaml:"shortName" json:"shortName"` | ||
Description string `yaml:"description" json:"description"` | ||
Enabled bool `yaml:"enabled" json:"enabled"` | ||
} | ||
|
||
type Config struct { | ||
Record []Record `yaml:"category" json:"category"` | ||
} | ||
|
||
func generateYaml(ctx context.Context) error { | ||
cnf := Config{} | ||
for _, category := range scorer.Categories { | ||
record := Record{ | ||
Name: category, | ||
Enabled: true, | ||
} | ||
if len(scorer.CategorieMapWithCriteria(category)) > 0 { | ||
for _, crita := range scorer.CategorieMapWithCriteria(category) { | ||
record.Criteria = append(record.Criteria, criteria{ | ||
Name: (string(lo.Invert(scorer.CriteriaArgMap)[crita])), | ||
Description: crita, | ||
Enabled: true, | ||
}) | ||
} | ||
} | ||
cnf.Record = append(cnf.Record, record) | ||
|
||
} | ||
buf, err := yaml.Marshal(&cnf) | ||
if err != nil { | ||
return err | ||
} | ||
err = os.WriteFile(features_file_name, buf, 0755) | ||
return err | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
category: | ||
kchetans marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- name: NTIA-minimum-elements | ||
enabled: true | ||
criteria: | ||
- shortName: comp-supplier-name | ||
description: Components have supplier names | ||
enabled: true | ||
- shortName: comp-name | ||
description: Components have names | ||
enabled: true | ||
- shortName: comp-version | ||
description: Components have versions | ||
enabled: true | ||
- shortName: comp-uniq-ids | ||
description: Components have uniq ids | ||
enabled: true | ||
- shortName: doc-relationship | ||
description: Doc has relationships | ||
enabled: true | ||
- shortName: doc-author | ||
description: Doc has authors | ||
enabled: true | ||
- shortName: doc-timestamp | ||
description: Doc has creation timestamp | ||
enabled: true | ||
- name: Quality | ||
enabled: true | ||
criteria: | ||
- shortName: comp-valid-licence | ||
description: Components have valid spdx licenses | ||
enabled: true | ||
- shortName: comp-primary-purpose | ||
description: Components have primary purpose defined | ||
enabled: true | ||
- shortName: comp-no-deprecat-licence | ||
description: Components have no deprecated licenses | ||
enabled: true | ||
- shortName: comp-no-restric-licence | ||
description: Components have no restricted licenses | ||
enabled: true | ||
- name: Semantic | ||
enabled: true | ||
criteria: | ||
- shortName: doc-all-req-fileds | ||
description: Doc has all required fields | ||
enabled: true | ||
- shortName: comp-licence | ||
description: Components have licenses | ||
enabled: true | ||
- shortName: comp-checksums | ||
description: Components have checksums | ||
enabled: true | ||
- name: Sharing | ||
enabled: true | ||
criteria: | ||
- shortName: doc-licence | ||
description: Doc sharable license | ||
enabled: true | ||
- name: Structural | ||
enabled: true | ||
criteria: | ||
- shortName: sbom-spec | ||
description: SBOM Specification | ||
enabled: true | ||
- shortName: spec-version | ||
description: Spec Version | ||
enabled: true | ||
- shortName: spec-file-format | ||
description: Spec File Format | ||
enabled: true | ||
- shortName: spec-parsable | ||
description: Spec is parsable | ||
enabled: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix Copyright for Interlynk