diff --git a/.gitignore b/.gitignore index 50876d0..00cebf9 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -SOURCES/rhc-0.2.0.tar.gz +SOURCES/rhc-0.2.1.tar.gz +SOURCES/yggdrasil-0.2.1.tar.gz +SOURCES/yggdrasil-worker-package-manager-0.1.0.tar.gz diff --git a/.rhc.metadata b/.rhc.metadata index b1110d3..bce74d3 100644 --- a/.rhc.metadata +++ b/.rhc.metadata @@ -1 +1,3 @@ -8f9f437c9d7ee2afe09b2000aa77fd384fc91d2f SOURCES/rhc-0.2.0.tar.gz +2209827b582aff0a0ddea854c116de223e8ee604 SOURCES/rhc-0.2.1.tar.gz +55a3abc8515dede8b7ff41905447e08f5e6c01d7 SOURCES/yggdrasil-0.2.1.tar.gz +0582350e1001af0d608772860045f7f4964aa321 SOURCES/yggdrasil-worker-package-manager-0.1.0.tar.gz diff --git a/SOURCES/0001-feat-default-config-file-location.patch b/SOURCES/0001-feat-default-config-file-location.patch new file mode 100644 index 0000000..07ab750 --- /dev/null +++ b/SOURCES/0001-feat-default-config-file-location.patch @@ -0,0 +1,28 @@ +--- main.go.orig 2022-02-11 15:41:53.199642591 -0500 ++++ main.go 2022-02-11 15:42:43.738219604 -0500 +@@ -6,6 +6,7 @@ + "fmt" + "net" + "os" ++ "path/filepath" + "strconv" + "strings" + "time" +@@ -21,7 +22,7 @@ + ) + + func main() { +- fs := flag.NewFlagSet("yggd-package-manager-worker", flag.ExitOnError) ++ fs := flag.NewFlagSet(filepath.Base(os.Args[0]), flag.ExitOnError) + + var ( + socketAddr = "" +@@ -32,7 +33,7 @@ + fs.StringVar(&socketAddr, "socket-addr", "", "dispatcher socket address") + fs.Var(&logLevel, "log-level", "log verbosity level (error (default), warn, info, debug, trace)") + fs.Var(&allowPatterns, "allow-pattern", "regular expression pattern to allow package operations\n(can be specified multiple times)") +- _ = fs.String("config", "", "path to `file` containing configuration values (optional)") ++ _ = fs.String("config", filepath.Join("etc", "rhc", "workers", fs.Name()+".toml"), "path to `file` containing configuration values (optional)") + + ff.Parse(fs, os.Args[1:], ff.WithEnvVarPrefix("YGG"), ff.WithConfigFileFlag("config"), ff.WithConfigFileParser(fftoml.Parser)) + diff --git a/SOURCES/0001-fix-Improve-output-during-disconnect.patch b/SOURCES/0001-fix-Improve-output-during-disconnect.patch deleted file mode 100644 index 2059b7e..0000000 --- a/SOURCES/0001-fix-Improve-output-during-disconnect.patch +++ /dev/null @@ -1,45 +0,0 @@ -From 31db6e5a21afb62183ea6721fd79d515fc9b77b9 Mon Sep 17 00:00:00 2001 -From: Link Dupont -Date: Wed, 30 Jun 2021 12:36:17 -0400 -Subject: [PATCH 1/2] fix: Improve output during 'disconnect' - -Now print the status of the disconnection process, including the results afterwards. - -Fixes ESSNTL-837 - -Signed-off-by: Link Dupont ---- - cmd/ygg/main.go | 8 ++++++-- - 1 file changed, 6 insertions(+), 2 deletions(-) - -diff --git a/cmd/ygg/main.go b/cmd/ygg/main.go -index 5226bce..f5c5c47 100644 ---- a/cmd/ygg/main.go -+++ b/cmd/ygg/main.go -@@ -162,17 +162,21 @@ func main() { - fmt.Printf("Disconnecting %v from %v.\nThis might take a few seconds.\n\n", hostname, yggdrasil.Provider) - - s := spinner.New(spinner.CharSets[9], 100*time.Millisecond) -- defer s.Stop() -- s.Suffix = " Disconnecting..." -+ s.Suffix = fmt.Sprintf(" Deactivating the %v daemon", yggdrasil.BrandName) - s.Start() - if err := deactivate(); err != nil { - return cli.Exit(err, 1) - } -+ s.Stop() -+ fmt.Printf(failPrefix+" Deactivated the %v daemon\n", yggdrasil.BrandName) - -+ s.Suffix = " Disconnecting from Red Hat Subscription Management..." -+ s.Start() - if err := unregister(); err != nil { - return cli.Exit(err, 1) - } - s.Stop() -+ fmt.Printf(failPrefix + " Disconnected from Red Hat Subscription Management\n") - - fmt.Printf("\nManage your Red Hat connector systems: https://red.ht/connector\n") - --- -2.31.1 - diff --git a/SOURCES/0002-feat-Include-Description-in-help-output.patch b/SOURCES/0002-feat-Include-Description-in-help-output.patch deleted file mode 100644 index bb66650..0000000 --- a/SOURCES/0002-feat-Include-Description-in-help-output.patch +++ /dev/null @@ -1,34 +0,0 @@ -From 1d2d42276b6acc8cba062da9536e8acae69034be Mon Sep 17 00:00:00 2001 -From: Link Dupont -Date: Wed, 30 Jun 2021 14:47:00 -0400 -Subject: [PATCH 2/2] feat: Include Description in help output - -Fixes ESSNTL-838 - -Signed-off-by: Link Dupont ---- - cmd/ygg/main.go | 8 ++++++++ - 1 file changed, 8 insertions(+) - -diff --git a/cmd/ygg/main.go b/cmd/ygg/main.go -index f5c5c47..5524347 100644 ---- a/cmd/ygg/main.go -+++ b/cmd/ygg/main.go -@@ -28,6 +28,14 @@ func main() { - app.Name = yggdrasil.ShortName - app.Version = yggdrasil.Version - app.Usage = "control the system's connection to " + yggdrasil.Provider -+ app.Description = "The " + app.Name + " command controls the system's connection to " + yggdrasil.Provider + ".\n\n" + -+ "To connect the system using an activation key:\n" + -+ "\t" + app.Name + " connect --organization ID --activation-key KEY\n\n" + -+ "To connect the system using a username and password:\n" + -+ "\t" + app.Name + " connect --username USERNAME --password PASSWORD\n\n" + -+ "To disconnect the system:\n" + -+ "\t" + app.Name + " disconnect\n\n" + -+ "Run '" + app.Name + " command --help' for more details." - - log.SetFlags(0) - log.SetPrefix("") --- -2.31.1 - diff --git a/SOURCES/0003-fix-collect-error-messages-during-disconnect.patch b/SOURCES/0003-fix-collect-error-messages-during-disconnect.patch new file mode 100644 index 0000000..19d2a5b --- /dev/null +++ b/SOURCES/0003-fix-collect-error-messages-during-disconnect.patch @@ -0,0 +1,102 @@ +From 0e3ce2489f92cc037936866a1d6d7901fb14d440 Mon Sep 17 00:00:00 2001 +From: Link Dupont +Date: Mon, 14 Feb 2022 15:15:54 -0500 +Subject: [PATCH] fix: collect error messages during disconnect + +If an error occurs during disconnect, the error is collected and +reported at the end of the operation instead of aborting the operation +part-way through. + +Fixes: ESSNTL-2281 +--- + main.go | 42 +++++++++++++++++++++++++++++++++--------- + 1 file changed, 33 insertions(+), 9 deletions(-) + +diff --git a/main.go b/main.go +index 0e6cc07..db5a34d 100644 +--- a/main.go ++++ b/main.go +@@ -6,6 +6,7 @@ import ( + "fmt" + "os" + "strings" ++ "text/tabwriter" + "time" + + "git.sr.ht/~spc/go-log" +@@ -18,6 +19,7 @@ import ( + + const successPrefix = "\033[32m●\033[0m" + const failPrefix = "\033[31m●\033[0m" ++const errorPrefix = "\033[31m!\033[0m" + + func main() { + app := cli.NewApp() +@@ -169,6 +171,7 @@ func main() { + UsageText: fmt.Sprintf("%v disconnect", app.Name), + Description: fmt.Sprintf("The disconnect command disconnects the system from Red Hat Subscription Management, Red Hat Insights and %v and deactivates the %v daemon. %v will no longer be able to interact with the system.", Provider, BrandName, Provider), + Action: func(c *cli.Context) error { ++ errorMessages := make(map[string]error) + hostname, err := os.Hostname() + if err != nil { + return cli.Exit(err, 1) +@@ -180,29 +183,50 @@ func main() { + s.Suffix = fmt.Sprintf(" Deactivating the %v daemon", BrandName) + s.Start() + if err := deactivate(); err != nil { +- return cli.Exit(err, 1) ++ errorMessages[BrandName] = fmt.Errorf("cannot deactivate daemon: %w", err) ++ s.Stop() ++ fmt.Printf(errorPrefix+" Cannot deactivate the %v daemon\n", BrandName) ++ } else { ++ s.Stop() ++ fmt.Printf(failPrefix+" Deactivated the %v daemon\n", BrandName) + } +- s.Stop() +- fmt.Printf(failPrefix+" Deactivated the %v daemon\n", BrandName) + + s.Suffix = " Disconnecting from Red Hat Insights..." + s.Start() + if err := unregisterInsights(); err != nil { +- return cli.Exit(err, 1) ++ errorMessages["insights"] = fmt.Errorf("cannot disconnect from Red Hat Insights: %w", err) ++ s.Stop() ++ fmt.Printf(errorPrefix + " Cannot disconnect from Red Hat Insights\n") ++ } else { ++ s.Stop() ++ fmt.Print(failPrefix + " Disconnected from Red Hat Insights\n") + } +- s.Stop() +- fmt.Print(failPrefix + " Disconnected from Red Hat Insights\n") + + s.Suffix = " Disconnecting from Red Hat Subscription Management..." + s.Start() + if err := unregister(); err != nil { +- return cli.Exit(err, 1) ++ errorMessages["rhsm"] = fmt.Errorf("cannot disconnect from Red Hat Subscription Management: %w", err) ++ s.Stop() ++ fmt.Printf(errorPrefix + " Cannot disconnect from Red Hat Subscription Management\n") ++ } else { ++ s.Stop() ++ fmt.Printf(failPrefix + " Disconnected from Red Hat Subscription Management\n") + } +- s.Stop() +- fmt.Printf(failPrefix + " Disconnected from Red Hat Subscription Management\n") + + fmt.Printf("\nManage your Red Hat connector systems: https://red.ht/connector\n") + ++ if len(errorMessages) > 0 { ++ fmt.Println() ++ fmt.Printf("The following errors were encountered during disconnect:\n\n") ++ w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0) ++ fmt.Fprintln(w, "STEP\tERROR\t") ++ for svc, err := range errorMessages { ++ fmt.Fprintf(w, "%v\t%v\n", svc, err) ++ } ++ w.Flush() ++ return cli.Exit("", 1) ++ } ++ + return nil + }, + }, diff --git a/SOURCES/rhc-package-manager.toml b/SOURCES/rhc-package-manager.toml new file mode 100644 index 0000000..1abdda4 --- /dev/null +++ b/SOURCES/rhc-package-manager.toml @@ -0,0 +1,5 @@ +# regular expression patterns to allow package operations +allow-pattern = ["^rhc-worker-playbook$"] + +# log verbosity level (error (default), warn, info, debug, trace) +log-level = "error" diff --git a/SPECS/rhc.spec b/SPECS/rhc.spec index 3991fbf..aa474d8 100644 --- a/SPECS/rhc.spec +++ b/SPECS/rhc.spec @@ -1,22 +1,34 @@ %define debug_package %{nil} +%global buildflags -buildmode pie -compiler gc -a -v -x +%global goldflags %{expand:-linkmode=external -compressdwarf=false -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n') -extldflags '%__global_ldflags'} + +%global yggdrasil_ver 0.2.1 +%global ygg_pkg_mgr_ver 0.1.0 + Name: rhc -Version: 0.2.0 -Release: 2%{?dist} +Version: 0.2.1 +Release: 3%{?dist} Epoch: 1 Summary: Message dispatch agent for cloud-connected systems License: GPLv3 -URL: https://github.com/redhatinsights/yggdrasil +URL: https://github.com/redhatinsights/rhc -Source0: %{name}-%{version}.tar.gz +Source0: https://github.com/RedHatInsights/rhc/releases/download/%{version}/%{name}-%{version}.tar.gz Source1: config.toml +Source2: https://github.com/RedHatInsights/yggdrasil/releases/download/%{yggdrasil_ver}/yggdrasil-%{yggdrasil_ver}.tar.gz +Source3: https://github.com/RedHatInsights/yggdrasil-worker-package-manager/releases/download/%{ygg_pkg_mgr_ver}/yggdrasil-worker-package-manager-%{ygg_pkg_mgr_ver}.tar.gz +Source4: rhc-package-manager.toml -# Fixed upstream -Patch0: 0001-fix-Improve-output-during-disconnect.patch -Patch1: 0002-feat-Include-Description-in-help-output.patch +# Fixed upstream https://github.com/RedHatInsights/yggdrasil-worker-package-manager/commit/22105b0016abfc7c743c1eadb0372e4ef93cc65e +Patch0: 0001-feat-default-config-file-location.patch +# Fixed upstream https://github.com/RedHatInsights/rhc/commit/0e3ce2489f92cc037936866a1d6d7901fb14d440 +Patch1: 0003-fix-collect-error-messages-during-disconnect.patch ExclusiveArch: %{go_arches} +Requires: insights-client + BuildRequires: git BuildRequires: golang BuildRequires: dbus-devel @@ -27,46 +39,72 @@ BuildRequires: systemd-devel %{name} is pair of utilities that register systems with RHSM and establishes a receiving queue for instructions to be sent to the system via a broker. +%global makeflags %{expand:PREFIX=%{_prefix} \\ + SYSCONFDIR=%{_sysconfdir} \\ + LOCALSTATEDIR=%{_localstatedir} \\ + SHORTNAME=%{name} \\ + LONGNAME=%{name} \\ + PKGNAME=%{name} \\ + 'BRANDNAME=Red Hat connector' \\ + TOPICPREFIX=redhat/insights \\ + VERSION=%{version} \\ + DATAHOST=cert.cloud.redhat.com \\ + 'PROVIDER=Red Hat'} + + %prep -%autosetup -p1 +%setup -T -D -c -n %{name} -a 0 +%setup -T -D -c -n %{name} -a 2 +%setup -T -D -c -n %{name} -a 3 +sed -i -e "s/LDFLAGS :=/LDFLAGS ?=/" %{_builddir}/%{name}/yggdrasil-%{yggdrasil_ver}/Makefile +sed -i -e "s/LDFLAGS :=/LDFLAGS ?=/" %{_builddir}/%{name}/%{name}-%{version}/Makefile +cd %{_builddir}/%{name}/yggdrasil-worker-package-manager +%patch0 -p0 +cd %{_builddir}/%{name}/%{name}-%{version} +%patch1 -p1 %build -make PREFIX=%{_prefix} \ - SYSCONFDIR=%{_sysconfdir} \ - LOCALSTATEDIR=%{_localstatedir} \ - SHORTNAME=%{name} \ - LONGNAME=%{name} \ - PKGNAME=%{name} \ - 'BRANDNAME=Red Hat connector' \ - TOPICPREFIX=redhat/insights \ - VERSION=%{version} \ - DATAHOST=cert.cloud.redhat.com \ - 'PROVIDER=Red Hat' +%set_build_flags +export BUILDFLAGS="%{buildflags}" +export LDFLAGS="%{goldflags}" +cd %{_builddir}/%{name}/yggdrasil-%{yggdrasil_ver} +make %{makeflags} + +cd %{_builddir}/%{name}/yggdrasil-worker-package-manager +go build -o rhc-package-manager-worker -mod=vendor . + +cd %{_builddir}/%{name}/%{name}-%{version} +make %{makeflags} %install -make PREFIX=%{_prefix} \ - SYSCONFDIR=%{_sysconfdir} \ - LOCALSTATEDIR=%{_localstatedir} \ +%set_build_flags +export BUILDFLAGS="%{buildflags}" +export LDFLAGS="%{goldflags}" +cd %{_builddir}/%{name}/yggdrasil-%{yggdrasil_ver} +make %{makeflags} \ DESTDIR=%{buildroot} \ - SHORTNAME=%{name} \ - LONGNAME=%{name} \ - PKGNAME=%{name} \ - 'BRANDNAME=Red Hat connector' \ - TOPICPREFIX=redhat/insights \ - VERSION=%{version} \ - DATAHOST=cert.cloud.redhat.com \ - 'PROVIDER=Red Hat' \ install + %{__install} -m 644 %{SOURCE1} %{buildroot}%{_sysconfdir}/%{name}/ +cd %{_builddir}/%{name}/yggdrasil-worker-package-manager +%{__install} -D -m 755 rhc-package-manager-worker %{buildroot}%{_libexecdir}/%{name}/ +%{__install} -D -m 644 %{SOURCE4} %{buildroot}%{_sysconfdir}/%{name}/workers/rhc-package-manager.toml + +cd %{_builddir}/%{name}/%{name}-%{version} +make %{makeflags} \ + DESTDIR=%{buildroot} \ + install + %files -%doc README.md +%doc %{name}-%{version}/README.md yggdrasil-%{yggdrasil_ver}/doc/tags.toml %{_bindir}/%{name} %{_sbindir}/%{name}d %config(noreplace) %{_sysconfdir}/%{name}/config.toml +%config(noreplace) %{_sysconfdir}/%{name}/workers/rhc-package-manager.toml %{_unitdir}/%{name}d.service %{_datadir}/bash-completion/completions/* %{_mandir}/man1/* @@ -75,6 +113,21 @@ make PREFIX=%{_prefix} \ %changelog +* Tue Feb 15 2022 Link Dupont - 0.2.1-3 +- Include patch to collect and report errors during disconnect + +* Fri Feb 11 2022 Link Dupont - 0.2.1-2 +- Include patch to default worker config location + +* Fri Feb 11 2022 Link Dupont - 0.2.1-1 +- New upstream version + +* Tue Nov 16 2021 Link Dupont - 0.2.0-5 +- Enable building with PIE and other build flags (Resolves: RHBZ#2023489) + +* Fri Sep 24 2021 Link Dupont - 0.2.0-4 +- Fix an issue reporting workers on reconnect (Resolves: RHBZ#2009641) + * Thu Jul 1 2021 Link Dupont - 0.2.0-2 - Add two patches that fix some UX issues