Skip to content

Commit 8b560fb

Browse files
authored
Merge pull request #742 from hooksie1/seed
Add ability to pass seed to context
2 parents 6148837 + b3e3cbf commit 8b560fb

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

natscontext/context.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ type settings struct {
6868
JSEventPrefix string `json:"jetstream_event_prefix"`
6969
InboxPrefix string `json:"inbox_prefix"`
7070
UserJwt string `json:"user_jwt"`
71+
UserSeed string `json:"user_seed"`
7172
ColorScheme string `json:"color_scheme"`
7273
TLSFirst bool `json:"tls_first"`
7374
WinCertStoreType string `json:"windows_cert_store"`
@@ -379,7 +380,10 @@ func (c *Context) NATSOptions(opts ...nats.Option) ([]nats.Option, error) {
379380

380381
nopts = append(nopts, nko)
381382

382-
case c.UserJWT() != "":
383+
case c.UserJWT() != "" && c.UserSeed() != "":
384+
nopts = append(nopts, nats.UserJWTAndSeed(c.UserJWT(), c.UserSeed()))
385+
386+
case c.UserJWT() != "" && c.UserSeed() == "":
383387
userCB := func() (string, error) {
384388
return c.UserJWT(), nil
385389
}
@@ -963,11 +967,25 @@ func WithUserJWT(p string) Option {
963967
}
964968
}
965969

970+
// WithUserSeed sets the user seed
971+
func WithUserSeed(p string) Option {
972+
return func(s *settings) {
973+
if p != "" {
974+
s.UserSeed = p
975+
}
976+
}
977+
}
978+
966979
// UserJWT retrieves the configured user jwt, empty if not set
967980
func (c *Context) UserJWT() string {
968981
return c.config.UserJwt
969982
}
970983

984+
// UserSeed retrieves the configured user seed, empty if not set
985+
func (c *Context) UserSeed() string {
986+
return c.config.UserSeed
987+
}
988+
971989
// WithSocksProxy sets the SOCKS5 Proxy.
972990
// To explicitly remove an already configured proxy, use the string "none".
973991
func WithSocksProxy(p string) Option {

natscontext/testdata/nats/context/user_pass_token_creds.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"jetstream_event_prefix": "",
1717
"inbox_prefix": "",
1818
"user_jwt": "",
19+
"user_seed": "",
1920
"color_scheme": "",
2021
"tls_first": false,
2122
"windows_cert_store": "",

0 commit comments

Comments
 (0)