@@ -58,6 +58,7 @@ type Config struct {
5858 BoostrapNodeIsLocal bool
5959 Username string
6060 Password string
61+ SingleUserAuth bool
6162
6263 BindAddress string
6364 BindDataPort int
@@ -273,20 +274,31 @@ func (g *Gateway) Run(ctx context.Context) error {
273274 }
274275
275276 // initialize cb-auth
276- authenticator , err := auth .NewCbAuthAuthenticator (ctx , auth.NewCbAuthAuthenticatorOptions {
277- NodeId : nodeID ,
278- Addresses : []string {authHostPort },
279- Username : config .Username ,
280- Password : config .Password ,
281- ClusterUUID : clusterUUID ,
282- Logger : config .Logger .Named ("cbauth" ),
283- })
284- if err != nil {
285- config .Logger .Error ("failed to initialize cbauth connection" ,
286- zap .Error (err ),
287- zap .String ("hostPort" , authHostPort ),
288- zap .String ("user" , config .Username ))
289- return err
277+ var cbAuthAuthenticator * auth.CbAuthAuthenticator
278+ var authenticator auth.Authenticator
279+ if ! config .SingleUserAuth {
280+ cbAuthAuthenticator , err = auth .NewCbAuthAuthenticator (ctx , auth.NewCbAuthAuthenticatorOptions {
281+ NodeId : nodeID ,
282+ Addresses : []string {authHostPort },
283+ Username : config .Username ,
284+ Password : config .Password ,
285+ ClusterUUID : clusterUUID ,
286+ Logger : config .Logger .Named ("cbauth" ),
287+ })
288+ if err != nil {
289+ config .Logger .Error ("failed to initialize cbauth connection" ,
290+ zap .Error (err ),
291+ zap .String ("hostPort" , authHostPort ),
292+ zap .String ("user" , config .Username ))
293+ return err
294+ }
295+
296+ authenticator = cbAuthAuthenticator
297+ } else {
298+ authenticator = & auth.SingleUserAuthenticator {
299+ Username : config .Username ,
300+ Password : config .Password ,
301+ }
290302 }
291303
292304 // try to establish a client connection to the cluster
@@ -319,45 +331,47 @@ func (g *Gateway) Run(ctx context.Context) error {
319331 proxyServices = append (proxyServices , proxy .ServiceType (serviceName ))
320332 }
321333
322- go func () {
323- watchCh := agentMgr .WatchConfig (context .Background ())
324- runLoop:
325- for {
326- select {
327- case <- g .shutdownSig :
328- break runLoop
329- case cfg := <- watchCh :
330- if cfg == nil {
331- continue
332- }
334+ if cbAuthAuthenticator != nil {
335+ go func () {
336+ watchCh := agentMgr .WatchConfig (context .Background ())
337+ runLoop:
338+ for {
339+ select {
340+ case <- g .shutdownSig :
341+ break runLoop
342+ case cfg := <- watchCh :
343+ if cfg == nil {
344+ continue
345+ }
333346
334- mgmtEndpointsList := make ([]string , 0 , len (cfg .Nodes ))
335- for _ , node := range cfg .Nodes {
336- if node .Addresses .NonSSLPorts .Mgmt > 0 {
337- mgmtEndpointsList = append (mgmtEndpointsList ,
338- fmt .Sprintf ("%s:%d" , node .Addresses .Hostname , node .Addresses .NonSSLPorts .Mgmt ))
347+ mgmtEndpointsList := make ([]string , 0 , len (cfg .Nodes ))
348+ for _ , node := range cfg .Nodes {
349+ if node .Addresses .NonSSLPorts .Mgmt > 0 {
350+ mgmtEndpointsList = append (mgmtEndpointsList ,
351+ fmt .Sprintf ("%s:%d" , node .Addresses .Hostname , node .Addresses .NonSSLPorts .Mgmt ))
352+ }
339353 }
340- }
341354
342- err := authenticator .Reconfigure (auth.CbAuthAuthenticatorReconfigureOptions {
343- Addresses : mgmtEndpointsList ,
344- Username : config .Username ,
345- Password : config .Password ,
346- ClusterUUID : clusterUUID ,
347- })
348- if err != nil {
349- config .Logger .Warn ("failed to reconfigure cbauth" ,
350- zap .Error (err ))
355+ err := cbAuthAuthenticator .Reconfigure (auth.CbAuthAuthenticatorReconfigureOptions {
356+ Addresses : mgmtEndpointsList ,
357+ Username : config .Username ,
358+ Password : config .Password ,
359+ ClusterUUID : clusterUUID ,
360+ })
361+ if err != nil {
362+ config .Logger .Warn ("failed to reconfigure cbauth" ,
363+ zap .Error (err ))
364+ }
351365 }
352366 }
353- }
354367
355- err := authenticator .Close ()
356- if err != nil {
357- config .Logger .Warn ("failed to shutdown cbauth" ,
358- zap .Error (err ))
359- }
360- }()
368+ err := cbAuthAuthenticator .Close ()
369+ if err != nil {
370+ config .Logger .Warn ("failed to shutdown cbauth" ,
371+ zap .Error (err ))
372+ }
373+ }()
374+ }
361375
362376 startInstance := func (ctx context.Context , instanceIdx int ) error {
363377 rateLimiter := ratelimiting .NewGlobalRateLimiter (uint64 (config .RateLimit ), time .Second )
0 commit comments