From 154f4390b5aafc89e8eddb37edef0c50c67576cf Mon Sep 17 00:00:00 2001 From: Moses Narrow Date: Sun, 22 Sep 2024 11:15:29 -0500 Subject: [PATCH] embed services-config.json and dmsghttp-config.json in skywire.go --- services-config.json | 2 + skywire.go | 94 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 95 insertions(+), 1 deletion(-) diff --git a/services-config.json b/services-config.json index e8ae80f4df..7dea112283 100644 --- a/services-config.json +++ b/services-config.json @@ -1,5 +1,6 @@ { "test": { + "conf": "http://conf.skywire.dev", "dmsg_discovery": "http://dmsgd.skywire.dev", "transport_discovery": "http://tpd.skywire.dev", "address_resolver": "http://ar.skywire.dev", @@ -43,6 +44,7 @@ ] }, "prod": { + "conf": "http://conf.skywire.skycoin.com", "dmsg_discovery": "http://dmsgd.skywire.skycoin.com", "transport_discovery": "http://tpd.skywire.skycoin.com", "address_resolver": "http://ar.skywire.skycoin.com", diff --git a/skywire.go b/skywire.go index 2b778f83a6..ac53ec55aa 100644 --- a/skywire.go +++ b/skywire.go @@ -1,6 +1,98 @@ // Package skywire skywire.go package skywire +import ( + _ "embed" + "encoding/json" + "log" + + "github.com/skycoin/skywire-utilities/pkg/cipher" +) + /* -workaround to avoid go module errors. +Embedded Deployment Defaults + +Change the contents of services-config.json and / or dmsghttp-config.json to embed updated values */ + +// ServicesJSON is the embedded services-config.json file +// +//go:embed services-config.json +var ServicesJSON []byte + +// DmsghttpJSON is the embedded dmsghttp-config.json file +// +//go:embed dmsghttp-config.json +var DmsghttpJSON []byte + +// EnvServices is the wrapper struct for the outer JSON - i.e. 'prod' or 'test' deployment config +type EnvServices struct { + Test json.RawMessage `json:"test"` + Prod json.RawMessage `json:"prod"` +} + +// Services are URLs, IP addresses, and public keys of the skywire services as deployed +type Services struct { + DmsgDiscovery string `json:"dmsg_discovery,omitempty"` + TransportDiscovery string `json:"transport_discovery,omitempty"` + AddressResolver string `json:"address_resolver,omitempty"` + RouteFinder string `json:"route_finder,omitempty"` + RouteSetupNodes []cipher.PubKey `json:"route_setup_nodes,omitempty"` + TransportSetupPKs []cipher.PubKey `json:"transport_setup,omitempty"` + UptimeTracker string `json:"uptime_tracker,omitempty"` + ServiceDiscovery string `json:"service_discovery,omitempty"` + StunServers []string `json:"stun_servers,omitempty"` + DNSServer string `json:"dns_server,omitempty"` + SurveyWhitelist []cipher.PubKey `json:"survey_whitelist,omitempty"` +} + +// Conf is the configuration URL for the deployment which may be fetched on `skywire cli config gen` +type Conf struct { + Conf string `json:"conf,omitempty"` +} + +// Prod is the production deployment services +var Prod Services + +// ProdConf is the service configuration address / URL for the skywire production deployment +var ProdConf Conf + +// Test is the test deployment services +var Test Services + +// TestConf is the service configuration address / URL for the skywire test deployment +var TestConf Conf + +// initialize the embedded files into variables +func init() { + var js interface{} + err := json.Unmarshal([]byte(ServicesJSON), &js) + if err != nil { + log.Panic("services-config.json ", err) + } + err = json.Unmarshal([]byte(DmsghttpJSON), &js) + if err != nil { + log.Panic("dmsghttp-config.json ", err) + } + var envServices EnvServices + err = json.Unmarshal(ServicesJSON, &envServices) + if err != nil { + log.Panic(err) + } + err = json.Unmarshal(envServices.Prod, &Prod) + if err != nil { + log.Panic(err) + } + err = json.Unmarshal(envServices.Prod, &ProdConf) + if err != nil { + log.Panic(err) + } + err = json.Unmarshal(envServices.Test, &Test) + if err != nil { + log.Panic(err) + } + err = json.Unmarshal(envServices.Test, &TestConf) + if err != nil { + log.Panic(err) + } +}