Skip to content

Commit

Permalink
fix: streams secrets inference + support none value
Browse files Browse the repository at this point in the history
  • Loading branch information
palkan committed Mar 6, 2024
1 parent b64797f commit c5adbe7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 31 deletions.
8 changes: 4 additions & 4 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,13 +498,13 @@ func (r *Runner) defaultRouter() *router.RouterController {
router.Route(r.config.Streams.PubSubChannel, streamController) // nolint:errcheck
}

if r.config.Streams.Turbo && r.config.Streams.Secret != "" {
turboController := streams.NewTurboController(r.config.Streams.Secret, r.log)
if r.config.Streams.Turbo && r.config.Streams.GetTurboSecret() != "" {
turboController := streams.NewTurboController(r.config.Streams.GetTurboSecret(), r.log)
router.Route("Turbo::StreamsChannel", turboController) // nolint:errcheck
}

if r.config.Streams.CableReady && r.config.Streams.Secret != "" {
crController := streams.NewCableReadyController(r.config.Streams.Secret, r.log)
if r.config.Streams.CableReady && r.config.Streams.GetCableReadySecret() != "" {
crController := streams.NewCableReadyController(r.config.Streams.GetCableReadySecret(), r.log)
router.Route("CableReady::Stream", crController) // nolint:errcheck
}

Expand Down
49 changes: 24 additions & 25 deletions cli/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,9 @@ Use shutdown_timeout instead.`)
if turboRailsKey != "" {
fmt.Println(`DEPRECATION WARNING: turbo_rails_key option is deprecated
and will be removed in the next major release of anycable-go.
Use streams_secret instead.`)
Use turbo_streams_secret instead.`)

if c.Streams.Secret == "" {
c.Streams.TurboSecret = turboRailsKey
}
c.Streams.TurboSecret = turboRailsKey

c.Streams.Turbo = true
}
Expand All @@ -215,11 +213,9 @@ It has no effect anymore, use public streams instead.`)
if cableReadyKey != "" {
fmt.Println(`DEPRECATION WARNING: cable_ready_key option is deprecated
and will be removed in the next major release of anycable-go.
Use streams_secret instead.`)
Use cable_ready_secret instead.`)

if c.Streams.Secret == "" {
c.Streams.CableReadySecret = cableReadyKey
}
c.Streams.CableReadySecret = cableReadyKey

c.Streams.CableReady = true
}
Expand Down Expand Up @@ -263,24 +259,15 @@ It has no effect anymore, use public streams instead.`)
c.RPC.Implementation = "none"
}

// Configure secrets
if c.Streams.Secret == "" {
c.Streams.Secret = c.Secret
}

if c.JWT.Secret == "" {
c.JWT.Secret = c.Secret
}

if c.HTTPBroadcast.Secret == "" {
c.HTTPBroadcast.Secret = c.Secret
}
configureSecrets(
c.Secret,
&c.Streams.Secret,
&c.JWT.Secret,
&c.HTTPBroadcast.Secret,
&c.RPC.Secret,
)

if c.RPC.Secret == "" {
c.RPC.Secret = c.Secret
}

// Configure public mode
// Configure public mode and other insecure features
if isPublic {
c.SkipAuth = true
c.Streams.Public = true
Expand Down Expand Up @@ -1231,3 +1218,15 @@ func parseTags(str string) map[string]string {

return res
}

func configureSecrets(source string, targets ...*string) {
for _, t := range targets {
if (*t) == "" {
(*t) = source
}

if (*t) == "none" {
(*t) = ""
}
}
}
2 changes: 1 addition & 1 deletion features/sse.testfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
launch :anycable,
"./dist/anycable-go --sse --public_streams --secret=qwerty --broadcast_adapter=http --presets=broker"
"./dist/anycable-go --sse --public_streams --secret=qwerty --broadcast_adapter=http --presets=broker --http_broadcast_secret=none"

wait_tcp 8080

Expand Down
2 changes: 1 addition & 1 deletion streams/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (c Config) GetTurboSecret() string {
return c.Secret
}

func (c Config) GetCableReaDySecret() string {
func (c Config) GetCableReadySecret() string {
if c.CableReadySecret != "" {
return c.CableReadySecret
}
Expand Down

0 comments on commit c5adbe7

Please sign in to comment.