Skip to content

Commit

Permalink
use current tokens when reconnecting to NATS
Browse files Browse the repository at this point in the history
This required forking NATS. I'm trying to get the changes upstreamed in
nats-io/nats.go#1599
  • Loading branch information
btoews committed Apr 8, 2024
1 parent 47c499b commit 1fc2e38
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
7 changes: 5 additions & 2 deletions go.mod
Expand Up @@ -25,6 +25,7 @@ require (
github.com/docker/go-units v0.5.0
github.com/dustin/go-humanize v1.0.1
github.com/ejcx/sshcert v1.1.0
github.com/fsnotify/fsnotify v1.7.0
github.com/getsentry/sentry-go v0.27.0
github.com/go-logr/logr v1.4.1
github.com/gofrs/flock v0.8.1
Expand Down Expand Up @@ -154,7 +155,6 @@ require (
github.com/emirpasic/gods v1.18.1 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gdamore/encoding v1.0.0 // indirect
github.com/gdamore/tcell/v2 v2.7.0 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
Expand Down Expand Up @@ -245,4 +245,7 @@ require (
gvisor.dev/gvisor v0.0.0-20230927004350-cbd86285d259 // indirect
)

replace github.com/loadsmart/calver-go => github.com/ndarilek/calver-go v0.0.0-20230710153822-893bbd83a936
replace (
github.com/loadsmart/calver-go => github.com/ndarilek/calver-go v0.0.0-20230710153822-893bbd83a936
github.com/nats-io/nats.go => github.com/btoews/nats.go v0.0.0-20240401180931-476bea7f4158
)
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -147,6 +147,8 @@ github.com/bradleyjkemp/cupaloy/v2 v2.6.0 h1:knToPYa2xtfg42U3I6punFEjaGFKWQRXJwj
github.com/bradleyjkemp/cupaloy/v2 v2.6.0/go.mod h1:bm7JXdkRd4BHJk9HpwqAI8BoAY1lps46Enkdqw6aRX0=
github.com/briandowns/spinner v1.23.0 h1:alDF2guRWqa/FOZZYWjlMIx2L6H0wyewPxo/CH4Pt2A=
github.com/briandowns/spinner v1.23.0/go.mod h1:rPG4gmXeN3wQV/TsAY4w8lPdIM6RX3yqeBQJSrbXjuE=
github.com/btoews/nats.go v0.0.0-20240401180931-476bea7f4158 h1:dyIdqIvZvxRjekfXZL+ZD3FdJzQS5gq/I7IFSyQ/aNg=
github.com/btoews/nats.go v0.0.0-20240401180931-476bea7f4158/go.mod h1:Ubdu4Nh9exXdSz0RVWRFBbRfrbSxOYd26oF0wkWclB8=
github.com/buildpacks/imgutil v0.0.0-20240118145509-e94a1b7de8a9 h1:kxe31xfMWJAIAzDfGQ3lL0j8QSSRfEHyLg7dRWIHA8I=
github.com/buildpacks/imgutil v0.0.0-20240118145509-e94a1b7de8a9/go.mod h1:PsazEB9yz+NG/cgm0Z1oQ0Xq6rD/U7eNMt5Su41afYY=
github.com/buildpacks/lifecycle v0.18.5 h1:lfoUX8jYCUZ2/Tr2AopaRjinqDivkNkcTChzysQTo00=
Expand Down Expand Up @@ -469,8 +471,6 @@ github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7P
github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo=
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nats-io/nats.go v1.34.1 h1:syWey5xaNHZgicYBemv0nohUPPmaLteiBEUT6Q5+F/4=
github.com/nats-io/nats.go v1.34.1/go.mod h1:Ubdu4Nh9exXdSz0RVWRFBbRfrbSxOYd26oF0wkWclB8=
github.com/nats-io/nkeys v0.4.7 h1:RwNJbbIdYCoClSDNY7QVKZlyb/wfT6ugvFCiKy6vDvI=
github.com/nats-io/nkeys v0.4.7/go.mod h1:kqXRgRDPlGy7nGaEDMuYzmiJCIAAWDK0IMBtDmGD0nc=
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
Expand Down
7 changes: 6 additions & 1 deletion logs/nats.go
Expand Up @@ -75,7 +75,12 @@ func newNatsClient(ctx context.Context, dialer agent.Dialer, orgSlug string) (*n
natsIP := net.IP(natsIPBytes[:])

url := fmt.Sprintf("nats://[%s]:4223", natsIP.String())
conn, err := nats.Connect(url, nats.SetCustomDialer(&natsDialer{dialer, ctx}), nats.UserInfo(orgSlug, config.Tokens(ctx).NATS()))
toks := config.Tokens(ctx)
conn, err := nats.Connect(
url,
nats.SetCustomDialer(&natsDialer{dialer, ctx}),
nats.UserInfoHandler(func() (string, string) { return orgSlug, toks.NATS() }),
)
if err != nil {
return nil, fmt.Errorf("failed connecting to nats: %w", err)
}
Expand Down

0 comments on commit 1fc2e38

Please sign in to comment.