-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support preprod dual install (#1834)
- Loading branch information
1 parent
1b40334
commit c48ff7c
Showing
9 changed files
with
197 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package launcher | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"strings" | ||
|
||
"github.com/serenize/snaker" | ||
) | ||
|
||
var nonAlphanumericRegex = regexp.MustCompile(`[^a-zA-Z0-9]+`) | ||
|
||
// ServiceName embeds the given identifier into our service name template after sanitization, | ||
// and returns the camelCased service name 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 := nonAlphanumericRegex.ReplaceAllString(identifier, "_") // e.g. identifier=kolide-k2 becomes kolide_k2 | ||
sanitizedServiceName = fmt.Sprintf("launcher_%s_svc", sanitizedServiceName) // wrapped as launcher_kolide_k2_svc | ||
return snaker.SnakeToCamel(sanitizedServiceName) // will produce LauncherKolideK2Svc | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package launcher | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_ServiceName(t *testing.T) { | ||
t.Parallel() | ||
|
||
for _, tt := range []struct { | ||
testCaseName string | ||
identifier string | ||
expectedServiceName string | ||
}{ | ||
{ | ||
testCaseName: "empty identifier expecting default service name", | ||
identifier: " ", | ||
expectedServiceName: "LauncherKolideK2Svc", | ||
}, | ||
{ | ||
testCaseName: "default identifier expecting default service name", | ||
identifier: "kolide-k2", | ||
expectedServiceName: "LauncherKolideK2Svc", | ||
}, | ||
{ | ||
testCaseName: "preprod identifier expecting preprod service name", | ||
identifier: "kolide-preprod-k2", | ||
expectedServiceName: "LauncherKolidePreprodK2Svc", | ||
}, | ||
{ | ||
testCaseName: "mangled identifier expecting default service name", | ||
identifier: "kolide-!@_k2", | ||
expectedServiceName: "LauncherKolideK2Svc", | ||
}, | ||
} { | ||
tt := tt | ||
t.Run(tt.testCaseName, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
serviceName := ServiceName(tt.identifier) | ||
require.Equal(t, tt.expectedServiceName, serviceName, "expected sanitized service name value to match") | ||
}) | ||
} | ||
} |
Oops, something went wrong.