-
Notifications
You must be signed in to change notification settings - Fork 126
/
pulsarclient.go
43 lines (37 loc) · 1.5 KB
/
pulsarclient.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package pulsarutils
import (
"strings"
"github.com/apache/pulsar-client-go/pulsar"
"github.com/pkg/errors"
"github.com/armadaproject/armada/internal/armada/configuration"
"github.com/armadaproject/armada/internal/common/armadaerrors"
)
func NewPulsarClient(config *configuration.PulsarConfig) (pulsar.Client, error) {
var authentication pulsar.Authentication
// Sanity check that supplied Pulsar authentication parameters make sense
if config.AuthenticationEnabled {
if strings.ToLower(config.AuthenticationType) != "jwt" {
return nil, errors.WithStack(&armadaerrors.ErrInvalidArgument{
Name: "pulsar.AuthenticationType",
Value: config.AuthenticationType,
Message: "Only JWT Authentication for Pulsar is supported right now.",
})
}
if strings.TrimSpace(config.JwtTokenPath) == "" {
return nil, errors.WithStack(&armadaerrors.ErrInvalidArgument{
Name: "pulsar.JwtTokenPath",
Value: config.JwtTokenPath,
Message: "JWT authentication was configured for Pulsar but no JwtTokenPath was supplied",
})
}
authentication = pulsar.NewAuthenticationTokenFromFile(config.JwtTokenPath)
}
return pulsar.NewClient(pulsar.ClientOptions{
URL: config.URL,
TLSTrustCertsFilePath: config.TLSTrustCertsFilePath,
TLSValidateHostname: config.TLSValidateHostname,
TLSAllowInsecureConnection: config.TLSAllowInsecureConnection,
MaxConnectionsPerBroker: config.MaxConnectionsPerBroker,
Authentication: authentication,
})
}