Skip to content

Commit 6cf13bb

Browse files
committed
refactor: clarify NTP validation and config formatting
Signed-off-by: Navaneeth <me@rizexor.com>
1 parent 6af6746 commit 6cf13bb

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

‎ntp.go‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ import (
1010
"github.com/goccy/go-yaml/ast"
1111
)
1212

13-
var ntpHostnameLabel = regexp.MustCompile(`^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$`)
13+
// A hostname label is 1–63 ASCII letters, digits, or hyphens.
14+
// The first and last characters must be letters or digits.
15+
var ntpHostnameLabel = regexp.MustCompile(
16+
`^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$`,
17+
)
1418

1519
func parseNTP(document map[string]any, file *ast.File) ([]base.File, ValidationErrors) {
1620
raw, exists := document["ntp"]
@@ -55,7 +59,10 @@ func parseNTP(document map[string]any, file *ast.File) ([]base.File, ValidationE
5559
return nil, problems
5660
}
5761
// Reset earlier global servers, leaving per-link/DHCP sources untouched.
58-
contents := "[Time]\nNTP=\nNTP=" + strings.Join(servers, " ") + "\n"
62+
contents := fmt.Sprintf(`[Time]
63+
NTP=
64+
NTP=%s
65+
`, strings.Join(servers, " "))
5966
mode := 0o644
6067
overwrite := true
6168
return []base.File{{

0 commit comments

Comments
 (0)