Files
kopia/internal/testutil/serverparameters.go
Julio Lopez 995e7fd893 refactor(general): modernize (#4903)
Applies the modernize changes for the following categories:

- mapsloop
- stringsseq
- stringscutprefix
- sortslice
2025-10-23 17:11:38 -07:00

43 lines
1.1 KiB
Go

package testutil
import "strings"
// Pattern in stderr that `kopia server` uses to pass ephemeral data.
const (
serverOutputAddress = "SERVER ADDRESS: "
serverOutputCertSHA256 = "SERVER CERT SHA256: "
serverOutputPassword = "SERVER PASSWORD: "
serverOutputControlPassword = "SERVER CONTROL PASSWORD: "
)
// ServerParameters encapsulates parameters captured by processing stderr of
// 'kopia server start'.
type ServerParameters struct {
BaseURL string
SHA256Fingerprint string
Password string
ServerControlPassword string
}
// ProcessOutput processes output lines from a server that's starting up.
func (s *ServerParameters) ProcessOutput(l string) bool {
if after, ok := strings.CutPrefix(l, serverOutputAddress); ok {
s.BaseURL = after
return false
}
if after, ok := strings.CutPrefix(l, serverOutputCertSHA256); ok {
s.SHA256Fingerprint = after
}
if after, ok := strings.CutPrefix(l, serverOutputPassword); ok {
s.Password = after
}
if after, ok := strings.CutPrefix(l, serverOutputControlPassword); ok {
s.ServerControlPassword = after
}
return true
}