MCPcopy
hub / github.com/snyk/cli / legacycliWorkflow

Function legacycliWorkflow

cliv2/pkg/basic_workflows/legacycli.go:71–178  ·  view source on GitHub ↗
(
	invocation workflow.InvocationContext,
	_ []workflow.Data,
)

Source from the content-addressed store, hash-verified

69}
70
71func legacycliWorkflow(
72 invocation workflow.InvocationContext,
73 _ []workflow.Data,
74) (output []workflow.Data, err error) {
75 output = []workflow.Data{}
76 var outBuffer bytes.Buffer
77 var outWriter *bufio.Writer
78
79 config := invocation.GetConfiguration()
80 debugLogger := invocation.GetEnhancedLogger() // uses zerolog
81 debugLoggerDefault := invocation.GetLogger() // uses log
82 ri := invocation.GetRuntimeInfo()
83
84 staticNodeJsBinaryBool, parseErr := strconv.ParseBool(constants.StaticNodeJsBinary)
85 if parseErr != nil {
86 debugLogger.Print("Failed to parse staticNodeJsBinary:", parseErr)
87 }
88
89 err = ValidateGlibcVersion(debugLogger, utils.DefaultGlibcVersion(), runtime.GOOS, runtime.GOARCH, staticNodeJsBinaryBool)
90 if err != nil {
91 return output, err
92 }
93
94 args := config.GetStringSlice(configuration.RAW_CMD_ARGS)
95 useStdIo := config.GetBool(configuration.WORKFLOW_USE_STDIO)
96 workingDirectory := config.GetString(configuration.WORKING_DIRECTORY)
97 analyticsDisabled := config.GetBool(configuration.ANALYTICS_DISABLED)
98
99 debugLogger.Print("Use StdIO:", useStdIo)
100 debugLogger.Print("Working directory:", workingDirectory)
101
102 // init cli object
103 var cli *cliv2.CLI
104 cli, err = cliv2.NewCLIv2(config, debugLoggerDefault, ri)
105 if err != nil {
106 return output, err
107 }
108
109 cli.WorkingDirectory = workingDirectory
110
111 // ensure to disable analytics based on configuration
112 if _, exists := os.LookupEnv(constants.SNYK_ANALYTICS_DISABLED_ENV); !exists && analyticsDisabled {
113 env := []string{constants.SNYK_ANALYTICS_DISABLED_ENV + "=1"}
114 cli.AppendEnvironmentVariables(env)
115 }
116
117 // In general all authentication if handled through the Extensible CLI now. But there is some legacy logic
118 // that checks for an API token to be available. Until this logic is safely removed, we will be injecting a
119 // fake/random API token to bypass this logic.
120 apiToken := config.GetString(configuration.AUTHENTICATION_TOKEN)
121 if len(apiToken) == 0 {
122 apiToken = "random"
123 }
124 cli.AppendEnvironmentVariables([]string{constants.SNYK_API_TOKEN_ENV + "=" + apiToken, "DEBUG_HIDE_DATE=true"})
125
126 err = cli.Init()
127 if err != nil {
128 return output, err

Callers

nothing calls this directly

Calls 9

InitMethod · 0.95
SetIoStreamsMethod · 0.95
ExecuteMethod · 0.95
ValidateGlibcVersionFunction · 0.85
createInternalProxyFunction · 0.85
finalizeArgumentsFunction · 0.85
appendFunction · 0.85
ProxyInfoMethod · 0.80

Tested by

no test coverage detected