A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
feat(rexctl): define settings with validation and masking
Hampus38b076f35e3d
diff --git a/fluxer_rexctl/internal/settings/effective.go b/fluxer_rexctl/internal/settings/effective.gonew file mode 100644index 000000000..92ffccac4--- /dev/null+++ b/fluxer_rexctl/internal/settings/effective.go@@ -0,0 +1,145 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++package settings++import (+ "fmt"+ "net"+ "slices"+ "strconv"+ "strings"++ "github.com/fluxerapp/fluxer/fluxer_rexctl/internal/stack"+)++func Effective(set *stack.Set, chosen, secrets, adminImport map[string]string) (map[string]string, error) {+ env := map[string]string{}+ reads := func(v string) bool { return slices.Contains(set.Vars, v) }+ put := func(v, value string) {+ if reads(v) {+ env[v] = value+ }+ }++ if name := chosen[MemoryProfile]; name != "" {+ values, ok := set.Profiles[name]+ if !ok {+ return nil, &Error{Key: MemoryProfile, Problem: fmt.Sprintf("Fluxer %s has no memory profile called %s.", set.Release, name),+ Fix: "Run rexctl config unset memory.profile."}+ }+ for v, value := range values {+ put(v, value)+ }+ }++ for v, value := range derived(chosen) {+ put(v, value)+ }++ operator := map[string]bool{}+ for name, value := range chosen {+ k, ok := namedKey(name)+ if !ok {+ continue+ }+ for v, value := range namedVars(k, value) {+ if reads(v) {+ env[v] = value+ operator[v] = true+ }+ }+ }+ for name, value := range chosen {+ if isRawName(name) {+ env[name] = value+ operator[name] = true+ }+ }++ for adminKey, value := range adminImport {+ if v, ok := TwinVar(adminKey); ok {+ put(v, value)+ }+ }++ for v, value := range secrets {+ if !operator[v] {+ put(v, value)+ }+ }++ if registry := chosen[ImagesRegistry]; registry != "" {+ for _, v := range ImageVars {+ if ref, ok := env[v]; ok {+ env[v] = RewriteRegistry(ref, registry)+ }+ }+ }+ return env, nil+}++func namedVars(k Key, value string) map[string]string {+ switch k.Name {+ case VoicePublicIP:+ if value == "" {+ return nil+ }+ return map[string]string{"FLUXER_LIVEKIT_NODE_IP": value, "FLUXER_LIVEKIT_USE_EXTERNAL_IP": "false"}+ case StoragePath:+ if b, err := strconv.ParseBool(value); err == nil {+ value = strconv.FormatBool(b)+ }+ }+ if len(k.Vars) == 0 {+ return nil+ }+ return map[string]string{k.Vars[0]: value}+}++func derived(chosen map[string]string) map[string]string {+ out := map[string]string{}+ mode := chosen[EdgeMode]+ if mode == "" {+ mode = EdgeBundled+ }+ port := "443"+ if mode == EdgeBundled && chosen[EdgeHTTPSPort] != "" {+ port = chosen[EdgeHTTPSPort]+ }+ out["FLUXER_PUBLIC_SCHEME"] = "https"+ out["FLUXER_PUBLIC_PORT"] = port+ scheme := "https"+ if raw := strings.ToLower(strings.TrimSpace(chosen["FLUXER_PUBLIC_SCHEME"])); raw != "" {+ scheme = raw+ }+ if raw := strings.TrimSpace(chosen[EdgePublicPort]); raw != "" {+ port = raw+ }+ if domain := strings.ToLower(strings.TrimSpace(chosen[Domain])); domain != "" {+ origin := scheme + "://" + domain+ if (scheme == "https" && port != "443") || (scheme == "http" && port != "80") {+ origin = scheme + "://" + net.JoinHostPort(domain, port)+ }+ out["FLUXER_PUBLIC_ORIGIN"] = origin+ if mode == EdgeBundled {+ out["FLUXER_EDGE_SITE_ADDRESS"] = "https://" + domain+ }+ }+ return out+}++func RewriteRegistry(ref, registry string) string {+ name, digest, ok := strings.Cut(ref, "@")+ if !ok || !strings.HasPrefix(digest, "sha256:") || registry == "" {+ return ref+ }+ registry = strings.TrimSuffix(registry, "/")+ first, rest, hasSlash := strings.Cut(name, "/")+ switch {+ case hasSlash && (strings.ContainsAny(first, ".:") || first == "localhost"):+ name = rest+ case !hasSlash:+ name = "library/" + name+ }+ return registry + "/" + name + "@" + digest+}diff --git a/fluxer_rexctl/internal/settings/keys.go b/fluxer_rexctl/internal/settings/keys.gonew file mode 100644index 000000000..f377f7e9b--- /dev/null+++ b/fluxer_rexctl/internal/settings/keys.go@@ -0,0 +1,266 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++package settings++import (+ "errors"+ "fmt"+ "maps"+ "slices"+ "strings"++ "github.com/fluxerapp/fluxer/fluxer_rexctl/internal/adminapi"+ "github.com/fluxerapp/fluxer/fluxer_rexctl/internal/secrets"+ "github.com/fluxerapp/fluxer/fluxer_rexctl/internal/stack"+)++type Kind int++const (+ Deployment Kind = iota+ Instance+ Raw+)++type Key struct {+ Name string+ Kind Kind+ Type string+ Vars []string+ Secret bool+ Stateful bool+ Confirm string+ Validate func(string) error+ Options []string+ Help string+}++const (+ Domain = "domain"+ EdgeMode = "edge.mode"+ EdgeBind = "edge.bind"+ EdgeHTTPPort = "edge.http_port"+ EdgeHTTPSPort = "edge.https_port"+ EdgePublicPort = "edge.public_port"+ EdgeTrusted = "edge.trusted_proxies"+ VoiceTCPPort = "voice.tcp_port"+ VoiceUDPPort = "voice.udp_port"+ VoicePublicIP = "voice.public_ip"+ StorageEndpoint = "storage.endpoint"+ StoragePublic = "storage.public_endpoint"+ StorageRegion = "storage.region"+ StoragePath = "storage.path_style"+ StorageAccess = "storage.access_key"+ StorageSecret = "storage.secret_key"+ HTTPProxy = "network.http_proxy"+ HTTPSProxy = "network.https_proxy"+ NoProxy = "network.no_proxy"+ IPv6 = "network.ipv6"+ ImagesRegistry = "images.registry"+ MemoryProfile = "memory.profile"+ EngineHost = "engine.host"+ ImagesPrefix = "images."+)++const (+ EdgeBundled = "bundled"+ EdgeProxy = "proxy"+ EdgeTunnel = "tunnel"+)++var ImageVars = map[string]string{+ "postgres": "FLUXER_POSTGRES_IMAGE",+ "valkey": "FLUXER_VALKEY_IMAGE",+ "nats": "FLUXER_NATS_IMAGE",+ "meilisearch": "FLUXER_MEILISEARCH_IMAGE",+ "seaweedfs": "FLUXER_SEAWEEDFS_IMAGE",+ "livekit": "FLUXER_LIVEKIT_IMAGE",+ "edge": "FLUXER_CADDY_IMAGE",+}++const storageConfirm = "Files people already uploaded stay where they are. rexctl doesn't move them."++var named = buildNamed()++func buildNamed() []Key {+ keys := []Key{+ {Name: Domain, Type: "hostname", Vars: []string{"FLUXER_DOMAIN"}, Validate: validHostname,+ Help: "The domain people use to reach Fluxer",+ Confirm: "Fluxer gets a new certificate for the new domain. Passkeys made for the old domain stop working. The domain_migration settings help people move over."},+ {Name: EdgeMode, Type: "choice", Options: []string{EdgeBundled, EdgeProxy, EdgeTunnel}, Validate: oneOf(EdgeBundled, EdgeProxy, EdgeTunnel),+ Help: "Whether Fluxer serves HTTPS itself, sits behind your reverse proxy or behind a tunnel"},+ {Name: EdgeBind, Type: "address", Vars: []string{"FLUXER_EDGE_BIND"}, Validate: validBind,+ Help: "The address your reverse proxy or tunnel connects to"},+ {Name: EdgeHTTPPort, Type: "port", Vars: []string{"FLUXER_HTTP_PORT"}, Validate: validPort,+ Help: "The port Fluxer listens on for HTTP"},+ {Name: EdgeHTTPSPort, Type: "port", Vars: []string{"FLUXER_HTTPS_PORT"}, Validate: validPort,+ Help: "The port Fluxer listens on for HTTPS"},+ {Name: EdgePublicPort, Type: "port", Vars: []string{"FLUXER_PUBLIC_PORT"}, Validate: validPort,+ Help: "The port people use in Fluxer's address, when it differs from the one Fluxer listens on"},+ {Name: EdgeTrusted, Type: "list", Vars: []string{"FLUXER_EDGE_TRUSTED_PROXIES"}, Validate: validText,+ Help: "Proxies whose client address headers Fluxer trusts"},+ {Name: VoiceTCPPort, Type: "port", Vars: []string{"FLUXER_LIVEKIT_TCP_PORT"}, Validate: validPort,+ Help: "The TCP port for voice and video"},+ {Name: VoiceUDPPort, Type: "port", Vars: []string{"FLUXER_LIVEKIT_UDP_PORT"}, Validate: validPort,+ Help: "The UDP port for voice and video"},+ {Name: VoicePublicIP, Type: "ip", Vars: []string{"FLUXER_LIVEKIT_NODE_IP", "FLUXER_LIVEKIT_USE_EXTERNAL_IP"}, Validate: validIP,+ Help: "The public IP address voice and video use, when Fluxer can't find it by itself"},+ {Name: StorageEndpoint, Type: "url", Vars: []string{"FLUXER_S3_ENDPOINT"}, Validate: validURL, Confirm: storageConfirm,+ Help: "An S3-compatible object store to use instead of the bundled one"},+ {Name: StoragePublic, Type: "url", Vars: []string{"FLUXER_S3_PUBLIC_ENDPOINT"}, Validate: validURL, Confirm: storageConfirm,+ Help: "The object store address browsers use, when it differs from the one Fluxer uses"},+ {Name: StorageRegion, Type: "text", Vars: []string{"FLUXER_S3_REGION"}, Validate: validText, Confirm: storageConfirm,+ Help: "The object store region"},+ {Name: StoragePath, Type: "bool", Vars: []string{"FLUXER_S3_FORCE_PATH_STYLE"}, Validate: validBool, Confirm: storageConfirm,+ Help: "Whether the object store needs path-style addresses"},+ {Name: StorageAccess, Type: "text", Vars: []string{"FLUXER_S3_ACCESS_KEY"}, Validate: validText, Confirm: storageConfirm,+ Help: "The object store access key"},+ {Name: StorageSecret, Type: "secret", Vars: []string{"FLUXER_S3_SECRET_KEY"}, Validate: validText, Secret: true, Confirm: storageConfirm,+ Help: "The object store secret key"},+ {Name: HTTPProxy, Type: "url", Vars: []string{"HTTP_PROXY"}, Validate: validURL,+ Help: "The proxy Fluxer uses for outgoing HTTP requests"},+ {Name: HTTPSProxy, Type: "url", Vars: []string{"HTTPS_PROXY"}, Validate: validURL,+ Help: "The proxy Fluxer uses for outgoing HTTPS requests"},+ {Name: NoProxy, Type: "list", Vars: []string{"NO_PROXY"}, Validate: validText,+ Help: "Hosts Fluxer reaches without the proxy"},+ {Name: IPv6, Type: "bool", Validate: validBool, Confirm: "Every Fluxer service restarts.",+ Help: "Whether Fluxer's network uses IPv6"},+ {Name: ImagesRegistry, Type: "registry", Validate: validRegistry,+ Help: "A registry mirror for the database, cache, search, storage, voice and edge images"},+ {Name: MemoryProfile, Type: "choice", Options: []string{"small", "medium", "large"}, Validate: oneOf("small", "medium", "large"),+ Help: "How much memory Fluxer's services may use"},+ {Name: EngineHost, Type: "endpoint", Validate: validEndpoint,+ Help: "The Docker or Podman engine that runs Fluxer"},+ }+ for _, svc := range slices.Sorted(maps.Keys(ImageVars)) {+ keys = append(keys, Key{Name: ImagesPrefix + svc, Type: "image", Vars: []string{ImageVars[svc]}, Validate: validImage,+ Help: "The image for " + svc})+ }+ for i := range keys {+ keys[i].Kind = Deployment+ }+ return keys+}++func Named() []Key {+ out := make([]Key, len(named))+ for i, k := range named {+ k.Vars = slices.Clone(k.Vars)+ k.Options = slices.Clone(k.Options)+ out[i] = k+ }+ return out+}++func namedKey(name string) (Key, bool) {+ for _, k := range named {+ if k.Name == name {+ return k, true+ }+ }+ return Key{}, false+}++func namedByVar(v string) (Key, bool) {+ for _, k := range named {+ if slices.Contains(k.Vars, v) {+ return k, true+ }+ }+ return Key{}, false+}++var (+ ErrUnknownKey = errors.New("settings: unknown setting")+ ErrNeedsUpgrade = errors.New("settings: the release doesn't read this setting")+ ErrOtherName = errors.New("settings: set under another name")+)++type Error struct {+ Key string+ Use string+ Problem string+ Fix string+ Err error+}++func (e *Error) Error() string { return e.Problem }++func (e *Error) Unwrap() error { return e.Err }++func Lookup(set *stack.Set, custom []string, name string, adminSchema []adminapi.ConfigKey) (Key, error) {+ if k, ok := namedKey(name); ok {+ if !releaseReads(set, custom, k) {+ return Key{}, &Error{Key: name, Err: ErrNeedsUpgrade,+ Problem: "This setting needs a newer Fluxer.", Fix: "Run rexctl upgrade first."}+ }+ return k, nil+ }+ for _, a := range adminSchema {+ if a.Key == name {+ return Key{Name: a.Key, Kind: Instance, Type: a.Type, Secret: a.SecretSet != "", Options: slices.Clone(a.Options), Help: a.Help}, nil+ }+ }+ if !isRawName(name) {+ return Key{}, unknown(name)+ }+ if k, ok := namedByVar(name); ok {+ return Key{}, otherName(name, k.Name)+ }+ if admin, ok := Twins[name]; ok {+ return Key{}, otherName(name, admin)+ }+ if !slices.Contains(set.Vars, name) && !slices.Contains(custom, name) {+ return Key{}, unknown(name)+ }+ return Key{Name: name, Kind: Raw, Type: "text", Vars: []string{name}, Secret: SecretName(name),+ Stateful: generatedStateful(name), Validate: validText}, nil+}++func unknown(name string) error {+ return &Error{Key: name, Err: ErrUnknownKey,+ Problem: fmt.Sprintf("rexctl doesn't know a setting called %s.", name),+ Fix: "Run rexctl config list to see every setting."}+}++func otherName(name, use string) error {+ return &Error{Key: name, Use: use, Err: ErrOtherName,+ Problem: fmt.Sprintf("%s is set through %s.", name, use),+ Fix: fmt.Sprintf("Use rexctl config set %s instead.", use)}+}++func releaseReads(set *stack.Set, custom []string, k Key) bool {+ if k.Name == MemoryProfile {+ return len(set.Profiles) > 0+ }+ for _, v := range k.Vars {+ if !slices.Contains(set.Vars, v) && !slices.Contains(custom, v) {+ return false+ }+ }+ return true+}++func isRawName(name string) bool {+ if name == "" || strings.ToUpper(name) != name {+ return false+ }+ for i, r := range name {+ switch {+ case r >= 'A' && r <= 'Z', r == '_':+ case r >= '0' && r <= '9' && i > 0:+ default:+ return false+ }+ }+ return true+}++func generatedStateful(name string) bool {+ for _, s := range secrets.Required {+ if s.Key == name {+ return s.Stateful+ }+ }+ return false+}diff --git a/fluxer_rexctl/internal/settings/mask.go b/fluxer_rexctl/internal/settings/mask.gonew file mode 100644index 000000000..0280c14dc--- /dev/null+++ b/fluxer_rexctl/internal/settings/mask.go@@ -0,0 +1,47 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++package settings++import (+ "net/url"+ "strings"++ "github.com/fluxerapp/fluxer/fluxer_rexctl/internal/secrets"+)++const Masked = "set"++var secretParts = []string{"PASSWORD", "SECRET", "_TOKEN", "PRIVATE_KEY", "COOKIE", "API_KEY", "PROXY_KEY", "BLUESKY_KEYS", "SECRETS_BASE64"}++func SecretName(name string) bool {+ for _, p := range secretParts {+ if strings.Contains(name, p) {+ return true+ }+ }+ for _, s := range secrets.Required {+ if s.Key == name {+ return s.Kind != secrets.KindFixed && s.Key != secrets.VAPIDPublicKey+ }+ }+ return false+}++func Mask(key Key, value string) string {+ if value == "" {+ return ""+ }+ if key.Secret {+ return Masked+ }+ return maskUserinfo(value)+}++func maskUserinfo(value string) string {+ u, err := url.Parse(value)+ if err != nil || u.User == nil || u.Host == "" {+ return value+ }+ u.User = nil+ return strings.Replace(u.String(), "://", "://•••@", 1)+}diff --git a/fluxer_rexctl/internal/settings/twins.go b/fluxer_rexctl/internal/settings/twins.gonew file mode 100644index 000000000..ac7cfef23--- /dev/null+++ b/fluxer_rexctl/internal/settings/twins.go@@ -0,0 +1,59 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++package settings++var Twins = map[string]string{+ "FLUXER_APP_FAVICON_DARK_URL": "app_public.branding.favicon_dark_url",+ "FLUXER_APP_FAVICON_URL": "app_public.branding.favicon_url",+ "FLUXER_APP_ICON_URL": "app_public.branding.icon_url",+ "FLUXER_APP_LOGO_URL": "app_public.branding.logo_url",+ "FLUXER_APP_PRODUCT_NAME": "app_public.branding.product_name",+ "FLUXER_APP_SIGN_IN_BACKDROP_URL": "app_public.branding.sign_in_backdrop_url",+ "FLUXER_APP_STATUS_PAGE_INCIDENT_HISTORY_URL": "app_public.branding.status_page_incident_history_url",+ "FLUXER_APP_STATUS_PAGE_URL": "app_public.branding.status_page_url",+ "FLUXER_APP_SYMBOL_URL": "app_public.branding.symbol_url",+ "FLUXER_APP_THEME_COLOR": "app_public.branding.theme_color",+ "FLUXER_APP_WORDMARK_URL": "app_public.branding.wordmark_url",+ "FLUXER_AUTH_BLUESKY_CLIENT_NAME": "integrations.bluesky.client_name",+ "FLUXER_AUTH_BLUESKY_CLIENT_URI": "integrations.bluesky.client_uri",+ "FLUXER_AUTH_BLUESKY_ENABLED": "integrations.bluesky.enabled",+ "FLUXER_AUTH_BLUESKY_KEYS": "integrations.bluesky.keys",+ "FLUXER_AUTH_BLUESKY_LOGO_URI": "integrations.bluesky.logo_uri",+ "FLUXER_AUTH_BLUESKY_POLICY_URI": "integrations.bluesky.policy_uri",+ "FLUXER_AUTH_BLUESKY_TOS_URI": "integrations.bluesky.tos_uri",+ "FLUXER_EMAIL_DELIVERY": "integrations.email.delivery",+ "FLUXER_EMAIL_ENABLED": "integrations.email.delivery",+ "FLUXER_EMAIL_FROM_EMAIL": "integrations.email.from_email",+ "FLUXER_EMAIL_FROM_NAME": "integrations.email.from_name",+ "FLUXER_EMAIL_PROVIDER": "integrations.email.delivery",+ "FLUXER_EMAIL_SMTP_HOST": "integrations.email.smtp.host",+ "FLUXER_EMAIL_SMTP_PASSWORD": "integrations.email.smtp.password",+ "FLUXER_EMAIL_SMTP_PORT": "integrations.email.smtp.port",+ "FLUXER_EMAIL_SMTP_SECURE": "integrations.email.smtp.tls_mode",+ "FLUXER_EMAIL_SMTP_TLS_MODE": "integrations.email.smtp.tls_mode",+ "FLUXER_EMAIL_SMTP_USERNAME": "integrations.email.smtp.username",+ "FLUXER_KLIPY_API_KEY": "integrations.gif.klipy_api_key",+ "FLUXER_STRIPE_ENABLED": "billing.enabled",+ "FLUXER_STRIPE_LEGACY_PRICES": "billing.legacy_prices",+ "FLUXER_STRIPE_PRICES": "billing.prices",+ "FLUXER_STRIPE_SECRET_KEY": "billing.stripe_secret_key",+ "FLUXER_STRIPE_WEBHOOK_SECRET": "billing.stripe_webhook_secret",+ "FLUXER_YOUTUBE_API_KEY": "integrations.youtube.api_key",+}++var twinVars = map[string]string{+ "integrations.email.delivery": "FLUXER_EMAIL_DELIVERY",+ "integrations.email.smtp.tls_mode": "FLUXER_EMAIL_SMTP_TLS_MODE",+}++func TwinVar(adminKey string) (string, bool) {+ if v, ok := twinVars[adminKey]; ok {+ return v, true+ }+ for v, k := range Twins {+ if k == adminKey {+ return v, true+ }+ }+ return "", false+}diff --git a/fluxer_rexctl/internal/settings/validate.go b/fluxer_rexctl/internal/settings/validate.gonew file mode 100644index 000000000..c6762b1ed--- /dev/null+++ b/fluxer_rexctl/internal/settings/validate.go@@ -0,0 +1,141 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++package settings++import (+ "errors"+ "fmt"+ "net"+ "net/url"+ "runtime"+ "strconv"+ "strings"++ "github.com/distribution/reference"+)++func oneOf(options ...string) func(string) error {+ return func(v string) error {+ for _, o := range options {+ if v == o {+ return nil+ }+ }+ return fmt.Errorf("Use one of %s.", strings.Join(options, ", "))+ }+}++func validText(v string) error {+ if strings.ContainsAny(v, "\r\n\x00") {+ return errors.New("The value has to fit on one line.")+ }+ return nil+}++func validBool(v string) error {+ if _, err := strconv.ParseBool(v); err != nil {+ return errors.New("Use true or false.")+ }+ return nil+}++func validPort(v string) error {+ n, err := strconv.Atoi(v)+ if err != nil || n < 1 || n > 65535 {+ return errors.New("Use a port number from 1 to 65535.")+ }+ return nil+}++func validIP(v string) error {+ if v == "" || net.ParseIP(v) != nil {+ return nil+ }+ return errors.New("Use an IP address, for example 203.0.113.7.")+}++func validHostname(v string) error {+ bad := errors.New("Use a domain name such as chat.example.com, without https:// or a port.")+ if v == "" || len(v) > 253 || strings.HasSuffix(v, ".") {+ return bad+ }+ for _, label := range strings.Split(v, ".") {+ if label == "" || len(label) > 63 || strings.HasPrefix(label, "-") || strings.HasSuffix(label, "-") {+ return bad+ }+ for _, r := range label {+ if !(r >= 'a' && r <= 'z' || r >= 'A' && r <= 'Z' || r >= '0' && r <= '9' || r == '-') {+ return bad+ }+ }+ }+ return nil+}++func validBind(v string) error {+ bad := errors.New("Use an address and port such as 127.0.0.1:8080, or only a port.")+ if validPort(v) == nil {+ return nil+ }+ host, port, err := net.SplitHostPort(v)+ if err != nil || validPort(port) != nil {+ return bad+ }+ if host != "" && net.ParseIP(host) == nil {+ return bad+ }+ return nil+}++func validURL(v string) error {+ u, err := url.Parse(v)+ if err != nil || (u.Scheme != "http" && u.Scheme != "https") || u.Host == "" {+ return errors.New("Use a full address that starts with http:// or https://.")+ }+ return nil+}++func validImage(v string) error {+ if _, err := reference.ParseNormalizedNamed(v); err != nil {+ return errors.New("Use an image reference such as postgres:16-alpine.")+ }+ return nil+}++func validRegistry(v string) error {+ bad := errors.New("Use a registry host such as registry.example.com or localhost:5000, without https://.")+ if v == "" || strings.Contains(v, "://") {+ return bad+ }+ named, err := reference.ParseNormalizedNamed(v + "/fluxer")+ if err != nil || reference.Domain(named) != strings.SplitN(v, "/", 2)[0] {+ return bad+ }+ return nil+}++func EngineExample() string {+ if runtime.GOOS == "windows" {+ return "npipe:////./pipe/docker_engine"+ }+ return "unix:///var/run/docker.sock"+}++func validEndpoint(v string) error {+ bad := errors.New("Use an engine address such as " + EngineExample() + ".")+ u, err := url.Parse(v)+ if err != nil {+ return bad+ }+ switch u.Scheme {+ case "unix", "npipe":+ if u.Path != "" {+ return nil+ }+ case "tcp", "ssh":+ if u.Host != "" {+ return nil+ }+ }+ return bad+}diff --git a/fluxer_rexctl/internal/settings/vars.go b/fluxer_rexctl/internal/settings/vars.gonew file mode 100644index 000000000..22019ab98--- /dev/null+++ b/fluxer_rexctl/internal/settings/vars.go@@ -0,0 +1,65 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++package settings++import (+ "io/fs"+ "maps"+ "slices"++ "github.com/fluxerapp/fluxer/fluxer_rexctl/internal/stack"+)++const CustomFile = "custom.compose.yml"++func Vars(set *stack.Set, customFile []byte) ([]string, error) {+ seen := map[string]bool{}+ for _, v := range set.Vars {+ seen[v] = true+ }+ if len(customFile) > 0 {+ fv, err := stack.ParseVars(CustomFile, customFile)+ if err != nil {+ return nil, err+ }+ for _, v := range fv.All {+ seen[v] = true+ }+ }+ return slices.Sorted(maps.Keys(seen)), nil+}++func Services(set *stack.Set, customFile []byte, vars []string) []string {+ want := map[string]bool{}+ for _, v := range vars {+ want[v] = true+ }+ found := map[string]bool{}+ add := func(fv *stack.FileVars) {+ for svc, used := range fv.Services {+ for _, v := range used {+ if want[v] {+ found[svc] = true+ break+ }+ }+ }+ }+ if names, err := stack.ComposeFileNames(set.Files); err == nil {+ for _, name := range names {+ data, err := fs.ReadFile(set.Files, name)+ if err != nil {+ continue+ }+ if fv, err := stack.ParseVars(name, data); err == nil {+ add(fv)+ }+ }+ }+ if len(customFile) > 0 {+ if fv, err := stack.ParseVars(CustomFile, customFile); err == nil {+ add(fv)+ }+ }+ return slices.Sorted(maps.Keys(found))+}