]> go.fuhry.dev Git - runtime.git/commitdiff
Make some other constants overrideable
authorDan Fuhry <dan@fuhry.com>
Mon, 15 Jan 2024 01:00:32 +0000 (20:00 -0500)
committerDan Fuhry <dan@fuhry.com>
Mon, 15 Jan 2024 01:00:32 +0000 (20:00 -0500)
Makefile
constants/constants.go
grpc/acl/acl_yaml.go
metrics/metricbus/constants.go
metrics/metricbus/internal/dbus_interface.go
metrics/metricbus/internal/server.go
metrics/metricbus/mbclient/conn.go

index 1978c74f56c78ee217eb9b4d0693b198eca2d76e..0251cc03318a5b75d0283b9bc995131d4e85cad2 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -10,22 +10,32 @@ SD_DOMAIN := v.$(ROOT_DOMAIN)
 WEB_SERVICES_DOMAIN := $(ROOT_DOMAIN)
 MACHINES_HOST := machines.$(WEB_SERVICES_DOMAIN)
 MACHINES_MQTT_TOPIC := machines/events
-ROOT_CA_NAME := FooCorp Root
-INT_CA_NAME := FooCorp Intermediate mTLS
-DEVICE_TRUST_TOKEN_NAME := FooCorp Device Trust
+DBUS_PREFIX := dev.fuhry.runtime
+DBUS_PATH := /$(subst .,/,$(DBUS_PREFIX))
+ORG_NAME := FooCorp
+ORG_SLUG := runtime
+SYSTEM_CONF_DIR := /etc/$(ORG_SLUG)
+ROOT_CA_NAME := $(ORG_NAME) Root
+INT_CA_NAME := $(ORG_NAME) Intermediate mTLS
+DEVICE_TRUST_TOKEN_NAME := $(ORG_NAME) Device Trust
 
 LDFLAGS :=
 
-LDFLAGS += -X=go.fuhry.dev/runtime/constants.RootDomain=$(ROOT_DOMAIN)
-LDFLAGS += -X=go.fuhry.dev/runtime/constants.DefaultRegion=$(DEFAULT_REGION)
-LDFLAGS += -X=go.fuhry.dev/runtime/constants.DefaultHostDomain=$(DEFAULT_HOST_DOMAIN)
-LDFLAGS += -X=go.fuhry.dev/runtime/constants.SDDomain=$(SD_DOMAIN)
-LDFLAGS += -X=go.fuhry.dev/runtime/constants.WebServicesDomain=$(WEB_SERVICES_DOMAIN)
-LDFLAGS += -X=go.fuhry.dev/runtime/constants.MachinesHost=$(MACHINES_HOST)
-LDFLAGS += -X=go.fuhry.dev/runtime/constants.MachinesMqttTopic=$(MACHINES_MQTT_TOPIC)
-#LDFLAGS += -X="go.fuhry.dev/runtime/constants.RootCAName=$(ROOT_CA_NAME)"
-#LDFLAGS += -X="go.fuhry.dev/runtime/constants.IntCAName=$(INT_CA_NAME)"
-#LDFLAGS += -X="go.fuhry.dev/runtime/constants.DeviceTrustTokenName=$(DEVICE_TRUST_TOKEN_NAME)"
+LDFLAGS += -X "go.fuhry.dev/runtime/constants.RootDomain=$(ROOT_DOMAIN)"
+LDFLAGS += -X "go.fuhry.dev/runtime/constants.DefaultRegion=$(DEFAULT_REGION)"
+LDFLAGS += -X "go.fuhry.dev/runtime/constants.DefaultHostDomain=$(DEFAULT_HOST_DOMAIN)"
+LDFLAGS += -X "go.fuhry.dev/runtime/constants.SDDomain=$(SD_DOMAIN)"
+LDFLAGS += -X "go.fuhry.dev/runtime/constants.WebServicesDomain=$(WEB_SERVICES_DOMAIN)"
+LDFLAGS += -X "go.fuhry.dev/runtime/constants.MachinesHost=$(MACHINES_HOST)"
+LDFLAGS += -X "go.fuhry.dev/runtime/constants.MachinesMqttTopic=$(MACHINES_MQTT_TOPIC)"
+LDFLAGS += -X "go.fuhry.dev/runtime/constants.DbusPrefix=$(DBUS_PREFIX)"
+LDFLAGS += -X "go.fuhry.dev/runtime/constants.DbusPath=$(DBUS_PATH)"
+LDFLAGS += -X "go.fuhry.dev/runtime/constants.OrgName=$(ORG_NAME)"
+LDFLAGS += -X "go.fuhry.dev/runtime/constants.OrgSlug=$(ORG_SLUG)"
+LDFLAGS += -X "go.fuhry.dev/runtime/constants.SystemConfDir=$(SYSTEM_CONF_DIR)"
+LDFLAGS += -X "go.fuhry.dev/runtime/constants.RootCAName=$(ROOT_CA_NAME)"
+LDFLAGS += -X "go.fuhry.dev/runtime/constants.IntCAName=$(INT_CA_NAME)"
+LDFLAGS += -X "go.fuhry.dev/runtime/constants.DeviceTrustTokenName=$(DEVICE_TRUST_TOKEN_NAME)"
 
 define GOPROG_template =
 GOMAINS += $(1)/$(2)
index 05d1e7f8cfb619cbe39f008b699c5e0fa2c49ab9..972804596203b8fb98d296f8ff96981a927e45ef 100644 (file)
@@ -1,5 +1,7 @@
 package constants
 
