This commit is contained in:
1 parent
df94fc6d8b
commit
a2a96f6a46
5 files changed
+434
-42
No files matched your search
@@ -37,6 +37,7 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -796,6 +797,49 @@ func SaveSetting(ctx context.Context, db *pgxpool.Pool, key, value string) error
|
||||
return err
|
||||
}
|
||||
|
||||
// carrierNodeInstancePattern matches a registered project key naming a CarrierNode instance: the
|
||||
// base "carriernode" itself, or a numbered peer like "carriernode_2" - see
|
||||
// ProjectConfigurator/backend/cmd/projectconfigurator/settings.go's identical pattern (kept in
|
||||
// sync manually since one is the sender's copy and this is the direct-DB-read receiver's copy of
|
||||
// the same convention, not literally shared code).
|
||||
var carrierNodeInstancePattern = regexp.MustCompile(`^carriernode(_\d+)?$`)
|
||||
|
||||
// CarrierNodeURLs returns every CarrierNode instance registered in ProjectConfigurator's Projects
|
||||
// workspace ("carriernode_url", "carriernode_2_url", ...), read directly from the shared
|
||||
// `settings` table in registration order, dropping any instance with no URL set. This is for the
|
||||
// 7 MEDIA_SERVICE instances that share this database directly instead of going through
|
||||
// ProjectConfigurator's coreconfig push (see ProjectConfigurator/README.md's "Pushing core service
|
||||
// info to other projects" section) - wire it as a carriernodeclient.Client's BaseURLs:
|
||||
//
|
||||
// carriernodeclient.NewMulti(secret, func(ctx context.Context) []string {
|
||||
// return mediacore.CarrierNodeURLs(ctx, db, fallback)
|
||||
// })
|
||||
//
|
||||
// Returns fallback if no carriernode* instance is registered (or none has a URL) yet.
|
||||
func CarrierNodeURLs(ctx context.Context, db *pgxpool.Pool, fallback []string) []string {
|
||||
var registered []string
|
||||
_ = json.Unmarshal([]byte(SettingValue(ctx, db, "configured_central", "")), ®istered)
|
||||
var urls []string
|
||||
for _, project := range registered {
|
||||
key := strings.ToLower(strings.TrimSpace(project))
|
||||
if !carrierNodeInstancePattern.MatchString(key) {
|
||||
continue
|
||||
}
|
||||
if url := strings.TrimSpace(SettingValue(ctx, db, key+"_url", "")); url != "" {
|
||||
urls = append(urls, url)
|
||||
}
|
||||
}
|
||||
if len(urls) == 0 {
|
||||
if url := strings.TrimSpace(SettingValue(ctx, db, "carriernode_url", "")); url != "" {
|
||||
urls = []string{url}
|
||||
}
|
||||
}
|
||||
if len(urls) == 0 {
|
||||
return fallback
|
||||
}
|
||||
return urls
|
||||
}
|
||||
|
||||
// --- path-safety helpers (generic, no Core dependency) ---
|
||||
|
||||
// SafeRelative reports whether value is a relative path with no `..`
|
||||
|
||||
Reference in new issue
Block a user