Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,15 @@ test-license: ## Check if all files has the license

.PHONY: generate-samples ## Generate the samples in the testdata
generate-samples:
make install
go run ./hack/samples/generate_samples.go

.PHONY: full-report ## Generate the full report for all images in the the testdata
full-report:
.PHONY: generate-testdata ## Generate the full testdata directory
generate-testdata:
make install
go run ./hack/report/full.go
go run ./hack/samples/generate_samples.go
go run ./hack/report/full.go



2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ That would only return the bundles which contains `mybundlename` as part of its

## Testdata

The samples in `testdata/samples` which are generated by running `make generate-samples`. Also, to run a full report for all images in `testdata/reports` run `make full-report`.
The samples in `testdata/samples` which are generated by running `make generate-samples`. Also, to run `make generate-testdata` to re-generate all reports in the testdata.

## FAQ

Expand Down
29 changes: 4 additions & 25 deletions cmd/bundles/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,38 +113,23 @@ func indexRun(cmd *cobra.Command, args []string) error {
log.Info("Starting audit...")
reportData := index.Data{}
reportData.Flags = flags

// Create tmp dir to process the reportData
// Cleanup
command := exec.Command("rm", "-rf", "tmp")
_, _ = pkg.RunCommand(command)
command = exec.Command("mkdir", "tmp")
_, err := pkg.RunCommand(command)
if err != nil {
return err
}
pkg.GenerateTemporaryDirs()

if err := extractIndexDB(); err != nil {
return err
}

reportData, err = getDataFromIndexDB(reportData)
reportData, err := getDataFromIndexDB(reportData)
if err != nil {
return err
}

// Cleanup
command = exec.Command("rm", "-rf", "tmp")
_, _ = pkg.RunCommand(command)

// Cleanup
command = exec.Command("rm", "-rf", "output")
_, _ = pkg.RunCommand(command)

log.Infof("Start to generate the reportData")
if err := reportData.OutputReport(); err != nil {
return err
}

pkg.CleanupTemporaryDirs()
log.Infof("Operation completed.")

return nil
Expand All @@ -162,12 +147,6 @@ func extractIndexDB() error {
return fmt.Errorf("unable to create container image %s : %s", flags.IndexImage, err)
}

command = exec.Command("mkdir", "output")
_, err = pkg.RunCommand(command)
if err != nil {
return fmt.Errorf("unable to extract the image for index.db %s : %s", flags.IndexImage, err)
}

// Extract
command = exec.Command("docker", "cp", fmt.Sprintf("%s:/database/index.db", catalogIndex), "./output/")
_, err = pkg.RunCommand(command)
Expand Down
19 changes: 4 additions & 15 deletions cmd/channels/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,34 +101,23 @@ func indexRun(cmd *cobra.Command, args []string) error {
log.Info("Starting audit...")
reportData := channels.Data{}
reportData.Flags = flags

// Create tmp dir to process the report
// Cleanup
command := exec.Command("rm", "-rf", "tmp")
_, _ = pkg.RunCommand(command)
command = exec.Command("mkdir", "tmp")
_, err := pkg.RunCommand(command)
if err != nil {
return err
}
pkg.GenerateTemporaryDirs()

if err := extractIndexDB(); err != nil {
return err
}

reportData, err = getDataFromIndexDB(reportData)
reportData, err := getDataFromIndexDB(reportData)
if err != nil {
return err
}

// Cleanup
command = exec.Command("rm", "-rf", "tmp")
_, _ = pkg.RunCommand(command)

log.Infof("Start to generate the report")
if err := reportData.OutputReport(); err != nil {
return err
}

pkg.CleanupTemporaryDirs()
log.Infof("Operation completed.")

return nil
Expand Down
19 changes: 4 additions & 15 deletions cmd/packages/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,34 +114,23 @@ func indexRun(cmd *cobra.Command, args []string) error {
log.Info("Starting audit...")
reportData := packages.Data{}
reportData.Flags = flags

// Create tmp dir to process the report
// Cleanup
command := exec.Command("rm", "-rf", "tmp")
_, _ = pkg.RunCommand(command)
command = exec.Command("mkdir", "tmp")
_, err := pkg.RunCommand(command)
if err != nil {
return err
}
pkg.GenerateTemporaryDirs()

if err := extractIndexDB(); err != nil {
return err
}

reportData, err = getDataFromIndexDB(reportData)
reportData, err := getDataFromIndexDB(reportData)
if err != nil {
return err
}

// Cleanup
command = exec.Command("rm", "-rf", "tmp")
_, _ = pkg.RunCommand(command)

log.Infof("Start to generate the report")
if err := reportData.OutputReport(); err != nil {
return err
}

pkg.CleanupTemporaryDirs()
log.Infof("Operation completed.")

return nil
Expand Down
10 changes: 2 additions & 8 deletions hack/backport/backport.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ import (

func main() {

command := exec.Command("make", "install")
_, err := pkg.RunCommand(command)
if err != nil {
log.Errorf("running command :%s", err)
}

currentPath, err := os.Getwd()
if err != nil {
log.Error(err)
Expand All @@ -44,9 +38,9 @@ func main() {
const testdataPath = "/testdata/"

reportPath := filepath.Join(currentPath, testdataPath, "backport")
binPath := filepath.Join(currentPath, "bin", "audit")
binPath := filepath.Join(currentPath, "bin", "audit-tool")

command = exec.Command("rm", "-rf", reportPath)
command := exec.Command("rm", "-rf", reportPath)
_, err = pkg.RunCommand(command)
if err != nil {
log.Errorf("running command :%s", err)
Expand Down
10 changes: 2 additions & 8 deletions hack/report/full.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ import (

func main() {

command := exec.Command("make", "install")
_, err := pkg.RunCommand(command)
if err != nil {
log.Errorf("running command :%s", err)
}

currentPath, err := os.Getwd()
if err != nil {
log.Error(err)
Expand All @@ -44,9 +38,9 @@ func main() {
const testdataPath = "/testdata/"

reportPath := filepath.Join(currentPath, testdataPath, "reports")
binPath := filepath.Join(currentPath, "bin", "audit")
binPath := filepath.Join(currentPath, "bin", "audit-tool")

command = exec.Command("rm", "-rf", reportPath)
command := exec.Command("rm", "-rf", reportPath)
_, err = pkg.RunCommand(command)
if err != nil {
log.Errorf("running command :%s", err)
Expand Down
16 changes: 5 additions & 11 deletions hack/samples/generate_samples.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ import (

func main() {

command := exec.Command("make", "install")
_, err := pkg.RunCommand(command)
if err != nil {
log.Errorf("running command :%s", err)
}

currentPath, err := os.Getwd()
if err != nil {
log.Error(err)
Expand All @@ -43,12 +37,12 @@ func main() {
const testdataPath = "/testdata/samples/"

samplesDir := filepath.Join(currentPath, testdataPath)
binPath := filepath.Join(currentPath, "bin", "audit")
binPath := filepath.Join(currentPath, "bin", "audit-tool")

log.Infof("using the path: (%v)", samplesDir)
log.Infof("using the bin: (%v)", binPath)

command = exec.Command("rm", "-rf", filepath.Join(samplesDir))
command := exec.Command("rm", "-rf", filepath.Join(samplesDir))
_, err = pkg.RunCommand(command)
if err != nil {
log.Errorf("running command :%s", err)
Expand Down Expand Up @@ -129,7 +123,7 @@ func main() {
log.Infof("creating bundles testdata Sample json")
command = exec.Command(binPath, "bundles",
"--index-image=registry.redhat.io/redhat/certified-operator-index:v4.8",
"--limit=5",
"--limit=2",
"--output=json",
"--head-only",
fmt.Sprintf("--output-path=%s", filepath.Join(samplesDir, "bundles", "json")),
Expand All @@ -142,7 +136,7 @@ func main() {
log.Infof("creating packages testdata Sample XLS")
command = exec.Command(binPath, "packages",
"--index-image=registry.redhat.io/redhat/certified-operator-index:v4.8",
"--limit=5",
"--limit=2",
fmt.Sprintf("--output-path=%s", filepath.Join(samplesDir, "packages", "xls")),
)
_, err = pkg.RunCommand(command)
Expand All @@ -153,7 +147,7 @@ func main() {
log.Infof("creating packages testdata Sample json")
command = exec.Command(binPath, "packages",
"--index-image=registry.redhat.io/redhat/certified-operator-index:v4.8",
"--limit=5",
"--limit=2",
"--output=json",
fmt.Sprintf("--output-path=%s", filepath.Join(samplesDir, "packages", "json")),
)
Expand Down
Binary file not shown.
28 changes: 28 additions & 0 deletions pkg/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,31 @@ func GetReportName(imageName, typeName, typeFile string) string {

return fmt.Sprintf("%s_%s_%s.%s", typeName, name, dt, typeFile)
}

func GenerateTemporaryDirs() {
command := exec.Command("rm", "-rf", "tmp")
_, _ = RunCommand(command)

command = exec.Command("rm", "-rf", "./output/")
_, _ = RunCommand(command)

command = exec.Command("mkdir", "./output/")
_, err := RunCommand(command)
if err != nil {
log.Fatal(err)
}

command = exec.Command("mkdir", "tmp")
_, err = RunCommand(command)
if err != nil {
log.Fatal(err)
}
}

func CleanupTemporaryDirs() {
command := exec.Command("rm", "-rf", "tmp")
_, _ = RunCommand(command)

command = exec.Command("rm", "-rf", "./output/")
_, _ = RunCommand(command)
}
2 changes: 1 addition & 1 deletion pkg/reports/channels/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (d *Data) BuildChannelsQuery() (string, error) {
}

if len(d.Flags.Filter) > 0 {
like := "%" + d.Flags.Filter + "%"
like := "'%" + d.Flags.Filter + "%'"
query = query.Where(fmt.Sprintf("name like %s", like))
}

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading