Skip to content

Commit 5ec9315

Browse files
authored
fix: mcp-server failed to start when connecting to external pulsar cluster without authentication (#48)
This change is based on PR #47
1 parent 9638b54 commit 5ec9315

File tree

1 file changed

+59
-16
lines changed

1 file changed

+59
-16
lines changed

pkg/pulsar/connection.go

Lines changed: 59 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,36 +78,79 @@ func init() {
7878
func (pc *PulsarContext) SetPulsarContext() error {
7979
var err error
8080
// Configure pulsarctl with the token
81-
if pc.Token != "" {
81+
switch {
82+
case pc.Token != "":
8283
cmdutils.PulsarCtlConfig = &cmdutils.ClusterConfig{
83-
WebServiceURL: pc.WebServiceURL,
84-
AuthPlugin: "org.apache.pulsar.client.impl.auth.AuthenticationToken",
85-
AuthParams: fmt.Sprintf("token:%s", pc.Token),
84+
WebServiceURL: pc.WebServiceURL,
85+
AuthPlugin: "org.apache.pulsar.client.impl.auth.AuthenticationToken",
86+
AuthParams: fmt.Sprintf("token:%s", pc.Token),
87+
TLSAllowInsecureConnection: pc.TLSAllowInsecureConnection,
88+
TLSEnableHostnameVerification: pc.TLSEnableHostnameVerification,
89+
TLSTrustCertsFilePath: pc.TLSTrustCertsFilePath,
90+
TLSCertFile: pc.TLSCertFile,
91+
TLSKeyFile: pc.TLSKeyFile,
8692
}
8793

8894
// Set the global client options
8995
CurrentPulsarClientOptions = pulsar.ClientOptions{
90-
URL: pc.ServiceURL,
91-
Authentication: pulsar.NewAuthenticationToken(pc.Token),
92-
OperationTimeout: DefaultClientTimeout,
93-
ConnectionTimeout: DefaultClientTimeout,
96+
URL: pc.ServiceURL,
97+
Authentication: pulsar.NewAuthenticationToken(pc.Token),
98+
OperationTimeout: DefaultClientTimeout,
99+
ConnectionTimeout: DefaultClientTimeout,
100+
TLSAllowInsecureConnection: pc.TLSAllowInsecureConnection,
101+
TLSValidateHostname: pc.TLSEnableHostnameVerification,
102+
TLSTrustCertsFilePath: pc.TLSTrustCertsFilePath,
103+
TLSCertificateFile: pc.TLSCertFile,
104+
TLSKeyFilePath: pc.TLSKeyFile,
94105
}
95-
} else if pc.AuthPlugin != "" && pc.AuthParams != "" {
106+
case pc.AuthPlugin != "" && pc.AuthParams != "":
96107
cmdutils.PulsarCtlConfig = &cmdutils.ClusterConfig{
97-
WebServiceURL: pc.WebServiceURL,
98-
AuthPlugin: pc.AuthPlugin,
99-
AuthParams: pc.AuthParams,
108+
WebServiceURL: pc.WebServiceURL,
109+
AuthPlugin: pc.AuthPlugin,
110+
AuthParams: pc.AuthParams,
111+
TLSAllowInsecureConnection: pc.TLSAllowInsecureConnection,
112+
TLSEnableHostnameVerification: pc.TLSEnableHostnameVerification,
113+
TLSTrustCertsFilePath: pc.TLSTrustCertsFilePath,
114+
TLSCertFile: pc.TLSCertFile,
115+
TLSKeyFile: pc.TLSKeyFile,
100116
}
101117

102118
authProvider, err := pulsar.NewAuthentication(pc.AuthPlugin, pc.AuthParams)
103119
if err != nil {
104120
return fmt.Errorf("failed to create authentication provider: %w", err)
105121
}
106122
CurrentPulsarClientOptions = pulsar.ClientOptions{
107-
URL: pc.ServiceURL,
108-
Authentication: authProvider,
109-
OperationTimeout: DefaultClientTimeout,
110-
ConnectionTimeout: DefaultClientTimeout,
123+
URL: pc.ServiceURL,
124+
Authentication: authProvider,
125+
OperationTimeout: DefaultClientTimeout,
126+
ConnectionTimeout: DefaultClientTimeout,
127+
TLSAllowInsecureConnection: pc.TLSAllowInsecureConnection,
128+
TLSValidateHostname: pc.TLSEnableHostnameVerification,
129+
TLSTrustCertsFilePath: pc.TLSTrustCertsFilePath,
130+
TLSCertificateFile: pc.TLSCertFile,
131+
TLSKeyFilePath: pc.TLSKeyFile,
132+
}
133+
default:
134+
// No authentication provided
135+
cmdutils.PulsarCtlConfig = &cmdutils.ClusterConfig{
136+
WebServiceURL: pc.WebServiceURL,
137+
TLSAllowInsecureConnection: pc.TLSAllowInsecureConnection,
138+
TLSEnableHostnameVerification: pc.TLSEnableHostnameVerification,
139+
TLSTrustCertsFilePath: pc.TLSTrustCertsFilePath,
140+
TLSCertFile: pc.TLSCertFile,
141+
TLSKeyFile: pc.TLSKeyFile,
142+
}
143+
144+
// Set the global client options without authentication
145+
CurrentPulsarClientOptions = pulsar.ClientOptions{
146+
URL: pc.ServiceURL,
147+
OperationTimeout: DefaultClientTimeout,
148+
ConnectionTimeout: DefaultClientTimeout,
149+
TLSAllowInsecureConnection: pc.TLSAllowInsecureConnection,
150+
TLSValidateHostname: pc.TLSEnableHostnameVerification,
151+
TLSTrustCertsFilePath: pc.TLSTrustCertsFilePath,
152+
TLSCertificateFile: pc.TLSCertFile,
153+
TLSKeyFilePath: pc.TLSKeyFile,
111154
}
112155
}
113156

0 commit comments

Comments
 (0)