From 99bc2716c42eda24cb082678a9470eb260d6e2d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miquel=20Sabat=C3=A9=20Sol=C3=A0?= Date: Thu, 11 Jul 2024 14:29:28 +0200 Subject: [PATCH] Add a command to show the info being gathered MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miquel Sabaté Solà --- cmd/suseconnect/connectUsage.txt | 2 ++ cmd/suseconnect/suseconnect.go | 11 +++++++++++ internal/connect/api.go | 4 ++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/cmd/suseconnect/connectUsage.txt b/cmd/suseconnect/connectUsage.txt index 8e58dbda..fe7248d7 100644 --- a/cmd/suseconnect/connectUsage.txt +++ b/cmd/suseconnect/connectUsage.txt @@ -46,6 +46,8 @@ Manage subscriptions at https://scc.suse.com services installed by SUSEConnect. --rollback Revert the registration state in case of a failed migration. + -i, --info Show the information that will be reported to the + server. --version Print program version. Common options: diff --git a/cmd/suseconnect/suseconnect.go b/cmd/suseconnect/suseconnect.go index cdbcfcdd..86c08344 100644 --- a/cmd/suseconnect/suseconnect.go +++ b/cmd/suseconnect/suseconnect.go @@ -75,6 +75,7 @@ func main() { email string version bool jsonFlag bool + info bool ) // display help like the ruby SUSEConnect @@ -109,6 +110,8 @@ func main() { flag.Var(&product, "product", "") flag.Var(&product, "p", "") flag.BoolVar(&jsonFlag, "json", false, "") + flag.BoolVar(&info, "info", false, "") + flag.BoolVar(&info, "i", false, "") flag.Parse() if version { @@ -246,6 +249,14 @@ func main() { } err := connect.Rollback() exitOnError(err) + } else if info { + sysInfo, err := connect.FetchSystemInformation() + exitOnError(err) + + out, err := json.Marshal(sysInfo) + exitOnError(err) + + fmt.Print(string(out)) } else { if instanceDataFile != "" && connect.URLDefault() { fmt.Print("Please use --instance-data only in combination ") diff --git a/internal/connect/api.go b/internal/connect/api.go index 87c9cdd8..5905a027 100644 --- a/internal/connect/api.go +++ b/internal/connect/api.go @@ -251,7 +251,7 @@ func makeSysInfoBody(distroTarget, namespace string, instanceData []byte, includ } } - sysinfo, err := fetchSystemInformation() + sysinfo, err := FetchSystemInformation() if err != nil { return nil, err } @@ -277,7 +277,7 @@ var mandatoryCollectors = []collectors.Collector{ collectors.SAP{}, } -func fetchSystemInformation() (collectors.Result, error) { +func FetchSystemInformation() (collectors.Result, error) { arch, err := collectors.DetectArchitecture() if err != nil {