Skip to content

Commit

Permalink
Remove hardcoded defaults (#286)
Browse files Browse the repository at this point in the history
* fix var name

* eliminate hardcoded defaults in skywire utilities

* update vendored deps

* make format

* fix CI error

* fix ci errors
  • Loading branch information
0pcom authored Sep 22, 2024
1 parent dc25f3d commit ced25b3
Show file tree
Hide file tree
Showing 752 changed files with 211,371 additions and 70,087 deletions.
7 changes: 0 additions & 7 deletions cmd/dmsg-discovery/commands/dmsg-discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/skycoin/skywire-utilities/pkg/cmdutil"
"github.com/skycoin/skywire-utilities/pkg/logging"
"github.com/skycoin/skywire-utilities/pkg/metricsutil"
"github.com/skycoin/skywire-utilities/pkg/skyenv"
"github.com/spf13/cobra"

"github.com/skycoin/dmsg/internal/discmetrics"
Expand Down Expand Up @@ -124,12 +123,6 @@ skywire dmsg disc --sk $(tail -n1 dmsgd-config.json)`,
var whitelistPKs []string
if whitelistKeys != "" {
whitelistPKs = strings.Split(whitelistKeys, ",")
} else {
if testEnvironment {
whitelistPKs = strings.Split(skyenv.TestNetworkMonitorPKs, ",")
} else {
whitelistPKs = strings.Split(skyenv.NetworkMonitorPKs, ",")
}
}

for _, v := range whitelistPKs {
Expand Down
16 changes: 12 additions & 4 deletions cmd/dmsg-socks5/commands/dmsg-socks5.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package commands

import (
"context"
"encoding/json"
"fmt"
"log"
"net/http"
Expand All @@ -13,10 +14,10 @@ import (
"time"

socks5 "github.com/confiant-inc/go-socks5"
"github.com/skycoin/skywire"
"github.com/skycoin/skywire-utilities/pkg/buildinfo"
"github.com/skycoin/skywire-utilities/pkg/cipher"
"github.com/skycoin/skywire-utilities/pkg/logging"
"github.com/skycoin/skywire-utilities/pkg/skyenv"
"github.com/spf13/cobra"

"github.com/skycoin/dmsg/pkg/disc"
Expand All @@ -40,13 +41,20 @@ func Execute() {
}
}
func init() {
var envServices skywire.EnvServices
var services skywire.Services
if err := json.Unmarshal([]byte(skywire.ServicesJSON), &envServices); err == nil {
if err := json.Unmarshal(envServices.Prod, &services); err == nil {
dmsgDisc = services.DmsgDiscovery
}
}
RootCmd.AddCommand(
serveCmd,
proxyCmd,
)
serveCmd.Flags().Uint16VarP(&dmsgPort, "dport", "q", 1081, "dmsg port to serve socks5")
serveCmd.Flags().StringVarP(&wl, "wl", "w", "", "whitelist keys, comma separated")
serveCmd.Flags().StringVarP(&dmsgDisc, "dmsg-disc", "D", skyenv.DmsgDiscAddr, "dmsg discovery url")
serveCmd.Flags().StringVarP(&dmsgDisc, "dmsg-disc", "D", dmsgDisc, "dmsg discovery url")
if os.Getenv("DMSGSK") != "" {
sk.Set(os.Getenv("DMSGSK")) //nolint
}
Expand All @@ -55,7 +63,7 @@ func init() {
proxyCmd.Flags().IntVarP(&proxyPort, "port", "p", 1081, "TCP port to serve SOCKS5 proxy locally")
proxyCmd.Flags().Uint16VarP(&dmsgPort, "dport", "q", 1081, "dmsg port to connect to socks5 server")
proxyCmd.Flags().StringVarP(&pubk, "pk", "k", "", "dmsg socks5 proxy server public key to connect to")
proxyCmd.Flags().StringVarP(&dmsgDisc, "dmsg-disc", "D", skyenv.DmsgDiscAddr, "dmsg discovery url")
proxyCmd.Flags().StringVarP(&dmsgDisc, "dmsg-disc", "D", dmsgDisc, "dmsg discovery url")
if os.Getenv("DMSGSK") != "" {
sk.Set(os.Getenv("DMSGSK")) //nolint
}
Expand Down Expand Up @@ -181,7 +189,7 @@ var proxyCmd = &cobra.Command{
if err != nil {
pk, sk = cipher.GenerateKeyPair()
}
initC := dmsg.NewClient(pk, sk, disc.NewHTTP(skyenv.DmsgDiscAddr, &http.Client{}, log), dmsg.DefaultConfig())
initC := dmsg.NewClient(pk, sk, disc.NewHTTP(dmsgDisc, &http.Client{}, log), dmsg.DefaultConfig())
go initC.Serve(context.Background())
initL, err := initC.Listen(dmsgPort)
if err != nil {
Expand Down
21 changes: 14 additions & 7 deletions cmd/dmsgcurl/commands/dmsgcurl.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package commands

import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
Expand All @@ -17,11 +18,11 @@ import (
"time"

"github.com/sirupsen/logrus"
"github.com/skycoin/skywire"
"github.com/skycoin/skywire-utilities/pkg/buildinfo"
"github.com/skycoin/skywire-utilities/pkg/cipher"
"github.com/skycoin/skywire-utilities/pkg/cmdutil"
"github.com/skycoin/skywire-utilities/pkg/logging"
"github.com/skycoin/skywire-utilities/pkg/skyenv"
"github.com/spf13/cobra"

"github.com/skycoin/dmsg/pkg/disc"
Expand All @@ -45,7 +46,14 @@ var (
)

func init() {
RootCmd.Flags().StringVarP(&dmsgDisc, "dmsg-disc", "c", "", "dmsg discovery url default:\n"+skyenv.DmsgDiscAddr)
var envServices skywire.EnvServices
var services skywire.Services
if err := json.Unmarshal([]byte(skywire.ServicesJSON), &envServices); err == nil {
if err := json.Unmarshal(envServices.Prod, &services); err == nil {
dmsgDisc = services.DmsgDiscovery
}
}
RootCmd.Flags().StringVarP(&dmsgDisc, "dmsg-disc", "c", dmsgDisc, "dmsg discovery url")
RootCmd.Flags().IntVarP(&dmsgSessions, "sess", "e", 1, "number of dmsg servers to connect to")
RootCmd.Flags().StringVarP(&logLvl, "loglvl", "l", "fatal", "[ debug | warn | error | fatal | panic | trace | info ]\033[0m")
RootCmd.Flags().StringVarP(&dmsgcurlData, "data", "d", "", "dmsghttp POST data")
Expand Down Expand Up @@ -77,11 +85,7 @@ DMSG curl utility`,
DisableSuggestions: true,
DisableFlagsInUseLine: true,
Version: buildinfo.Version(),
PreRun: func(cmd *cobra.Command, args []string) {
if dmsgDisc == "" {
dmsgDisc = skyenv.DmsgDiscAddr
}
},

RunE: func(cmd *cobra.Command, args []string) error {
if dmsgcurlLog == nil {
dmsgcurlLog = logging.MustGetLogger("dmsgcurl")
Expand All @@ -91,6 +95,9 @@ DMSG curl utility`,
logging.SetLevel(lvl)
}
}
if dmsgDisc == "" {
dmsgcurlLog.Fatal("Dmsg Discovery URL not specified")
}

ctx, cancel := cmdutil.SignalContext(context.Background(), dmsgcurlLog)
defer cancel()
Expand Down
13 changes: 5 additions & 8 deletions cmd/dmsghttp/commands/dmsghttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/skycoin/skywire-utilities/pkg/cipher"
"github.com/skycoin/skywire-utilities/pkg/cmdutil"
"github.com/skycoin/skywire-utilities/pkg/logging"
"github.com/skycoin/skywire-utilities/pkg/skyenv"
"github.com/spf13/cobra"

"github.com/skycoin/dmsg/pkg/disc"
Expand All @@ -38,7 +37,7 @@ func init() {
RootCmd.Flags().StringVarP(&serveDir, "dir", "d", ".", "local dir to serve via dmsghttp")
RootCmd.Flags().UintVarP(&dmsgPort, "port", "p", 80, "dmsg port to serve from")
RootCmd.Flags().StringVarP(&wl, "wl", "w", "", "whitelist keys, comma separated")
RootCmd.Flags().StringVarP(&dmsgDisc, "dmsg-disc", "D", "", "dmsg discovery url default:\n"+skyenv.DmsgDiscAddr)
RootCmd.Flags().StringVarP(&dmsgDisc, "dmsg-disc", "D", dmsg.DiscAddr(false), "dmsg discovery url")
if os.Getenv("DMSGHTTP_SK") != "" {
sk.Set(os.Getenv("DMSGHTTP_SK")) //nolint
}
Expand All @@ -62,14 +61,12 @@ DMSG http file server`,
DisableSuggestions: true,
DisableFlagsInUseLine: true,
Version: buildinfo.Version(),
PreRun: func(cmd *cobra.Command, args []string) {
if dmsgDisc == "" {
dmsgDisc = skyenv.DmsgDiscAddr
}
},

Run: func(cmd *cobra.Command, args []string) {
log := logging.MustGetLogger("dmsghttp")

if dmsgDisc == "" {
log.Fatal("Dmsg Discovery URL not specified")
}
ctx, cancel := cmdutil.SignalContext(context.Background(), log)
defer cancel()
pk, err := sk.PubKey()
Expand Down
4 changes: 2 additions & 2 deletions cmd/dmsgpty-host/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var json = jsoniter.ConfigFastest
// variables
var (
// persistent flags
dmsgDisc = dmsg.DefaultDiscAddr
dmsgDisc = dmsg.DiscAddr(false)
dmsgSessions = dmsg.DefaultMinSessions
dmsgPort = dmsgpty.DefaultPort
cliNet = dmsgpty.DefaultCLINet
Expand Down Expand Up @@ -275,7 +275,7 @@ func fillConfigFromENV(conf dmsgpty.Config) (dmsgpty.Config, error) {
}

func fillConfigFromFlags(conf dmsgpty.Config) dmsgpty.Config {
if dmsgDisc != dmsg.DefaultDiscAddr {
if dmsgDisc != dmsg.DiscAddr(false) {
conf.DmsgDisc = dmsgDisc
}

Expand Down
9 changes: 5 additions & 4 deletions cmd/dmsgweb/commands/dmsgweb.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/skycoin/skywire-utilities/pkg/cipher"
"github.com/skycoin/skywire-utilities/pkg/cmdutil"
"github.com/skycoin/skywire-utilities/pkg/logging"
"github.com/skycoin/skywire-utilities/pkg/skyenv"
"github.com/spf13/cobra"
"golang.org/x/net/proxy"

Expand Down Expand Up @@ -56,13 +55,12 @@ const dmsgwebenvname = "DMSGWEB"
var dmsgwebconffile = os.Getenv(dmsgwebenvname)

func init() {

RootCmd.Flags().StringVarP(&filterDomainSuffix, "filter", "f", ".dmsg", "domain suffix to filter")
RootCmd.Flags().UintVarP(&proxyPort, "socks", "q", scriptExecUint("${PROXYPORT:-4445}", dmsgwebconffile), "port to serve the socks5 proxy")
RootCmd.Flags().StringVarP(&addProxy, "proxy", "r", scriptExecString("${ADDPROXY}", dmsgwebconffile), "configure additional socks5 proxy for dmsgweb (i.e. 127.0.0.1:1080)")
RootCmd.Flags().UintSliceVarP(&webPort, "port", "p", scriptExecUintSlice("${WEBPORT[@]:-8080}", dmsgwebconffile), "port(s) to serve the web application")
RootCmd.Flags().StringSliceVarP(&resolveDmsgAddr, "resolve", "t", scriptExecStringSlice("${RESOLVEPK[@]}", dmsgwebconffile), "resolve the specified dmsg address:port on the local port & disable proxy")
RootCmd.Flags().StringVarP(&dmsgDisc, "dmsg-disc", "d", skyenv.DmsgDiscAddr, "dmsg discovery url")
RootCmd.Flags().StringVarP(&dmsgDisc, "dmsg-disc", "d", dmsg.DiscAddr(false), "dmsg discovery url")
RootCmd.Flags().IntVarP(&dmsgSessions, "sess", "e", scriptExecInt("${DMSGSESSIONS:-1}", dmsgwebconffile), "number of dmsg servers to connect to")
RootCmd.Flags().BoolSliceVarP(&rawTCP, "rt", "c", scriptExecBoolSlice("${RAWTCP[@]:-false}", dmsgwebconffile), "proxy local port as raw TCP")
RootCmd.Flags().StringVarP(&logLvl, "loglvl", "l", "", "[ debug | warn | error | fatal | panic | trace | info ]\033[0m")
Expand Down Expand Up @@ -132,6 +130,9 @@ dmsgweb conf file detected: ` + dmsgwebconffile
logging.SetLevel(lvl)
}
}
if dmsgDisc == "" {
dmsgWebLog.Fatal("Dmsg Discovery URL not specified")
}

if len(resolveDmsgAddr) > 0 && len(webPort) != len(resolveDmsgAddr) {
dmsgWebLog.Fatal("-resolve --t flag cannot contain a different number of elements than -port -p flag")
Expand Down Expand Up @@ -168,7 +169,7 @@ dmsgweb conf file detected: ` + dmsgwebconffile
dmsgWebLog.Fatal("domain suffix to filter cannot be an empty string")
}
if dmsgDisc == "" {
dmsgDisc = skyenv.DmsgDiscAddr
dmsgDisc = dmsg.DiscAddr(false)
}
ctx, cancel := cmdutil.SignalContext(context.Background(), dmsgWebLog)
defer cancel()
Expand Down
3 changes: 1 addition & 2 deletions cmd/dmsgweb/commands/dmsgwebsrv.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/skycoin/skywire-utilities/pkg/cipher"
"github.com/skycoin/skywire-utilities/pkg/cmdutil"
"github.com/skycoin/skywire-utilities/pkg/logging"
"github.com/skycoin/skywire-utilities/pkg/skyenv"
"github.com/spf13/cobra"

"github.com/skycoin/dmsg/pkg/disc"
Expand All @@ -36,7 +35,7 @@ func init() {
srvCmd.Flags().UintSliceVarP(&localPort, "lport", "l", scriptExecUintSlice("${LOCALPORT[@]:-8086}", dmsgwebsrvconffile), "local application http interface port(s)")
srvCmd.Flags().UintSliceVarP(&dmsgPort, "dport", "d", scriptExecUintSlice("${DMSGPORT[@]:-80}", dmsgwebsrvconffile), "dmsg port(s) to serve")
srvCmd.Flags().StringSliceVarP(&wl, "wl", "w", scriptExecStringSlice("${WHITELISTPKS[@]}", dmsgwebsrvconffile), "whitelisted keys for dmsg authenticated routes\r")
srvCmd.Flags().StringVarP(&dmsgDisc, "dmsg-disc", "D", skyenv.DmsgDiscAddr, "dmsg discovery url")
srvCmd.Flags().StringVarP(&dmsgDisc, "dmsg-disc", "D", dmsg.DiscAddr(false), "dmsg discovery url")
srvCmd.Flags().IntVarP(&dmsgSess, "dsess", "e", scriptExecInt("${DMSGSESSIONS:-1}", dmsgwebsrvconffile), "dmsg sessions")
srvCmd.Flags().BoolSliceVarP(&rawTCP, "rt", "c", scriptExecBoolSlice("${RAWTCP[@]:-false}", dmsgwebsrvconffile), "proxy local port as raw TCP")
if os.Getenv("DMSGWEBSRVSK") != "" {
Expand Down
49 changes: 27 additions & 22 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ toolchain go1.21.4

require (
github.com/ActiveState/termtest/conpty v0.5.0
github.com/VictoriaMetrics/metrics v1.18.1
github.com/VictoriaMetrics/metrics v1.24.0
github.com/bitfield/script v0.22.1
github.com/confiant-inc/go-socks5 v0.0.0-20210816151940-c1124825b1d6
github.com/creack/pty v1.1.18
Expand All @@ -17,59 +17,64 @@ require (
github.com/ivanpirog/coloredcobra v1.0.1
github.com/json-iterator/go v1.1.12
github.com/pires/go-proxyproto v0.6.2
github.com/sirupsen/logrus v1.8.1
github.com/sirupsen/logrus v1.9.3
github.com/skycoin/noise v0.0.0-20180327030543-2492fe189ae6
github.com/skycoin/skycoin v0.27.1
github.com/skycoin/skywire v1.3.26-0.20240922162315-789cef41c9a1
github.com/skycoin/skywire-utilities v1.3.25
github.com/spf13/cobra v1.4.0
github.com/stretchr/testify v1.8.3
golang.org/x/net v0.10.0
golang.org/x/sys v0.10.0
golang.org/x/term v0.8.0
nhooyr.io/websocket v1.8.2
github.com/spf13/cobra v1.7.0
github.com/stretchr/testify v1.9.0
golang.org/x/net v0.21.0
golang.org/x/sys v0.20.0
golang.org/x/term v0.17.0
nhooyr.io/websocket v1.8.7
)

require (
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/bytedance/sonic v1.10.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.14.0 // indirect
github.com/go-playground/validator/v10 v10.15.1 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/itchyny/gojq v0.12.13 // indirect
github.com/itchyny/timefmt-go v0.1.5 // indirect
github.com/klauspost/compress v1.11.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pelletier/go-toml/v2 v2.0.9 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/valyala/fastrand v1.1.0 // indirect
github.com/valyala/histogram v1.2.0 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/text v0.9.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
golang.org/x/arch v0.4.0 // indirect
golang.org/x/crypto v0.20.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
mvdan.cc/sh/v3 v3.7.0 // indirect
)

// Uncomment for tests with alternate branches of 'skywire-utilities'
//replace github.com/skycoin/skywire => ../skywire
//replace github.com/skycoin/skywire => github.com/skycoin/skywire <commit-hash>

// replace github.com/skycoin/skywire-utilities => ../skywire-utilities
// replace github.com/skycoin/skywire-utilities => github.com/skycoin/skywire-utilities
Loading

0 comments on commit ced25b3

Please sign in to comment.