Skip to content

Commit

Permalink
Add method to run analyzerManager directly
Browse files Browse the repository at this point in the history
  • Loading branch information
guyshe-jfrog committed Jul 16, 2024
1 parent 819414c commit a76c224
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion cli/scancommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package cli

import (
"fmt"
"github.com/jfrog/jfrog-cli-core/v2/utils/usage"
"os"
"os/exec"
"strings"

"github.com/jfrog/jfrog-cli-core/v2/utils/usage"

"github.com/jfrog/jfrog-cli-core/v2/common/cliutils"
commandsCommon "github.com/jfrog/jfrog-cli-core/v2/common/commands"
outputFormat "github.com/jfrog/jfrog-cli-core/v2/common/format"
Expand Down Expand Up @@ -77,6 +79,14 @@ func getAuditAndScansCommands() []components.Command {
Category: auditScanCategory,
Action: AuditCmd,
},
{
Name: "run-am",
Aliases: []string{"aud"},
Flags: flags.GetCommandFlags(flags.Audit),
Description: auditDocs.GetDescription(),
Category: auditScanCategory,
Action: runAnalyzerManager,
},
{
Name: "curation-audit",
Aliases: []string{"ca"},
Expand Down Expand Up @@ -337,6 +347,49 @@ func AuditCmd(c *components.Context) error {
return err
}

func runCommand(cmd string, args ...string) ([]string, error) {
parts := append([]string{cmd}, args...)
cmdStr := strings.Join(parts, " ")

outBytes, err := exec.Command("sh", "-c", cmdStr).CombinedOutput()
if err != nil {
return nil, err
}

outStr := string(outBytes)
return strings.Split(outStr, "\n"), nil
}

func runAnalyzerManager(c *components.Context) error {
config_path := c.Arguments[0]
log.Info("Make sure to set CI=true JFROG_CLI_LOG_LEVEL=DEBUG")
log.Info(fmt.Sprintf("Using following config file: %s", config_path))

serverDetails, err := createServerDetailsWithConfigOffer(c)
if err != nil {
return err
}

if err = utils.SetAnalyzerManagerEnvVariables(serverDetails); err != nil {
return err
}
// TODO: equivelent of
// os.Setenv("CI", "true")
// os.Setenv("JFROG_CLI_LOG_LEVEL", "DEBUG")

cmd := "~/.jfrog/dependencies/analyzerManager/analyzerManager"
args := []string{"ca", config_path}

cmdOut, err := runCommand(cmd, args...)
if err != nil {
fmt.Fprintln(os.Stderr, "Error running command:", err)
return err
}

fmt.Println(strings.Join(cmdOut, "\n"))
return nil
}

func reportErrorIfExists(err error, auditCmd *audit.AuditCommand) {
if err == nil || !usage.ShouldReportUsage() {
return
Expand Down

0 comments on commit a76c224

Please sign in to comment.