Skip to content

Commit

Permalink
Merge pull request #17 from gateway-fm/fix/messed-consul-protocols
Browse files Browse the repository at this point in the history
wip: add checking for fake https
  • Loading branch information
andskur authored Feb 3, 2023
2 parents 7d192ea + 551ff2d commit d1d95fa
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 73 deletions.
7 changes: 6 additions & 1 deletion discovery/consul_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (

consul "github.com/hashicorp/consul/api"

"github.com/gateway-fm/scriptorium/logger"

"github.com/gateway-fm/service-pool/service"
)

Expand Down Expand Up @@ -62,5 +64,8 @@ func (d *ConsulDiscovery) createNodesFromServices(consulServices []*consul.Servi
// createServiceFromConsul create BaseService model
// instance from consul service
func (d *ConsulDiscovery) createServiceFromConsul(srv *consul.ServiceEntry) service.IService {
return service.NewService(fmt.Sprintf("%s:%d", d.transport.FormatAddress(srv.Service.Address), srv.Service.Port), srv.Node.Node)
addr := d.transport.FormatAddress(srv.Service.Address)
logger.Log().Debug(fmt.Sprintf("discovered new service: %s", addr))

return service.NewService(fmt.Sprintf("%s:%d", addr, srv.Service.Port), srv.Node.Node)
}
13 changes: 13 additions & 0 deletions discovery/transport_protocols.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,22 @@ func (s TransportProtocol) String() string {
return Transports[s] + "://"
}

const (
httpsPrefix = "https//"
wssPrefix = "wss//"
)

// FormatAddress add protocol prefix to
// given address
func (s TransportProtocol) FormatAddress(addr string) string {
if strings.Contains(addr, httpsPrefix) {
return TransportHttps.String() + strings.TrimPrefix(addr, httpsPrefix)
}

if strings.Contains(addr, wssPrefix) {
return TransportWss.String() + strings.TrimPrefix(addr, wssPrefix)
}

if s == TransportGrpc ||
strings.Contains(addr, TransportHttps.String()) ||
strings.Contains(addr, TransportWss.String()) {
Expand Down
33 changes: 17 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,41 @@ go 1.19

require (
github.com/gateway-fm/scriptorium v0.0.14
github.com/hashicorp/consul/api v1.12.0
github.com/hashicorp/consul/api v1.15.3
)

require (
github.com/armon/go-metrics v0.3.10 // indirect
github.com/armon/go-metrics v0.4.0 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/gofrs/uuid v4.2.0+incompatible // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gofrs/uuid v4.3.1+incompatible // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-hclog v1.2.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/serf v0.9.7 // indirect
github.com/hashicorp/serf v0.9.8 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/spf13/afero v1.8.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.12.0 // indirect
github.com/subosito/gotenv v1.3.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.7.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/ini.v1 v1.66.4 // indirect
github.com/spf13/viper v1.14.0 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/net v0.4.0 // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/text v0.5.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit d1d95fa

Please sign in to comment.