+import "strings"
+
 var (
        RootDomain        = "fuhry.dev"
        DefaultRegion     = "hq"
@@ -8,8 +10,14 @@ var (
        WebServicesDomain = RootDomain
        MachinesHost      = "machines." + WebServicesDomain
        MachinesMqttTopic = "machines/events"
+       DbusPrefix        = "dev.fuhry.runtime"
+       DbusPath          = "/" + strings.ReplaceAll(DbusPrefix, ".", "/")
+
+       OrgName       = "FooCorp"
+       OrgSlug       = "runtime"
+       SystemConfDir = "/etc/" + OrgSlug
 
-       RootCAName           = "FooCorp Root"
-       IntCAName            = "FooCorp Intermediate mTLS"
-       DeviceTrustTokenName = "FooCorp Device Trust"
+       RootCAName           = OrgName + " Root"
+       IntCAName            = OrgName + " Intermediate mTLS"
+       DeviceTrustTokenName = OrgName + " Device Trust"
 )
index 53ed63224df72b255a3b2a156e33edf9346f47e7..648ef44deaccf73bbdcf4b5a820d489bf401d75a 100644 (file)
@@ -7,6 +7,7 @@ import (
        "path"
        "strings"
 
+       "go.fuhry.dev/runtime/constants"
        "go.fuhry.dev/runtime/mtls"
        "go.fuhry.dev/runtime/utils/log"
        "gopkg.in/yaml.v3"
@@ -42,7 +43,7 @@ type aclYaml struct {
 
 var aclSearchPaths = []string{
        ".",
-       "/etc/runtime/grpc",
+       path.Join(constants.SystemConfDir, "grpc"),
 }
 
 func TryLoadAcl(serverId mtls.Identity) ACLChecker {
index 3bdf05e64e9aab32dcfe1ff81f8744061193bc71..94f7f5570b3af64abca1d22b083281ce610f1e92 100644 (file)
@@ -4,6 +4,7 @@ import (
        "fmt"
 
        "github.com/godbus/dbus/v5"
+       "go.fuhry.dev/runtime/constants"
 )
 
 type MetricType uint
@@ -21,8 +22,9 @@ const (
        ErrMetricNotFound
 )
 
-const DbusServiceName = "dev.fuhry.runtime.metrics.MetricCollector.v1"
-const DbusServicePath = "/dev/fuhry/runtime/metrics/MetricCollector"
+var DbusServiceName = constants.DbusPrefix + ".metrics.MetricCollector.v1"
+var DbusServicePath = constants.DbusPath + "/metrics/MetricCollector"
+
 const SingletonInstanceDiscriminator = "GLOBAL"
 
 type KV map[string]string
index d5fffd0053748f5ec8657bc00d72371c954200b3..58e25d7ab98c2c12f2d1f8f28292fcf0ba4dd958 100644 (file)
@@ -21,7 +21,7 @@ func DbusConn() (*dbus.Conn, error) {
        return dbus.ConnectSystemBus()
 }
 
-const dbusInterface = `
+var dbusInterface = `
 <node>
        <interface name="` + metricbus.DbusServiceName + `">
                <method name="Ping">
index 8c51d6004ae2810f711d37cdb1db6afba98851dc..8700142fb58a5927062e8a8d897b00264c6b1dff 100644 (file)
@@ -163,8 +163,8 @@ func (s *mbServer) Start(ctx context.Context) error {
 
        s.log.V(2).Notice("Connected to D-Bus")
 
-       dbusConn.Export(s.servicer, metricbus.DbusServicePath, metricbus.DbusServiceName)
-       dbusConn.Export(introspect.Introspectable(dbusInterface), metricbus.DbusServicePath, "org.fredesktop.DBus.Introspectable")
+       dbusConn.Export(s.servicer, dbus.ObjectPath(metricbus.DbusServicePath), metricbus.DbusServiceName)
+       dbusConn.Export(introspect.Introspectable(dbusInterface), dbus.ObjectPath(metricbus.DbusServicePath), "org.fredesktop.DBus.Introspectable")
 
        reply, err := dbusConn.RequestName(metricbus.DbusServiceName, dbus.NameFlagDoNotQueue)
        if err != nil {
index 80e8e9317e940a4eebf367fd19e20dfab97c963c..2065ccde5cb9d81af5d32c3f994822d034e11651 100644 (file)
@@ -17,7 +17,7 @@ var globalDbusConnOnce sync.Once
 var globalDbusMetricBusObj dbus.BusObject
 var globalDbusMetricBusObjMu sync.Mutex
 
-const metricBusApiPrefix = metricbus.DbusServiceName
+var metricBusApiPrefix = metricbus.DbusServiceName
 
 type metricBusLowLevelClient struct {
        ctx context.Context
@@ -59,7 +59,7 @@ func metricBusDbusObject(ctx context.Context) (dbus.BusObject, error) {
 
        if globalDbusMetricBusObj == nil {
                conn := mustGlobalDbusConn(ctx)
-               globalDbusMetricBusObj = conn.Object(metricBusApiPrefix, metricbus.DbusServicePath)
+               globalDbusMetricBusObj = conn.Object(metricBusApiPrefix, dbus.ObjectPath(metricbus.DbusServicePath))
 
                if globalDbusMetricBusObj == nil {
                        log.Default().Errorf("failed to get BusObject")