|
|
@@ -8,15 +8,23 @@ import (
|
|
|
"strings"
|
|
|
)
|
|
|
|
|
|
-const (
|
|
|
- // URI format error message template
|
|
|
- uriFormatErrorMsg = "invalid listener URI %q: %v. Valid format: SCHEME://HOST:PORT (e.g., LOCAL://0.0.0.0:5190)"
|
|
|
- // Missing scheme error message template
|
|
|
- missingSchemeErrorMsg = "invalid listener URI %q: missing scheme. Valid format: SCHEME://HOST:PORT (e.g., LOCAL://0.0.0.0:5190)"
|
|
|
- // Duplicate listener error message
|
|
|
- duplicateListenerErrorMsg = "duplicate listener definition"
|
|
|
+var (
|
|
|
+ // Simple error for duplicate listener definitions
|
|
|
+ errDuplicateListener = errors.New("duplicate listener definition")
|
|
|
+ // Simple error for missing BOS listeners
|
|
|
+ errNoBOSListeners = errors.New("at least one BOS listener is required")
|
|
|
)
|
|
|
|
|
|
+// Custom error types for URI-related errors
|
|
|
+type uriFormatError struct {
|
|
|
+ URI string
|
|
|
+ Err error
|
|
|
+}
|
|
|
+
|
|
|
+func (e uriFormatError) Error() string {
|
|
|
+ return fmt.Sprintf("invalid listener URI %q: %v. Valid format: SCHEME://HOST:PORT (e.g., LOCAL://0.0.0.0:5190)", e.URI, e.Err)
|
|
|
+}
|
|
|
+
|
|
|
//go:generate go run ../cmd/config_generator unix settings.env ssl
|
|
|
type Config struct {
|
|
|
BOSListeners string `envconfig:"OSCAR_LISTENERS" required:"true" basic:"LOCAL://0.0.0.0:5190" ssl:"PLAINTEXT://0.0.0.0:5190,SSL://0.0.0.0:5192" description:"Network listeners for core OSCAR services. For multi-homed servers, allows users to connect from multiple networks. For example, you can allow both LAN and Internet clients to connect to the same server using different connection settings.\n\nFormat:\n\t- Comma-separated list of [NAME]://[HOSTNAME]:[PORT]\n\t- Listener names and ports must be unique\n\t- Listener names are user-defined\n\t- Each listener needs OSCAR_ADVERTISED_LISTENERS/KERBEROS_LISTENERS configs\n\nExamples:\n\t// Listen on all interfaces\n\tLAN://0.0.0.0:5190\n\t// Separate Internet and LAN config\n\tWAN://142.250.176.206:5190,LAN://192.168.1.10:5191"`
|
|
|
@@ -52,10 +60,10 @@ func ParseListenersCfg(BOSListeners string, BOSAdvertisedListeners string, kerbe
|
|
|
|
|
|
u, err := url.Parse(uriStr)
|
|
|
if err != nil {
|
|
|
- return nil, fmt.Errorf(uriFormatErrorMsg, uriStr, err)
|
|
|
+ return nil, uriFormatError{URI: uriStr, Err: err}
|
|
|
}
|
|
|
if u.Scheme == "" {
|
|
|
- return nil, fmt.Errorf(missingSchemeErrorMsg, uriStr)
|
|
|
+ return nil, uriFormatError{URI: uriStr, Err: errors.New("missing scheme")}
|
|
|
}
|
|
|
|
|
|
return u, nil
|
|
|
@@ -77,7 +85,7 @@ func ParseListenersCfg(BOSListeners string, BOSAdvertisedListeners string, kerbe
|
|
|
m[u.Scheme] = &Listener{}
|
|
|
}
|
|
|
if m[u.Scheme].BOSListenAddress != "" {
|
|
|
- return nil, errors.New(duplicateListenerErrorMsg)
|
|
|
+ return nil, errDuplicateListener
|
|
|
}
|
|
|
m[u.Scheme].BOSListenAddress = net.JoinHostPort(u.Hostname(), u.Port())
|
|
|
}
|
|
|
@@ -96,7 +104,7 @@ func ParseListenersCfg(BOSListeners string, BOSAdvertisedListeners string, kerbe
|
|
|
m[u.Scheme] = &Listener{}
|
|
|
}
|
|
|
if m[u.Scheme].BOSAdvertisedHost != "" {
|
|
|
- return nil, errors.New(duplicateListenerErrorMsg)
|
|
|
+ return nil, errDuplicateListener
|
|
|
}
|
|
|
m[u.Scheme].BOSAdvertisedHost = net.JoinHostPort(u.Hostname(), u.Port())
|
|
|
}
|
|
|
@@ -115,7 +123,7 @@ func ParseListenersCfg(BOSListeners string, BOSAdvertisedListeners string, kerbe
|
|
|
m[u.Scheme] = &Listener{}
|
|
|
}
|
|
|
if m[u.Scheme].KerberosListenAddress != "" {
|
|
|
- return nil, errors.New(duplicateListenerErrorMsg)
|
|
|
+ return nil, errDuplicateListener
|
|
|
}
|
|
|
m[u.Scheme].KerberosListenAddress = net.JoinHostPort(u.Hostname(), u.Port())
|
|
|
}
|
|
|
@@ -133,7 +141,7 @@ func ParseListenersCfg(BOSListeners string, BOSAdvertisedListeners string, kerbe
|
|
|
}
|
|
|
|
|
|
if len(ret) == 0 {
|
|
|
- return nil, errors.New("at least one BOS listener is required")
|
|
|
+ return nil, errNoBOSListeners
|
|
|
}
|
|
|
|
|
|
return ret, nil
|