From e4f91b7fdd7cee0d8f972b9150d1a9ea04c302d3 Mon Sep 17 00:00:00 2001 From: Arjun Mahishi Date: Fri, 24 Jan 2025 19:34:02 +0530 Subject: [PATCH] pkg/cli: validate input file in tsdump command In the tsdump command, when the --format is datadog or datadoginit, the input file is a mandatory argument. This commit adds validation logic for it before it's used to prevent panic. Fixes: #138170 Epic: none --- pkg/cli/tsdump.go | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/pkg/cli/tsdump.go b/pkg/cli/tsdump.go index 3aad2b0a3bbe..003dc2570db3 100644 --- a/pkg/cli/tsdump.go +++ b/pkg/cli/tsdump.go @@ -82,7 +82,7 @@ will then convert it to the --format requested in the current invocation. } var w tsWriter - switch debugTimeSeriesDumpOpts.format { + switch cmd := debugTimeSeriesDumpOpts.format; cmd { case tsDumpRaw: if convertFile != "" { return errors.Errorf("input file is already in raw format") @@ -104,22 +104,11 @@ will then convert it to the --format requested in the current invocation. 10_000_000, /* threshold */ doRequest, ) - case tsDumpDatadog: - targetURL, err := getDatadogTargetURL(debugTimeSeriesDumpOpts.ddSite) - if err != nil { - return err + case tsDumpDatadogInit, tsDumpDatadog: + if len(args) < 1 { + return errors.New("no input file provided") } - var datadogWriter = makeDatadogWriter( - targetURL, - false, - debugTimeSeriesDumpOpts.ddApiKey, - 100, - doDDRequest, - ) - return datadogWriter.upload(args[0]) - - case tsDumpDatadogInit: targetURL, err := getDatadogTargetURL(debugTimeSeriesDumpOpts.ddSite) if err != nil { return err @@ -127,7 +116,7 @@ will then convert it to the --format requested in the current invocation. var datadogWriter = makeDatadogWriter( targetURL, - true, + cmd == tsDumpDatadogInit, debugTimeSeriesDumpOpts.ddApiKey, 100, doDDRequest,