Skip to content

Commit f1bd2a3

Browse files
committed
Add comment, add strings.TrimSpace
1 parent 3c21014 commit f1bd2a3

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

x-pack/elastic-agent/pkg/agent/cmd/container.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ const (
3737
)
3838

3939
var (
40+
// Used to strip the appended ({uuid}) from the name of an enrollment token. This makes much easier for
41+
// a container to reference a token by name, without having to know what the generated UUID is for that name.
4042
tokenNameStrip = regexp.MustCompile(`\s\([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\)$`)
4143
)
4244

@@ -327,7 +329,7 @@ func findPolicy(policies []kibanaPolicy) (*kibanaPolicy, error) {
327329
func findKey(keys []kibanaAPIKey, policy *kibanaPolicy) (*kibanaAPIKey, error) {
328330
tokenName := envWithDefault(defaultTokenName, "FLEET_TOKEN_NAME")
329331
for _, key := range keys {
330-
name := tokenNameStrip.ReplaceAllString(key.Name, "")
332+
name := strings.TrimSpace(tokenNameStrip.ReplaceAllString(key.Name, ""))
331333
if name == tokenName && key.PolicyID == policy.ID {
332334
return &key, nil
333335
}

0 commit comments

Comments
 (0)