forked from ribice/glice
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First pass at getting
glice audit
working.
Incomplete as of this commit.
- Loading branch information
Mike Schinkel
committed
Oct 18, 2022
1 parent
c425f38
commit f28b4a2
Showing
16 changed files
with
284 additions
and
70 deletions.
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,32 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/ribice/glice/v3/pkg" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// auditCmd represents the audit command | ||
var auditCmd = &cobra.Command{ | ||
Use: "audit", | ||
Run: glice.RunAudit, | ||
Short: "Audit your project's path for disallowed open-source licenses", | ||
Long: `Audit your project's path for Go-specific dependencies using disallowed open-source licenses ` + | ||
`while comparing with allowed licenses and dependency overrides in glice.yaml and only auditing ` + | ||
`those dependencies that have not been audited within a specifiable TTL (time-to-live) where` + | ||
`the default TLL is 24*60*60 seconds (1 day)`, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(auditCmd) | ||
initCmd.Flags().Int("ttl", 24*60*60, "Time-to-Live for data in the cache file allowing recently audited dependencies to be skipped") | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// auditCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
// auditCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} |
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
This file was deleted.
Oops, something went wrong.
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,49 @@ | ||
package glice | ||
|
||
import ( | ||
"fmt" | ||
"github.com/spf13/cobra" | ||
"os" | ||
) | ||
|
||
func RunAudit(cmd *cobra.Command, args []string) { | ||
var err error | ||
var deps Dependencies | ||
|
||
options := GetOptions() | ||
|
||
fmt.Println("\nAuditing...") | ||
yf, err := LoadYAMLFile(options.SourceDir) | ||
if err != nil { | ||
LogAndExit(exitYAMLFileDoesNotExist, | ||
"Cannot run scan; %s", | ||
err.Error()) | ||
|
||
} | ||
fmt.Printf("YAML file %s loaded\n", yf.Filepath) | ||
|
||
fmt.Print("Scanning dependencies...") | ||
deps, err = ScanDependencies(options) | ||
if err != nil { | ||
LogAndExit(exitCannotParseDependencies, | ||
"Failed while parsing dependencies: %s", | ||
err.Error()) | ||
} | ||
|
||
changes, el := yf.AuditDependencies(deps) | ||
if !changes.HasChanges() { | ||
fmt.Println("\nNo chances detected") | ||
} else { | ||
fmt.Println() | ||
changes.Print() | ||
} | ||
|
||
if !el.HasErrors() { | ||
fmt.Println("\nNo disallowed licenses detected") | ||
} else { | ||
el.LogPrintWithHeader("ERROR! Disallowed Licenses Detected:") | ||
os.Exit(exitAuditFoundDisallowedLicenses) | ||
} | ||
|
||
fmt.Println("\nAudit completed successfully") | ||
} |
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,40 @@ | ||
package glice | ||
|
||
import ( | ||
"log" | ||
) | ||
|
||
type Changes struct { | ||
Old []string | ||
New []string | ||
} | ||
|
||
func NewChanges() *Changes { | ||
return &Changes{ | ||
Old: make([]string, 0), | ||
New: make([]string, 0), | ||
} | ||
} | ||
|
||
// HasChanges returns true if there are either old or new changes | ||
func (c *Changes) HasChanges() bool { | ||
return len(c.Old) > 0 || len(c.New) > 0 | ||
} | ||
|
||
// Print outputs all changes, old and new | ||
func (c *Changes) Print() { | ||
LogPrintFunc(func() { | ||
showChanges(c.Old, "Old", "These imports were not found in glice.yaml but were found when scanning.") | ||
showChanges(c.New, "New", "These imports were not found when scanning but were found in glice.yaml.") | ||
}) | ||
} | ||
|
||
func showChanges(list []string, _type, descr string) { | ||
log.Printf("\nChanges: %s", _type) | ||
log.Println("------------") | ||
log.Println(descr) | ||
for _, imp := range list { | ||
log.Printf(" - %s\n", imp) | ||
} | ||
log.Println("") | ||
} |
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
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
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
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
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.