Skip to content

Commit

Permalink
Merge pull request #802 from ersonp/config-refactor
Browse files Browse the repository at this point in the history
Config refactor
  • Loading branch information
jdknives authored Jun 9, 2021
2 parents 5eba16d + 27d7eec commit 528bfcb
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 58 deletions.
14 changes: 5 additions & 9 deletions pkg/skyenv/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ const (
const (
DmsgPtyPort uint16 = 22

DefaultDmsgPtyCLINet = "unix"
DefaultDmsgPtyCLIAddr = "/tmp/dmsgpty.sock"
DefaultDmsgPtyWhitelist = DefaultSkywirePath + "/dmsgpty/whitelist.json"
PackageDmsgPtyWhiteList = PackageSkywirePath + "/dmsgpty/whitelist.json"
DefaultDmsgPtyCLINet = "unix"
DefaultDmsgPtyCLIAddr = "/tmp/dmsgpty.sock"
)

// Default STCP constants.
Expand Down Expand Up @@ -93,17 +91,15 @@ const (
const (
DefaultAppSrvAddr = "localhost:5505"
AppDiscUpdateInterval = time.Minute
DefaultAppLocalPath = DefaultSkywirePath + "/local"
DefaultAppBinPath = DefaultSkywirePath + "/apps"
DefaultLogLevel = "info"
PackageAppLocalPath = PackageSkywirePath + "/local"
PackageAppBinPath = PackageSkywirePath + "/apps"
)

// Default routing constants
// Default local constants
const (
DefaultTpLogStore = DefaultSkywirePath + "/transport_logs"
PackageTpLogStore = PackageSkywirePath + "/transport_logs"
DefaultLocalPath = DefaultSkywirePath + "/local"
PackageLocalPath = PackageSkywirePath + "/local"
)

// Default hypervisor constants
Expand Down
18 changes: 2 additions & 16 deletions pkg/visor/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,28 +235,14 @@ func initDmsgCtrl(ctx context.Context, v *Visor, _ *logging.Logger) error {
}

func initTransport(ctx context.Context, v *Visor, log *logging.Logger) error {
conf := v.conf.Transport

tpdC, err := connectToTpDisc(v)
if err != nil {
err := fmt.Errorf("failed to create transport discovery client: %w", err)
return err
}

var logS transport.LogStore
switch conf.LogStore.Type {
case visorconfig.FileLogStore:
logS, err = transport.FileTransportLogStore(conf.LogStore.Location)
if err != nil {
err := fmt.Errorf("failed to create %s log store: %w", visorconfig.FileLogStore, err)
return err
}
case visorconfig.MemoryLogStore:
logS = transport.InMemoryTransportLogStore()
default:
err := fmt.Errorf("invalid log store type: %s", conf.LogStore.Type)
return err
}
logS := transport.InMemoryTransportLogStore()

tpMConf := transport.ManagerConfig{
PubKey: v.conf.PK,
Expand Down Expand Up @@ -402,7 +388,7 @@ func initLauncher(ctx context.Context, v *Visor, log *logging.Logger) error {
Apps: conf.Apps,
ServerAddr: conf.ServerAddr,
BinPath: conf.BinPath,
LocalPath: conf.LocalPath,
LocalPath: v.conf.LocalPath,
}

launchLog := v.MasterLogger().PackageLogger("launcher")
Expand Down
18 changes: 2 additions & 16 deletions pkg/visor/visorconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ func MakeBaseConfig(common *Common) *V1 {
conf.Transport = &V1Transport{
Discovery: skyenv.DefaultTpDiscAddr,
AddressResolver: skyenv.DefaultAddressResolverAddr,
LogStore: &V1LogStore{
Type: "memory",
},
}
conf.Routing = &V1Routing{
SetupNodes: []cipher.PubKey{skyenv.MustPK(skyenv.DefaultSetupPK)},
Expand All @@ -39,10 +36,10 @@ func MakeBaseConfig(common *Common) *V1 {
Apps: nil,
ServerAddr: skyenv.DefaultAppSrvAddr,
BinPath: skyenv.DefaultAppBinPath,
LocalPath: skyenv.DefaultAppLocalPath,
}
conf.CLIAddr = skyenv.DefaultRPCAddr
conf.LogLevel = skyenv.DefaultLogLevel
conf.LocalPath = skyenv.DefaultLocalPath
conf.ShutdownTimeout = DefaultTimeout
conf.RestartCheckDelay = Duration(restart.DefaultCheckDelay)
return conf
Expand Down Expand Up @@ -81,11 +78,6 @@ func defaultConfigFromCommon(cc *Common, hypervisor bool) (*V1, error) {
PKTable: nil,
}

conf.Transport.LogStore = &V1LogStore{
Type: "file",
Location: skyenv.DefaultTpLogStore,
}

conf.UptimeTracker = &V1UptimeTracker{
Addr: skyenv.DefaultUptimeTrackerAddr,
}
Expand Down Expand Up @@ -160,14 +152,8 @@ func MakePackageConfig(log *logging.MasterLogger, confPath string, sk *cipher.Se
CLINet: skyenv.DefaultDmsgPtyCLINet,
CLIAddr: skyenv.DefaultDmsgPtyCLIAddr,
}

conf.Transport.LogStore = &V1LogStore{
Type: "file",
Location: skyenv.PackageTpLogStore,
}

conf.LocalPath = skyenv.PackageLocalPath
conf.Launcher.BinPath = skyenv.PackageAppBinPath
conf.Launcher.LocalPath = skyenv.PackageAppLocalPath

if conf.Hypervisor != nil {
conf.Hypervisor.EnableAuth = skyenv.DefaultEnableAuth
Expand Down
9 changes: 2 additions & 7 deletions pkg/visor/visorconfig/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ func Parse(log *logging.MasterLogger, path string, raw []byte) (*V1, error) {

switch cc.Version {
// parse any v1-compatible version with v1 parse procedure
case V112Name:
fallthrough
case V111Name:
fallthrough
case V110Name:
fallthrough
case V100Name:
Expand All @@ -52,7 +48,6 @@ func Parse(log *logging.MasterLogger, path string, raw []byte) (*V1, error) {

func parseV1(cc *Common, raw []byte) (*V1, error) {
conf := MakeBaseConfig(cc)

dec := json.NewDecoder(bytes.NewReader(raw))
if err := dec.Decode(&conf); err != nil {
return nil, err
Expand All @@ -61,6 +56,7 @@ func parseV1(cc *Common, raw []byte) (*V1, error) {
if err := conf.ensureKeys(); err != nil {
return nil, fmt.Errorf("%v: %w", ErrInvalidSK, err)
}
conf.Version = V1Name
return conf, conf.flush(conf)
}

Expand Down Expand Up @@ -106,7 +102,6 @@ func parseV0(cc *Common, raw []byte) (*V1, error) {

if old.Transport != nil {
conf.Transport.Discovery = old.Transport.Discovery
conf.Transport.LogStore = old.Transport.LogStore
}

if old.Routing != nil {
Expand Down Expand Up @@ -142,8 +137,8 @@ func parseV0(cc *Common, raw []byte) (*V1, error) {

conf.Launcher.Apps = append(conf.Launcher.Apps, vpnApps...)

conf.LocalPath = old.LocalPath
conf.Launcher.BinPath = old.AppsPath
conf.Launcher.LocalPath = old.LocalPath
conf.Launcher.ServerAddr = old.AppServerAddr

for _, hv := range old.Hypervisors {
Expand Down
14 changes: 4 additions & 10 deletions pkg/visor/visorconfig/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,16 @@ const V100Name = "v1.0.0"

// V110Name is the semantic version string for v1.1.0.
// Added MinHops field to V1Routing section of config
const V110Name = "v1.1.0"

// V111Name is the semantic version string for v1.1.1.
// Removed public_trusted_visor field from root section
// Removed trusted_visors field from transport section
// Added is_public field to root section
// Added public_autoconnect field to transport section
const V111Name = "v1.1.1"

// V112Name is the semantic version string for v1.1.2.
// Added transport_setup_nodes field to transport section
const V112Name = "v1.1.2"
// Removed authorization_file field from dmsgpty section
const V110Name = "v1.1.0"

// V1Name is the semantic version string for the most recent version of V1.
const V1Name = V112Name
const V1Name = V110Name

// V1 is visor config
type V1 struct {
Expand All @@ -52,6 +47,7 @@ type V1 struct {
CLIAddr string `json:"cli_addr"`

LogLevel string `json:"log_level"`
LocalPath string `json:"local_path"`
ShutdownTimeout Duration `json:"shutdown_timeout,omitempty"` // time value, examples: 10s, 1m, etc
RestartCheckDelay Duration `json:"restart_check_delay,omitempty"` // time value, examples: 10s, 1m, etc
IsPublic bool `json:"is_public"`
Expand All @@ -70,7 +66,6 @@ type V1Dmsgpty struct {
type V1Transport struct {
Discovery string `json:"discovery"`
AddressResolver string `json:"address_resolver"`
LogStore *V1LogStore `json:"log_store"`
AutoconnectPublic bool `json:"public_autoconnect"`
TransportSetup []cipher.PubKey `json:"transport_setup_nodes"`
}
Expand Down Expand Up @@ -107,7 +102,6 @@ type V1Launcher struct {
Apps []launcher.AppConfig `json:"apps"`
ServerAddr string `json:"server_addr"`
BinPath string `json:"bin_path"`
LocalPath string `json:"local_path"`
}

// Flush flushes the config to file (if specified).
Expand Down

0 comments on commit 528bfcb

Please sign in to comment.