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

source a .conf file with skywire-cli config gen #1644

Merged
merged 43 commits into from
Jul 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
0219ce8
add explicit dmsgpty whitelist
0pcom May 13, 2023
30d4055
add WIP env detection to skywire-cli config gen
0pcom May 14, 2023
2136e61
stashing changes
0pcom May 15, 2023
28cf999
add whitelist for survey collecton over dmsghttp
0pcom May 15, 2023
7f5f6a7
Merge branch 'dmsghttp-wl' into config-envs
0pcom May 15, 2023
13d67d6
small fixes and formatting optimizations
0pcom May 15, 2023
cc0f8b0
make format
0pcom May 15, 2023
598a398
add nolint
0pcom May 15, 2023
f4a5b85
remove unused variable, use print-style function instead of printf-style
0pcom May 15, 2023
664b652
merge develop
0pcom May 19, 2023
1c6cd55
update config gen with more flags ; support survey whitelist, route &…
0pcom May 21, 2023
68adf7b
update vendor
0pcom May 21, 2023
22a5d5c
update vendor
0pcom May 21, 2023
8eb076e
update vendor dependencies and go.mod
0pcom May 22, 2023
9728b5b
add error checks, comments
0pcom May 22, 2023
bb13cd4
fix merge conflicts
0pcom May 22, 2023
26ee1f8
update vendor
0pcom May 22, 2023
7662a3d
fix vendor deps & update go.mod
0pcom May 22, 2023
e19f5de
make format & fix test error
0pcom May 22, 2023
4361174
remove viper from config gen
0pcom May 23, 2023
9a3e04e
make format
0pcom May 23, 2023
289b167
prepare to revert some changes
0pcom May 23, 2023
93a7f7e
prepare to revert some changes
0pcom May 23, 2023
f9df75d
fix panic on visor startup
0pcom May 23, 2023
e94d07b
fix ci errors
0pcom May 23, 2023
3287ca4
fix ci errors
0pcom May 23, 2023
15fc1c6
fix golangci-lint errors for version 1.52.1
0pcom May 23, 2023
7a7cdab
update golangci-lint version used by github-actions CI in test workfl…
0pcom May 23, 2023
5174f48
fix CI darwin error
0pcom May 23, 2023
d10f37d
update excluded
0pcom May 25, 2023
e83c489
make format check
0pcom Jun 26, 2023
b82ae84
merge develop ; fix merge conflicts
0pcom Jun 26, 2023
b7ee62a
update go.mod & go.sum
0pcom Jun 26, 2023
41d020f
make format check ; merge develop
0pcom Jun 26, 2023
af06f99
remove unneeded file
0pcom Jun 27, 2023
8c6ad68
change vars to consts
0pcom Jun 28, 2023
e6a04cc
remove comment
0pcom Jun 28, 2023
76ed7c0
use http.Get
0pcom Jun 28, 2023
2e8ded5
require 1 argument for config check-pk
0pcom Jun 28, 2023
0057b42
include accidentally omitted
0pcom Jul 9, 2023
4af35ae
revert skywire-cli ut to previous state
0pcom Jul 9, 2023
8343527
merge develop & fix merge conflicts. remove comments
0pcom Jul 9, 2023
1da8eb6
update go.mod ; make format check
0pcom Jul 9, 2023
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
196 changes: 167 additions & 29 deletions cmd/skywire-cli/commands/config/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,18 @@ func init() {
genConfigCmd.Flags().BoolVar(&isAll, "all", false, "show all flags")
genConfigCmd.Flags().StringVar(&binPath, "binpath", scriptExecString("${BINPATH}"), "set bin_path\033[0m")
gHiddenFlags = append(gHiddenFlags, "binpath")
// genConfigCmd.Flags().StringVar(&addSkysocksClientSrv, "proxyclientpk", scriptExecString("${PROXYCLIENTPK}"), "set server public key for proxy client")
// genConfigCmd.Flags().BoolVar(&proxyClientAutostart, "startproxyclient", scriptExecBool("${STARTPROXYCLIENT:-false}"), "autostart proxy client")
// genConfigCmd.Flags().BoolVar(&disableProxyServerAutostart, "noproxyserver", scriptExecBool("${NOPROXYSERVER:-false}"), "disable autostart of proxy server")
// genConfigCmd.Flags().StringVar(&proxyServerPass, "proxyserverpass", "", "set password for the proxy server")
// genConfigCmd.Flags().StringVar(&proxyClientPass, "proxyclientpass", "", "set password for the proxy client to access the proxy server (if needed)")
// // TODO: Password for accessing proxy client
// genConfigCmd.Flags().StringVar(&setVPNClientKillswitch, "killsw", "", "vpn client killswitch")
// genConfigCmd.Flags().StringVar(&addVPNClientSrv, "addvpn", "", "set vpn server public key for vpn client")
// genConfigCmd.Flags().StringVar(&addVPNClientPasscode, "vpnpass", "", "password for vpn client to access the vpn server (if needed)")
// genConfigCmd.Flags().StringVar(&addVPNServerPasscode, "vpnserverpass", "", "set password to the vpn server")
// genConfigCmd.Flags().StringVar(&setVPNServerSecure, "secure", "", "change secure mode status of vpn server")
// genConfigCmd.Flags().StringVar(&setVPNServerNetIfc, "netifc", "", "VPN Server network interface (detected: "+getInterfaceNames()+")")
genConfigCmd.Flags().StringVar(&addSkysocksClientSrv, "proxyclientpk", scriptExecString("${PROXYCLIENTPK}"), "set server public key for proxy client")
genConfigCmd.Flags().BoolVar(&enableProxyClientAutostart, "startproxyclient", scriptExecBool("${STARTPROXYCLIENT:-false}"), "autostart proxy client")
genConfigCmd.Flags().BoolVar(&disableProxyServerAutostart, "noproxyserver", scriptExecBool("${NOPROXYSERVER:-false}"), "disable autostart of proxy server")
genConfigCmd.Flags().StringVar(&proxyServerPass, "proxyserverpass", scriptExecString("${PROXYSEVERPASS}"), "set proxy server password")
genConfigCmd.Flags().StringVar(&proxyClientPass, "proxyclientpass", scriptExecString("${PROXYCLIENTPASS}"), "password for the proxy client to access the server (if needed)")
// TODO: Password for accessing proxy client
genConfigCmd.Flags().StringVar(&setVPNClientKillswitch, "killsw", scriptExecString("${VPNKS}"), "vpn client killswitch")
genConfigCmd.Flags().StringVar(&addVPNClientSrv, "addvpn", scriptExecString("${ADDVPNPK}"), "set vpn server public key for vpn client")
genConfigCmd.Flags().StringVar(&addVPNClientPasscode, "vpnpass", scriptExecString("${VPNCLIENTPASS}"), "password for vpn client to access the vpn server (if needed)")
genConfigCmd.Flags().StringVar(&addVPNServerPasscode, "vpnserverpass", scriptExecString("${VPNSEVERPASS}"), "set password to the vpn server")
genConfigCmd.Flags().StringVar(&setVPNServerSecure, "secure", scriptExecString("${VPNSEVERSECURE}"), "change secure mode status of vpn server")
genConfigCmd.Flags().StringVar(&setVPNServerNetIfc, "netifc", scriptExecString("${VPNSEVERNETIFC}"), "VPN Server network interface (detected: "+getInterfaceNames()+")")
genConfigCmd.Flags().BoolVarP(&isEnvs, "envs", "q", false, "show the environmental variable settings")
gHiddenFlags = append(gHiddenFlags, "envs")
genConfigCmd.Flags().BoolVar(&noFetch, "nofetch", false, "do not fetch the services from the service conf url")
Expand Down Expand Up @@ -497,24 +497,23 @@ var genConfigCmd = &cobra.Command{
log.WithError(err).Error("Failed to fetch servers\n")
log.Warn("Falling back on hardcoded servers")
}
} else {
// nil error from client.Get
if res.Body != nil {
defer res.Body.Close() //nolint
}
body, err := io.ReadAll(res.Body)
if err != nil {
log.WithError(err).Fatal("Failed to read response\n")
}
//fill in services struct with the response
err = json.Unmarshal(body, &services)
if err != nil {
log.WithError(err).Fatal("Failed to unmarshal json response\n")
}
if !isStdout {
log.Infof("Fetched service endpoints from '%s'", serviceConfURL)
}
}
if res.Body != nil {
defer res.Body.Close() //nolint
}
body, err := io.ReadAll(res.Body)
if err != nil {
log.WithError(err).Fatal("Failed to read response\n")
}
//fill in services struct with the response
err = json.Unmarshal(body, &services)
if err != nil {
log.WithError(err).Fatal("Failed to unmarshal json response\n")
}
if !isStdout {
log.Infof("Fetched service endpoints from '%s'", serviceConfURL)
}

