From 70278dd31add11fc204e7e9032ce0daf844efe71 Mon Sep 17 00:00:00 2001 From: classabbyamp Date: Sat, 24 Sep 2022 17:55:02 -0400 Subject: [PATCH] NetAuth: add completions and manpages --- srcpkgs/NetAuth/patches/cli-generate.patch | 36 ++++++++ srcpkgs/NetAuth/patches/config-loading.patch | 87 ++++++++++++++++++++ srcpkgs/NetAuth/template | 10 +++ 3 files changed, 133 insertions(+) create mode 100644 srcpkgs/NetAuth/patches/cli-generate.patch create mode 100644 srcpkgs/NetAuth/patches/config-loading.patch diff --git a/srcpkgs/NetAuth/patches/cli-generate.patch b/srcpkgs/NetAuth/patches/cli-generate.patch new file mode 100644 index 000000000000..ba8c8bc97f96 --- /dev/null +++ b/srcpkgs/NetAuth/patches/cli-generate.patch @@ -0,0 +1,36 @@ +From cb7cfa5bc0530e43fdbc227783187a141d857139 Mon Sep 17 00:00:00 2001 +From: classabbyamp +Date: Sat, 24 Sep 2022 17:40:11 -0400 +Subject: [PATCH] internal/ctl/system-ctl: don't run initialize(), rename to + system-cli + +the default initialize() is not necessary when generating completions +and docs, so we can override it with an empty function. + +Also, the file was renamed to `system-cli` to put it more inline with +other files' naming conventions. +--- + internal/ctl/{system-ctl.go => system-cli.go} | 3 +++ + 1 file changed, 3 insertions(+) + rename internal/ctl/{system-ctl.go => system-cli.go} (68%) + +diff --git a/internal/ctl/system-ctl.go b/internal/ctl/system-cli.go +similarity index 68% +rename from internal/ctl/system-ctl.go +rename to internal/ctl/system-cli.go +index 3dbd9d3..0a42d05 100644 +--- a/internal/ctl/system-ctl.go ++++ b/internal/ctl/system-cli.go +@@ -8,9 +8,12 @@ var ( + cliCmd = &cobra.Command{ + Use: "cli", + Short: "Extra utilities for the CLI", ++ PersistentPreRun: cli_initialize, + } + ) + + func init() { + systemCmd.AddCommand(cliCmd) + } ++ ++func cli_initialize(*cobra.Command, []string) {} diff --git a/srcpkgs/NetAuth/patches/config-loading.patch b/srcpkgs/NetAuth/patches/config-loading.patch new file mode 100644 index 000000000000..c197c569bc06 --- /dev/null +++ b/srcpkgs/NetAuth/patches/config-loading.patch @@ -0,0 +1,87 @@ +From 1df568cd25d6ccac79e56451406e021ead49c0c4 Mon Sep 17 00:00:00 2001 +From: Michael Aldridge +Date: Wed, 31 Aug 2022 16:44:40 -0500 +Subject: [PATCH] pkg/netauth: Handle config loading in library layer + +--- + cmd/netauth/main.go | 7 ------- + internal/ctl/root.go | 9 --------- + pkg/netauth/netauth.go | 13 +++++++++++++ + 3 files changed, 13 insertions(+), 16 deletions(-) + +diff --git a/cmd/netauth/main.go b/cmd/netauth/main.go +index d66dd8a..7695cd5 100644 +--- a/cmd/netauth/main.go ++++ b/cmd/netauth/main.go +@@ -4,7 +4,6 @@ import ( + "os" + + "github.com/hashicorp/go-hclog" +- "github.com/spf13/viper" + + "github.com/netauth/netauth/internal/ctl" + +@@ -22,12 +21,6 @@ var ( + ) + + func main() { +- // This runs here so we can reset the defaults that are set +- // during various init() methods. +- viper.SetDefault("token.cache", "fs") +- viper.SetDefault("token.keyprovider", "fs") +- viper.SetDefault("token.backend", "jwt-rsa") +- + level, set := os.LookupEnv("NETAUTH_LOGLEVEL") + if !set { + appLogger = hclog.NewNullLogger() +diff --git a/internal/ctl/root.go b/internal/ctl/root.go +index faf35b0..b20c0d2 100644 +--- a/internal/ctl/root.go ++++ b/internal/ctl/root.go +@@ -61,15 +61,6 @@ func onInit() { + viper.BindPFlags(pflag.CommandLine) + if cfg != "" { + viper.SetConfigFile(cfg) +- } else { +- viper.SetConfigName("config") +- viper.AddConfigPath(".") +- viper.AddConfigPath("$HOME/.netauth") +- viper.AddConfigPath("/etc/netauth/") +- } +- if err := viper.ReadInConfig(); err != nil { +- fmt.Println("Error reading config:", err) +- os.Exit(1) + } + viper.Set("client.ServiceName", "netauth") + +diff --git a/pkg/netauth/netauth.go b/pkg/netauth/netauth.go +index 831d64f..77a203c 100644 +--- a/pkg/netauth/netauth.go ++++ b/pkg/netauth/netauth.go +@@ -17,6 +17,14 @@ import ( + func init() { + viper.SetDefault("core.port", 1729) + viper.SetDefault("tls.certificate", "keys/tls.pem") ++ viper.SetDefault("token.cache", "fs") ++ viper.SetDefault("token.keyprovider", "fs") ++ viper.SetDefault("token.backend", "jwt-rsa") ++ ++ viper.SetConfigName("config") ++ viper.AddConfigPath(".") ++ viper.AddConfigPath("$HOME/.netauth") ++ viper.AddConfigPath("/etc/netauth/") + } + + // NewWithLog uses the specified logger to contruct a NetAuth client. +@@ -24,6 +32,11 @@ func init() { + // handler that is provided should have the correct name and be + // parented to the correct point on the log tree. + func NewWithLog(l hclog.Logger) (*Client, error) { ++ if err := viper.ReadInConfig(); err != nil { ++ fmt.Println("Error reading config:", err) ++ os.Exit(1) ++ } ++ + if viper.GetString("core.conf") == "" { + viper.Set("core.conf", filepath.Dir(viper.ConfigFileUsed())) + l.Debug("Config relative load path set", "path", viper.GetString("core.conf")) diff --git a/srcpkgs/NetAuth/template b/srcpkgs/NetAuth/template index be7f2cb0f81f..cf02007c3c1c 100644 --- a/srcpkgs/NetAuth/template +++ b/srcpkgs/NetAuth/template @@ -4,6 +4,7 @@ version=0.6.1 revision=1 wrksrc=netauth-$version build_style="go" +build_helper="qemu" go_import_path="github.com/netauth/netauth" go_package="${go_import_path}/cmd/netauth ${go_import_path}/cmd/netauthd" @@ -15,6 +16,15 @@ distfiles="https://github.com/NetAuth/NetAuth/archive/v$version.tar.gz" checksum=cf84b2e63b7a59ec6e415ead1a94994b040b30fee2b27e482073371cfb0fb444 post_install() { + for sh in bash zsh; do + vtargetrun ${DESTDIR}/usr/bin/netauth system cli ${sh} netauth.${sh} + vcompletion netauth.${sh} ${sh} netauth + done + mkdir manpages + vtargetrun ${DESTDIR}/usr/bin/netauth system cli man manpages + for p in manpages/*; do + vman "${p}" + done vlicense LICENSE vsv netauthd }