From 2289b74b79609b7c5e338723777cde5738cbf5d8 Mon Sep 17 00:00:00 2001 From: zack olson Date: Wed, 14 Aug 2024 11:25:51 -0400 Subject: [PATCH] remove unused ServiceName implementations, fix up options tests --- pkg/launcher/options_test.go | 1 + pkg/launcher/pkg_utils_darwin.go | 28 ---------------------------- pkg/launcher/pkg_utils_linux.go | 28 ---------------------------- 3 files changed, 1 insertion(+), 56 deletions(-) delete mode 100644 pkg/launcher/pkg_utils_darwin.go delete mode 100644 pkg/launcher/pkg_utils_linux.go diff --git a/pkg/launcher/options_test.go b/pkg/launcher/options_test.go index 25fbc42224..5734f3d3a5 100644 --- a/pkg/launcher/options_test.go +++ b/pkg/launcher/options_test.go @@ -265,6 +265,7 @@ func getArgsAndResponse() (map[string]string, *Options) { WatchdogDelaySec: 120, WatchdogMemoryLimitMB: 600, WatchdogUtilizationLimitPercent: 50, + Identifier: "kolide-k2", } return args, opts diff --git a/pkg/launcher/pkg_utils_darwin.go b/pkg/launcher/pkg_utils_darwin.go deleted file mode 100644 index fd014f9fa3..0000000000 --- a/pkg/launcher/pkg_utils_darwin.go +++ /dev/null @@ -1,28 +0,0 @@ -//go:build darwin -// +build darwin - -package launcher - -import ( - "fmt" - "regexp" - "strings" -) - -// allow alphanumeric characters plus - or _ within the identifier, we will replace anything else with a dash -var darwinIdentifierWhitelistRegex = regexp.MustCompile(`[^a-zA-Z0-9-_]+`) - -const defaultLauncherIdentifier string = "kolide-k2" - -// ServiceName embeds the given identifier into our service name template after sanitization, -// and returns the service name (label) generated to match our packaging logic -func ServiceName(identifier string) string { - // this check might be overkill but is intended to prevent any backwards compatibility/misconfiguration issues - if strings.TrimSpace(identifier) == "" { - identifier = defaultLauncherIdentifier - } - - sanitizedServiceName := darwinIdentifierWhitelistRegex.ReplaceAllString(identifier, "-") - - return fmt.Sprintf("com.%s.launcher", sanitizedServiceName) -} diff --git a/pkg/launcher/pkg_utils_linux.go b/pkg/launcher/pkg_utils_linux.go deleted file mode 100644 index 5b1ee7b752..0000000000 --- a/pkg/launcher/pkg_utils_linux.go +++ /dev/null @@ -1,28 +0,0 @@ -//go:build linux -// +build linux - -package launcher - -import ( - "fmt" - "regexp" - "strings" -) - -// allow alphanumeric characters plus - or _ within the identifier, we will replace anything else with a dash -var linuxIdentifierWhitelistRegex = regexp.MustCompile(`[^a-zA-Z0-9-_]+`) - -const defaultLauncherIdentifier string = "kolide-k2" - -// ServiceName embeds the given identifier into our service name template after sanitization, -// and returns the service name (label) generated to match our packaging logic -func ServiceName(identifier string) string { - // this check might be overkill but is intended to prevent any backwards compatibility/misconfiguration issues - if strings.TrimSpace(identifier) == "" { - identifier = defaultLauncherIdentifier - } - - sanitizedServiceName := linuxIdentifierWhitelistRegex.ReplaceAllString(identifier, "-") - - return fmt.Sprintf("launcher.%s.service", sanitizedServiceName) -}