// reset the state of isStdout
isStdout = wasStdout
}
Expand Down Expand Up @@ -990,6 +989,79 @@ var genConfigCmd = &cobra.Command{
newConfLauncherApps := append(conf.Launcher.Apps, exampleApps...)
conf.Launcher.Apps = newConfLauncherApps
}

if addVPNServerPasscode != "" {
changeAppsConfig(conf, "vpn-server", "--passcode", addVPNServerPasscode)
}
if setVPNServerNetIfc != "" {
changeAppsConfig(conf, "vpn-server", "--netifc", setVPNServerNetIfc)
}
switch setVPNServerSecure {
case "true":
changeAppsConfig(conf, "vpn-server", "--secure", setVPNServerSecure)
case "false":
changeAppsConfig(conf, "vpn-server", "--secure", setVPNServerSecure)
}
switch setVPNServerAutostart {
case "true":
for i, app := range conf.Launcher.Apps {
if app.Name == "vpn-server" {
conf.Launcher.Apps[i].AutoStart = true
}
}
case "false":
for i, app := range conf.Launcher.Apps {
if app.Name == "vpn-server" {
conf.Launcher.Apps[i].AutoStart = false
}
}
}

switch setVPNClientKillswitch {
case "true":
changeAppsConfig(conf, "vpn-client", "--killswitch", setVPNClientKillswitch)
case "false":
changeAppsConfig(conf, "vpn-client", "--killswitch", setVPNClientKillswitch)
}
if addVPNClientSrv != "" {
keyParsed, err := coinCipher.PubKeyFromHex(strings.TrimSpace(addVPNClientSrv))
if err != nil {
log.WithError(err).Fatalf("Failed to parse hypervisor private key: %s.", addVPNClientSrv)
}
changeAppsConfig(conf, "vpn-client", "--srv", keyParsed.Hex())
}

