Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embed Deployment Configuration #1873

Merged
merged 1 commit into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions services-config.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand Down
94 changes: 93 additions & 1 deletion skywire.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
Loading