Skip to content

Commit

Permalink
eliminate hardcoded defaults in skywire utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
0pcom committed Sep 21, 2024
1 parent 4950ac4 commit bc0bba7
Show file tree
Hide file tree
Showing 749 changed files with 211,286 additions and 70,084 deletions.
11 changes: 1 addition & 10 deletions cmd/dmsghttp/commands/dmsghttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package commands

import (
"context"
"encoding/json"
"fmt"
"log"
"mime"
Expand All @@ -15,7 +14,6 @@ import (
"strings"
"time"

"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"
Expand All @@ -36,17 +34,10 @@ var (
)

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.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", dmsgDisc, "dmsg discovery url")
RootCmd.Flags().StringVarP(&dmsgDisc, "dmsg-disc", "D", dmsg.DmsgDiscAddr(false), "dmsg discovery url")
if os.Getenv("DMSGHTTP_SK") != "" {
sk.Set(os.Getenv("DMSGHTTP_SK")) //nolint
}
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.DmsgDiscAddr(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.DmsgDiscAddr(false) {
conf.DmsgDisc = dmsgDisc
}

Expand Down
14 changes: 2 additions & 12 deletions cmd/dmsgweb/commands/dmsgweb.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package commands

import (
"context"
"encoding/json"
"fmt"
"io"
"log"
Expand All @@ -21,12 +20,10 @@ import (
"github.com/bitfield/script"
"github.com/confiant-inc/go-socks5"
"github.com/gin-gonic/gin"
"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"
"golang.org/x/net/proxy"

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

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.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", dmsgDisc, "dmsg discovery url")
RootCmd.Flags().StringVarP(&dmsgDisc, "dmsg-disc", "d", dmsg.DmsgDiscAddr(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 @@ -179,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.DmsgDiscAddr(false)
}
ctx, cancel := cmdutil.SignalContext(context.Background(), dmsgWebLog)
defer cancel()
Expand Down
11 changes: 1 addition & 10 deletions cmd/dmsgweb/commands/dmsgwebsrv.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package commands

import (
"context"
"encoding/json"
"fmt"
"io"
"net"
Expand All @@ -18,7 +17,6 @@ import (

"github.com/bitfield/script"
"github.com/gin-gonic/gin"
"github.com/skycoin/skywire"
"github.com/skycoin/skywire-utilities/pkg/cipher"
"github.com/skycoin/skywire-utilities/pkg/cmdutil"
"github.com/skycoin/skywire-utilities/pkg/logging"
Expand All @@ -33,18 +31,11 @@ const dmsgwebsrvenvname = "DMSGWEBSRV"
var dmsgwebsrvconffile = os.Getenv(dmsgwebsrvenvname)

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(srvCmd)
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", dmsgDisc, "dmsg discovery url")
srvCmd.Flags().StringVarP(&dmsgDisc, "dmsg-disc", "D", dmsg.DmsgDiscAddr(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
48 changes: 26 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,63 @@ 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 v0.0.0-00010101000000-000000000000
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-utilities => ../skywire-utilities
// replace github.com/skycoin/skywire-utilities => github.com/skycoin/skywire-utilities
Loading

0 comments on commit bc0bba7

Please sign in to comment.