if addVPNClientPasscode != "" {
changeAppsConfig(conf, "vpn-client", "--passcode", addVPNClientPasscode)
}
if addSkysocksClientSrv != "" {
keyParsed, err := coinCipher.PubKeyFromHex(strings.TrimSpace(addSkysocksClientSrv))
if err != nil {
logger.WithError(err).Fatalf("Failed to parse public key: %s.", addSkysocksClientSrv)
}
changeAppsConfig(conf, "skysocks-client", "--srv", keyParsed.Hex())
}
if proxyServerPass != "" {
changeAppsConfig(conf, "skysocks", "--passcode", proxyServerPass)
}
if proxyClientPass != "" {
changeAppsConfig(conf, "skysocks-client", "--passcode", proxyClientPass)
}

if disableProxyServerAutostart {
for i, app := range conf.Launcher.Apps {
if app.Name == "skysocks" {
conf.Launcher.Apps[i].AutoStart = false
}
}
}
if enableProxyClientAutostart {
for i, app := range conf.Launcher.Apps {
if app.Name == "skysocks-client" {
conf.Launcher.Apps[i].AutoStart = true
}
}
}
if isHypervisor {
// Disable hypervisor UI authentication --disable-auth flag
if isDisableAuth {
Expand Down Expand Up @@ -1152,6 +1224,40 @@ const envfileLinux = `#
#-- Set app bin_path
#BINPATH='./apps'

#-- Set server public key for proxy client to connect to
#PROXYCLIENTPK=''

#-- Enable autostart of the proxy client
#STARTPROXYCLIENT=true

#-- Disable autostart of proxy server
#NOPROXYSERVER=true

#-- Set a password for the proxy server
#PROXYSEVERPASS=''

#-- Password for the proxy client to access the server (if password is set for the server)
#PROXYCLIENTPASS=''

#-- Set VPN client killswitch
#VPNKS=true

#-- Set vpn server public key for the vpn client to use
#ADDVPNPK=''

#-- Password for vpn client to access the server (if password is set forthe server)
#VPNCLIENTPASS=''

#-- Set password to the vpn server
#VPNSEVERPASS=''

#-- Change secure mode status of vpn server
#VPNSEVERSECURE=''

#-- Set VPN Server network interface
#VPNSEVERNETIFC=''


`
const envfileWindows = `#
# C:\ProgramData\skywire.ps1
Expand Down Expand Up @@ -1218,4 +1324,36 @@ const envfileWindows = `#
#-- Set app bin_path
#$BINPATH='./apps'

#-- Set server public key for proxy client to connect to
#$PROXYCLIENTPK=''

#-- Enable autostart of the proxy client
#$STARTPROXYCLIENT=true

#-- Disable autostart of proxy server
#$NOPROXYSERVER=true

#-- Set a password for the proxy server
#$PROXYSEVERPASS=''

#-- Password for the proxy client to access the server (if password is set for the server)
#$PROXYCLIENTPASS=''

#-- Set VPN client killswitch
#$VPNKS=true

#-- Set vpn server public key for the vpn client to use
#$ADDVPNPK=''

#-- Password for vpn client to access the server (if password is set forthe server)
#$VPNCLIENTPASS=''

#-- Set password to the vpn server
#$VPNSEVERPASS=''

#-- Change secure mode status of vpn server
#$VPNSEVERSECURE=''

#-- Set VPN Server network interface
#$VPNSEVERNETIFC=''
`
142 changes: 71 additions & 71 deletions cmd/skywire-cli/commands/config/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,83 +15,83 @@ import (

var logger = logging.MustGetLogger("skywire-cli")

// proxyClientAutostart bool //nolint Note: pending implementation for config gen
// disableProxyServerAutostart bool //nolint Note: pending implementation for config gen
// proxyServerPass string //nolint Note: pending implementation for config gen
// proxyClientPass string //nolint Note: pending implementation for config gen
var (
conf = new(visorconfig.V1)
dmsgHTTPServersList = &visorconfig.DmsgHTTPServers{
Test: visorconfig.DmsgHTTPServersData{DMSGServers: []*disc.Entry{}},
Prod: visorconfig.DmsgHTTPServersData{DMSGServers: []*disc.Entry{}},
}
noFetch bool
noDefaults bool
stcprPort int
sudphPort int
sk cipher.SecKey
output string
confPath string
configName string //nolint Note: configName used, but golangci-lint marked it unused in wrong
isStdout bool
isRegen bool
isRetainHypervisors bool
isTestEnv bool
pText string
isPkgEnv bool
isUsrEnv bool
isHypervisor bool
hypervisorPKs string
dmsgptyWlPKs string
surveyWhitelistPKs string
routeSetupNodes string
transportSetupPKs string
isDmsgHTTP bool
isVpnServerEnable bool
isDisableAuth bool
isEnableAuth bool
selectedOS string
disableApps string
isBestProtocol bool
serviceConfURL string
services *visorconfig.Services
isForce bool
isHide bool
isAll bool
isOutUnset bool
ver string
isRoot = visorconfig.IsRoot()
svcConf = strings.ReplaceAll(utilenv.ServiceConfAddr, "http://", "") //visorconfig.DefaultServiceConfAddr
testConf = strings.ReplaceAll(utilenv.TestServiceConfAddr, "http://", "") //visorconfig.DefaultServiceConfAddr
gHiddenFlags []string
uHiddenFlags []string
binPath string
logLevel string
isPkg bool
input string
isUpdateEndpoints bool
addHypervisorPKs string
isResetHypervisor bool
setVPNClientKillswitch string
addVPNClientSrv string
addVPNClientPasscode string
isResetVPNclient bool
addVPNServerPasscode string
setVPNServerSecure string
setVPNServerAutostart string
setVPNServerNetIfc string
isResetVPNServer bool
addSkysocksClientSrv string
isResetSkysocksClient bool
skysocksPasscode string
isResetSkysocks bool
setPublicAutoconnect string
minHops int
isUsr bool
isPublic bool
disablePublicAutoConn bool
isDisplayNodeIP bool
addExampleApps bool
noFetch bool
noDefaults bool
stcprPort int
sudphPort int
sk cipher.SecKey
output string
confPath string
configName string //nolint Note: configName used, but golangci-lint marked it unused in wrong
isStdout bool
isRegen bool
isRetainHypervisors bool
isTestEnv bool
pText string
isPkgEnv bool
isUsrEnv bool
isHypervisor bool
hypervisorPKs string
dmsgptyWlPKs string
surveyWhitelistPKs string
routeSetupNodes string
transportSetupPKs string
isDmsgHTTP bool
isVpnServerEnable bool
isDisableAuth bool
isEnableAuth bool
selectedOS string
disableApps string
isBestProtocol bool
serviceConfURL string
services *visorconfig.Services
isForce bool
isHide bool
isAll bool
isOutUnset bool
ver string
isRoot = visorconfig.IsRoot()
svcConf = strings.ReplaceAll(utilenv.ServiceConfAddr, "http://", "") //visorconfig.DefaultServiceConfAddr
testConf = strings.ReplaceAll(utilenv.TestServiceConfAddr, "http://", "") //visorconfig.DefaultServiceConfAddr
gHiddenFlags []string
uHiddenFlags []string
binPath string
logLevel string
isPkg bool
input string
isUpdateEndpoints bool
addHypervisorPKs string
isResetHypervisor bool
setVPNClientKillswitch string
addVPNClientSrv string
addVPNClientPasscode string
isResetVPNclient bool
addVPNServerPasscode string
setVPNServerSecure string
setVPNServerAutostart string
setVPNServerNetIfc string
isResetVPNServer bool
addSkysocksClientSrv string
isResetSkysocksClient bool
skysocksPasscode string
isResetSkysocks bool
setPublicAutoconnect string
minHops int
isUsr bool
isPublic bool
disablePublicAutoConn bool
isDisplayNodeIP bool
addExampleApps bool
enableProxyClientAutostart bool
disableProxyServerAutostart bool
proxyServerPass string
proxyClientPass string
)

// RootCmd contains commands that interact with the config of local skywire-visor
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ require (
github.com/lib/pq v1.10.7
github.com/orandin/lumberjackrus v1.0.1
github.com/pterm/pterm v0.12.49
github.com/skycoin/dmsg v1.3.0-rc1.0.20230609193507-b02bb8f7d1bc
github.com/skycoin/skywire-utilities v0.0.0-20230601232053-0abbc9604fbc
github.com/skycoin/dmsg v1.3.11
github.com/skycoin/skywire-utilities v0.0.0-20230609191923-1e678802e17e
github.com/skycoin/systray v1.10.0
github.com/spf13/pflag v1.0.5
github.com/zcalusic/sysinfo v0.9.5
Expand Down
Loading
Loading