Skip to content

Commit

Permalink
feat: add ego.server.report.fqdn boolean setting
Browse files Browse the repository at this point in the history
If true, the fully-qualified domain name is reported for the
rest payload identifying the server. If false (the default)
then only the "shortname" is returned.
  • Loading branch information
tucats committed Jan 15, 2025
1 parent 8d8d668 commit c13089a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
5 changes: 5 additions & 0 deletions defs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ const (
// The prefix for all server configuration keys.
ServerKeyPrefix = PrivilegedKeyPrefix + "server."

// If true, the REST payload will report the fully-qualified domain name for
// the server. Otherwise, the "shortname" is used, which is the default case.
ServerReportFQDNSetting = ServerKeyPrefix + "report.fqdn"

// The default user if no userdatabase has been initialized yet. This is a
// string of the form "user:password", which is defined as the root user.
DefaultCredentialSetting = ServerKeyPrefix + "default.credential"
Expand Down Expand Up @@ -368,6 +372,7 @@ var ValidSettings map[string]bool = map[string]bool{
PrecisionErrorSetting: true,
UnusedVarsSetting: true,
UnusedVarLoggingSetting: true,
ServerReportFQDNSetting: true,
}

// RestrictedSettings is a list of settings that cannot be read using the
Expand Down
1 change: 1 addition & 0 deletions runtime/profile/initialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func InitProfileDefaults() error {
defs.StaticTypesSetting: defs.Dynamic,
defs.UnusedVarsSetting: defs.True,
defs.UnusedVarLoggingSetting: defs.False,
defs.ServerReportFQDNSetting: defs.False,
defs.OutputFormatSetting: ui.TextFormat,
defs.ExtensionsEnabledSetting: defs.False,
defs.UseReadline: defs.True,
Expand Down
2 changes: 1 addition & 1 deletion tools/buildver.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.5-1185
1.5-1186
14 changes: 7 additions & 7 deletions util/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"sort"
"strings"

"github.com/tucats/ego/app-cli/settings"
"github.com/tucats/ego/data"
"github.com/tucats/ego/defs"
)

// Hostname gets a short form of the host namme (i.e. the first part of an FQDN).
Expand All @@ -15,15 +17,13 @@ func Hostname() string {
if hostName, err := os.Hostname(); err == nil {
// If this is a multipart name, use only the first part.
// If this is not a multipart name, return the entire name.
// Note: This assumes that the FQDN will not contain multiple
// Note: This assumes that the FQDN will contain multiple
// dots, which is a common scenario.
if strings.Count(hostName, ".") > 1 {
parts := strings.SplitN(hostName, ".", 2)

return parts[0]
} else {
return hostName
if !settings.GetBool(defs.ServerReportFQDNSetting) {
hostName = strings.SplitN(hostName, ".", 2)[0]
}

return hostName
} else {
return "<unknown hostname>"
}
Expand Down

0 comments on commit c13089a

Please sign in to comment.