jetstream pubsub now supports token based auth (#2295)
Signed-off-by: Armin Schlegel <armin.schlegel@gmx.de> Signed-off-by: Armin Schlegel <armin.schlegel@gmx.de>
This commit is contained in:
parent
bd534a35db
commit
103624468f
|
@ -57,6 +57,9 @@ func (js *jetstreamPubSub) Init(metadata pubsub.Metadata) error {
|
||||||
} else if js.meta.tlsClientCert != "" && js.meta.tlsClientKey != "" {
|
} else if js.meta.tlsClientCert != "" && js.meta.tlsClientKey != "" {
|
||||||
js.l.Debug("Configure nats for tls client authentication")
|
js.l.Debug("Configure nats for tls client authentication")
|
||||||
opts = append(opts, nats.ClientCert(js.meta.tlsClientCert, js.meta.tlsClientKey))
|
opts = append(opts, nats.ClientCert(js.meta.tlsClientCert, js.meta.tlsClientKey))
|
||||||
|
} else if js.meta.token != "" {
|
||||||
|
js.l.Debug("Configure nats for token authentication")
|
||||||
|
opts = append(opts, nats.Token(js.meta.token))
|
||||||
}
|
}
|
||||||
|
|
||||||
js.nc, err = nats.Connect(js.meta.natsURL, opts...)
|
js.nc, err = nats.Connect(js.meta.natsURL, opts...)
|
||||||
|
|
|
@ -27,6 +27,7 @@ type metadata struct {
|
||||||
|
|
||||||
jwt string
|
jwt string
|
||||||
seedKey string
|
seedKey string
|
||||||
|
token string
|
||||||
|
|
||||||
tlsClientCert string
|
tlsClientCert string
|
||||||
tlsClientKey string
|
tlsClientKey string
|
||||||
|
@ -58,6 +59,7 @@ func parseMetadata(psm pubsub.Metadata) (metadata, error) {
|
||||||
return metadata{}, fmt.Errorf("missing nats URL")
|
return metadata{}, fmt.Errorf("missing nats URL")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.token = psm.Properties["token"]
|
||||||
m.jwt = psm.Properties["jwt"]
|
m.jwt = psm.Properties["jwt"]
|
||||||
m.seedKey = psm.Properties["seedKey"]
|
m.seedKey = psm.Properties["seedKey"]
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,50 @@ func TestParseMetadata(t *testing.T) {
|
||||||
},
|
},
|
||||||
expectErr: false,
|
expectErr: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
desc: "Valid Metadata with token",
|
||||||
|
input: pubsub.Metadata{Base: mdata.Base{
|
||||||
|
Properties: map[string]string{
|
||||||
|
"natsURL": "nats://localhost:4222",
|
||||||
|
"name": "myName",
|
||||||
|
"durableName": "myDurable",
|
||||||
|
"queueGroupName": "myQueue",
|
||||||
|
"startSequence": "1",
|
||||||
|
"startTime": "1629328511",
|
||||||
|
"deliverAll": "true",
|
||||||
|
"flowControl": "true",
|
||||||
|
"ackWait": "2s",
|
||||||
|
"maxDeliver": "10",
|
||||||
|
"backOff": "500ms, 2s, 10s",
|
||||||
|
"maxAckPending": "5000",
|
||||||
|
"replicas": "3",
|
||||||
|
"memoryStorage": "true",
|
||||||
|
"rateLimit": "20000",
|
||||||
|
"hearbeat": "1s",
|
||||||
|
"token": "myToken",
|
||||||
|
},
|
||||||
|
}},
|
||||||
|
want: metadata{
|
||||||
|
natsURL: "nats://localhost:4222",
|
||||||
|
name: "myName",
|
||||||
|
durableName: "myDurable",
|
||||||
|
queueGroupName: "myQueue",
|
||||||
|
startSequence: 1,
|
||||||
|
startTime: time.Unix(1629328511, 0),
|
||||||
|
deliverAll: true,
|
||||||
|
flowControl: true,
|
||||||
|
ackWait: 2 * time.Second,
|
||||||
|
maxDeliver: 10,
|
||||||
|
backOff: []time.Duration{time.Millisecond * 500, time.Second * 2, time.Second * 10},
|
||||||
|
maxAckPending: 5000,
|
||||||
|
replicas: 3,
|
||||||
|
memoryStorage: true,
|
||||||
|
rateLimit: 20000,
|
||||||
|
hearbeat: time.Second * 1,
|
||||||
|
token: "myToken",
|
||||||
|
},
|
||||||
|
expectErr: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
desc: "Invalid metadata with missing seed key",
|
desc: "Invalid metadata with missing seed key",
|
||||||
input: pubsub.Metadata{Base: mdata.Base{
|
input: pubsub.Metadata{Base: mdata.Base{
|
||||||
|
|
Loading…
Reference in New Issue