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

Remove hardcoded services #31

Merged
merged 7 commits into from
Sep 23, 2024
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -7,13 +7,13 @@ jobs:
- name: Setup golang
uses: actions/setup-go@v4
with:
go-version: 1.22.x
go-version: 1.23.x
- name: Check out code
uses: actions/checkout@v4
- name: Install Requirements
run: |
sudo apt update
make install-tools
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.55.2
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.60.3
- name: Test
run: make check
13 changes: 7 additions & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ run:
# output configuration options
output:
# colored-line-number|line-number|json|tab|checkstyle, default is "colored-line-number"
format: colored-line-number
formats: colored-line-number

# print lines of code with issue, default is true
print-issued-lines: true
@@ -66,8 +66,7 @@ linters-settings:
check-blank: true
govet:
# report about shadowed variables
check-shadowing: true

shadow: true
# Obtain type information from installed (to $GOPATH/pkg) package files:
# golangci-lint will execute `go install -i` and `go test -i` for analyzed packages
# before analyzing them.
@@ -81,6 +80,9 @@ linters-settings:
# 2. you use go >= 1.10
# 3. you do repeated runs (false for CI) or cache $GOPATH/pkg or `go env GOCACHE` dir in CI.
use-installed-packages: false
golint:
# minimal confidence for issues, default is 0.8
min-confidence: 0.8
gofmt:
# simplify code: gofmt with `-s` option, true by default
simplify: true
@@ -142,6 +144,8 @@ linters-settings:
simple: true
range-loops: true # Report preallocation suggestions on range loops, true by default
for-loops: false # Report preallocation suggestions on for loops, false by default
goimports:
local-prefixes: github.com/skycoin/skycoin-service-discovery


linters:
@@ -152,15 +156,12 @@ linters:
- errcheck
- gosimple
- staticcheck
- unused
- ineffassign
- typecheck
- gosec
- megacheck
- misspell
- nakedret
enable-all: false
disable:
disable-all: true
presets:
fast: false
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Skycoin Service Discovery

The Skycoin service discovery allows registering services to be discovered by other participants in the Skywire network. Currently it allows registration
and discovery of
The Skycoin service discovery allows registering services to be discovered by other participants in the Skywire network. Currently it allows registration
and discovery of

- VPNs
- Socks proxies
@@ -53,7 +53,7 @@ PG_USER=postgres PG_PASSWORD=postgres PG_DATABASE=postgres go run ./cmd/service-

The proxy service registration and de-registration endpoints require us to use specialised html header fields for authentication/authorization. When testing, this can be a pain. To disable auth completely, run `proxy-server` with the `--test` flag:

```bash
```bash
go run ./cmd/service-discovery/service-discovery.go --test
```

@@ -72,7 +72,7 @@ $ docker build -f Dockerfile -t skycoin/service-discovery:test .
To push the docker image run:

```bash
$ docker push skycoin/service-discovery:test
$ docker push skycoin/service-discovery:test
```

### Help
@@ -179,3 +179,14 @@ Response body:
The server will return the saved proxy service entry.

If the request has no `"geo"` field, the server may fill the field using the requester's IP address.


## Dependency Graph

made with [goda](https://github.com/loov/goda)

```
goda graph github.com/skycoin/skycoin-service-discovery/... | dot -Tsvg -o skycoin-service-discovery-goda-graph.svg
```

![Dependency Graph](skycoin-service-discovery-goda-graph.svg "github.com/skycoin/skycoin-service-discovery Dependency Graph")
61 changes: 26 additions & 35 deletions cmd/service-discovery/commands/root.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package commands cmd/service-discovery/root.go
// Package commands cmd/service-discovery/commands/root.go
package commands

import (
@@ -18,7 +18,6 @@ import (
"github.com/skycoin/skywire-utilities/pkg/httpauth"
"github.com/skycoin/skywire-utilities/pkg/logging"
"github.com/skycoin/skywire-utilities/pkg/metricsutil"
"github.com/skycoin/skywire-utilities/pkg/skyenv"
"github.com/skycoin/skywire-utilities/pkg/storeconfig"
"github.com/skycoin/skywire-utilities/pkg/tcpproxy"
"github.com/spf13/cobra"
@@ -35,35 +34,33 @@ var log = logging.MustGetLogger("service-discovery")
const redisPrefix = "service-discovery"

var (
addr string
metricsAddr string
redisURL string
pgHost string
pgPort string
testMode bool
apiKey string
dmsgDisc string
whitelistKeys string
testEnvironment bool
sk cipher.SecKey
dmsgPort uint16
dmsgServerType string
addr string
metricsAddr string
redisURL string
pgHost string
pgPort string
testMode bool
apiKey string
dmsgDisc string
whitelistKeys string
sk cipher.SecKey
dmsgPort uint16
dmsgServerType string
)

func init() {
RootCmd.Flags().StringVarP(&addr, "addr", "a", ":9098", "address to bind to")
RootCmd.Flags().StringVarP(&metricsAddr, "metrics", "m", "", "address to bind metrics API to")
RootCmd.Flags().StringVarP(&redisURL, "redis", "r", "redis://localhost:6379", "connections string for a redis store")
RootCmd.Flags().StringVarP(&pgHost, "pg-host", "o", "localhost", "host of postgres")
RootCmd.Flags().StringVarP(&pgPort, "pg-port", "p", "5432", "port of postgres")
RootCmd.Flags().StringVarP(&whitelistKeys, "whitelist-keys", "w", "", "list of whitelisted keys of network monitor used for deregistration")
RootCmd.Flags().BoolVarP(&testMode, "test", "t", false, "run in test mode and disable auth")
RootCmd.Flags().StringVarP(&apiKey, "api-key", "g", "", "geo API key")
RootCmd.Flags().StringVarP(&dmsgDisc, "dmsg-disc", "d", skyenv.DmsgDiscAddr, "url of dmsg-discovery")
RootCmd.Flags().StringVar(&dmsgServerType, "dmsg-server-type", "", "type of dmsg server on dmsghttp handler")
RootCmd.Flags().BoolVarP(&testEnvironment, "test-environment", "n", false, "distinguished between prod and test environment")
RootCmd.Flags().VarP(&sk, "sk", "s", "dmsg secret key\n")
RootCmd.Flags().Uint16Var(&dmsgPort, "dmsgPort", dmsg.DefaultDmsgHTTPPort, "dmsg port value")
RootCmd.Flags().StringVarP(&addr, "addr", "a", ":9098", "address to bind to\033[0m")
RootCmd.Flags().StringVarP(&metricsAddr, "metrics", "m", "", "address to bind metrics API to\033[0m")
RootCmd.Flags().StringVarP(&redisURL, "redis", "r", "redis://localhost:6379", "connections string for a redis store\033[0m")
RootCmd.Flags().StringVarP(&pgHost, "pg-host", "o", "localhost", "host of postgres\033[0m")
RootCmd.Flags().StringVarP(&pgPort, "pg-port", "p", "5432", "port of postgres\033[0m")
RootCmd.Flags().StringVarP(&whitelistKeys, "whitelist-keys", "w", "", "list of whitelisted keys of network monitor used for deregistration\033[0m")
RootCmd.Flags().BoolVarP(&testMode, "test", "t", false, "run in test mode and disable auth\033[0m")
RootCmd.Flags().StringVarP(&apiKey, "api-key", "g", "", "geo API key\033[0m")
RootCmd.Flags().StringVarP(&dmsgDisc, "dmsg-disc", "d", dmsg.DiscAddr(false), "url of dmsg-discovery\033[0m")
RootCmd.Flags().StringVar(&dmsgServerType, "dmsg-server-type", "", "type of dmsg server on dmsghttp handler\033[0m")
RootCmd.Flags().VarP(&sk, "sk", "s", "dmsg secret key\033[0m\n\r")
RootCmd.Flags().Uint16Var(&dmsgPort, "dmsgPort", dmsg.DefaultDmsgHTTPPort, "dmsg port value\033[0m")
}

// RootCmd contains the root service-discovery command
@@ -82,7 +79,7 @@ keys-gen | tee sd-config.json
PG_USER="postgres" PG_DATABASE="sd" PG_PASSWORD="" service-discovery --sk $(tail -n1 sd-config.json)`,
Run: func(_ *cobra.Command, _ []string) {
if dmsgDisc == "" {
dmsgDisc = skyenv.DmsgDiscAddr
dmsgDisc = dmsg.DiscAddr(false)
}
if _, err := buildinfo.Get().WriteTo(os.Stdout); err != nil {
log.Printf("Failed to output build info: %v", err)
@@ -151,12 +148,6 @@ PG_USER="postgres" PG_DATABASE="sd" PG_PASSWORD="" service-discovery --sk $(tail
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 {
api.WhitelistPKs.Set(v)
8 changes: 5 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -11,9 +11,9 @@ require (
github.com/ivanpirog/coloredcobra v1.0.1
github.com/lib/pq v1.10.9
github.com/sirupsen/logrus v1.9.3
github.com/skycoin/dmsg v1.3.26-0.20240910062314-dc25f3d9ea6c
github.com/skycoin/dmsg v1.3.26-0.20240922174815-ced25b343ec5
github.com/skycoin/skycoin v0.27.1
github.com/skycoin/skywire v1.3.25-beta
github.com/skycoin/skywire v1.3.26-0.20240922162315-789cef41c9a1
github.com/skycoin/skywire-utilities v1.3.25
github.com/spf13/cobra v1.7.0
github.com/stretchr/testify v1.9.0
@@ -83,7 +83,9 @@ require (
)

// Uncomment it for tests with alternative branches and run `make dep`
// replace github.com/skycoin/dmsg => ../dmsg
//replace github.com/skycoin/dmsg => ../dmsg
//replace github.com/skycoin/skywire => ../skywire

//replace github.com/skycoin/dmsg => github.com/skycoin/dmsg

// replace github.com/skycoin/skywire => ../skywire
10 changes: 4 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -215,16 +215,14 @@ github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMB
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/skycoin/dmsg v1.3.25 h1:Gs4aRhLq/ZCo5I0vN3nTv/N5/MC6sunWCuS50Tct6qI=
github.com/skycoin/dmsg v1.3.25/go.mod h1:3pyc9MmDJQYP0spTAWKLMctz4+ZKjMZgXtdMmXpYolw=
github.com/skycoin/dmsg v1.3.26-0.20240910062314-dc25f3d9ea6c h1:7miiImujaW74EAD/cqs6tAXzoVRK7K9yk69R8oqKC/g=
github.com/skycoin/dmsg v1.3.26-0.20240910062314-dc25f3d9ea6c/go.mod h1:3pyc9MmDJQYP0spTAWKLMctz4+ZKjMZgXtdMmXpYolw=
github.com/skycoin/dmsg v1.3.26-0.20240922174815-ced25b343ec5 h1:992WLADQdKjZbpJYdw0EYuOaI7mKHQQ57jDFebvUYPs=
github.com/skycoin/dmsg v1.3.26-0.20240922174815-ced25b343ec5/go.mod h1:qfF8cAig3JHLAojmfYEWn8ttV4aHsiitkZeD1TH8Wrg=
github.com/skycoin/noise v0.0.0-20180327030543-2492fe189ae6 h1:1Nc5EBY6pjfw1kwW0duwyG+7WliWz5u9kgk1h5MnLuA=
github.com/skycoin/noise v0.0.0-20180327030543-2492fe189ae6/go.mod h1:UXghlricA7J3aRD/k7p/zBObQfmBawwCxIVPVjz2Q3o=
github.com/skycoin/skycoin v0.27.1 h1:HatxsRwVSPaV4qxH6290xPBmkH/HgiuAoY2qC+e8C9I=
github.com/skycoin/skycoin v0.27.1/go.mod h1:78nHjQzd8KG0jJJVL/j0xMmrihXi70ti63fh8vXScJw=
github.com/skycoin/skywire v1.3.25-beta h1:F3oDF36CaK3YAFogl2/jNkAqJWHaJP4HVBVFRpP72BU=
github.com/skycoin/skywire v1.3.25-beta/go.mod h1:TAUZX3dAcvsJhblLMuwZ1MjmIJL85He73MZdKT95Qv4=
github.com/skycoin/skywire v1.3.26-0.20240922162315-789cef41c9a1 h1:3OFs/rnlDZYmhRGOEZq0wZk1LC45/UZTRpFXVDJ2lSA=
github.com/skycoin/skywire v1.3.26-0.20240922162315-789cef41c9a1/go.mod h1:jsyaaHXEIEDcbTcceUTIi23BZAYXqBDhk/tjRnfCUs4=
github.com/skycoin/skywire-utilities v1.3.25 h1:mk8dUonFdhVopFF3d9wbOyXXoiuAO+mN1y+ve6SzgX4=
github.com/skycoin/skywire-utilities v1.3.25/go.mod h1:yFKWpL1bDRPKU3uK+cTF4PnYUMe+eyIj5N2bk4sF5Cw=
github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g=
Loading
Loading